diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-26 07:34:39 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-01-26 07:34:39 +0200 |
commit | 85ccb7e82dc080e033d7aee621b53651aaa457e7 (patch) | |
tree | 65c05dedceb1de9ed95c52469ad2c643d63504a7 /src/macos.m | |
parent | c5668c7eb7004cb4edad0cb3a18422bf81a64c19 (diff) | |
parent | 37fefc85a9a23be7c3bc6dcddb8a30047459f534 (diff) |
Merge branch 'pullrequests/Br0000k/dev' into dev
Diffstat (limited to 'src/macos.m')
-rw-r--r-- | src/macos.m | 26 |
1 files changed, 20 insertions, 6 deletions
diff --git a/src/macos.m b/src/macos.m index 4e214923..9d46d84b 100644 --- a/src/macos.m +++ b/src/macos.m | |||
@@ -241,10 +241,20 @@ static void appearanceChanged_MacOS_(NSString *name) { | |||
241 | 241 | ||
242 | - (void)showPreferences { | 242 | - (void)showPreferences { |
243 | postCommand_App("preferences"); | 243 | postCommand_App("preferences"); |
244 | ignoreImmediateKeyDownEvents_(); | ||
245 | } | ||
246 | |||
247 | static void ignoreImmediateKeyDownEvents_(void) { | ||
248 | /* SDL ignores menu key equivalents so the keydown events will be posted regardless. | ||
249 | However, we shouldn't double-activate menu items when a shortcut key is used in our | ||
250 | widgets. Quite a kludge: take advantage of Window's focus-acquisition threshold to | ||
251 | ignore the immediately following key down events. */ | ||
252 | get_Window()->focusGainedAt = SDL_GetTicks(); | ||
244 | } | 253 | } |
245 | 254 | ||
246 | - (void)closeTab { | 255 | - (void)closeTab { |
247 | postCommand_App("tabs.close"); | 256 | postCommand_App("tabs.close"); |
257 | ignoreImmediateKeyDownEvents_(); | ||
248 | } | 258 | } |
249 | 259 | ||
250 | - (NSString *)commandForItem:(NSMenuItem *)menuItem { | 260 | - (NSString *)commandForItem:(NSMenuItem *)menuItem { |
@@ -255,11 +265,7 @@ static void appearanceChanged_MacOS_(NSString *name) { | |||
255 | NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]]; | 265 | NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]]; |
256 | if (command) { | 266 | if (command) { |
257 | postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]); | 267 | postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]); |
258 | /* Shouldn't double-activate menu items in case the same key is used in our widgets. | 268 | ignoreImmediateKeyDownEvents_(); |
259 | SDL ignores menu key equivalents so the keydown events will be posted regardless. | ||
260 | This is quite a kludge, but we can achieve this by taking advantage of Window's | ||
261 | focus-acquisition threshold for ignoring key events. */ | ||
262 | get_Window()->focusGainedAt = SDL_GetTicks(); | ||
263 | } | 269 | } |
264 | } | 270 | } |
265 | 271 | ||
@@ -501,11 +507,17 @@ void handleCommand_MacOS(const char *cmd) { | |||
501 | NSApplication *app = [NSApplication sharedApplication]; | 507 | NSApplication *app = [NSApplication sharedApplication]; |
502 | MyDelegate *myDel = (MyDelegate *) app.delegate; | 508 | MyDelegate *myDel = (MyDelegate *) app.delegate; |
503 | NSMenu *appMenu = [app mainMenu]; | 509 | NSMenu *appMenu = [app mainMenu]; |
510 | int mainIndex = 0; | ||
504 | for (NSMenuItem *mainMenuItem in appMenu.itemArray) { | 511 | for (NSMenuItem *mainMenuItem in appMenu.itemArray) { |
505 | NSMenu *menu = mainMenuItem.submenu; | 512 | NSMenu *menu = mainMenuItem.submenu; |
506 | if (menu) { | 513 | if (menu) { |
507 | for (NSMenuItem *menuItem in menu.itemArray) { | 514 | int itemIndex = 0; |
515 | for (NSMenuItem *menuItem in menu.itemArray) { | ||
508 | NSString *command = [myDel commandForItem:menuItem]; | 516 | NSString *command = [myDel commandForItem:menuItem]; |
517 | if (!command && mainIndex == 6 && itemIndex == 0) { | ||
518 | /* Window > Close */ | ||
519 | command = @"tabs.close"; | ||
520 | } | ||
509 | if (command) { | 521 | if (command) { |
510 | const iBinding *bind = findCommand_Keys( | 522 | const iBinding *bind = findCommand_Keys( |
511 | [command cStringUsingEncoding:NSUTF8StringEncoding]); | 523 | [command cStringUsingEncoding:NSUTF8StringEncoding]); |
@@ -513,8 +525,10 @@ void handleCommand_MacOS(const char *cmd) { | |||
513 | setShortcut_NSMenuItem_(menuItem, bind->key, bind->mods); | 525 | setShortcut_NSMenuItem_(menuItem, bind->key, bind->mods); |
514 | } | 526 | } |
515 | } | 527 | } |
528 | itemIndex++; | ||
516 | } | 529 | } |
517 | } | 530 | } |
531 | mainIndex++; | ||
518 | } | 532 | } |
519 | } | 533 | } |
520 | } | 534 | } |