tony / oxwm

added two opt-in flags to warp the pointer when changing monitors. both default to false Browse files
tonybanters committed 2026-05-31 parent 81a1296 commit 1ebf023b84d47b1252c4770d730949fda49b2fc7
Showing 5 changed files with 49 additions and 1 deletions. UnifiedSplit
+2 −0 src/config/config.zig
@@ -205,6 +205,8 @@ pub const Config = struct {
205 hide_vacant_tags: bool = false, 205 hide_vacant_tags: bool = false,
206 floating_position: FloatingPosition = .center, 206 floating_position: FloatingPosition = .center,
207 tiled_resize_mode: bool = false, 207 tiled_resize_mode: bool = false,
208 + warp_cursor_to_monitor: bool = false,
209 + warp_cursor_on_send: bool = false,
208 210
209 layout_tile_symbol: []const u8 = "[]=", 211 layout_tile_symbol: []const u8 = "[]=",
210 layout_monocle_symbol: []const u8 = "[M]", 212 layout_monocle_symbol: []const u8 = "[M]",
+21 −1 src/config/lua.zig
@@ -230,7 +230,7 @@ fn registerTagModule(state: *c.lua_State) void {
230 } 230 }
231 231
232 fn registerMonitorModule(state: *c.lua_State) void { 232 fn registerMonitorModule(state: *c.lua_State) void {
233 - c.lua_createtable(state, 0, 2); 233 + c.lua_createtable(state, 0, 4);
234 234
235 c.lua_pushcfunction(state, luaMonitorFocus); 235 c.lua_pushcfunction(state, luaMonitorFocus);
236 c.lua_setfield(state, -2, "focus"); 236 c.lua_setfield(state, -2, "focus");
@@ -238,6 +238,12 @@ fn registerMonitorModule(state: *c.lua_State) void {
238 c.lua_pushcfunction(state, luaMonitorTag); 238 c.lua_pushcfunction(state, luaMonitorTag);
239 c.lua_setfield(state, -2, "tag"); 239 c.lua_setfield(state, -2, "tag");
240 240
241 + c.lua_pushcfunction(state, luaMonitorWarpCursor);
242 + c.lua_setfield(state, -2, "warp_cursor");
243 +
244 + c.lua_pushcfunction(state, luaMonitorWarpCursorOnSend);
245 + c.lua_setfield(state, -2, "warp_cursor_on_send");
246 +
241 c.lua_setfield(state, -2, "monitor"); 247 c.lua_setfield(state, -2, "monitor");
242 } 248 }
243 249
@@ -703,6 +709,20 @@ fn luaMonitorTag(state: ?*c.lua_State) callconv(.c) c_int {
703 return 1; 709 return 1;
704 } 710 }
705 711
712 +fn luaMonitorWarpCursor(state: ?*c.lua_State) callconv(.c) c_int {
713 + const cfg = config orelse return 0;
714 + const s = state orelse return 0;
715 + cfg.warp_cursor_to_monitor = c.lua_toboolean(s, 1) != 0;
716 + return 0;
717 +}
718 +
719 +fn luaMonitorWarpCursorOnSend(state: ?*c.lua_State) callconv(.c) c_int {
720 + const cfg = config orelse return 0;
721 + const s = state orelse return 0;
722 + cfg.warp_cursor_on_send = c.lua_toboolean(s, 1) != 0;
723 + return 0;
724 +}
725 +
706 fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int { 726 fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int {
707 const cfg = config orelse return 0; 727 const cfg = config orelse return 0;
708 const s = state orelse return 0; 728 const s = state orelse return 0;
+13 −0 src/wm/actions.zig
@@ -438,6 +438,12 @@ pub fn setLayoutIndex(index: u32, wm: *WindowManager) void {
438 } 438 }
439 } 439 }
440 440
441 +fn warpCursorToMonitor(monitor: *Monitor, wm: *WindowManager) void {
442 + const center_x = monitor.win_x + @divTrunc(monitor.win_w, 2);
443 + const center_y = monitor.win_y + @divTrunc(monitor.win_h, 2);
444 + _ = xlib.XWarpPointer(wm.display.handle, xlib.None, wm.display.root, 0, 0, 0, 0, center_x, center_y);
445 +}
446 +
441 pub fn focusmon(direction: i32, wm: *WindowManager) void { 447 pub fn focusmon(direction: i32, wm: *WindowManager) void {
442 const selmon = wm.selected_monitor orelse return; 448 const selmon = wm.selected_monitor orelse return;
443 const target = monitor_mod.dirToMonitor(wm, direction) orelse return; 449 const target = monitor_mod.dirToMonitor(wm, direction) orelse return;
@@ -447,6 +453,9 @@ pub fn focusmon(direction: i32, wm: *WindowManager) void {
447 core.unfocusClient(selmon.sel, false, wm); 453 core.unfocusClient(selmon.sel, false, wm);
448 wm.selected_monitor = target; 454 wm.selected_monitor = target;
449 core.focus(null, wm); 455 core.focus(null, wm);
456 + if (wm.config.warp_cursor_to_monitor) {
457 + warpCursorToMonitor(target, wm);
458 + }
450 std.debug.print("focusmon: monitor {d}\n", .{target.num}); 459 std.debug.print("focusmon: monitor {d}\n", .{target.num});
451 } 460 }
452 461
@@ -470,6 +479,10 @@ pub fn sendmon(direction: i32, wm: *WindowManager) void {
470 core.arrange(source_monitor, wm); 479 core.arrange(source_monitor, wm);
471 core.arrange(target, wm); 480 core.arrange(target, wm);
472 481
482 + if (wm.config.warp_cursor_on_send) {
483 + warpCursorToMonitor(target, wm);
484 + }
485 +
473 std.debug.print("sendmon: window=0x{x} to monitor {d}\n", .{ client.window, target.num }); 486 std.debug.print("sendmon: window=0x{x} to monitor {d}\n", .{ client.window, target.num });
474 } 487 }
475 488
+5 −0 templates/config.lua
@@ -267,6 +267,11 @@ oxwm.key.bind({ modkey }, "Period", oxwm.monitor.focus(1))
267 oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1)) 267 oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1))
268 oxwm.key.bind({ modkey, "Shift" }, "Period", oxwm.monitor.tag(1)) 268 oxwm.key.bind({ modkey, "Shift" }, "Period", oxwm.monitor.tag(1))
269 269
270 +-- Warp the cursor to the focused monitor when switching monitors
271 +-- oxwm.monitor.warp_cursor(true)
272 +-- Warp the cursor along when sending a window to another monitor
273 +-- oxwm.monitor.warp_cursor_on_send(true)
274 +
270 -- Workspace (tag) navigation 275 -- Workspace (tag) navigation
271 -- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0) 276 -- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0)
272 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0)) 277 oxwm.key.bind({ modkey }, "1", oxwm.tag.view(0))
+8 −0 templates/oxwm.lua
@@ -204,6 +204,14 @@ function oxwm.monitor.focus(dir) end
204 ---@return table Action table for keybinding 204 ---@return table Action table for keybinding
205 function oxwm.monitor.tag(dir) end 205 function oxwm.monitor.tag(dir) end
206 206
207 +---Warp the cursor to the focused monitor when switching monitors
208 +---@param enabled boolean
209 +function oxwm.monitor.warp_cursor(enabled) end
210 +
211 +---Warp the cursor along when sending a window to another monitor
212 +---@param enabled boolean
213 +function oxwm.monitor.warp_cursor_on_send(enabled) end
214 +
207 ---Layout management module 215 ---Layout management module
208 ---@class oxwm.layout 216 ---@class oxwm.layout
209 oxwm.layout = {} 217 oxwm.layout = {}