Browse Source

Fix keyboard handling for gwin checkbox and button

inmarket 3 years ago
parent
commit
8603afd309
2 changed files with 10 additions and 11 deletions
  1. 7 7
      src/gwin/gwin_button.c
  2. 3 4
      src/gwin/gwin_checkbox.c

+ 7 - 7
src/gwin/gwin_button.c

@@ -53,15 +53,15 @@
53 53
 		// ENTER and SPACE keys to press the button
54 54
 		if (pke->c[0] == GKEY_ENTER || pke->c[0] == GKEY_SPACE) {
55 55
 
56
-			// Press or release event?
57
-			if (pke->keystate & GKEYSTATE_KEYUP) {
58
-				gw->g.flags &= ~GBUTTON_FLG_PRESSED;
59
-			} else {
60
-				gw->g.flags |= GBUTTON_FLG_PRESSED;
61
-			}
56
+			// Some keyboards (eg the virtual keyboard) can't send keyup events.
57
+			// Even for those that do we may not be listening for them.
58
+			// We should really process on a keydown and then set a timer to display
59
+			//	the button release but that requires an extra timer and lots of
60
+			//	complication. Instead we cheat by not providing user feedback of the keypress.
61
+			if (!(pke->keystate & GKEYSTATE_KEYUP))
62
+				_gwinSendEvent(&gw->g, GEVENT_GWIN_BUTTON);
62 63
 		}
63 64
 
64
-		_gwinUpdate((GHandle)gw);
65 65
 	}
66 66
 #endif
67 67
 

+ 3 - 4
src/gwin/gwin_checkbox.c

@@ -56,16 +56,15 @@ static void SendCheckboxEvent(GWidgetObject *gw) {
56 56
 	static void CheckboxKeyboard(GWidgetObject* gw, GEventKeyboard* pke)
57 57
 	{
58 58
 		// Only react on KEYDOWN events. Ignore KEYUP events.
59
-		if (pke->keystate & GKEYSTATE_KEYUP) {
59
+		if ((pke->keystate & GKEYSTATE_KEYUP))
60 60
 			return;
61
-		}
62 61
 
63 62
 		// ENTER and SPACE keys to check/uncheck the checkbox
64 63
 		if (pke->c[0] == GKEY_ENTER || pke->c[0] == GKEY_SPACE) {
65 64
 			gw->g.flags ^= GCHECKBOX_FLG_CHECKED;
65
+			_gwinUpdate((GHandle)gw);
66
+			SendCheckboxEvent(gw);
66 67
 		}
67
-
68
-		_gwinUpdate((GHandle)gw);
69 68
 	}
70 69
 #endif
71 70