Skip to content

Commit

Permalink
bump to swift 5
Browse files Browse the repository at this point in the history
  • Loading branch information
dshnkao committed Jul 4, 2019
1 parent e3ffb2f commit 7593d9a
Show file tree
Hide file tree
Showing 11 changed files with 224 additions and 53 deletions.
5 changes: 1 addition & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
![](https://raw.githubusercontent.com/dshnkao/SpaceId/master/images/k.png)
![](https://raw.githubusercontent.com/dshnkao/SpaceId/master/images/l.png)

## Notes
* Only tested on macOS Sierra 10.12

## Credits
* This project is based on [WhichSpace](https://github.com/gechr/WhichSpace/).
* This project is inspired by [WhichSpace](https://github.com/gechr/WhichSpace/).
* Icon made by [Lucy G](http://bylucyg.com) from [FLATICON](http://www.flaticon.com) under [CC By 3.0](https://creativecommons.org/licenses/by/3.0/)
35 changes: 27 additions & 8 deletions SpaceId.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,13 +195,13 @@
isa = PBXProject;
attributes = {
LastSwiftUpdateCheck = 0820;
LastUpgradeCheck = 0820;
LastUpgradeCheck = 1020;
ORGANIZATIONNAME = "Dennis Kao";
TargetAttributes = {
19A7AC781E44D493004FBE39 = {
CreatedOnToolsVersion = 8.2.1;
DevelopmentTeam = VBQ33APC27;
LastSwiftMigration = 0820;
LastSwiftMigration = 1020;
ProvisioningStyle = Automatic;
};
19A7AC871E44D493004FBE39 = {
Expand All @@ -217,6 +217,7 @@
developmentRegion = English;
hasScannedForEncodings = 0;
knownRegions = (
English,
en,
Base,
);
Expand Down Expand Up @@ -300,20 +301,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -349,20 +359,29 @@
isa = XCBuildConfiguration;
buildSettings = {
ALWAYS_SEARCH_USER_PATHS = NO;
CLANG_ANALYZER_LOCALIZABILITY_NONLOCALIZED = YES;
CLANG_ANALYZER_NONNULL = YES;
CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x";
CLANG_CXX_LIBRARY = "libc++";
CLANG_ENABLE_MODULES = YES;
CLANG_ENABLE_OBJC_ARC = YES;
CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES;
CLANG_WARN_BOOL_CONVERSION = YES;
CLANG_WARN_COMMA = YES;
CLANG_WARN_CONSTANT_CONVERSION = YES;
CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES;
CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR;
CLANG_WARN_DOCUMENTATION_COMMENTS = YES;
CLANG_WARN_EMPTY_BODY = YES;
CLANG_WARN_ENUM_CONVERSION = YES;
CLANG_WARN_INFINITE_RECURSION = YES;
CLANG_WARN_INT_CONVERSION = YES;
CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES;
CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES;
CLANG_WARN_OBJC_LITERAL_CONVERSION = YES;
CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR;
CLANG_WARN_RANGE_LOOP_ANALYSIS = YES;
CLANG_WARN_STRICT_PROTOTYPES = YES;
CLANG_WARN_SUSPICIOUS_MOVE = YES;
CLANG_WARN_UNREACHABLE_CODE = YES;
CLANG_WARN__DUPLICATE_METHOD_MATCH = YES;
Expand Down Expand Up @@ -399,7 +418,7 @@
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SpaceId/SpaceId-Bridging-Header.h";
SWIFT_OPTIMIZATION_LEVEL = "-Onone";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Debug;
};
Expand All @@ -415,7 +434,7 @@
PRODUCT_BUNDLE_IDENTIFIER = com.dshnkao.SpaceId;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_OBJC_BRIDGING_HEADER = "SpaceId/SpaceId-Bridging-Header.h";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 5.0;
};
name = Release;
};
Expand All @@ -426,11 +445,11 @@
BUNDLE_LOADER = "$(TEST_HOST)";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = VBQ33APC27;
INFOPLIST_FILE = SpaceIdTests/Info.plist;
INFOPLIST_FILE = SpaceId/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dshnkao.SpaceIdTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpaceId.app/Contents/MacOS/SpaceId";
};
name = Debug;
Expand All @@ -442,11 +461,11 @@
BUNDLE_LOADER = "$(TEST_HOST)";
COMBINE_HIDPI_IMAGES = YES;
DEVELOPMENT_TEAM = VBQ33APC27;
INFOPLIST_FILE = SpaceIdTests/Info.plist;
INFOPLIST_FILE = SpaceId/Info.plist;
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/../Frameworks";
PRODUCT_BUNDLE_IDENTIFIER = com.dshnkao.SpaceIdTests;
PRODUCT_NAME = "$(TARGET_NAME)";
SWIFT_VERSION = 3.0;
SWIFT_VERSION = 4.2;
TEST_HOST = "$(BUILT_PRODUCTS_DIR)/SpaceId.app/Contents/MacOS/SpaceId";
};
name = Release;
Expand Down
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>BuildLocationStyle</key>
<string>UseAppPreferences</string>
<key>CustomBuildLocationType</key>
<string>RelativeToDerivedData</string>
<key>DerivedDataLocationStyle</key>
<string>Default</string>
<key>EnabledFullIndexStoreVisibility</key>
<false/>
<key>IssueFilterStyle</key>
<string>ShowActiveSchemeOnly</string>
<key>LiveSourceIssuesEnabled</key>
<true/>
</dict>
</plist>
101 changes: 101 additions & 0 deletions SpaceId.xcodeproj/xcshareddata/xcschemes/SpaceId.xcscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,101 @@
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "1020"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "YES"
buildForRunning = "YES"
buildForProfiling = "YES"
buildForArchiving = "YES"
buildForAnalyzing = "YES">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19A7AC781E44D493004FBE39"
BuildableName = "SpaceId.app"
BlueprintName = "SpaceId"
ReferencedContainer = "container:SpaceId.xcodeproj">
</BuildableReference>
</BuildActionEntry>
</BuildActionEntries>
</BuildAction>
<TestAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
shouldUseLaunchSchemeArgsEnv = "YES">
<Testables>
<TestableReference
skipped = "NO">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19A7AC871E44D493004FBE39"
BuildableName = "SpaceIdTests.xctest"
BlueprintName = "SpaceIdTests"
ReferencedContainer = "container:SpaceId.xcodeproj">
</BuildableReference>
</TestableReference>
</Testables>
<MacroExpansion>
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19A7AC781E44D493004FBE39"
BuildableName = "SpaceId.app"
BlueprintName = "SpaceId"
ReferencedContainer = "container:SpaceId.xcodeproj">
</BuildableReference>
</MacroExpansion>
<AdditionalOptions>
</AdditionalOptions>
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "NO"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
allowLocationSimulation = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19A7AC781E44D493004FBE39"
BuildableName = "SpaceId.app"
BlueprintName = "SpaceId"
ReferencedContainer = "container:SpaceId.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
<AdditionalOptions>
</AdditionalOptions>
</LaunchAction>
<ProfileAction
buildConfiguration = "Release"
shouldUseLaunchSchemeArgsEnv = "YES"
savedToolIdentifier = ""
useCustomWorkingDirectory = "NO"
debugDocumentVersioning = "YES">
<BuildableProductRunnable
runnableDebuggingMode = "0">
<BuildableReference
BuildableIdentifier = "primary"
BlueprintIdentifier = "19A7AC781E44D493004FBE39"
BuildableName = "SpaceId.app"
BlueprintName = "SpaceId"
ReferencedContainer = "container:SpaceId.xcodeproj">
</BuildableReference>
</BuildableProductRunnable>
</ProfileAction>
<AnalyzeAction
buildConfiguration = "Debug">
</AnalyzeAction>
<ArchiveAction
buildConfiguration = "Release"
revealArchiveInOrganizer = "YES">
</ArchiveAction>
</Scheme>
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>SchemeUserState</key>
<dict>
<key>SpaceId.xcscheme_^#shared#^_</key>
<dict>
<key>orderHint</key>
<integer>0</integer>
</dict>
</dict>
<key>SuppressBuildableAutocreation</key>
<dict>
<key>19A7AC781E44D493004FBE39</key>
<dict>
<key>primary</key>
<true/>
</dict>
<key>19A7AC871E44D493004FBE39</key>
<dict>
<key>primary</key>
<true/>
</dict>
</dict>
</dict>
</plist>
22 changes: 15 additions & 7 deletions SpaceId/Application/ButtonImage.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@ class ButtonImage {
}
}

private func textAttributes(color: NSColor) -> [String: Any] {
private func textAttributes(color: NSColor) -> [NSAttributedString.Key: Any] {
let font = NSFont.boldSystemFont(ofSize: 11)
let paragraphStyle = NSMutableParagraphStyle()
paragraphStyle.alignment = NSTextAlignment.center

return [ NSFontAttributeName: font,
NSForegroundColorAttributeName: color,
NSParagraphStyleAttributeName: paragraphStyle
] as [String : Any]
return [ .font: font,
.foregroundColor: color,
.paragraphStyle: paragraphStyle
]
}

private func blackOnWhite(text: String, alpha: CGFloat = 1) -> NSImage {
Expand Down Expand Up @@ -124,9 +124,17 @@ class ButtonImage {
}

extension NSString {
func drawVerticallyCentered(in rect: CGRect, withAttributes attributes: [String : Any]? = nil) {
func drawVerticallyCentered(
in rect: CGRect,
withAttributes attributes: [NSAttributedString.Key : Any]? = nil)
{
let size = self.size(withAttributes: attributes)
let centeredRect = CGRect(x: rect.origin.x, y: rect.origin.y + (rect.size.height-size.height)/2.0, width: rect.size.width, height: size.height)
let centeredRect = CGRect(
x: rect.origin.x,
y: rect.origin.y + (rect.size.height-size.height)/2.0,
width: rect.size.width,
height: size.height
)
self.draw(in: centeredRect, withAttributes: attributes)
}
}
18 changes: 9 additions & 9 deletions SpaceId/Application/Observer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import Foundation
class Observer {

let defaults = UserDefaults.standard
let center = NSWorkspace.shared().notificationCenter
let center = NSWorkspace.shared.notificationCenter
var workspace = false
var monitor = false
var activeApp: NSObjectProtocol?
Expand Down Expand Up @@ -32,35 +32,35 @@ class Observer {

private func addActiveWorkSpaceEvent(using: @escaping (Notification) -> Void) {
center.addObserver(
forName: NSNotification.Name.NSWorkspaceActiveSpaceDidChange,
object: nil,
queue: OperationQueue.main,
using: using)
forName: NSWorkspace.activeSpaceDidChangeNotification,
object: nil,
queue: OperationQueue.main,
using: using)
}

private func addMonitorEvent(using: @escaping (Notification) -> Void) {
center.addObserver(
forName: NSNotification.Name.NSApplicationDidChangeScreenParameters,
forName: NSApplication.didChangeScreenParametersNotification,
object: nil,
queue: OperationQueue.main,
using: using)
}

private func addActiveApplicationEvent(using: @escaping (Notification) -> Void) {
activeApp = center.addObserver(
forName: NSNotification.Name.NSWorkspaceDidActivateApplication,
forName: NSWorkspace.didActivateApplicationNotification,
object: nil,
queue: OperationQueue.main, using: using)
}

private func addLeftMouseClickEvent(handler: @escaping (NSEvent) -> Void) {
leftMouseClick = NSEvent.addGlobalMonitorForEvents(matching: NSEventMask.leftMouseDown, handler: handler)
leftMouseClick = NSEvent.addGlobalMonitorForEvents(matching: NSEvent.EventTypeMask.leftMouseDown, handler: handler)
}

private func removeActiveApplicationEvent() {
if let observer = activeApp {
center.removeObserver(observer,
name: NSNotification.Name.NSWorkspaceDidActivateApplication,
name: NSWorkspace.didActivateApplicationNotification,
object: nil)
activeApp = nil
}
Expand Down
6 changes: 3 additions & 3 deletions SpaceId/Application/SpaceIdentifier.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ class SpaceIdentifier {
typealias ScreenUUID = String

func getSpaceInfo() -> SpaceInfo {

let nskey = NSDeviceDescriptionKey(rawValue:("NSScreenNumber"))
guard let monitors = CGSCopyManagedDisplaySpaces(conn) as? [[String : Any]],
let mainDisplay = NSScreen.main(),
let screenNumber = mainDisplay.deviceDescription["NSScreenNumber"] as? UInt32
let mainDisplay = NSScreen.main,
let screenNumber = mainDisplay.deviceDescription[nskey] as? UInt32
else { return SpaceInfo(keyboardFocusSpace: nil, activeSpaces: [], allSpaces: []) }

let cfuuid = CGDisplayCreateUUIDFromDisplayID(screenNumber).takeRetainedValue()
Expand Down
Loading

0 comments on commit 7593d9a

Please sign in to comment.