shithub: npe

Download patch

ref: 1a9bd82a0d44bd6220ee986cc7bc2f556eb53973
parent: e9af700c67b80a62075dac2faf0520715ba95aca
author: Sigrid Solveig Haflínudóttir <ftrvxmtrx@gmail.com>
date: Fri Jul 30 07:52:02 EDT 2021

kbd: make repeats work for both text & non-text while also simplifying the logic

--- a/libnpe_sdl2/events.c
+++ b/libnpe_sdl2/events.c
@@ -73,10 +73,12 @@
 	return -1;
 }
 
+#define ISTEXT(r) ((r) >= 0x20 && ((r) < KF || (r) >= KF+0x1000))
+
 int
 SDL_PollEvent(SDL_Event *e)
 {
-	int t, down, text;
+	int t, down;
 
 	if(e == nil) /* FIXME need to buffer the event so it won't get lost */
 		return 0;
@@ -85,24 +87,23 @@
 	case Ckey:
 		memset(e, 0, sizeof(*e));
 		recv(salt[Ckeytype].c, &t);
-		text = rune >= 0x20 && (rune < KF || rune >= KF+0x1000);
-		if(npe_sdl.textinput && (kmod & ~KMOD_LSHIFT) == 0 && text){
-			if(t != Rrepeat)
+		if(npe_sdl.textinput && ISTEXT(rune)){
+			if(t == Rup)
 				break;
 			e->type = SDL_TEXTINPUT;
 			e->text.text[runetochar(e->text.text, &rune)] = 0;
+			return 1;
 		}else if((npe_sdl.hints & Altf4noclose) == 0 && (kmod & KMOD_LALT) != 0 && rune == (KF|4)){
 			e->type = SDL_QUIT;
 			return 1;
-		}else if(npe_sdl.textinput && t == Rrepeat && !text){
-			break;
 		}else{
 			e->type = (t == Rup) ? SDL_KEYUP : SDL_KEYDOWN;
-			e->key.repeat = !npe_sdl.textinput && t == Rrepeat;
+			e->key.repeat = t == Rrepeat;
 			e->key.keysym.scancode = rune2scancode(rune);
 			e->key.keysym.sym = rune;
+			return 1;
 		}
-		return 1;
+		break;
 
 	case Cmouse:
 		memset(e, 0, sizeof(*e));
@@ -246,7 +247,6 @@
 	buf2[1] = 0;
 	buf[0] = 0;
 	kmod = 0;
-	o = 0;
 	for(;;){
 		if(buf[0] != 0){
 			n = strlen(buf)+1;
@@ -263,14 +263,11 @@
 		switch(buf[0]){
 		case 'c':
 			if(chartorune(&r, buf+1) > 0 && r != Runeerror){
+				if(ISTEXT(r))
+					o = r;
+				send(salt[Ckey].c, &o);
+				send(salt[Ckeytype].c, &t);
 				t = Rrepeat;
-				if(!npe_sdl.textinput)
-					r = tolowerrune(r);
-				if(npe_sdl.textinput || o != r){
-					send(salt[Ckey].c, &r);
-					send(salt[Ckeytype].c, &t);
-				}
-				o = 0;
 			}
 		default:
 			continue;
@@ -291,9 +288,7 @@
 						kmod |= KMOD_LCTRL;
 					else{
 						t = Rdown;
-						send(salt[Ckey].c, &r);
-						send(salt[Ckeytype].c, &t);
-						o = r;
+						o = npe_sdl.textinput ? r : tolowerrune(r);
 					}
 				}
 			}