XQuartz: Better avoid stuck keys on context switches

(cherry picked from commit e9963f1a4f4f12f253eae9d4f01694b6cabe35ad)
This commit is contained in:
Jeremy Huddleston 2008-12-29 19:54:12 -08:00
parent f464b5a916
commit 1a69d56afd

View File

@ -63,6 +63,9 @@ extern BOOL xpbproxy_init (void);
#define ProximityIn 0 #define ProximityIn 0
#define ProximityOut 1 #define ProximityOut 1
/* Stuck modifier / button state... force release when we context switch */
static NSEventType keyState[NUM_KEYCODES];
int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE; int X11EnableKeyEquivalents = TRUE, quartzFullscreenMenu = FALSE;
int quartzHasRoot = FALSE, quartzEnableRootless = TRUE; int quartzHasRoot = FALSE, quartzEnableRootless = TRUE;
@ -181,6 +184,7 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
/* Create a TSM document that supports full Unicode input, and /* Create a TSM document that supports full Unicode input, and
have it activated while X is active */ have it activated while X is active */
static TSMDocumentID x11_document; static TSMDocumentID x11_document;
size_t i;
DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active) DEBUG_LOG("state=%d, _x_active=%d, \n", state, _x_active)
if (state) { if (state) {
DarwinSendDDXEvent(kXquartzActivate, 0); DarwinSendDDXEvent(kXquartzActivate, 0);
@ -195,6 +199,13 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
if (x11_document != 0) ActivateTSMDocument (x11_document); if (x11_document != 0) ActivateTSMDocument (x11_document);
} }
} else { } else {
DarwinUpdateModKeys(0);
for(i=0; i < NUM_KEYCODES; i++) {
if(keyState[i] == NSKeyDown)
DarwinSendKeyboardEvents(KeyRelease, i);
}
DarwinSendDDXEvent(kXquartzDeactivate, 0); DarwinSendDDXEvent(kXquartzDeactivate, 0);
if (_x_active && x11_document != 0) if (_x_active && x11_document != 0)
@ -1127,6 +1138,11 @@ static inline int ensure_flag(int flags, int device_independent, int device_depe
} }
} }
/* Avoid stuck keys on context switch */
if(keyState[[e keyCode]] == [e type])
return;
keyState[[e keyCode]] = [e type];
DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]); DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
break; break;