XQuartz: Release all buttons and keys when deactivating

http://xquartz.macosforge.org/trac/ticket/486

Signed-off-by: Jeremy Huddleston <jeremyhu@apple.com>
Reviewed-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Jeremy Huddleston 2012-01-28 16:06:28 -08:00
parent 47b457541b
commit 85cecd9811
3 changed files with 32 additions and 17 deletions

View File

@ -68,9 +68,6 @@ extern int xpbproxy_run (void);
static dispatch_queue_t eventTranslationQueue; static dispatch_queue_t eventTranslationQueue;
#endif #endif
/* Stuck modifier / button state... force release when we context switch */
static NSEventType keyState[NUM_KEYCODES];
extern Bool noTestExtensions; extern Bool noTestExtensions;
#if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050 #if MAC_OS_X_VERSION_MIN_REQUIRED >= 1050
@ -194,7 +191,6 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
} }
- (void) activateX:(OSX_BOOL)state { - (void) activateX:(OSX_BOOL)state {
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) {
if(bgMouseLocationUpdated) { if(bgMouseLocationUpdated) {
@ -206,13 +202,13 @@ static void message_kit_thread (SEL selector, NSObject *arg) {
if(darwin_all_modifier_flags) if(darwin_all_modifier_flags)
DarwinUpdateModKeys(0); DarwinUpdateModKeys(0);
for(i=0; i < NUM_KEYCODES; i++) {
if(keyState[i] == NSKeyDown) { DarwinInputReleaseButtonsAndKeys(darwinKeyboard);
DarwinSendKeyboardEvents(KeyRelease, i); DarwinInputReleaseButtonsAndKeys(darwinPointer);
keyState[i] = NSKeyUp; DarwinInputReleaseButtonsAndKeys(darwinTabletCursor);
} DarwinInputReleaseButtonsAndKeys(darwinTabletStylus);
} DarwinInputReleaseButtonsAndKeys(darwinTabletEraser);
DarwinSendDDXEvent(kXquartzDeactivate, 0); DarwinSendDDXEvent(kXquartzDeactivate, 0);
} }
@ -1407,12 +1403,8 @@ static const char *untrusted_str(NSEvent *e) {
} }
} }
/* Avoid stuck keys on context switch */ ev_type = ([e type] == NSKeyDown) ? KeyPress : KeyRelease;
if(keyState[[e keyCode]] == [e type]) DarwinSendKeyboardEvents(ev_type, [e keyCode]);
return;
keyState[[e keyCode]] = [e type];
DarwinSendKeyboardEvents(([e type] == NSKeyDown) ? KeyPress : KeyRelease, [e keyCode]);
break; break;
default: break; /* for gcc */ default: break; /* for gcc */

View File

@ -434,6 +434,28 @@ static void DarwinPrepareValuators(DeviceIntPtr pDev, int *valuators, ScreenPtr
// valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]); // valuators[0], valuators[1], valuators[2], valuators[3], valuators[4]);
} }
void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev) {
darwinEvents_lock(); {
int i;
if (pDev->button) {
for (i = 0; i < pDev->button->numButtons; i++) {
if (BitIsOn(pDev->button->down, i)) {
QueuePointerEvents(pDev, ButtonRelease, i, POINTER_ABSOLUTE, NULL);
}
}
}
if (pDev->key) {
for (i = 0; i < NUM_KEYCODES; i++) {
if (BitIsOn(pDev->key->down, i + MIN_KEYCODE)) {
QueueKeyboardEvents(pDev, KeyRelease, i + MIN_KEYCODE, NULL);
}
}
}
DarwinPokeEQ();
} darwinEvents_unlock();
}
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y, void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y) { float pressure, float tilt_x, float tilt_y) {
static int darwinFakeMouseButtonDown = 0; static int darwinFakeMouseButtonDown = 0;

View File

@ -36,6 +36,7 @@ void DarwinEQFini(void);
void DarwinEQEnqueue(const xEventPtr e); void DarwinEQEnqueue(const xEventPtr e);
void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e); void DarwinEQPointerPost(DeviceIntPtr pDev, xEventPtr e);
void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX); void DarwinEQSwitchScreen(ScreenPtr pScreen, Bool fromDIX);
void DarwinInputReleaseButtonsAndKeys(DeviceIntPtr pDev);
void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y, void DarwinSendPointerEvents(DeviceIntPtr pDev, int ev_type, int ev_button, float pointer_x, float pointer_y,
float pressure, float tilt_x, float tilt_y); float pressure, float tilt_x, float tilt_y);
void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y, void DarwinSendProximityEvents(DeviceIntPtr pDev, int ev_type, float pointer_x, float pointer_y,