From b31902e7cbf59c2ece523bae839c7c42dc4393dc Mon Sep 17 00:00:00 2001 From: ManoloFLTK <41016272+ManoloFLTK@users.noreply.github.com> Date: Sat, 13 Jun 2026 16:11:55 +0200 Subject: [PATCH] Restore use of Cmd-+ under macOS with the US keyboard layout and others (#1454) --- FL/core/options.H | 4 ++-- src/Fl_cocoa.mm | 12 ++++++++++-- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/FL/core/options.H b/FL/core/options.H index 43f4bec20..eb4e2a279 100644 --- a/FL/core/options.H +++ b/FL/core/options.H @@ -102,8 +102,8 @@ typedef enum { /// When switched on and when the keyboard in use has '+' in the shifted position of its key, /// pressing that key and ctrl triggers the zoom-in operation. /// When switched off (default), the zoom-in operation requires that also the shift key is pressed. - /// Under macOS, this option has no effect because the OS itself generates ⌘= followed - /// by ⌘+ when pressing ⌘ and the '=|+' key without pressing shift. + /// Under macOS, this option has no effect with some keyboard layouts because the OS itself + /// generates ⌘= followed by ⌘+ when pressing ⌘ and the '=|+' key without pressing shift. OPTION_SIMPLE_ZOOM_SHORTCUT, // don't change this, leave it always as the last element diff --git a/src/Fl_cocoa.mm b/src/Fl_cocoa.mm index abecc78e5..96a43c55c 100644 --- a/src/Fl_cocoa.mm +++ b/src/Fl_cocoa.mm @@ -2092,7 +2092,8 @@ static void q_set_window_title(NSWindow *nsw, const char * name, const char *mi Keyboard input sends keyDown: and performKeyEquivalent: messages to myview. The latter occurs for keys such as ForwardDelete, arrows and F1, and when the Ctrl or Cmd modifiers are used. Other key presses send keyDown: messages. - The performKeyEquivalent: method directly calls Fl::handle(FL_KEYBOARD, focus-window) and returns always YES. + The performKeyEquivalent: method directly calls Fl::handle(FL_KEYBOARD, focus-window) and generally returns YES; + it returns NO for some keyboard layouts. The keyDown: method calls [[myview inputContext] handleEvent:theEvent], and triggers system processing of keyboard events. Three sorts of messages are then sent back by the system to myview: doCommandBySelector:, setMarkedText: and insertText:. All 3 messages eventually produce Fl::handle(FL_KEYBOARD, win) calls. @@ -2343,10 +2344,17 @@ static void cocoaKeyboardHandler(NSEvent *theEvent) if ( (mods & NSEventModifierFlagControl) && (mods & NSEventModifierFlagCommand) && !(mods & (NSEventModifierFlagShift|NSEventModifierFlagOption)) && [pure isEqualToString:@" "] ) { [NSApp orderFrontCharacterPalette:self]; + handled = YES; + } else if ([theEvent keyCode] != 24 || ![s isEqualToString:@"="]) { + // It seems difficult to predict what [theEvent characters] returns for keyboard layouts + // where character '+' is in uppercase and the keystroke is Cmd-Shift-+. + // Some layouts return '+': French, Vietnamese, Russian, Greek, Arabic, Serbian; + // other layouts return '=': US, Korean, Thai. For them, this Kludge is necessary. + handled = YES; } } fl_unlock_function(); - return YES; + return (handled ? YES : [super performKeyEquivalent:theEvent]); } - (BOOL)acceptsFirstMouse:(NSEvent*)theEvent {