Merge branch 'experimental' into 'experimental'

Option-Command Menu shortcuts

This adds an option modifier to all the SDL menu keyboard shortcuts (Command-Q to quit becomes Option+Command-Q).

See merge request !9
This commit is contained in:
Dagen Brock 2017-04-05 09:46:56 -05:00
commit 15e37c5de2
3 changed files with 42 additions and 19 deletions

26
src/fix_mac_menu.m Normal file
View File

@ -0,0 +1,26 @@
#import <Cocoa/Cocoa.h>
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];
}
}
}
}
}

View File

@ -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:
{

View File

@ -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 =