From 9df797575fc771f87dc6bedf89b46aab3236a21f Mon Sep 17 00:00:00 2001 From: Akemi Date: Tue, 20 Sep 2016 23:30:54 +0200 Subject: cocoa: fix macOS 10.12 deprecation warnings --- osdep/macosx_compat.h | 25 +++++++++++++++++++++++++ osdep/macosx_events.m | 18 +++++++++--------- osdep/macosx_versions.h | 8 ++++++++ video/out/cocoa_common.m | 6 +++--- 4 files changed, 45 insertions(+), 12 deletions(-) diff --git a/osdep/macosx_compat.h b/osdep/macosx_compat.h index 9775529bc6..76308c6f98 100644 --- a/osdep/macosx_compat.h +++ b/osdep/macosx_compat.h @@ -24,6 +24,31 @@ #import #include "osdep/macosx_versions.h" +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12) +typedef NSUInteger NSWindowStyleMask; +static const NSWindowStyleMask NSWindowStyleMaskClosable = NSClosableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskTitled = NSTitledWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskMiniaturizable = NSMiniaturizableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskResizable = NSResizableWindowMask; +static const NSWindowStyleMask NSWindowStyleMaskBorderless = NSBorderlessWindowMask; + +static const NSEventType NSEventTypeSystemDefined = NSSystemDefined; +static const NSEventType NSEventTypeKeyDown = NSKeyDown; +static const NSEventType NSEventTypeKeyUp = NSKeyUp; + +static const NSEventMask NSEventMaskKeyDown = NSKeyDownMask; +static const NSEventMask NSEventMaskKeyUp = NSKeyUpMask; + +#if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_10) +typedef NSUInteger NSEventModifierFlags; +#endif + +static const NSEventModifierFlags NSEventModifierFlagShift = NSShiftKeyMask; +static const NSEventModifierFlags NSEventModifierFlagControl = NSControlKeyMask; +static const NSEventModifierFlags NSEventModifierFlagCommand = NSCommandKeyMask; +static const NSEventModifierFlags NSEventModifierFlagOption = NSAlternateKeyMask; +#endif + #if (MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_8) @interface NSArray (SubscriptingAdditions) - (id)objectAtIndexedSubscript:(NSUInteger)index; diff --git a/osdep/macosx_events.m b/osdep/macosx_events.m index 6090a1937e..6ad22584dc 100644 --- a/osdep/macosx_events.m +++ b/osdep/macosx_events.m @@ -60,8 +60,8 @@ @end -#define NSLeftAlternateKeyMask (0x000020 | NSAlternateKeyMask) -#define NSRightAlternateKeyMask (0x000040 | NSAlternateKeyMask) +#define NSLeftAlternateKeyMask (0x000020 | NSEventModifierFlagOption) +#define NSRightAlternateKeyMask (0x000040 | NSEventModifierFlagOption) static bool LeftAltPressed(int mask) { @@ -163,7 +163,7 @@ static CGEventRef tap_event_callback(CGEventTapProxy proxy, CGEventType type, NSEvent *nse = [NSEvent eventWithCGEvent:event]; - if ([nse type] != NSSystemDefined || [nse subtype] != 8) + if ([nse type] != NSEventTypeSystemDefined || [nse subtype] != 8) // This is not a media key return event; @@ -285,7 +285,7 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (void)startEventMonitor { - [NSEvent addLocalMonitorForEventsMatchingMask:NSKeyDownMask|NSKeyUpMask + [NSEvent addLocalMonitorForEventsMatchingMask:NSEventMaskKeyDown|NSEventMaskKeyUp handler:^(NSEvent *event) { BOOL equivalent = [[NSApp mainMenu] performKeyEquivalent:event]; if (equivalent) { @@ -395,14 +395,14 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (int)mapKeyModifiers:(int)cocoaModifiers { int mask = 0; - if (cocoaModifiers & NSShiftKeyMask) + if (cocoaModifiers & NSEventModifierFlagShift) mask |= MP_KEY_MODIFIER_SHIFT; - if (cocoaModifiers & NSControlKeyMask) + if (cocoaModifiers & NSEventModifierFlagControl) mask |= MP_KEY_MODIFIER_CTRL; if (LeftAltPressed(cocoaModifiers) || (RightAltPressed(cocoaModifiers) && ![self useAltGr])) mask |= MP_KEY_MODIFIER_ALT; - if (cocoaModifiers & NSCommandKeyMask) + if (cocoaModifiers & NSEventModifierFlagCommand) mask |= MP_KEY_MODIFIER_META; return mask; } @@ -410,8 +410,8 @@ void cocoa_set_input_context(struct input_ctx *input_context) - (int)mapTypeModifiers:(NSEventType)type { NSDictionary *map = @{ - @(NSKeyDown) : @(MP_KEY_STATE_DOWN), - @(NSKeyUp) : @(MP_KEY_STATE_UP), + @(NSEventTypeKeyDown) : @(MP_KEY_STATE_DOWN), + @(NSEventTypeKeyUp) : @(MP_KEY_STATE_UP), }; return [map[@(type)] intValue]; } diff --git a/osdep/macosx_versions.h b/osdep/macosx_versions.h index 83bcf5ddd7..f4c49ab4e3 100644 --- a/osdep/macosx_versions.h +++ b/osdep/macosx_versions.h @@ -26,4 +26,12 @@ # define MAC_OS_X_VERSION_10_9 1090 #endif +#if !defined(MAC_OS_X_VERSION_10_10) +# define MAC_OS_X_VERSION_10_10 101000 +#endif + +#if !defined(MAC_OS_X_VERSION_10_12) +# define MAC_OS_X_VERSION_10_12 101200 +#endif + #endif /* MPV_MACOSX_VERSIONS */ diff --git a/video/out/cocoa_common.m b/video/out/cocoa_common.m index 18e6860e7d..9690ddb10f 100644 --- a/video/out/cocoa_common.m +++ b/video/out/cocoa_common.m @@ -458,10 +458,10 @@ static MpvVideoWindow *create_window(NSRect rect, NSScreen *s, bool border, { int window_mask = 0; if (border) { - window_mask = NSTitledWindowMask|NSClosableWindowMask| - NSMiniaturizableWindowMask|NSResizableWindowMask; + window_mask = NSWindowStyleMaskTitled|NSWindowStyleMaskClosable| + NSWindowStyleMaskMiniaturizable|NSWindowStyleMaskResizable; } else { - window_mask = NSBorderlessWindowMask|NSResizableWindowMask; + window_mask = NSWindowStyleMaskBorderless|NSWindowStyleMaskResizable; } MpvVideoWindow *w = -- cgit v1.2.3