added two opt-in flags to warp the pointer when changing monitors. both default to false
Browse files
+2 −0 src/config/config.zig
| @@ -205,6 +205,8 @@ pub const Config = struct { | ||
| 205 | 205 | hide_vacant_tags: bool = false, |
| 206 | 206 | floating_position: FloatingPosition = .center, |
| 207 | 207 | tiled_resize_mode: bool = false, |
| 208 | + warp_cursor_to_monitor: bool = false, | |
| 209 | + warp_cursor_on_send: bool = false, | |
| 208 | 210 | |
| 209 | 211 | layout_tile_symbol: []const u8 = "[]=", |
| 210 | 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 | 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 | 235 | c.lua_pushcfunction(state, luaMonitorFocus); |
| 236 | 236 | c.lua_setfield(state, -2, "focus"); |
| @@ -238,6 +238,12 @@ fn registerMonitorModule(state: *c.lua_State) void { | ||
| 238 | 238 | c.lua_pushcfunction(state, luaMonitorTag); |
| 239 | 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 | 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 | 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 | 726 | fn luaRuleAdd(state: ?*c.lua_State) callconv(.c) c_int { |
| 707 | 727 | const cfg = config orelse return 0; |
| 708 | 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 | 447 | pub fn focusmon(direction: i32, wm: *WindowManager) void { |
| 442 | 448 | const selmon = wm.selected_monitor orelse return; |
| 443 | 449 | const target = monitor_mod.dirToMonitor(wm, direction) orelse return; |
| @@ -447,6 +453,9 @@ pub fn focusmon(direction: i32, wm: *WindowManager) void { | ||
| 447 | 453 | core.unfocusClient(selmon.sel, false, wm); |
| 448 | 454 | wm.selected_monitor = target; |
| 449 | 455 | core.focus(null, wm); |
| 456 | + if (wm.config.warp_cursor_to_monitor) { | |
| 457 | + warpCursorToMonitor(target, wm); | |
| 458 | + } | |
| 450 | 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 | 479 | core.arrange(source_monitor, wm); |
| 471 | 480 | core.arrange(target, wm); |
| 472 | 481 | |
| 482 | + if (wm.config.warp_cursor_on_send) { | |
| 483 | + warpCursorToMonitor(target, wm); | |
| 484 | + } | |
| 485 | + | |
| 473 | 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 | 267 | oxwm.key.bind({ modkey, "Shift" }, "Comma", oxwm.monitor.tag(-1)) |
| 268 | 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 | 275 | -- Workspace (tag) navigation |
| 271 | 276 | -- Switch to workspace N (tags are 0-indexed, so tag "1" is index 0) |
| 272 | 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 | 204 | ---@return table Action table for keybinding |
| 205 | 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 | 215 | ---Layout management module |
| 208 | 216 | ---@class oxwm.layout |
| 209 | 217 | oxwm.layout = {} |