Skip to content

Commit 567b1ec

Browse files
committed
Cocoa: Fix some key events not being emitted
The key combinations Cmd+Period, Ctrl+Tab and Ctrl+Esc are not passed to the first responder as key events. This commit catches and claims these specific key events via the key equivalents mechanism and emits them from there instead. Closes glfw#1362 Fixes glfw#2278
1 parent 0136feb commit 567b1ec

3 files changed

Lines changed: 32 additions & 0 deletions

File tree

CONTRIBUTORS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ excludes other invaluable contributions like language bindings and text and
66
video tutorials.
77

88
- Bobyshev Alexander
9+
- Alzathar
910
- Laurent Aphecetche
1011
- Matt Arsenault
1112
- Takuro Ashie
@@ -235,6 +236,7 @@ video tutorials.
235236
- Ed Ropple
236237
- Aleksey Rybalkin
237238
- Mikko Rytkönen
239+
- saikyun
238240
- Riku Salminen
239241
- Yoshinori Sano
240242
- Brandon Schaefer

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ information on what to include when reporting a bug.
129129
- [Win32] Removed support for Windows XP and Vista (#2505)
130130
- [Cocoa] Added `QuartzCore` framework as link-time dependency
131131
- [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506)
132+
- [Cocoa] Bugfix: Cmd+Period, Ctrl+Tab and Ctrl+Esc key events were not emitted
133+
(#1362,#2278)
132134
- [Wayland] Bugfix: The fractional scaling related objects were not destroyed
133135
- [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517)
134136
- [Wayland] Bugfix: A drag entering a non-GLFW surface could cause a segfault

src/cocoa_window.m

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -599,6 +599,34 @@ - (void)keyUp:(NSEvent *)event
599599
_glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods);
600600
}
601601

602+
- (BOOL)performKeyEquivalent:(NSEvent *)event
603+
{
604+
// HACK: Some key combinations are consumed before reaching keyDown:
605+
// so we claim those events and emit them here
606+
const int key = translateKey([event keyCode]);
607+
const int mods = translateFlags([event modifierFlags]);
608+
609+
if (mods & GLFW_MOD_CONTROL)
610+
{
611+
if (key == GLFW_KEY_TAB || key == GLFW_KEY_ESCAPE)
612+
{
613+
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
614+
return YES;
615+
}
616+
}
617+
618+
if (mods & GLFW_MOD_SUPER)
619+
{
620+
if (key == GLFW_KEY_PERIOD)
621+
{
622+
_glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods);
623+
return YES;
624+
}
625+
}
626+
627+
return [super performKeyEquivalent:event];
628+
}
629+
602630
- (void)scrollWheel:(NSEvent *)event
603631
{
604632
double deltaX = [event scrollingDeltaX];

0 commit comments

Comments
 (0)