| @@ -597,75 +597,6 @@ impl WindowManager { |
| 597 |
Ok(()) |
597 |
Ok(()) |
| 598 |
} |
598 |
} |
| 599 |
|
599 |
|
| 600 |
- fn exchange_client(&mut self, direction: i32) -> WmResult<()> { |
|
|
| 601 |
- let focused = match self |
|
|
| 602 |
- .monitors |
|
|
| 603 |
- .get(self.selected_monitor) |
|
|
| 604 |
- .and_then(|m| m.selected_client) |
|
|
| 605 |
- { |
|
|
| 606 |
- Some(win) => win, |
|
|
| 607 |
- None => return Ok(()), |
|
|
| 608 |
- }; |
|
|
| 609 |
- |
|
|
| 610 |
- if self.floating_windows.contains(&focused) { |
|
|
| 611 |
- return Ok(()); |
|
|
| 612 |
- } |
|
|
| 613 |
- |
|
|
| 614 |
- let visible = self.visible_windows(); |
|
|
| 615 |
- if visible.len() < 2 { |
|
|
| 616 |
- return Ok(()); |
|
|
| 617 |
- } |
|
|
| 618 |
- |
|
|
| 619 |
- let current_idx = match visible.iter().position(|&w| w == focused) { |
|
|
| 620 |
- Some(idx) => idx, |
|
|
| 621 |
- None => return Ok(()), |
|
|
| 622 |
- }; |
|
|
| 623 |
- |
|
|
| 624 |
- let target_idx = match direction { |
|
|
| 625 |
- 0 | 2 => { |
|
|
| 626 |
- // UP or LEFT - previous in stack |
|
|
| 627 |
- if current_idx == 0 { |
|
|
| 628 |
- visible.len() - 1 |
|
|
| 629 |
- } else { |
|
|
| 630 |
- current_idx - 1 |
|
|
| 631 |
- } |
|
|
| 632 |
- } |
|
|
| 633 |
- 1 | 3 => { |
|
|
| 634 |
- // DOWN or RIGHT - next in stack |
|
|
| 635 |
- (current_idx + 1) % visible.len() |
|
|
| 636 |
- } |
|
|
| 637 |
- _ => return Ok(()), |
|
|
| 638 |
- }; |
|
|
| 639 |
- |
|
|
| 640 |
- let target = visible[target_idx]; |
|
|
| 641 |
- |
|
|
| 642 |
- let focused_pos = self.windows.iter().position(|&w| w == focused); |
|
|
| 643 |
- let target_pos = self.windows.iter().position(|&w| w == target); |
|
|
| 644 |
- |
|
|
| 645 |
- if let (Some(f_pos), Some(t_pos)) = (focused_pos, target_pos) { |
|
|
| 646 |
- self.windows.swap(f_pos, t_pos); |
|
|
| 647 |
- |
|
|
| 648 |
- self.apply_layout()?; |
|
|
| 649 |
- |
|
|
| 650 |
- self.focus(Some(focused))?; |
|
|
| 651 |
- |
|
|
| 652 |
- if let Ok(geometry) = self.connection.get_geometry(focused)?.reply() { |
|
|
| 653 |
- self.connection.warp_pointer( |
|
|
| 654 |
- x11rb::NONE, |
|
|
| 655 |
- focused, |
|
|
| 656 |
- 0, |
|
|
| 657 |
- 0, |
|
|
| 658 |
- 0, |
|
|
| 659 |
- 0, |
|
|
| 660 |
- geometry.width as i16 / 2, |
|
|
| 661 |
- geometry.height as i16 / 2, |
|
|
| 662 |
- )?; |
|
|
| 663 |
- } |
|
|
| 664 |
- } |
|
|
| 665 |
- |
|
|
| 666 |
- Ok(()) |
|
|
| 667 |
- } |
|
|
| 668 |
- |
|
|
| 669 |
|
600 |
|
| 670 |
fn get_layout_symbol(&self) -> String { |
601 |
fn get_layout_symbol(&self) -> String { |
| 671 |
let layout_name = self.layout.name(); |
602 |
let layout_name = self.layout.name(); |
| @@ -846,27 +777,11 @@ impl WindowManager { |
| 846 |
self.restack()?; |
777 |
self.restack()?; |
| 847 |
} |
778 |
} |
| 848 |
|
779 |
|
| 849 |
- KeyAction::ExchangeClient => { |
|
|
| 850 |
- if let Arg::Int(direction) = arg { |
|
|
| 851 |
- self.exchange_client(*direction)?; |
|
|
| 852 |
- } |
|
|
| 853 |
- } |
|
|
| 854 |
- |
|
|
| 855 |
KeyAction::FocusStack => { |
780 |
KeyAction::FocusStack => { |
| 856 |
if let Arg::Int(direction) = arg { |
781 |
if let Arg::Int(direction) = arg { |
| 857 |
self.focusstack(*direction)?; |
782 |
self.focusstack(*direction)?; |
| 858 |
} |
783 |
} |
| 859 |
} |
784 |
} |
| 860 |
- KeyAction::FocusDirection => { |
|
|
| 861 |
- if let Arg::Int(direction) = arg { |
|
|
| 862 |
- self.focus_direction(*direction)?; |
|
|
| 863 |
- } |
|
|
| 864 |
- } |
|
|
| 865 |
- KeyAction::SwapDirection => { |
|
|
| 866 |
- if let Arg::Int(direction) = arg { |
|
|
| 867 |
- self.swap_direction(*direction)?; |
|
|
| 868 |
- } |
|
|
| 869 |
- } |
|
|
| 870 |
KeyAction::Quit | KeyAction::Restart => { |
785 |
KeyAction::Quit | KeyAction::Restart => { |
| 871 |
// Handled in handle_event |
786 |
// Handled in handle_event |
| 872 |
} |
787 |
} |
| @@ -1296,104 +1211,6 @@ impl WindowManager { |
| 1296 |
Ok(()) |
1211 |
Ok(()) |
| 1297 |
} |
1212 |
} |
| 1298 |
|
1213 |
|
| 1299 |
- fn find_directional_window_candidate(&mut self, focused_window: Window, direction: i32) -> Option<Window> { |
|
|
| 1300 |
- let visible_windows = self.visible_windows(); |
|
|
| 1301 |
- if visible_windows.len() < 2 { |
|
|
| 1302 |
- return None; |
|
|
| 1303 |
- } |
|
|
| 1304 |
- |
|
|
| 1305 |
- let focused_geometry = self.get_or_query_geometry(focused_window).ok()?; |
|
|
| 1306 |
- let focused_center_x = focused_geometry.x_position + (focused_geometry.width as i16 / 2); |
|
|
| 1307 |
- let focused_center_y = focused_geometry.y_position + (focused_geometry.height as i16 / 2); |
|
|
| 1308 |
- |
|
|
| 1309 |
- let mut candidates = Vec::new(); |
|
|
| 1310 |
- |
|
|
| 1311 |
- for &window in &visible_windows { |
|
|
| 1312 |
- if window == focused_window { |
|
|
| 1313 |
- continue; |
|
|
| 1314 |
- } |
|
|
| 1315 |
- |
|
|
| 1316 |
- let geometry = match self.get_or_query_geometry(window) { |
|
|
| 1317 |
- Ok(geometry) => geometry, |
|
|
| 1318 |
- Err(_) => continue, |
|
|
| 1319 |
- }; |
|
|
| 1320 |
- |
|
|
| 1321 |
- let center_x = geometry.x_position + (geometry.width as i16 / 2); |
|
|
| 1322 |
- let center_y = geometry.y_position + (geometry.height as i16 / 2); |
|
|
| 1323 |
- |
|
|
| 1324 |
- let is_valid_direction = match direction { |
|
|
| 1325 |
- 0 => center_y < focused_center_y, |
|
|
| 1326 |
- 1 => center_y > focused_center_y, |
|
|
| 1327 |
- 2 => center_x < focused_center_x, |
|
|
| 1328 |
- 3 => center_x > focused_center_x, |
|
|
| 1329 |
- _ => false, |
|
|
| 1330 |
- }; |
|
|
| 1331 |
- |
|
|
| 1332 |
- if is_valid_direction { |
|
|
| 1333 |
- let delta_x = (center_x - focused_center_x) as i32; |
|
|
| 1334 |
- let delta_y = (center_y - focused_center_y) as i32; |
|
|
| 1335 |
- let distance_squared = delta_x * delta_x + delta_y * delta_y; |
|
|
| 1336 |
- candidates.push((window, distance_squared)); |
|
|
| 1337 |
- } |
|
|
| 1338 |
- } |
|
|
| 1339 |
- |
|
|
| 1340 |
- candidates.iter().min_by_key(|&(_window, distance)| distance).map(|&(window, _distance)| window) |
|
|
| 1341 |
- } |
|
|
| 1342 |
- |
|
|
| 1343 |
- pub fn focus_direction(&mut self, direction: i32) -> WmResult<()> { |
|
|
| 1344 |
- let focused_window = match self |
|
|
| 1345 |
- .monitors |
|
|
| 1346 |
- .get(self.selected_monitor) |
|
|
| 1347 |
- .and_then(|monitor| monitor.selected_client) |
|
|
| 1348 |
- { |
|
|
| 1349 |
- Some(window) => window, |
|
|
| 1350 |
- None => return Ok(()), |
|
|
| 1351 |
- }; |
|
|
| 1352 |
- |
|
|
| 1353 |
- if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) { |
|
|
| 1354 |
- self.focus(Some(target_window))?; |
|
|
| 1355 |
- } |
|
|
| 1356 |
- |
|
|
| 1357 |
- Ok(()) |
|
|
| 1358 |
- } |
|
|
| 1359 |
- |
|
|
| 1360 |
- pub fn swap_direction(&mut self, direction: i32) -> WmResult<()> { |
|
|
| 1361 |
- let focused_window = match self |
|
|
| 1362 |
- .monitors |
|
|
| 1363 |
- .get(self.selected_monitor) |
|
|
| 1364 |
- .and_then(|monitor| monitor.selected_client) |
|
|
| 1365 |
- { |
|
|
| 1366 |
- Some(window) => window, |
|
|
| 1367 |
- None => return Ok(()), |
|
|
| 1368 |
- }; |
|
|
| 1369 |
- |
|
|
| 1370 |
- if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) { |
|
|
| 1371 |
- let focused_position = self.windows.iter().position(|&window| window == focused_window); |
|
|
| 1372 |
- let target_position = self.windows.iter().position(|&window| window == target_window); |
|
|
| 1373 |
- |
|
|
| 1374 |
- if let (Some(focused_index), Some(target_index)) = (focused_position, target_position) { |
|
|
| 1375 |
- self.windows.swap(focused_index, target_index); |
|
|
| 1376 |
- self.apply_layout()?; |
|
|
| 1377 |
- self.focus(Some(focused_window))?; |
|
|
| 1378 |
- |
|
|
| 1379 |
- if let Ok(geometry) = self.get_or_query_geometry(focused_window) { |
|
|
| 1380 |
- self.connection.warp_pointer( |
|
|
| 1381 |
- x11rb::NONE, |
|
|
| 1382 |
- focused_window, |
|
|
| 1383 |
- 0, |
|
|
| 1384 |
- 0, |
|
|
| 1385 |
- 0, |
|
|
| 1386 |
- 0, |
|
|
| 1387 |
- geometry.width as i16 / 2, |
|
|
| 1388 |
- geometry.height as i16 / 2, |
|
|
| 1389 |
- )?; |
|
|
| 1390 |
- } |
|
|
| 1391 |
- } |
|
|
| 1392 |
- } |
|
|
| 1393 |
- |
|
|
| 1394 |
- Ok(()) |
|
|
| 1395 |
- } |
|
|
| 1396 |
- |
|
|
| 1397 |
fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> { |
1214 |
fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> { |
| 1398 |
use std::collections::HashMap; |
1215 |
use std::collections::HashMap; |
| 1399 |
use x11rb::protocol::xproto::Keycode; |
1216 |
use x11rb::protocol::xproto::Keycode; |
| @@ -2191,43 +2008,6 @@ impl WindowManager { |
| 2191 |
)?; |
2008 |
)?; |
| 2192 |
} |
2009 |
} |
| 2193 |
|
2010 |
|
| 2194 |
- let is_normie_layout = self.layout.name() == "normie"; |
|
|
| 2195 |
- if is_normie_layout && !is_transient && !is_dialog && !is_rule_floating { |
|
|
| 2196 |
- if let Ok(pointer) = self.connection.query_pointer(self.root)?.reply() { |
|
|
| 2197 |
- let cursor_monitor = self.get_monitor_at_point(pointer.root_x as i32, pointer.root_y as i32) |
|
|
| 2198 |
- .and_then(|idx| self.monitors.get(idx)) |
|
|
| 2199 |
- .unwrap_or(&monitor); |
|
|
| 2200 |
- |
|
|
| 2201 |
- let float_width = (cursor_monitor.screen_width as f32 * 0.6) as u32; |
|
|
| 2202 |
- let float_height = (cursor_monitor.screen_height as f32 * 0.6) as u32; |
|
|
| 2203 |
- let spawn_x = pointer.root_x as i32 - (float_width as i32 / 2); |
|
|
| 2204 |
- let spawn_y = pointer.root_y as i32 - (float_height as i32 / 2); |
|
|
| 2205 |
- |
|
|
| 2206 |
- let clamped_x = spawn_x |
|
|
| 2207 |
- .max(cursor_monitor.screen_x) |
|
|
| 2208 |
- .min(cursor_monitor.screen_x + cursor_monitor.screen_width as i32 - float_width as i32); |
|
|
| 2209 |
- let clamped_y = spawn_y |
|
|
| 2210 |
- .max(cursor_monitor.screen_y) |
|
|
| 2211 |
- .min(cursor_monitor.screen_y + cursor_monitor.screen_height as i32 - float_height as i32); |
|
|
| 2212 |
- |
|
|
| 2213 |
- self.connection.configure_window( |
|
|
| 2214 |
- window, |
|
|
| 2215 |
- &ConfigureWindowAux::new() |
|
|
| 2216 |
- .x(clamped_x) |
|
|
| 2217 |
- .y(clamped_y) |
|
|
| 2218 |
- .width(float_width) |
|
|
| 2219 |
- .height(float_height) |
|
|
| 2220 |
- .border_width(border_width) |
|
|
| 2221 |
- .stack_mode(StackMode::ABOVE), |
|
|
| 2222 |
- )?; |
|
|
| 2223 |
- |
|
|
| 2224 |
- if let Some(client) = self.clients.get_mut(&window) { |
|
|
| 2225 |
- client.is_floating = true; |
|
|
| 2226 |
- } |
|
|
| 2227 |
- self.floating_windows.insert(window); |
|
|
| 2228 |
- } |
|
|
| 2229 |
- } |
|
|
| 2230 |
- |
|
|
| 2231 |
self.set_wm_state(window, 1)?; |
2011 |
self.set_wm_state(window, 1)?; |
| 2232 |
if let Err(error) = self.save_client_tag(window, window_tags) { |
2012 |
if let Err(error) = self.save_client_tag(window, window_tags) { |
| 2233 |
eprintln!("Failed to save client tag for new window: {:?}", error); |
2013 |
eprintln!("Failed to save client tag for new window: {:?}", error); |
| @@ -3083,12 +2863,11 @@ impl WindowManager { |
| 3083 |
} |
2863 |
} |
| 3084 |
|
2864 |
|
| 3085 |
fn apply_layout(&mut self) -> WmResult<()> { |
2865 |
fn apply_layout(&mut self) -> WmResult<()> { |
| 3086 |
- if self.layout.name() == LayoutType::Normie.as_str() { |
2866 |
+ let is_normie = self.layout.name() == LayoutType::Normie.as_str(); |
| 3087 |
- return Ok(()); |
|
|
| 3088 |
- } |
|
|
| 3089 |
|
2867 |
|
| 3090 |
- let monitor_count = self.monitors.len(); |
2868 |
+ if !is_normie { |
| 3091 |
- for monitor_index in 0..monitor_count { |
2869 |
+ let monitor_count = self.monitors.len(); |
|
|
2870 |
+ for monitor_index in 0..monitor_count { |
| 3092 |
let monitor = &self.monitors[monitor_index]; |
2871 |
let monitor = &self.monitors[monitor_index]; |
| 3093 |
let border_width = self.config.border_width; |
2872 |
let border_width = self.config.border_width; |
| 3094 |
|
2873 |
|
| @@ -3191,6 +2970,7 @@ impl WindowManager { |
| 3191 |
border_width: border_width as u16, |
2970 |
border_width: border_width as u16, |
| 3192 |
}); |
2971 |
}); |
| 3193 |
} |
2972 |
} |
|
|
2973 |
+ } |
| 3194 |
} |
2974 |
} |
| 3195 |
|
2975 |
|
| 3196 |
for monitor_index in 0..self.monitors.len() { |
2976 |
for monitor_index in 0..self.monitors.len() { |