oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git

deprecated directional/exchange client movement for now since they interfere with core window/client management structural logic.

Commit
51b0e02282faa1af7cbb79a55e9e1e8518cb9ca3
Parent
c755274
Author
tonybtw <tonybtw@tonybtw.com>
Date
2025-12-01 20:53:00

Diff

diff --git a/resources/test-config.lua b/resources/test-config.lua
index 0b5522b..3db44ae 100644
--- a/resources/test-config.lua
+++ b/resources/test-config.lua
@@ -94,13 +94,6 @@ oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
 
 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1))
 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1))
-oxwm.key.bind({ modkey }, "H", oxwm.client.focus_direction("left"))
-oxwm.key.bind({ modkey }, "L", oxwm.client.focus_direction("right"))
-
-oxwm.key.bind({ modkey, "Shift" }, "H", oxwm.client.swap_direction("left"))
-oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.swap_direction("down"))
-oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.swap_direction("up"))
-oxwm.key.bind({ modkey, "Shift" }, "L", oxwm.client.swap_direction("right"))
 
 -- View tag (switch workspace)
 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
diff --git a/src/config/lua_api.rs b/src/config/lua_api.rs
index 65132a8..c88e982 100644
--- a/src/config/lua_api.rs
+++ b/src/config/lua_api.rs
@@ -255,27 +255,10 @@ fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
         create_action_table(lua, "FocusStack", Value::Integer(dir as i64))
     })?;
 
-    let focus_direction = lua.create_function(|lua, dir: String| {
-        let dir_int = direction_string_to_int(&dir)?;
-        create_action_table(lua, "FocusDirection", Value::Integer(dir_int))
-    })?;
-
-    let swap_direction = lua.create_function(|lua, dir: String| {
-        let dir_int = direction_string_to_int(&dir)?;
-        create_action_table(lua, "SwapDirection", Value::Integer(dir_int))
-    })?;
-
-    let exchange = lua.create_function(|lua, ()| {
-        create_action_table(lua, "ExchangeClient", Value::Nil)
-    })?;
-
     client_table.set("kill", kill)?;
     client_table.set("toggle_fullscreen", toggle_fullscreen)?;
     client_table.set("toggle_floating", toggle_floating)?;
     client_table.set("focus_stack", focus_stack)?;
-    client_table.set("focus_direction", focus_direction)?;
-    client_table.set("swap_direction", swap_direction)?;
-    client_table.set("exchange", exchange)?;
 
     parent.set("client", client_table)?;
     Ok(())
@@ -790,8 +773,6 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
         "SpawnTerminal" => Ok(KeyAction::SpawnTerminal),
         "KillClient" => Ok(KeyAction::KillClient),
         "FocusStack" => Ok(KeyAction::FocusStack),
-        "FocusDirection" => Ok(KeyAction::FocusDirection),
-        "SwapDirection" => Ok(KeyAction::SwapDirection),
         "Quit" => Ok(KeyAction::Quit),
         "Restart" => Ok(KeyAction::Restart),
         "Recompile" => Ok(KeyAction::Recompile),
@@ -808,7 +789,6 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
         "CycleLayout" => Ok(KeyAction::CycleLayout),
         "FocusMonitor" => Ok(KeyAction::FocusMonitor),
         "TagMonitor" => Ok(KeyAction::TagMonitor),
-        "ExchangeClient" => Ok(KeyAction::ExchangeClient),
         "ShowKeybindOverlay" => Ok(KeyAction::ShowKeybindOverlay),
         _ => Err(mlua::Error::RuntimeError(format!("unknown action '{}'. this is an internal error, please report it", s))),
     }
diff --git a/src/keyboard/handlers.rs b/src/keyboard/handlers.rs
index a21fb91..8a99eaa 100644
--- a/src/keyboard/handlers.rs
+++ b/src/keyboard/handlers.rs
@@ -15,8 +15,6 @@ pub enum KeyAction {
     SpawnTerminal,
     KillClient,
     FocusStack,
-    FocusDirection,
-    SwapDirection,
     Quit,
     Restart,
     Recompile,
@@ -31,7 +29,6 @@ pub enum KeyAction {
     CycleLayout,
     FocusMonitor,
     TagMonitor,
-    ExchangeClient,
     ShowKeybindOverlay,
     SetMasterFactor,
     IncNumMaster,
diff --git a/src/layout/normie.rs b/src/layout/normie.rs
index 6bd87cb..d299982 100644
--- a/src/layout/normie.rs
+++ b/src/layout/normie.rs
@@ -15,33 +15,14 @@ impl Layout for NormieLayout {
 
     fn arrange(
         &self,
-        windows: &[Window],
-        screen_width: u32,
-        screen_height: u32,
+        _windows: &[Window],
+        _screen_width: u32,
+        _screen_height: u32,
         _gaps: &GapConfig,
         _master_factor: f32,
         _num_master: i32,
         _smartgaps_enabled: bool,
     ) -> Vec<WindowGeometry> {
-        const DEFAULT_WIDTH_RATIO: f32 = 0.6;
-        const DEFAULT_HEIGHT_RATIO: f32 = 0.6;
-
-        windows
-            .iter()
-            .map(|_| {
-                let width = ((screen_width as f32) * DEFAULT_WIDTH_RATIO) as u32;
-                let height = ((screen_height as f32) * DEFAULT_HEIGHT_RATIO) as u32;
-
-                let x = ((screen_width - width) / 2) as i32;
-                let y = ((screen_height - height) / 2) as i32;
-
-                WindowGeometry {
-                    x_coordinate: x,
-                    y_coordinate: y,
-                    width,
-                    height,
-                }
-            })
-            .collect()
+        Vec::new()
     }
 }
diff --git a/src/lib.rs b/src/lib.rs
index 1006247..b216328 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -174,30 +174,6 @@ impl Default for Config {
                     KeyAction::FocusStack,
                     Arg::Int(1),
                 ),
-                KeyBinding::single_key(
-                    vec![MODKEY, SHIFT],
-                    keysyms::XK_K,
-                    KeyAction::ExchangeClient,
-                    Arg::Int(0), // UP
-                ),
-                KeyBinding::single_key(
-                    vec![MODKEY, SHIFT],
-                    keysyms::XK_J,
-                    KeyAction::ExchangeClient,
-                    Arg::Int(1), // DOWN
-                ),
-                KeyBinding::single_key(
-                    vec![MODKEY, SHIFT],
-                    keysyms::XK_H,
-                    KeyAction::ExchangeClient,
-                    Arg::Int(2), // LEFT
-                ),
-                KeyBinding::single_key(
-                    vec![MODKEY, SHIFT],
-                    keysyms::XK_L,
-                    KeyAction::ExchangeClient,
-                    Arg::Int(3), // RIGHT
-                ),
                 KeyBinding::single_key(
                     vec![MODKEY],
                     keysyms::XK_1,
diff --git a/src/overlay/keybind.rs b/src/overlay/keybind.rs
index 391b848..2665832 100644
--- a/src/overlay/keybind.rs
+++ b/src/overlay/keybind.rs
@@ -203,8 +203,6 @@ impl KeybindOverlay {
             },
             KeyAction::SpawnTerminal => "Launch Terminal".to_string(),
             KeyAction::FocusStack => "Focus Next/Previous Window".to_string(),
-            KeyAction::FocusDirection => "Focus Window in Direction".to_string(),
-            KeyAction::SwapDirection => "Swap Window in Direction".to_string(),
             KeyAction::ViewTag => match &binding.arg {
                 Arg::Int(n) => format!("View Workspace {}", n),
                 _ => "View Workspace".to_string(),
@@ -222,7 +220,6 @@ impl KeybindOverlay {
             KeyAction::CycleLayout => "Cycle Through Layouts".to_string(),
             KeyAction::FocusMonitor => "Focus Next Monitor".to_string(),
             KeyAction::TagMonitor => "Send Window to Monitor".to_string(),
-            KeyAction::ExchangeClient => "Exchange Client Windows".to_string(),
             KeyAction::SetMasterFactor => "Adjust Master Area Size".to_string(),
             KeyAction::IncNumMaster => "Adjust Number of Master Windows".to_string(),
             KeyAction::None => "No Action".to_string(),
diff --git a/src/window_manager.rs b/src/window_manager.rs
index 30857ec..10256b4 100644
--- a/src/window_manager.rs
+++ b/src/window_manager.rs
@@ -597,75 +597,6 @@ impl WindowManager {
         Ok(())
     }
 
-    fn exchange_client(&mut self, direction: i32) -> WmResult<()> {
-        let focused = match self
-            .monitors
-            .get(self.selected_monitor)
-            .and_then(|m| m.selected_client)
-        {
-            Some(win) => win,
-            None => return Ok(()),
-        };
-
-        if self.floating_windows.contains(&focused) {
-            return Ok(());
-        }
-
-        let visible = self.visible_windows();
-        if visible.len() < 2 {
-            return Ok(());
-        }
-
-        let current_idx = match visible.iter().position(|&w| w == focused) {
-            Some(idx) => idx,
-            None => return Ok(()),
-        };
-
-        let target_idx = match direction {
-            0 | 2 => {
-                // UP or LEFT - previous in stack
-                if current_idx == 0 {
-                    visible.len() - 1
-                } else {
-                    current_idx - 1
-                }
-            }
-            1 | 3 => {
-                // DOWN or RIGHT - next in stack
-                (current_idx + 1) % visible.len()
-            }
-            _ => return Ok(()),
-        };
-
-        let target = visible[target_idx];
-
-        let focused_pos = self.windows.iter().position(|&w| w == focused);
-        let target_pos = self.windows.iter().position(|&w| w == target);
-
-        if let (Some(f_pos), Some(t_pos)) = (focused_pos, target_pos) {
-            self.windows.swap(f_pos, t_pos);
-
-            self.apply_layout()?;
-
-            self.focus(Some(focused))?;
-
-            if let Ok(geometry) = self.connection.get_geometry(focused)?.reply() {
-                self.connection.warp_pointer(
-                    x11rb::NONE,
-                    focused,
-                    0,
-                    0,
-                    0,
-                    0,
-                    geometry.width as i16 / 2,
-                    geometry.height as i16 / 2,
-                )?;
-            }
-        }
-
-        Ok(())
-    }
-
 
     fn get_layout_symbol(&self) -> String {
         let layout_name = self.layout.name();
@@ -846,27 +777,11 @@ impl WindowManager {
                 self.restack()?;
             }
 
-            KeyAction::ExchangeClient => {
-                if let Arg::Int(direction) = arg {
-                    self.exchange_client(*direction)?;
-                }
-            }
-
             KeyAction::FocusStack => {
                 if let Arg::Int(direction) = arg {
                     self.focusstack(*direction)?;
                 }
             }
-            KeyAction::FocusDirection => {
-                if let Arg::Int(direction) = arg {
-                    self.focus_direction(*direction)?;
-                }
-            }
-            KeyAction::SwapDirection => {
-                if let Arg::Int(direction) = arg {
-                    self.swap_direction(*direction)?;
-                }
-            }
             KeyAction::Quit | KeyAction::Restart => {
                 // Handled in handle_event
             }
@@ -1296,104 +1211,6 @@ impl WindowManager {
         Ok(())
     }
 
-    fn find_directional_window_candidate(&mut self, focused_window: Window, direction: i32) -> Option<Window> {
-        let visible_windows = self.visible_windows();
-        if visible_windows.len() < 2 {
-            return None;
-        }
-
-        let focused_geometry = self.get_or_query_geometry(focused_window).ok()?;
-        let focused_center_x = focused_geometry.x_position + (focused_geometry.width as i16 / 2);
-        let focused_center_y = focused_geometry.y_position + (focused_geometry.height as i16 / 2);
-
-        let mut candidates = Vec::new();
-
-        for &window in &visible_windows {
-            if window == focused_window {
-                continue;
-            }
-
-            let geometry = match self.get_or_query_geometry(window) {
-                Ok(geometry) => geometry,
-                Err(_) => continue,
-            };
-
-            let center_x = geometry.x_position + (geometry.width as i16 / 2);
-            let center_y = geometry.y_position + (geometry.height as i16 / 2);
-
-            let is_valid_direction = match direction {
-                0 => center_y < focused_center_y,
-                1 => center_y > focused_center_y,
-                2 => center_x < focused_center_x,
-                3 => center_x > focused_center_x,
-                _ => false,
-            };
-
-            if is_valid_direction {
-                let delta_x = (center_x - focused_center_x) as i32;
-                let delta_y = (center_y - focused_center_y) as i32;
-                let distance_squared = delta_x * delta_x + delta_y * delta_y;
-                candidates.push((window, distance_squared));
-            }
-        }
-
-        candidates.iter().min_by_key(|&(_window, distance)| distance).map(|&(window, _distance)| window)
-    }
-
-    pub fn focus_direction(&mut self, direction: i32) -> WmResult<()> {
-        let focused_window = match self
-            .monitors
-            .get(self.selected_monitor)
-            .and_then(|monitor| monitor.selected_client)
-        {
-            Some(window) => window,
-            None => return Ok(()),
-        };
-
-        if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) {
-            self.focus(Some(target_window))?;
-        }
-
-        Ok(())
-    }
-
-    pub fn swap_direction(&mut self, direction: i32) -> WmResult<()> {
-        let focused_window = match self
-            .monitors
-            .get(self.selected_monitor)
-            .and_then(|monitor| monitor.selected_client)
-        {
-            Some(window) => window,
-            None => return Ok(()),
-        };
-
-        if let Some(target_window) = self.find_directional_window_candidate(focused_window, direction) {
-            let focused_position = self.windows.iter().position(|&window| window == focused_window);
-            let target_position = self.windows.iter().position(|&window| window == target_window);
-
-            if let (Some(focused_index), Some(target_index)) = (focused_position, target_position) {
-                self.windows.swap(focused_index, target_index);
-                self.apply_layout()?;
-                self.focus(Some(focused_window))?;
-
-                if let Ok(geometry) = self.get_or_query_geometry(focused_window) {
-                    self.connection.warp_pointer(
-                        x11rb::NONE,
-                        focused_window,
-                        0,
-                        0,
-                        0,
-                        0,
-                        geometry.width as i16 / 2,
-                        geometry.height as i16 / 2,
-                    )?;
-                }
-            }
-        }
-
-        Ok(())
-    }
-
     fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> {
         use std::collections::HashMap;
         use x11rb::protocol::xproto::Keycode;
@@ -2191,43 +2008,6 @@ impl WindowManager {
             )?;
         }
 
-        let is_normie_layout = self.layout.name() == "normie";
-        if is_normie_layout && !is_transient && !is_dialog && !is_rule_floating {
-            if let Ok(pointer) = self.connection.query_pointer(self.root)?.reply() {
-                let cursor_monitor = self.get_monitor_at_point(pointer.root_x as i32, pointer.root_y as i32)
-                    .and_then(|idx| self.monitors.get(idx))
-                    .unwrap_or(&monitor);
-
-                let float_width = (cursor_monitor.screen_width as f32 * 0.6) as u32;
-                let float_height = (cursor_monitor.screen_height as f32 * 0.6) as u32;
-                let spawn_x = pointer.root_x as i32 - (float_width as i32 / 2);
-                let spawn_y = pointer.root_y as i32 - (float_height as i32 / 2);
-
-                let clamped_x = spawn_x
-                    .max(cursor_monitor.screen_x)
-                    .min(cursor_monitor.screen_x + cursor_monitor.screen_width as i32 - float_width as i32);
-                let clamped_y = spawn_y
-                    .max(cursor_monitor.screen_y)
-                    .min(cursor_monitor.screen_y + cursor_monitor.screen_height as i32 - float_height as i32);
-
-                self.connection.configure_window(
-                    window,
-                    &ConfigureWindowAux::new()
-                        .x(clamped_x)
-                        .y(clamped_y)
-                        .width(float_width)
-                        .height(float_height)
-                        .border_width(border_width)
-                        .stack_mode(StackMode::ABOVE),
-                )?;
-
-                if let Some(client) = self.clients.get_mut(&window) {
-                    client.is_floating = true;
-                }
-                self.floating_windows.insert(window);
-            }
-        }
-
         self.set_wm_state(window, 1)?;
         if let Err(error) = self.save_client_tag(window, window_tags) {
             eprintln!("Failed to save client tag for new window: {:?}", error);
@@ -3083,12 +2863,11 @@ impl WindowManager {
     }
 
     fn apply_layout(&mut self) -> WmResult<()> {
-        if self.layout.name() == LayoutType::Normie.as_str() {
-            return Ok(());
-        }
+        let is_normie = self.layout.name() == LayoutType::Normie.as_str();
 
-        let monitor_count = self.monitors.len();
-        for monitor_index in 0..monitor_count {
+        if !is_normie {
+            let monitor_count = self.monitors.len();
+            for monitor_index in 0..monitor_count {
             let monitor = &self.monitors[monitor_index];
             let border_width = self.config.border_width;
 
@@ -3191,6 +2970,7 @@ impl WindowManager {
                     border_width: border_width as u16,
                 });
             }
+            }
         }
 
         for monitor_index in 0..self.monitors.len() {