From 98cc8b1223ee3fb885ecbbe1ef3efdf6bcb2c554 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 10 Feb 2017 20:06:11 -0500 Subject: [PATCH] tweak the apple menu bar to add option-key to all key equivalents. Eg, Command-Q => Option+Command-Q --- src/fix_mac_menu.m | 26 ++++++++++++++++++++++++++ src/sdl2_driver.c | 23 ++++++++++------------- src/vars_osx_sdl2 | 12 ++++++------ 3 files changed, 42 insertions(+), 19 deletions(-) create mode 100644 src/fix_mac_menu.m diff --git a/src/fix_mac_menu.m b/src/fix_mac_menu.m new file mode 100644 index 0000000..a8aaf8d --- /dev/null +++ b/src/fix_mac_menu.m @@ -0,0 +1,26 @@ + +#import + + +void fix_mac_menu(void) { + + /* + * add an option-key modifier to all menu shortcuts + * eg, command-Q -> option+command-Q + */ + + @autoreleasepool { + if (NSApp) { + NSMenu *menu = [NSApp mainMenu]; + + for (NSMenuItem *a in [menu itemArray]) { + for (NSMenuItem *b in [[a submenu] itemArray]) { + unsigned m = [b keyEquivalentModifierMask]; + if (m & NSEventModifierFlagCommand) + [b setKeyEquivalentModifierMask: m | NSEventModifierFlagOption]; + } + } + } + } + +} diff --git a/src/sdl2_driver.c b/src/sdl2_driver.c index 031f7cf..d2038f4 100644 --- a/src/sdl2_driver.c +++ b/src/sdl2_driver.c @@ -288,6 +288,11 @@ void do_icon() { void dev_video_init_sdl() { SDL_Init(SDL_INIT_VIDEO); // Initialize SDL2 + #if defined __APPLE__ + extern void fix_mac_menu(); + fix_mac_menu(); + #endif + // Create an application window with the following settings: char window_title[32]; sprintf(window_title, "GSplus v%-6s", g_gsplus_version_str), @@ -439,19 +444,11 @@ void check_input_events_sdl() { motion |= handle_sdl_mouse_motion_event(event); break; case SDL_QUIT: - { - const Uint8 *state = SDL_GetKeyboardState(NULL); - if (state[SDL_SCANCODE_Q]) { - glog("Skipping keyboard quit event. Not allowed."); - } else { - //quit = 1; /* SDL_QUIT event (window close) */ - SDL_DestroyWindow(window); - iwm_shut(); - // Clean up - SDL_Quit(); - my_exit(1); - } - } + SDL_DestroyWindow(window); + iwm_shut(); + // Clean up + SDL_Quit(); + my_exit(1); break; case SDL_DROPFILE: { diff --git a/src/vars_osx_sdl2 b/src/vars_osx_sdl2 index 34a6d30..be7462c 100644 --- a/src/vars_osx_sdl2 +++ b/src/vars_osx_sdl2 @@ -5,17 +5,17 @@ CC = clang LD = clang++ AS = cc -OBJECTS = $(OBJECTS1) $(TFEOBJ) $(ATOBJ) $(PCAPOBJ) $(FSTOBJ) sdl2_driver.o sdl2snd_driver.o +OBJECTS = $(OBJECTS1) $(TFEOBJ) $(ATOBJ) $(PCAPOBJ) $(FSTOBJ) sdl2_driver.o sdl2snd_driver.o fix_mac_menu.o ARCHS = ppc, i386, ppc64, x86_64 # OPTIONS FOR COMPILING C SOURCE -CCOPTS = -O2 -Wall -fomit-frame-pointer -std=gnu99 -DHAVE_ICON -DHAVE_SDL -DTOGGLE_STATUS -I/usr/local/include/SDL2 +CCOPTS = -O2 -Wall -fomit-frame-pointer -std=gnu99 -DHAVE_ICON -DHAVE_SDL -DTOGGLE_STATUS `sdl2-config --cflags` # OPTIONS FOR COMPILING C++ SOURCE -CPPOPTS = -O2 -DHAVE_TFE -DHAVE_SDL -DTOGGLE_STATUS -I/usr/local/include/freetype2 -I/usr/local/include/SDL2 +CPPOPTS = -O2 -DHAVE_TFE -DHAVE_SDL -DTOGGLE_STATUS `freetype-config --cflags` `sdl2-config --cflags` -EXTRA_LIBS = -lSDL2 -lSDL2_image -lfreetype +EXTRA_LIBS = -lSDL2_image OPTS = -DGSPLUS_LITTLE_ENDIAN -g SUFFIX = -LDFLAGS = `sdl2-config --static-libs` -L/usr/local/lib -LDOPTS = -I. +LDFLAGS = `sdl2-config --static-libs` `freetype-config --libs` -framework Cocoa +LDOPTS = EXTRA_SPECIALS =