9front - general discussion about 9front
 help / color / mirror / Atom feed
* [9front] [PATCH] Fix shift release events in X11 drawterm with shift:both_capslock xmodmap option
@ 2024-06-28 23:53 Timothy Robert Bednarzyk
  2024-06-29  0:30 ` Jacob Moody
  2024-06-29 16:31 ` hiro
  0 siblings, 2 replies; 9+ messages in thread
From: Timothy Robert Bednarzyk @ 2024-06-28 23:53 UTC (permalink / raw)
  To: 9front

I have recently started using 9front on a couple of different machines
(including a native installation on my Thinkpad T470) and use drawterm
on my main laptop (which uses the X11 window manager dwm on Artix Linux)
to connect to one of them. However, on that laptop, I have the caps lock
key remapped to be another control key (ctrl:no_caps) and I have it set
to toggle caps lock when I press both shift keys at the same time
(shift:both_capslock). As it turns out, when the latter xmodmap option
is set, XLookupString interprets shift key release events as caps lock
key release events. This was causing my middle and right mouse buttons
to effectively be swapped permanently after pressing a shift key even
once in a drawterm session (although I didn't know why it was happening
until I did some research and found someone else mentioning them having
shift-related problems in a different program whenever they were using
shift:both_capslock).

I ended up solving this by utilizing the rather strange and unintuitive
fact that the xkey event's state still has the ShiftMask bit set during
the release event (even for actual shift key release events, according
to what I found during my research) and using that to determine whether
the release event should be interpreted as being for a shift key or for
the caps lock key. This likely will cause the middle and right mouse
buttons to unswap if the user is holding down the shift key while
releasing the caps lock key, but considering how unlikely of a scenario
that is and the fact that it is only a temporary and mild problem (all
they would have to do is release and re-press the shift key), I think
this fix is acceptable enough (unless someone else can think of a better
solution, which I would greatly appreciate).

diff --git a/gui-x11/x11.c b/gui-x11/x11.c
index b4f1ad3..8f2b694 100644
--- a/gui-x11/x11.c
+++ b/gui-x11/x11.c
@@ -882,7 +882,16 @@ xkeyboard(XEvent *e)
 			break;
 		case XK_Shift_Lock:
 		case XK_Caps_Lock:
-			k = Kcaps;
+			/*
+			 * Using the xmodmap option shift:both_capslock causes shift
+			 * release events to appear as capslock release events instead.
+			 * Not having this causes the middle and right mouse buttons to
+			 * be swapped permanently after the shift key is pressed once.
+			 */
+			if(e->xany.type == KeyRelease && (e->xkey.state & ShiftMask))
+				k = Kshift;
+			else
+				k = Kcaps;
 			break;
 		case XK_Scroll_Lock:
 			k = Kscroll;

--
trb

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-06-30 19:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-06-28 23:53 [9front] [PATCH] Fix shift release events in X11 drawterm with shift:both_capslock xmodmap option Timothy Robert Bednarzyk
2024-06-29  0:30 ` Jacob Moody
2024-06-29 11:16   ` Timothy Robert Bednarzyk
2024-06-30 16:53     ` Jacob Moody
2024-06-30 19:22       ` Timothy Robert Bednarzyk
2024-06-29 16:31 ` hiro
2024-06-29 17:19   ` Timothy Robert Bednarzyk
2024-06-30 16:39     ` hiro
2024-06-30 19:08       ` Timothy Robert Bednarzyk

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).