1
mirror of https://github.com/mpv-player/mpv synced 2024-11-03 03:19:24 +01:00

cocoa: fix macOS 10.12 deprecation warnings

This commit is contained in:
Akemi 2016-09-20 23:30:54 +02:00 committed by wm4
parent 78b3852f7e
commit 9df797575f
4 changed files with 45 additions and 12 deletions

View File

@ -24,6 +24,31 @@
#import <Cocoa/Cocoa.h>
#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;

View File

@ -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];
}

View File

@ -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 */

View File

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