diff --git a/hw/darwin/darwinEvents.c b/hw/darwin/darwinEvents.c index bc3a041a5..06c4cc7dd 100644 --- a/hw/darwin/darwinEvents.c +++ b/hw/darwin/darwinEvents.c @@ -147,6 +147,16 @@ static void DarwinUpdateModifiers( } } +/* + * DarwinReleaseModifiers + * This hacky function releases all modifier keys. It should be called when X11.app + * is deactivated (kXDarwinDeactivate) to prevent modifiers from getting stuck if they + * are held down during a "context" switch -- otherwise, we would miss the KeyUp. + */ +static void DarwinReleaseModifiers(void) { + xEvent e; + DarwinUpdateModifiers(&e, KeyRelease, COMMAND_MASK(-1) | CONTROL_MASK(-1) | ALTERNATE_MASK(-1) | SHIFT_MASK(-1)); +} /* * DarwinSimulateMouseClick @@ -347,6 +357,9 @@ void ProcessInputEvents(void) { ErrorF("Unexpected XDarwinScrollWheel event in DarwinProcessInputEvents\n"); break; + case kXDarwinDeactivate: + DarwinReleaseModifiers(); + // fall through default: // Check for mode specific event DarwinModeProcessEvent(&xe);