summaryrefslogtreecommitdiff
path: root/src/macos.m
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-11-14 11:06:59 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-11-14 11:06:59 +0200
commit70b1483eb567dd44b603d0f4f5338b7df0e99959 (patch)
tree32ba00b0c3a0bd1392dab302530af940853d00c9 /src/macos.m
parente88b83f054db139b66ee947c907de8f9f894738e (diff)
macOS: Workaround for menu shortcut keys
Avoid double-triggering actions because SDL doesn't eat the keydown events — it ignores key equivalents.
Diffstat (limited to 'src/macos.m')
-rw-r--r--src/macos.m16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/macos.m b/src/macos.m
index 1d972ebd..28ebcc43 100644
--- a/src/macos.m
+++ b/src/macos.m
@@ -25,6 +25,9 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
25#include "ui/command.h" 25#include "ui/command.h"
26#include "ui/widget.h" 26#include "ui/widget.h"
27#include "ui/color.h" 27#include "ui/color.h"
28#include "ui/window.h"
29
30#include <SDL_timer.h>
28 31
29#import <AppKit/AppKit.h> 32#import <AppKit/AppKit.h>
30 33
@@ -217,7 +220,6 @@ static void appearanceChanged_MacOS_(NSString *name) {
217 } 220 }
218} 221}
219 222
220#if 1
221- (NSTouchBar *)makeTouchBar { 223- (NSTouchBar *)makeTouchBar {
222 NSTouchBar *bar = [[NSTouchBar alloc] init]; 224 NSTouchBar *bar = [[NSTouchBar alloc] init];
223 bar.delegate = self; 225 bar.delegate = self;
@@ -235,7 +237,6 @@ static void appearanceChanged_MacOS_(NSString *name) {
235 } 237 }
236 return bar; 238 return bar;
237} 239}
238#endif
239 240
240- (void)showPreferences { 241- (void)showPreferences {
241 postCommand_App("preferences"); 242 postCommand_App("preferences");
@@ -249,6 +250,11 @@ static void appearanceChanged_MacOS_(NSString *name) {
249 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]]; 250 NSString *command = [menuCommands objectForKey:[(NSMenuItem *)sender title]];
250 if (command) { 251 if (command) {
251 postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]); 252 postCommand_App([command cStringUsingEncoding:NSUTF8StringEncoding]);
253 /* Shouldn't double-activate menu items in case the same key is used in our widgets.
254 SDL ignores menu key equivalents so the keydown events will be posted regardless.
255 This is quite a kludge, but we can achieve this by taking advantage of Window's
256 focus-acquisition threshold for ignoring key events. */
257 get_Window()->focusGainedAt = SDL_GetTicks();
252 } 258 }
253} 259}
254 260
@@ -513,6 +519,12 @@ void insertMenuItems_MacOS(const char *menuLabel, int atIndex, const iMenuItem *
513 else if (items[i].key == SDLK_RIGHT) { 519 else if (items[i].key == SDLK_RIGHT) {
514 appendChar_String(&key, 0x2192); 520 appendChar_String(&key, 0x2192);
515 } 521 }
522 else if (items[i].key == SDLK_UP) {
523 appendChar_String(&key, 0x2191);
524 }
525 else if (items[i].key == SDLK_DOWN) {
526 appendChar_String(&key, 0x2193);
527 }
516 else if (items[i].key) { 528 else if (items[i].key) {
517 appendChar_String(&key, items[i].key); 529 appendChar_String(&key, items[i].key);
518 } 530 }