aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomáš Znamenáček2016-10-28 14:40:32 +0200
committerTomáš Znamenáček2016-10-28 14:40:32 +0200
commitf12ed861b095d0734173948594202e25ee7e926d (patch)
tree70529b576a710a13fe84fd591328c9de6b9bbc80
parentbf4329178d3982f25be96ff3156477349e6bc25d (diff)
downloadMASShortcut-f12ed861b095d0734173948594202e25ee7e926d.tar.bz2
Use modern key mask constants instead of the ones deprecated in 10.12
See #99 for details.
-rw-r--r--Demo/AppDelegate.m2
-rw-r--r--Framework/MASKeyCodes.h11
-rw-r--r--Framework/MASKeyMasks.h16
-rw-r--r--MASShortcut.xcodeproj/project.pbxproj4
4 files changed, 27 insertions, 6 deletions
diff --git a/Demo/AppDelegate.m b/Demo/AppDelegate.m
index 6a5dd03..d9e5727 100644
--- a/Demo/AppDelegate.m
+++ b/Demo/AppDelegate.m
@@ -83,7 +83,7 @@ static void *MASObservingContext = &MASObservingContext;
- (void) setHardcodedShortcutEnabled: (BOOL) enabled
{
- MASShortcut *shortcut = [MASShortcut shortcutWithKeyCode:kVK_F2 modifierFlags:NSCommandKeyMask];
+ MASShortcut *shortcut = [MASShortcut shortcutWithKeyCode:kVK_F2 modifierFlags:NSEventModifierFlagCommand];
if (enabled) {
[[MASShortcutMonitor sharedMonitor] registerShortcut:shortcut withAction:^{
[self playShortcutFeedback];
diff --git a/Framework/MASKeyCodes.h b/Framework/MASKeyCodes.h
index 989c942..b6b53fe 100644
--- a/Framework/MASKeyCodes.h
+++ b/Framework/MASKeyCodes.h
@@ -1,5 +1,6 @@
#import <Carbon/Carbon.h>
#import <AppKit/AppKit.h>
+#import "MASKeyCodes.h"
// These glyphs are missed in Carbon.h
enum {
@@ -30,14 +31,14 @@ NS_INLINE NSString* NSStringFromMASKeyCode(unsigned short ch)
NS_INLINE NSUInteger MASPickCocoaModifiers(NSUInteger flags)
{
- return (flags & (NSControlKeyMask | NSShiftKeyMask | NSAlternateKeyMask | NSCommandKeyMask));
+ return (flags & (NSEventModifierFlagControl | NSEventModifierFlagShift | NSEventModifierFlagOption | NSEventModifierFlagCommand));
}
NS_INLINE UInt32 MASCarbonModifiersFromCocoaModifiers(NSUInteger cocoaFlags)
{
return
- (cocoaFlags & NSCommandKeyMask ? cmdKey : 0)
- | (cocoaFlags & NSAlternateKeyMask ? optionKey : 0)
- | (cocoaFlags & NSControlKeyMask ? controlKey : 0)
- | (cocoaFlags & NSShiftKeyMask ? shiftKey : 0);
+ (cocoaFlags & NSEventModifierFlagCommand ? cmdKey : 0)
+ | (cocoaFlags & NSEventModifierFlagOption ? optionKey : 0)
+ | (cocoaFlags & NSEventModifierFlagControl ? controlKey : 0)
+ | (cocoaFlags & NSEventModifierFlagShift ? shiftKey : 0);
}
diff --git a/Framework/MASKeyMasks.h b/Framework/MASKeyMasks.h
new file mode 100644
index 0000000..1c3a0b9
--- /dev/null
+++ b/Framework/MASKeyMasks.h
@@ -0,0 +1,16 @@
+// https://github.com/shpakovski/MASShortcut/issues/99
+//
+// Long story short: NSControlKeyMask and friends were replaced with NSEventModifierFlagControl
+// and similar in macOS Sierra. The project builds fine & clean, but including MASShortcut in
+// a project with deployment target set to 10.12 results in several deprecation warnings because
+// of the control masks. Simply replacing the old symbols with the new ones isn’t an option,
+// since it breaks the build on older SDKs – in Travis, for example.
+//
+// It should be safe to remove this whole thing once the 10.12 SDK is ubiquitous.
+//
+#if MAC_OS_X_VERSION_MAX_ALLOWED < MAC_OS_X_VERSION_10_12
+#define NSEventModifierFlagCommand NSCommandKeyMask
+#define NSEventModifierFlagControl NSControlKeyMask
+#define NSEventModifierFlagOption NSAlternateKeyMask
+#define NSEventModifierFlagShift NSShiftKeyMask
+#endif
diff --git a/MASShortcut.xcodeproj/project.pbxproj b/MASShortcut.xcodeproj/project.pbxproj
index 7147d3a..74af59c 100644
--- a/MASShortcut.xcodeproj/project.pbxproj
+++ b/MASShortcut.xcodeproj/project.pbxproj
@@ -33,6 +33,7 @@
0D827D9F19911A190010B8EF /* MASShortcutValidator.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D827D9D19911A190010B8EF /* MASShortcutValidator.m */; };
0D827DA519912D240010B8EF /* MASShortcutMonitor.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D827DA319912D240010B8EF /* MASShortcutMonitor.h */; settings = {ATTRIBUTES = (Public, ); }; };
0D827DAD199132840010B8EF /* MASShortcutBinder.h in Headers */ = {isa = PBXBuildFile; fileRef = 0D827DAB199132840010B8EF /* MASShortcutBinder.h */; settings = {ATTRIBUTES = (Public, ); }; };
+ 0DA8BCFC1DC37D8000C96EB9 /* MASKeyMasks.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DA8BCFB1DC37D8000C96EB9 /* MASKeyMasks.h */; };
0DC2F17619922798003A0131 /* MASHotKey.h in Headers */ = {isa = PBXBuildFile; fileRef = 0DC2F17419922798003A0131 /* MASHotKey.h */; };
0DC2F17719922798003A0131 /* MASHotKey.m in Sources */ = {isa = PBXBuildFile; fileRef = 0DC2F17519922798003A0131 /* MASHotKey.m */; };
0DC2F17C199232EA003A0131 /* MASShortcutMonitor.m in Sources */ = {isa = PBXBuildFile; fileRef = 0D827DA419912D240010B8EF /* MASShortcutMonitor.m */; };
@@ -114,6 +115,7 @@
0D827DA419912D240010B8EF /* MASShortcutMonitor.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASShortcutMonitor.m; path = Framework/MASShortcutMonitor.m; sourceTree = "<group>"; };
0D827DAB199132840010B8EF /* MASShortcutBinder.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MASShortcutBinder.h; path = Framework/MASShortcutBinder.h; sourceTree = "<group>"; };
0D827DAC199132840010B8EF /* MASShortcutBinder.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASShortcutBinder.m; path = Framework/MASShortcutBinder.m; sourceTree = "<group>"; };
+ 0DA8BCFB1DC37D8000C96EB9 /* MASKeyMasks.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MASKeyMasks.h; path = Framework/MASKeyMasks.h; sourceTree = "<group>"; };
0DC2F17419922798003A0131 /* MASHotKey.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = MASHotKey.h; path = Framework/MASHotKey.h; sourceTree = "<group>"; };
0DC2F17519922798003A0131 /* MASHotKey.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASHotKey.m; path = Framework/MASHotKey.m; sourceTree = "<group>"; };
0DC2F18819925F8F003A0131 /* MASShortcutBinderTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = MASShortcutBinderTests.m; path = Framework/MASShortcutBinderTests.m; sourceTree = "<group>"; };
@@ -237,6 +239,7 @@
0D827DA019912A660010B8EF /* Model */ = {
isa = PBXGroup;
children = (
+ 0DA8BCFB1DC37D8000C96EB9 /* MASKeyMasks.h */,
0D827D9619910FF70010B8EF /* MASKeyCodes.h */,
0D827D1B1990D55E0010B8EF /* MASShortcut.h */,
0D827D1C1990D55E0010B8EF /* MASShortcut.m */,
@@ -300,6 +303,7 @@
0DC2F19819938EFA003A0131 /* MASShortcutView+Bindings.h in Headers */,
0D827D9E19911A190010B8EF /* MASShortcutValidator.h in Headers */,
0DC2F18D1993708A003A0131 /* MASDictionaryTransformer.h in Headers */,
+ 0DA8BCFC1DC37D8000C96EB9 /* MASKeyMasks.h in Headers */,
0D827DA519912D240010B8EF /* MASShortcutMonitor.h in Headers */,
0D827DAD199132840010B8EF /* MASShortcutBinder.h in Headers */,
0D2CAB191B8339F4005431FC /* MASLocalization.h in Headers */,