diff options
author | Michael Lutz <michi@icosahedron.de> | 2021-06-21 23:37:49 +0200 |
---|---|---|
committer | Michael Lutz <michi@icosahedron.de> | 2021-06-22 21:09:37 +0200 |
commit | 0d5d3083bd6f0f3c51b15d58a6cb525912e1b775 (patch) | |
tree | 5d76eeb4100c7ba023212b773c21a925983fe743 /src/video/cocoa/cocoa_v.mm | |
parent | 8c1b89e1079e411a2a87f2faae4c8546de6979de (diff) | |
download | openttd-0d5d3083bd6f0f3c51b15d58a6cb525912e1b775.tar.xz |
Codechange: [OSX] Use more exact enum names where introduced with the 10.12 SDK.
The enum values still have the exact same numerical values, but the 10.12
SDK introduced more explicit names (e.g. like NSEventTypeApplicationDefined
instead of NSApplicationDefined) for several enum constants.
Use them when available.
Diffstat (limited to 'src/video/cocoa/cocoa_v.mm')
-rw-r--r-- | src/video/cocoa/cocoa_v.mm | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/src/video/cocoa/cocoa_v.mm b/src/video/cocoa/cocoa_v.mm index 2a8737333..f43ea9b28 100644 --- a/src/video/cocoa/cocoa_v.mm +++ b/src/video/cocoa/cocoa_v.mm @@ -45,6 +45,17 @@ #import <sys/time.h> /* gettimeofday */ #include <array> +/* The 10.12 SDK added new names for some enum constants and + * deprecated the old ones. As there's no functional change in any + * way, just use a define for older SDKs to the old names. */ +#ifndef HAVE_OSX_1012_SDK +# define NSEventModifierFlagCommand NSCommandKeyMask +# define NSEventModifierFlagControl NSControlKeyMask +# define NSEventModifierFlagOption NSAlternateKeyMask +# define NSEventModifierFlagShift NSShiftKeyMask +# define NSEventModifierFlagCapsLock NSAlphaShiftKeyMask +#endif + /** * Important notice regarding all modifications!!!!!!! * There are certain limitations because the file is objective C++. @@ -360,7 +371,11 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) NSRect contentRect = NSMakeRect(0, 0, width, height); /* Create main window. */ +#ifdef HAVE_OSX_1012_SDK + unsigned int style = NSWindowStyleMaskTitled | NSWindowStyleMaskResizable | NSWindowStyleMaskMiniaturizable | NSWindowStyleMaskClosable; +#else unsigned int style = NSTitledWindowMask | NSResizableWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask; +#endif this->window = [ [ OTTD_CocoaWindow alloc ] initWithContentRect:contentRect styleMask:style backing:NSBackingStoreBuffered defer:NO driver:this ]; if (this->window == nil) { Debug(driver, 0, "Could not create the Cocoa window."); @@ -376,7 +391,7 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) behavior |= NSWindowCollectionBehaviorFullScreenPrimary; [ this->window setCollectionBehavior:behavior ]; - NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowFullScreenButton ]; + NSButton* fullscreenButton = [ this->window standardWindowButton:NSWindowZoomButton ]; [ fullscreenButton setAction:@selector(toggleFullScreen:) ]; [ fullscreenButton setTarget:this->window ]; } @@ -430,7 +445,12 @@ bool VideoDriver_Cocoa::MakeWindow(int width, int height) */ bool VideoDriver_Cocoa::PollEvent() { - NSEvent *event = [ NSApp nextEventMatchingMask:NSAnyEventMask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ]; +#ifdef HAVE_OSX_1012_SDK + NSEventMask mask = NSEventMaskAny; +#else + NSEventMask mask = NSAnyEventMask; +#endif + NSEvent *event = [ NSApp nextEventMatchingMask:mask untilDate:[ NSDate distantPast ] inMode:NSDefaultRunLoopMode dequeue:YES ]; if (event == nil) return false; @@ -445,8 +465,8 @@ void VideoDriver_Cocoa::InputLoop() bool old_ctrl_pressed = _ctrl_pressed; - _ctrl_pressed = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSControlKeyMask : NSCommandKeyMask)) != 0; - _shift_pressed = (cur_mods & NSShiftKeyMask) != 0; + _ctrl_pressed = (cur_mods & ( _settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? NSEventModifierFlagControl : NSEventModifierFlagCommand)) != 0; + _shift_pressed = (cur_mods & NSEventModifierFlagShift) != 0; #if defined(_DEBUG) this->fast_forward_key_pressed = _shift_pressed; |