tony / oxwm

Implemented movestack patch, so windows can be moved with a keybind, added keybind to lua file and lua lsp. Browse files
tonybtw committed 2025-12-02 parent ced2a2a commit d974d56ca26eae5d43340aab0865bed45aec1d82
Showing 6 changed files with 177 additions and 25 deletions. UnifiedSplit
+3 −0 resources/test-config.lua
@@ -95,6 +95,9 @@ oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart())
95 95 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1))
96 96 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1))
97 97
98 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1))
99 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1))
100 +
98 101 -- View tag (switch workspace)
99 102 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
100 103 oxwm.key.bind({ modkey }, "2", oxwm.tag.view(1))
+6 −0 src/config/lua_api.rs
@@ -255,10 +255,15 @@ fn register_client_module(lua: &Lua, parent: &Table) -> Result<(), ConfigError>
255 255 create_action_table(lua, "FocusStack", Value::Integer(dir as i64))
256 256 })?;
257 257
258 + let move_stack = lua.create_function(|lua, dir: i32| {
259 + create_action_table(lua, "MoveStack", Value::Integer(dir as i64))
260 + })?;
261 +
258 262 client_table.set("kill", kill)?;
259 263 client_table.set("toggle_fullscreen", toggle_fullscreen)?;
260 264 client_table.set("toggle_floating", toggle_floating)?;
261 265 client_table.set("focus_stack", focus_stack)?;
266 + client_table.set("move_stack", move_stack)?;
262 267
263 268 parent.set("client", client_table)?;
264 269 Ok(())
@@ -773,6 +778,7 @@ fn string_to_action(s: &str) -> mlua::Result<KeyAction> {
773 778 "SpawnTerminal" => Ok(KeyAction::SpawnTerminal),
774 779 "KillClient" => Ok(KeyAction::KillClient),
775 780 "FocusStack" => Ok(KeyAction::FocusStack),
781 + "MoveStack" => Ok(KeyAction::MoveStack),
776 782 "Quit" => Ok(KeyAction::Quit),
777 783 "Restart" => Ok(KeyAction::Restart),
778 784 "Recompile" => Ok(KeyAction::Recompile),
+1 −0 src/keyboard/handlers.rs
@@ -15,6 +15,7 @@ pub enum KeyAction {
15 15 SpawnTerminal,
16 16 KillClient,
17 17 FocusStack,
18 + MoveStack,
18 19 Quit,
19 20 Restart,
20 21 Recompile,
+1 −0 src/overlay/keybind.rs
@@ -203,6 +203,7 @@ impl KeybindOverlay {
203 203 },
204 204 KeyAction::SpawnTerminal => "Launch Terminal".to_string(),
205 205 KeyAction::FocusStack => "Focus Next/Previous Window".to_string(),
206 + KeyAction::MoveStack => "Move Window Up/Down Stack".to_string(),
206 207 KeyAction::ViewTag => match &binding.arg {
207 208 Arg::Int(n) => format!("View Workspace {}", n),
208 209 _ => "View Workspace".to_string(),
+162 −25 src/window_manager.rs
@@ -322,8 +322,7 @@ impl WindowManager {
322 322 pub fn show_migration_overlay(&mut self) {
323 323 let message = "We are on version 0.8.0 now.\n\n\
324 324 Your config file has been deprecated once again.\n\
325 - We apologize for this, but we have provided you\n\
326 - with a new default config.\n\n\
325 + Backup your current config, and run oxwm --init to generate a new one with correct values.\n\n\
327 326 Please reach out to Tony, or check out the\n\
328 327 documentation for help with migration.\n\n\
329 328 We appreciate you testing oxwm!\n\n\
@@ -790,6 +789,11 @@ impl WindowManager {
790 789 self.focusstack(*direction)?;
791 790 }
792 791 }
792 + KeyAction::MoveStack => {
793 + if let Arg::Int(direction) = arg {
794 + self.move_stack(*direction)?;
795 + }
796 + }
793 797 KeyAction::Quit | KeyAction::Restart => {
794 798 // Handled in handle_event
795 799 }
@@ -2282,6 +2286,139 @@ impl WindowManager {
2282 2286 Ok(())
2283 2287 }
2284 2288
2289 + pub fn move_stack(&mut self, direction: i32) -> WmResult<()> {
2290 + let monitor_index = self.selected_monitor;
2291 + let monitor = match self.monitors.get(monitor_index) {
2292 + Some(m) => m.clone(),
2293 + None => return Ok(()),
2294 + };
2295 +
2296 + let selected = match monitor.selected_client {
2297 + Some(win) => win,
2298 + None => return Ok(()),
2299 + };
2300 +
2301 + let selected_client = match self.clients.get(&selected) {
2302 + Some(c) => c,
2303 + None => return Ok(()),
2304 + };
2305 +
2306 + let target = if direction > 0 {
2307 + let next = self.next_tiled(selected_client.next, &monitor);
2308 + if next.is_some() {
2309 + next
2310 + } else {
2311 + self.next_tiled(monitor.clients_head, &monitor)
2312 + }
2313 + } else {
2314 + let mut previous = None;
2315 + let mut current = monitor.clients_head;
2316 + while let Some(window) = current {
2317 + if window == selected {
2318 + break;
2319 + }
2320 + if let Some(client) = self.clients.get(&window) {
2321 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
2322 + if visible_tags != 0 && !client.is_floating {
2323 + previous = Some(window);
2324 + }
2325 + current = client.next;
2326 + } else {
2327 + break;
2328 + }
2329 + }
2330 + if previous.is_none() {
2331 + let mut last = None;
2332 + let mut current = monitor.clients_head;
2333 + while let Some(window) = current {
2334 + if let Some(client) = self.clients.get(&window) {
2335 + let visible_tags = client.tags & monitor.tagset[monitor.selected_tags_index];
2336 + if visible_tags != 0 && !client.is_floating {
2337 + last = Some(window);
2338 + }
2339 + current = client.next;
2340 + } else {
2341 + break;
2342 + }
2343 + }
2344 + last
2345 + } else {
2346 + previous
2347 + }
2348 + };
2349 +
2350 + let target = match target {
2351 + Some(t) if t != selected => t,
2352 + _ => return Ok(()),
2353 + };
2354 +
2355 + let mut prev_selected = None;
2356 + let mut prev_target = None;
2357 + let mut current = monitor.clients_head;
2358 +
2359 + while let Some(window) = current {
2360 + if let Some(client) = self.clients.get(&window) {
2361 + if client.next == Some(selected) {
2362 + prev_selected = Some(window);
2363 + }
2364 + if client.next == Some(target) {
2365 + prev_target = Some(window);
2366 + }
2367 + current = client.next;
2368 + } else {
2369 + break;
2370 + }
2371 + }
2372 +
2373 + let selected_next = self.clients.get(&selected).and_then(|c| c.next);
2374 + let target_next = self.clients.get(&target).and_then(|c| c.next);
2375 +
2376 + let temp = if selected_next == Some(target) {
2377 + Some(selected)
2378 + } else {
2379 + selected_next
2380 + };
2381 +
2382 + if let Some(client) = self.clients.get_mut(&selected) {
2383 + client.next = if target_next == Some(selected) {
2384 + Some(target)
2385 + } else {
2386 + target_next
2387 + };
2388 + }
2389 +
2390 + if let Some(client) = self.clients.get_mut(&target) {
2391 + client.next = temp;
2392 + }
2393 +
2394 + if let Some(prev) = prev_selected {
2395 + if prev != target {
2396 + if let Some(client) = self.clients.get_mut(&prev) {
2397 + client.next = Some(target);
2398 + }
2399 + }
2400 + }
2401 +
2402 + if let Some(prev) = prev_target {
2403 + if prev != selected {
2404 + if let Some(client) = self.clients.get_mut(&prev) {
2405 + client.next = Some(selected);
2406 + }
2407 + }
2408 + }
2409 +
2410 + if let Some(monitor) = self.monitors.get_mut(monitor_index) {
2411 + if monitor.clients_head == Some(selected) {
2412 + monitor.clients_head = Some(target);
2413 + } else if monitor.clients_head == Some(target) {
2414 + monitor.clients_head = Some(selected);
2415 + }
2416 + }
2417 +
2418 + self.apply_layout()?;
2419 + Ok(())
2420 + }
2421 +
2285 2422 pub fn focus_monitor(&mut self, direction: i32) -> WmResult<()> {
2286 2423 if self.monitors.len() <= 1 {
2287 2424 return Ok(());
@@ -3669,6 +3806,22 @@ impl WindowManager {
3669 3806 None
3670 3807 }
3671 3808
3809 + fn next_tagged(&self, start: Option<Window>, tags: u32) -> Option<Window> {
3810 + let mut current = start;
3811 + while let Some(window) = current {
3812 + if let Some(client) = self.clients.get(&window) {
3813 + let visible_on_tags = (client.tags & tags) != 0;
3814 + if !client.is_floating && visible_on_tags {
3815 + return Some(window);
3816 + }
3817 + current = client.next;
3818 + } else {
3819 + break;
3820 + }
3821 + }
3822 + None
3823 + }
3824 +
3672 3825 fn attach(&mut self, window: Window, monitor_index: usize) {
3673 3826 if let Some(monitor) = self.monitors.get_mut(monitor_index) {
3674 3827 if let Some(client) = self.clients.get_mut(&window) {
@@ -3684,40 +3837,24 @@ impl WindowManager {
3684 3837 None => return,
3685 3838 };
3686 3839
3687 - if monitor.clients_head.is_none() {
3840 + let new_window_tags = self.clients.get(&window).map(|c| c.tags).unwrap_or(0);
3841 + let first_tagged = self.next_tagged(monitor.clients_head, new_window_tags);
3842 +
3843 + if first_tagged.is_none() {
3688 3844 self.attach(window, monitor_index);
3689 3845 return;
3690 3846 }
3691 3847
3692 - let num_master = monitor.num_master.max(1) as usize;
3693 - let mut current = monitor.clients_head;
3694 - let mut position = 0;
3695 -
3696 - while position < num_master - 1 {
3697 - if let Some(current_window) = current {
3698 - if let Some(current_client) = self.clients.get(&current_window) {
3699 - current = current_client.next;
3700 - position += 1;
3701 - } else {
3702 - break;
3703 - }
3704 - } else {
3705 - break;
3706 - }
3707 - }
3708 -
3709 - if let Some(insert_after) = current {
3710 - if let Some(after_client) = self.clients.get(&insert_after) {
3848 + if let Some(insert_after_window) = first_tagged {
3849 + if let Some(after_client) = self.clients.get(&insert_after_window) {
3711 3850 let old_next = after_client.next;
3712 3851 if let Some(new_client) = self.clients.get_mut(&window) {
3713 3852 new_client.next = old_next;
3714 3853 }
3715 - if let Some(after_client_mut) = self.clients.get_mut(&insert_after) {
3854 + if let Some(after_client_mut) = self.clients.get_mut(&insert_after_window) {
3716 3855 after_client_mut.next = Some(window);
3717 3856 }
3718 3857 }
3719 - } else {
3720 - self.attach(window, monitor_index);
3721 3858 }
3722 3859 }
3723 3860
+4 −0 templates/config.lua
@@ -204,6 +204,10 @@ oxwm.key.bind({ modkey, "Shift" }, "R", oxwm.restart()) -- Restart OXWM (reloads
204 204 oxwm.key.bind({ modkey }, "J", oxwm.client.focus_stack(1)) -- Focus next window in stack
205 205 oxwm.key.bind({ modkey }, "K", oxwm.client.focus_stack(-1)) -- Focus previous window in stack
206 206
207 +-- Window movement (swap position in stack)
208 +oxwm.key.bind({ modkey, "Shift" }, "J", oxwm.client.move_stack(1)) -- Move window down in stack
209 +oxwm.key.bind({ modkey, "Shift" }, "K", oxwm.client.move_stack(-1)) -- Move window up in stack
210 +
207 211 -- Multi-monitor support
208 212 oxwm.key.bind({ modkey }, "Comma", oxwm.monitor.focus(-1)) -- Focus previous monitor
209 213 oxwm.key.bind({ modkey }, "Period", oxwm.monitor.focus(1)) -- Focus next monitor