shithub: drawterm

Download patch

ref: 5f606aa3a211c2caee8d05299674a82963583474
parent: bab0c799de34fbba25ec08aae60bb40f2d394a67
author: Jacob Moody <moody@posixcafe.org>
date: Mon Jul 11 21:27:38 EDT 2022

gui-wl: track Kalt state

In order to 'cancel' alt key input, we need to send a alt
when the keyboard leaves. To do this we need to track the alt
state ourselves.

This also fixes ctrl-\ used by ktrans.

--- a/gui-wl/wl-cb.c
+++ b/gui-wl/wl-cb.c
@@ -168,10 +168,18 @@
 static void
 keyboard_leave (void *data, struct wl_keyboard *keyboard, uint32_t serial, struct wl_surface *surface)
 {
+	Wlwin *wl;
+
+	wl = data;
 	kbdkey(Kshift, 0);
+	kbdkey(Kmod4, 0);
 	kbdkey(Kctl, 0);
 	kbdkey(Kalt, 0);
-	kbdkey(Kmod4, 0);
+	if(wl->alt != Aunpress){
+		kbdkey(Kalt, 1);
+		kbdkey(Kalt, 0);
+		wl->alt = Aunpress;
+	}
 	qlock(&repeatstate.lk);
 	repeatstate.active = 0;
 	repeatstate.key = 0;
@@ -254,10 +262,30 @@
 	if(utf32 == 0)
 		return;
 
+	if(state == 1){
+		if(utf32 == Kalt){
+			if(wl->alt == Aunpress)
+				wl->alt = Apress;
+			else
+				wl->alt = Aunpress;
+		} else {
+			switch(wl->alt){
+			case Apress:
+			case Aenter1:
+				wl->alt++;
+				break;
+			case Aenter2:
+				wl->alt = Aunpress;
+			}
+		}
+	}
 	repeat = state && utf32 != Kctl && utf32 != Kshift && utf32 != Kalt && utf32 != Kmod4;
-	if(xkb_state_mod_name_is_active(wl->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0)
-	if(utf32 >= 'a' && utf32 <= 'z')
-		utf32 -= ('a' - 1);
+	if(xkb_state_mod_name_is_active(wl->xkb_state, XKB_MOD_NAME_CTRL, XKB_STATE_MODS_EFFECTIVE) > 0){
+		if(utf32 == '\\')
+			utf32 = 0x1c;
+		else if(utf32 >= 'a' && utf32 <= '~')
+			utf32 -= ('a' - 1);
+	}
 
 	kbdkey(utf32, state);
 	qlock(&repeatstate.lk);
--- a/gui-wl/wl-inc.h
+++ b/gui-wl/wl-inc.h
@@ -34,6 +34,13 @@
 	ulong msec;
 };
 
+enum{
+	Aunpress,
+	Apress,
+	Aenter1,
+	Aenter2,
+};
+
 struct Wlwin {
 	int dx;
 	int dy;
@@ -43,6 +50,7 @@
 	Clipboard clip;
 	Rectangle r;
 	int dirty;
+	int alt; /* Kalt state */
 
 	/* Wayland State */
 	int runing;