From 567b1ec2442d59525e24c19e8d413df6baf02496 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Camilla=20L=C3=B6wy?= Date: Tue, 9 Jun 2026 21:20:23 +0200 Subject: [PATCH] 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 #1362 Fixes #2278 --- CONTRIBUTORS.md | 2 ++ README.md | 2 ++ src/cocoa_window.m | 28 ++++++++++++++++++++++++++++ 3 files changed, 32 insertions(+) diff --git a/CONTRIBUTORS.md b/CONTRIBUTORS.md index 26e04006..6b453e72 100644 --- a/CONTRIBUTORS.md +++ b/CONTRIBUTORS.md @@ -6,6 +6,7 @@ excludes other invaluable contributions like language bindings and text and video tutorials. - Bobyshev Alexander + - Alzathar - Laurent Aphecetche - Matt Arsenault - Takuro Ashie @@ -235,6 +236,7 @@ video tutorials. - Ed Ropple - Aleksey Rybalkin - Mikko Rytkönen + - saikyun - Riku Salminen - Yoshinori Sano - Brandon Schaefer diff --git a/README.md b/README.md index 7e640c37..ed18b950 100644 --- a/README.md +++ b/README.md @@ -129,6 +129,8 @@ information on what to include when reporting a bug. - [Win32] Removed support for Windows XP and Vista (#2505) - [Cocoa] Added `QuartzCore` framework as link-time dependency - [Cocoa] Removed support for OS X 10.10 Yosemite and earlier (#2506) + - [Cocoa] Bugfix: Cmd+Period, Ctrl+Tab and Ctrl+Esc key events were not emitted + (#1362,#2278) - [Wayland] Bugfix: The fractional scaling related objects were not destroyed - [Wayland] Bugfix: `glfwInit` would segfault on compositor with no seat (#2517) - [Wayland] Bugfix: A drag entering a non-GLFW surface could cause a segfault diff --git a/src/cocoa_window.m b/src/cocoa_window.m index 1769f79b..61049808 100644 --- a/src/cocoa_window.m +++ b/src/cocoa_window.m @@ -599,6 +599,34 @@ static const NSRange kEmptyRange = { NSNotFound, 0 }; _glfwInputKey(window, key, [event keyCode], GLFW_RELEASE, mods); } +- (BOOL)performKeyEquivalent:(NSEvent *)event +{ + // HACK: Some key combinations are consumed before reaching keyDown: + // so we claim those events and emit them here + const int key = translateKey([event keyCode]); + const int mods = translateFlags([event modifierFlags]); + + if (mods & GLFW_MOD_CONTROL) + { + if (key == GLFW_KEY_TAB || key == GLFW_KEY_ESCAPE) + { + _glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods); + return YES; + } + } + + if (mods & GLFW_MOD_SUPER) + { + if (key == GLFW_KEY_PERIOD) + { + _glfwInputKey(window, key, [event keyCode], GLFW_PRESS, mods); + return YES; + } + } + + return [super performKeyEquivalent:event]; +} + - (void)scrollWheel:(NSEvent *)event { double deltaX = [event scrollingDeltaX];