foxygit / dotfiles Log in
commit bab658741ee146cc87ed3f2b1b6db2c1a59c300b
Author:     mrfox <jens.se@icloud.com>
AuthorDate: Sun Sep 20 21:46:49 2026 +0200
Commit:     mrfox <jens.se@icloud.com>
CommitDate: Sun Sep 20 21:46:49 2026 +0200

    sxwm: don't warp cursor on Electron/Chromium self-activation

    net-active-window.patch warped the cursor unconditionally for every
    _NET_ACTIVE_WINDOW ClientMessage. Confirmed with a small X11 sniffer
    that Chromium/Electron apps (VS Code, at least) send one of these with
    EWMH source indication 1 ("application request") when clicked while
    unfocused -- distinct from source 2 ("pager/taskbar acting on a user
    click", e.g. what xdotool windowactivate and sxbar's taskbar send),
    which is what the patch was actually written for. The unconditional
    warp meant clicking an unfocused VS Code window yanked the pointer to
    the window's center right after the click.

    Now only warps when source == 2; still focuses and raises either way.
    Verified: the sniffer caught win=0xe00003 source=1 from an unfocused
    click inside VS Code, and win=... source=2 from xdotool windowactivate.
    Rebuilt sxwm with all 6 local patches applied together, compiles clean.

    Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
---
 README.md               |  2 +-
 net-active-window.patch | 18 +++++++++++++-----
 2 files changed, 14 insertions(+), 6 deletions(-)

diff --git a/README.md b/README.md
index 3d99780..e69be86 100644
--- a/README.md
+++ b/README.md
@@ -193,7 +193,7 @@ order:
 | Patch | Fixes |
 |---|---|
 | [`cursor-dpi-fix.patch`](cursor-dpi-fix.patch) | Incorrect cursor scaling on high-DPI displays |
-| [`net-active-window.patch`](net-active-window.patch) | Adds `_NET_ACTIVE_WINDOW` support — required for sxbar's taskbar module; without it, clicking a taskbar entry does nothing |
+| [`net-active-window.patch`](net-active-window.patch) | Adds `_NET_ACTIVE_WINDOW` support — required for sxbar's taskbar module; without it, clicking a taskbar entry does nothing. Only warps the cursor for real pager/taskbar requests (EWMH source indication `2`); Chromium/Electron apps (VS Code and others) send a source-`1` self-activation request when clicked while unfocused, which used to yank the cursor to the window's center right after the click |
 | [`multi-monitor-struts.patch`](multi-monitor-struts.patch) | `_NET_WM_STRUT_PARTIAL` reservations weren't clamped to the panel's own monitor, so a monitor's reserved area could exceed its actual size and push windows off-screen |
 | [`monitor-hotplug-remap.patch`](monitor-hotplug-remap.patch) | Windows lost their correct monitor association on hotplug (e.g. `lid-display-watch` toggling eDP); monitor ownership is now recomputed from each window's actual position |
 | [`fullscreen-monitor-fix.patch`](fullscreen-monitor-fix.patch) | Fullscreening a window that had been moved to another monitor by an external tool (`xdotool`, `screensaver-launch`) fullscreened it on the wrong screen; the target monitor is now recomputed from the window's real geometry |
diff --git a/net-active-window.patch b/net-active-window.patch
index df71ee2..24cb2fd 100644
--- a/net-active-window.patch
+++ b/net-active-window.patch
@@ -1,8 +1,8 @@
 diff --git a/src/sxwm.c b/src/sxwm.c
-index 55fe97b..d25d872 100644
+index de43ce3..b170567 100644
 --- a/src/sxwm.c
 +++ b/src/sxwm.c
-@@ -1009,6 +1009,26 @@ void hdl_client_msg(XEvent *xev)
+@@ -1011,6 +1011,34 @@ void hdl_client_msg(XEvent *xev)
  		}
  		return;
  	}
@@ -14,7 +14,15 @@ index 55fe97b..d25d872 100644
 +		 * nothing accepted requests to change it until now. Switch to
 +		 * the client's workspace first if it's not the current one, same
 +		 * as a pager would expect, then focus/raise it exactly like
-+		 * focus_next/focus_prev do. */
++		 * focus_next/focus_prev do.
++		 *
++		 * data.l[0] is the EWMH source indication: 2 means a pager/taskbar
++		 * acting on an explicit user click (mouse already elsewhere, so
++		 * warp it to the window), 1 means the application is requesting
++		 * its own activation. Chromium/Electron apps (VS Code, among
++		 * others) send the latter when clicked while unfocused -- warping
++		 * there yanks the pointer away from right where the user just
++		 * clicked, so only warp for real pager/taskbar requests. */
 +		XClientMessageEvent *client_msg_ev = &xev->xclient;
 +		Window w = client_msg_ev->window;
 +		Client *c = find_client(find_toplevel(w));
@@ -23,9 +31,9 @@ index 55fe97b..d25d872 100644
 +
 +		if (c->ws != current_ws)
 +			change_workspace(c->ws);
-+		set_input_focus(c, True, True);
++		set_input_focus(c, True, client_msg_ev->data.l[0] == 2);
 +		return;
 +	}
  }
-
+
  void hdl_config_ntf(XEvent *xev)