tony / oxwm

removed unused functions, and renamed functions for more readability. adopted dwms G-loaded approach on the struct level. Browse files
tonybtw committed 2025-12-02 parent 4ca96ad commit c339298a4e7147dad0bf3dc1df45bf47e538aa62
Showing 2 changed files with 50 additions and 111 deletions. UnifiedSplit
+0 −12 src/config/lua_api.rs
@@ -819,18 +819,6 @@ fn create_action_table(lua: &Lua, action_name: &str, arg: Value) -> mlua::Result
819 819 Ok(table)
820 820 }
821 821
822 -fn direction_string_to_int(dir: &str) -> mlua::Result<i64> {
823 - match dir {
824 - "up" => Ok(0),
825 - "down" => Ok(1),
826 - "left" => Ok(2),
827 - "right" => Ok(3),
828 - _ => Err(mlua::Error::RuntimeError(
829 - format!("invalid direction '{}'. must be one of: up, down, left, right", dir)
830 - )),
831 - }
832 -}
833 -
834 822 fn parse_color_value(value: Value) -> mlua::Result<u32> {
835 823 match value {
836 824 Value::Integer(i) => Ok(i as u32),
+50 −99 src/window_manager.rs
@@ -17,9 +17,6 @@ use x11rb::protocol::Event;
17 17 use x11rb::protocol::xproto::*;
18 18 use x11rb::rust_connection::RustConnection;
19 19
20 -const DEFAULT_FLOAT_WIDTH_RATIO: f32 = 0.5;
21 -const DEFAULT_FLOAT_HEIGHT_RATIO: f32 = 0.5;
22 -
23 20 #[derive(Debug, Clone, Copy)]
24 21 pub struct CachedGeometry {
25 22 pub x_position: i16,
@@ -829,7 +826,7 @@ impl WindowManager {
829 826 }
830 827 KeyAction::TagMonitor => {
831 828 if let Arg::Int(direction) = arg {
832 - self.tag_monitor(*direction)?;
829 + self.send_window_to_adjacent_monitor(*direction)?;
833 830 }
834 831 }
835 832 KeyAction::ShowKeybindOverlay => {
@@ -912,7 +909,7 @@ impl WindowManager {
912 909 .position(|mon| mon.contains_point(x, y))
913 910 }
914 911
915 - fn rect_to_monitor(&self, x: i32, y: i32, w: i32, h: i32) -> usize {
912 + fn get_monitor_for_rect(&self, x: i32, y: i32, w: i32, h: i32) -> usize {
916 913 let mut best_monitor = self.selected_monitor;
917 914 let mut max_area = 0;
918 915
@@ -930,7 +927,7 @@ impl WindowManager {
930 927 best_monitor
931 928 }
932 929
933 - fn sendmon(&mut self, window: Window, target_monitor_index: usize) -> WmResult<()> {
930 + fn move_window_to_monitor(&mut self, window: Window, target_monitor_index: usize) -> WmResult<()> {
934 931 let current_monitor_index = self.clients
935 932 .get(&window)
936 933 .map(|c| c.monitor_index);
@@ -961,7 +958,7 @@ impl WindowManager {
961 958 Ok(())
962 959 }
963 960
964 - fn dir_to_monitor(&self, direction: i32) -> Option<usize> {
961 + fn get_adjacent_monitor(&self, direction: i32) -> Option<usize> {
965 962 if self.monitors.len() <= 1 {
966 963 return None;
967 964 }
@@ -981,22 +978,16 @@ impl WindowManager {
981 978 }
982 979 }
983 980
984 - // Dwm's g-loaded approach to handling the spam alternating crash.
985 - fn update_window_visibility(&self) -> WmResult<()> {
986 - for &window in &self.windows {
987 - if !self.is_window_visible(window) {
988 - if let Ok(geom) = self.connection.get_geometry(window)?.reply() {
989 - self.connection.configure_window(
990 - window,
991 - &ConfigureWindowAux::new()
992 - .x(-(geom.width as i32 * 2))
993 - .y(geom.y as i32),
994 - )?;
995 - }
996 - }
997 - }
998 - self.connection.flush()?;
999 - Ok(())
981 + fn is_visible(&self, window: Window) -> bool {
982 + let Some(client) = self.clients.get(&window) else {
983 + return false;
984 + };
985 +
986 + let Some(monitor) = self.monitors.get(client.monitor_index) else {
987 + return false;
988 + };
989 +
990 + (client.tags & monitor.tagset[monitor.selected_tags_index]) != 0
1000 991 }
1001 992
1002 993 fn showhide(&mut self, window: Option<Window>) -> WmResult<()> {
@@ -1442,7 +1433,7 @@ impl WindowManager {
1442 1433 Ok(())
1443 1434 }
1444 1435
1445 - fn get_state(&self, window: Window) -> WmResult<i32> {
1436 + fn get_window_state(&self, window: Window) -> WmResult<i32> {
1446 1437 let reply = self.connection.get_property(
1447 1438 false,
1448 1439 window,
@@ -1466,7 +1457,7 @@ impl WindowManager {
1466 1457 }
1467 1458 }
1468 1459
1469 - fn get_atom_prop(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1460 + fn get_window_atom_property(&self, window: Window, property: Atom) -> WmResult<Option<Atom>> {
1470 1461 let reply = self.connection.get_property(
1471 1462 false,
1472 1463 window,
@@ -1490,7 +1481,7 @@ impl WindowManager {
1490 1481 }
1491 1482 }
1492 1483
1493 - fn get_text_prop(&self, window: Window, atom: Atom) -> WmResult<Option<String>> {
1484 + fn get_window_text_property(&self, window: Window, atom: Atom) -> WmResult<Option<String>> {
1494 1485 let reply = self.connection.get_property(
1495 1486 false,
1496 1487 window,
@@ -1746,10 +1737,6 @@ impl WindowManager {
1746 1737 })
1747 1738 }
1748 1739
1749 - fn is_transient_window(&self, window: Window) -> bool {
1750 - self.get_transient_parent(window).is_some()
1751 - }
1752 -
1753 1740 fn is_dialog_window(&self, window: Window) -> bool {
1754 1741 let window_type_property = self.connection
1755 1742 .get_property(
@@ -2115,7 +2102,21 @@ impl WindowManager {
2115 2102 }
2116 2103 }
2117 2104
2118 - if let Some(win) = window {
2105 + let mut win = window;
2106 + if win.is_none() || !self.is_visible(win.unwrap()) {
2107 + let mut current = self.monitors.get(self.selected_monitor)
2108 + .and_then(|m| m.stack_head);
2109 +
2110 + while let Some(w) = current {
2111 + if self.is_visible(w) {
2112 + win = Some(w);
2113 + break;
2114 + }
2115 + current = self.clients.get(&w).and_then(|c| c.stack_next);
2116 + }
2117 + }
2118 +
2119 + if let Some(win) = win {
2119 2120 if !self.windows.contains(&win) {
2120 2121 return Ok(());
2121 2122 }
@@ -2277,7 +2278,7 @@ impl WindowManager {
2277 2278 return Ok(());
2278 2279 }
2279 2280
2280 - let target_monitor = match self.dir_to_monitor(direction) {
2281 + let target_monitor = match self.get_adjacent_monitor(direction) {
2281 2282 Some(idx) if idx != self.selected_monitor => idx,
2282 2283 _ => return Ok(()),
2283 2284 };
@@ -2296,7 +2297,7 @@ impl WindowManager {
2296 2297 Ok(())
2297 2298 }
2298 2299
2299 - pub fn tag_monitor(&mut self, direction: i32) -> WmResult<()> {
2300 + pub fn send_window_to_adjacent_monitor(&mut self, direction: i32) -> WmResult<()> {
2300 2301 if self.monitors.len() <= 1 {
2301 2302 return Ok(());
2302 2303 }
@@ -2310,12 +2311,12 @@ impl WindowManager {
2310 2311 None => return Ok(()),
2311 2312 };
2312 2313
2313 - let target_monitor = match self.dir_to_monitor(direction) {
2314 + let target_monitor = match self.get_adjacent_monitor(direction) {
2314 2315 Some(idx) => idx,
2315 2316 None => return Ok(()),
2316 2317 };
2317 2318
2318 - self.send_to_monitor(window, target_monitor)?;
2319 + self.move_window_to_monitor(window, target_monitor)?;
2319 2320
2320 2321 Ok(())
2321 2322 }
@@ -2353,7 +2354,7 @@ impl WindowManager {
2353 2354 Ok(())
2354 2355 }
2355 2356
2356 - fn move_mouse(&mut self, window: Window) -> WmResult<()> {
2357 + fn drag_window(&mut self, window: Window) -> WmResult<()> {
2357 2358 let is_fullscreen = self.clients
2358 2359 .get(&window)
2359 2360 .map(|c| c.is_fullscreen)
@@ -2458,9 +2459,9 @@ impl WindowManager {
2458 2459 });
2459 2460
2460 2461 if let Some((x, y, w, h)) = final_client {
2461 - let new_monitor = self.rect_to_monitor(x as i32, y as i32, w as i32, h as i32);
2462 + let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
2462 2463 if new_monitor != monitor_idx {
2463 - self.sendmon(window, new_monitor)?;
2464 + self.move_window_to_monitor(window, new_monitor)?;
2464 2465 self.selected_monitor = new_monitor;
2465 2466 self.focus(None)?;
2466 2467 }
@@ -2469,7 +2470,7 @@ impl WindowManager {
2469 2470 Ok(())
2470 2471 }
2471 2472
2472 - fn resize_mouse(&mut self, window: Window) -> WmResult<()> {
2473 + fn resize_window_with_mouse(&mut self, window: Window) -> WmResult<()> {
2473 2474 let is_fullscreen = self.clients
2474 2475 .get(&window)
2475 2476 .map(|c| c.is_fullscreen)
@@ -2604,9 +2605,9 @@ impl WindowManager {
2604 2605 });
2605 2606
2606 2607 if let Some((x, y, w, h)) = final_client_pos {
2607 - let new_monitor = self.rect_to_monitor(x as i32, y as i32, w as i32, h as i32);
2608 + let new_monitor = self.get_monitor_for_rect(x as i32, y as i32, w as i32, h as i32);
2608 2609 if new_monitor != monitor_idx {
2609 - self.sendmon(window, new_monitor)?;
2610 + self.move_window_to_monitor(window, new_monitor)?;
2610 2611 self.selected_monitor = new_monitor;
2611 2612 self.focus(None)?;
2612 2613 }
@@ -2736,7 +2737,7 @@ impl WindowManager {
2736 2737 client.hints_valid = false;
2737 2738 }
2738 2739 } else if event.atom == AtomEnum::WM_HINTS.into() {
2739 - self.update_wm_hints(event.window)?;
2740 + self.update_window_hints(event.window)?;
2740 2741 self.update_bar()?;
2741 2742 }
2742 2743
@@ -2912,9 +2913,9 @@ impl WindowManager {
2912 2913 self.focus(Some(event.child))?;
2913 2914
2914 2915 if event.detail == ButtonIndex::M1.into() {
2915 - self.move_mouse(event.child)?;
2916 + self.drag_window(event.child)?;
2916 2917 } else if event.detail == ButtonIndex::M3.into() {
2917 - self.resize_mouse(event.child)?;
2918 + self.resize_window_with_mouse(event.child)?;
2918 2919 }
2919 2920 }
2920 2921 }
@@ -3024,10 +3025,10 @@ impl WindowManager {
3024 3025 });
3025 3026
3026 3027 if is_floating {
3027 - let new_monitor = self.rect_to_monitor(final_x as i32, final_y as i32, final_width as i32, final_height as i32);
3028 + let new_monitor = self.get_monitor_for_rect(final_x as i32, final_y as i32, final_width as i32, final_height as i32);
3028 3029
3029 3030 if new_monitor != monitor_index {
3030 - self.send_to_monitor(event.window, new_monitor)?;
3031 + self.move_window_to_monitor(event.window, new_monitor)?;
3031 3032 }
3032 3033 }
3033 3034 } else {
@@ -3491,7 +3492,7 @@ impl WindowManager {
3491 3492 Ok(())
3492 3493 }
3493 3494
3494 - fn update_wm_hints(&mut self, window: Window) -> WmResult<()> {
3495 + fn update_window_hints(&mut self, window: Window) -> WmResult<()> {
3495 3496 let hints_reply = self.connection.get_property(
3496 3497 false,
3497 3498 window,
@@ -3557,13 +3558,13 @@ impl WindowManager {
3557 3558 }
3558 3559
3559 3560 fn update_window_type(&mut self, window: Window) -> WmResult<()> {
3560 - if let Ok(Some(state_atom)) = self.get_atom_prop(window, self.atoms.net_wm_state) {
3561 + if let Ok(Some(state_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_state) {
3561 3562 if state_atom == self.atoms.net_wm_state_fullscreen {
3562 3563 self.set_window_fullscreen(window, true)?;
3563 3564 }
3564 3565 }
3565 3566
3566 - if let Ok(Some(type_atom)) = self.get_atom_prop(window, self.atoms.net_wm_window_type) {
3567 + if let Ok(Some(type_atom)) = self.get_window_atom_property(window, self.atoms.net_wm_window_type) {
3567 3568 if type_atom == self.atoms.net_wm_window_type_dialog {
3568 3569 if let Some(client) = self.clients.get_mut(&window) {
3569 3570 client.is_floating = true;
@@ -3634,23 +3635,6 @@ impl WindowManager {
3634 3635 None
3635 3636 }
3636 3637
3637 - fn count_tiled(&self, monitor: &Monitor) -> usize {
3638 - let mut count = 0;
3639 - let mut current = monitor.clients_head;
3640 - while let Some(window) = current {
3641 - if let Some(client) = self.clients.get(&window) {
3642 - let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
3643 - if visible_tags != 0 && !client.is_floating {
3644 - count += 1;
3645 - }
3646 - current = client.next;
3647 - } else {
3648 - break;
3649 - }
3650 - }
3651 - count
3652 - }
3653 -
3654 3638 fn attach(&mut self, window: Window, monitor_index: usize) {
3655 3639 if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3656 3640 if let Some(client) = self.clients.get_mut(&window) {
@@ -3791,39 +3775,6 @@ impl WindowManager {
3791 3775 }
3792 3776 }
3793 3777
3794 - fn send_to_monitor(&mut self, window: Window, target_monitor: usize) -> WmResult<()> {
3795 - if target_monitor >= self.monitors.len() {
3796 - return Ok(());
3797 - }
3798 -
3799 - let current_monitor = self.clients.get(&window).map(|c| c.monitor_index);
3800 - if current_monitor == Some(target_monitor) {
3801 - return Ok(());
3802 - }
3803 -
3804 - self.unfocus(window)?;
3805 -
3806 - self.detach(window);
3807 - self.detach_stack(window);
3808 -
3809 - if let Some(client) = self.clients.get_mut(&window) {
3810 - client.monitor_index = target_monitor;
3811 - let new_tags = self.monitors
3812 - .get(target_monitor)
3813 - .map(|m| m.tagset[m.selected_tags_index])
3814 - .unwrap_or(1);
3815 - client.tags = new_tags;
3816 - }
3817 -
3818 - self.attach_aside(window, target_monitor);
3819 - self.attach_stack(window, target_monitor);
3820 -
3821 - self.focus(None)?;
3822 - self.apply_layout()?;
3823 -
3824 - Ok(())
3825 - }
3826 -
3827 3778 fn remove_window(&mut self, window: Window) -> WmResult<()> {
3828 3779 let initial_count = self.windows.len();
3829 3780