Compare commits

...

3 Commits

Author SHA1 Message Date
Max Thrun
bf8b4f90f7
Merge 89aea6bb95 into 0d2d85d19c 2025-08-18 12:02:08 +00:00
Doug Binks
0d2d85d19c Revert "Wayland: Keyboard leave event handler now processes key repeats" 2025-08-15 11:27:59 +02:00
Max Thrun
89aea6bb95 Cocoa: Fix modifier keys getting lost due to global system shortcuts
In normal situations modifier key release triggers flagsChanged with
the corresponding keyCode for that modifier key. If the user does a
global system shortcut such as screenshoting with cmd+ctrl+shift+4
then we will see the keyDown for the cmd+ctrl+shift but no keyUp or
flagsChanged after the screenshot is complete. This will leave
window->keys in the wrong state: the modifier keys will be stuck in
GLFW_PRESS until they are individually pressed and released again or
window focus changes.

When the screenshot chord is finished we _do_ get a flagsChanged event
but with the keyCode for "a" (which is weird) but the modifiers are
valid so we simply just emit each of their states and let _glfwInputKey
handle de-duplicating the event if needed.
2023-11-06 22:17:37 -08:00
2 changed files with 9 additions and 18 deletions

View File

@ -590,6 +590,15 @@ static const NSRange kEmptyRange = { NSNotFound, 0 };
action = GLFW_RELEASE; action = GLFW_RELEASE;
_glfwInputKey(window, key, [event keyCode], action, mods); _glfwInputKey(window, key, [event keyCode], action, mods);
_glfwInputKey(window, GLFW_KEY_LEFT_SHIFT , _glfw.ns.scancodes[GLFW_KEY_LEFT_SHIFT ], mods & GLFW_MOD_SHIFT ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_LEFT_CONTROL , _glfw.ns.scancodes[GLFW_KEY_LEFT_CONTROL ], mods & GLFW_MOD_CONTROL ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_LEFT_ALT , _glfw.ns.scancodes[GLFW_KEY_LEFT_ALT ], mods & GLFW_MOD_ALT ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_LEFT_SUPER , _glfw.ns.scancodes[GLFW_KEY_LEFT_SUPER ], mods & GLFW_MOD_SUPER ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_RIGHT_SHIFT , _glfw.ns.scancodes[GLFW_KEY_RIGHT_SHIFT ], mods & GLFW_MOD_SHIFT ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_RIGHT_CONTROL, _glfw.ns.scancodes[GLFW_KEY_RIGHT_CONTROL], mods & GLFW_MOD_CONTROL ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_RIGHT_ALT , _glfw.ns.scancodes[GLFW_KEY_RIGHT_ALT ], mods & GLFW_MOD_ALT ? GLFW_PRESS : GLFW_RELEASE, mods);
_glfwInputKey(window, GLFW_KEY_RIGHT_SUPER , _glfw.ns.scancodes[GLFW_KEY_RIGHT_SUPER ], mods & GLFW_MOD_SUPER ? GLFW_PRESS : GLFW_RELEASE, mods);
} }
- (void)keyUp:(NSEvent *)event - (void)keyUp:(NSEvent *)event

View File

@ -1778,24 +1778,6 @@ static void keyboardHandleLeave(void* userData,
if (!window) if (!window)
return; return;
// Handle any key repeats up to this point. We don't poll as this should be infrequent.
uint64_t repeats;
if (read(_glfw.wl.keyRepeatTimerfd, &repeats, sizeof(repeats)) == 8)
{
if(_glfw.wl.keyboardFocus)
{
for (uint64_t i = 0; i < repeats; i++)
{
_glfwInputKey(_glfw.wl.keyboardFocus,
translateKey(_glfw.wl.keyRepeatScancode),
_glfw.wl.keyRepeatScancode,
GLFW_PRESS,
_glfw.wl.xkb.modifiers);
inputText(_glfw.wl.keyboardFocus, _glfw.wl.keyRepeatScancode);
}
}
}
struct itimerspec timer = {0}; struct itimerspec timer = {0};
timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL); timerfd_settime(_glfw.wl.keyRepeatTimerfd, 0, &timer, NULL);