commit b8fbbb1

seiko  ·  2026-05-29 19:12:24 +0000 UTC
parent 0d6d5af
use keyChar events for text input

this fixes the "double processing" of key events
1 files changed,  +15, -7
+15, -7
 1@@ -81,25 +81,33 @@ static void cleanup(void)
 2  */
 3 static void handle_key(RGFW_event ev)
 4 {
 5+	int skip_keypress = 0;
 6+
 7 	/* regular character-
 8-	 * dont have to handle e.g. shift cases:
 9-	 * SHIFT+1 or `!`
10+	   dont have to handle e.g. shift cases:
11+	   SHIFT+1 or `!`
12 	 */
13 	if (ev.type == RGFW_keyChar) {
14 		uint32_t cp = ev.keyChar.value;
15-		if (cp >= ' ' && cp <= '~') {
16+
17+		skip_keypress = 1; /* key handled */
18+
19+		if (cp <= 0x7F) {
20 			char cpch = (char)cp;
21 			ptywrite(&cpch, 1);
22+			return;
23 		}
24+
25+		/* TODO? encode non ascii->UTF-8 */
26+		return;
27 	}
28 
29 	/* special character */
30 	if (ev.type == RGFW_keyPressed) {
31 		RGFW_key key = ev.key.value;
32-		if ((ev.key.mod & RGFW_modControl) &&
33-		    key >= RGFW_keyA && key <= RGFW_keyZ) {
34-			char c = (char)(key - RGFW_keyA + 1);
35-			ptywrite(&c, 1);
36+
37+		if (skip_keypress) {
38+			skip_keypress = 0;
39 			return;
40 		}
41