shithub: drawterm

Download patch

ref: eb34f4d41103232ab345279c4d31c1241798cb99
parent: b9347940d8f079bbf9f5301dc85a2223bdbaea6e
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Mon Apr 11 10:25:47 EDT 2016

gui-x11: simpler attempt on handling alt-compose cancel on window focus change

on some linux window managers, people switch focus with alt+[tab]
or alt+[123] which causes drawterm to see [alt] down, [alt] up
which starts a compose sequence.

we solve this by handling window focus change events, and send
a second alt press/release when alt was hold down.

--- a/gui-x11/x11.c
+++ b/gui-x11/x11.c
@@ -302,6 +302,9 @@
 		Button4MotionMask|
 		Button5MotionMask|
 		ExposureMask|
+		EnterWindowMask|
+		LeaveWindowMask|
+		FocusChangeMask|
 		StructureNotifyMask;
 
 	XSelectInput(xkmcon, xdrawable, mask);
@@ -727,15 +730,25 @@
 static void
 xkeyboard(XEvent *e)
 {
+	static int altdown;
 	KeySym k;
 
-	/*
-	 * I tried using XtGetActionKeysym, but it didn't seem to
-	 * do case conversion properly
-	 * (at least, with Xterminal servers and R4 intrinsics)
-	 */
-	if(e->xany.type != KeyPress && e->xany.type != KeyRelease)
+	switch(e->xany.type){
+	case KeyPress:
+	case KeyRelease:
+		break;
+	case FocusIn:
+	case FocusOut:
+		if(altdown){
+			altdown = 0;
+			kbdkey(Kalt, 0);
+			kbdkey(Kalt, 1);
+			kbdkey(Kalt, 0);
+		}
+		/* wet floor */
+	default:
 		return;
+	}
 
 	XLookupString((XKeyEvent*)e, NULL, 0, &k, NULL);
 
@@ -866,10 +879,9 @@
 	/* Do control mapping ourselves if translator doesn't */
 	if(e->xkey.state&ControlMask && k != Kalt && k != Kctl)
 		k &= 0x9f;
-	if(k == NoSymbol) {
+	if(k == NoSymbol)
 		return;
-	}
-
+	altdown = e->xany.type == KeyPress && k == Kalt;
 	kbdkey(k, e->xany.type == KeyPress);
 }