devdraw: fix stuck mouse button when using Ctrl/Alt+Click

When physical button 1 is remapped to button 2 (Ctrl) or 3 (Alt) on
ButtonPress, the ButtonRelease event still reports the physical button 1.
This caused the release to clear the wrong bit, leaving the simulated
button permanently stuck.

Fix by recording the button mapping on press and applying it on release.

Written mostly by Claude, but I've reviewed the code and it
seems like the right kind of fix, and it works for me.

Fixes #714.

Change-Id: I9f465e1dcbe766531a37088e0fc9df2570e1c01d
This commit is contained in:
Roger Peppe
2026-03-27 18:43:17 +01:00
committed by Dan Cross
parent 0d87d4b75e
commit 53b5ac1564
2 changed files with 12 additions and 0 deletions

View File

@@ -67,6 +67,7 @@ struct Xprivate {
int kbuttons;
int kstate;
int altdown;
int button1map; /* logical button that physical button 1 maps to */
Xwin* windows;
};

View File

@@ -408,9 +408,20 @@ runxevent(XEvent *xev)
be->button = 2;
else if(_x.kstate & Mod1Mask)
be->button = 3;
_x.button1map = be->button;
}
// fall through
case ButtonRelease:
/*
* X reports the physical button on release, but ButtonPress
* may have remapped button 1 to 2 or 3 (via Ctrl or Alt).
* Use the same mapping so we clear the correct bit.
*/
if(xev->type == ButtonRelease) {
be = (XButtonEvent*)xev;
if(be->button == 1 && _x.button1map != 0)
be->button = _x.button1map;
}
_x.altdown = 0;
// fall through
case MotionNotify: