Skip to content

Commit

Permalink
Merge pull request #16 from creasty/witch
Browse files Browse the repository at this point in the history
Support Witch
  • Loading branch information
creasty authored Jul 30, 2019
2 parents 17a7eb5 + c3be76d commit 824d543
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
8 changes: 7 additions & 1 deletion keyboard/AppComponent.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,14 @@ final class AppComponent {

let nsWorkspace = NSWorkspace.shared

let fileManager = FileManager.default

func navigationHandler() -> Handler {
return NavigationHandler(workspace: nsWorkspace, emitter: emitter)
return NavigationHandler(
workspace: nsWorkspace,
fileManager: fileManager,
emitter: emitter
)
}

func emacsHandler() -> Handler {
Expand Down
52 changes: 46 additions & 6 deletions keyboard/Handlers/NavigationHandler.swift
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import Cocoa

private let witch3BundleId = "com.manytricks.WitchWrapper"
private let witch4PrefPanePath = "Library/PreferencePanes/Witch.prefPane"

// Window/Space navigations:
//
// S+H Move to left space
Expand All @@ -12,10 +15,31 @@ import Cocoa
//
final class NavigationHandler: Handler, ApplicationLaunchable {
let workspace: NSWorkspace
private let fileManager: FileManager
private let emitter: EmitterType

init(workspace: NSWorkspace, emitter: EmitterType) {
private var homeDirectory: URL {
if #available(OSX 10.12, *) {
return fileManager.homeDirectoryForCurrentUser
} else {
return URL(fileURLWithPath: NSHomeDirectory())
}
}

private lazy var hasWitch3: Bool = {
return workspace.absolutePathForApplication(withBundleIdentifier: witch3BundleId) != nil
}()
private lazy var hasWitch4: Bool = {
let prefPath = homeDirectory.appendingPathComponent(witch4PrefPanePath, isDirectory: false).path
return fileManager.fileExists(atPath: prefPath)
}()
private lazy var hasWitch: Bool = {
return hasWitch4 || hasWitch3
}()

init(workspace: NSWorkspace, fileManager: FileManager, emitter: EmitterType) {
self.workspace = workspace
self.fileManager = fileManager
self.emitter = emitter
}

Expand All @@ -35,19 +59,35 @@ final class NavigationHandler: Handler, ApplicationLaunchable {
emitter.emit(code: .leftArrow, flags: [.maskControl, .maskSecondaryFn])
return true
case [.j]:
emitter.emit(code: .tab, flags: [.maskCommand])
if hasWitch {
emitter.emit(code: .tab, flags: [.maskAlternate])
} else {
emitter.emit(code: .tab, flags: [.maskCommand])
}
return true
case [.k]:
emitter.emit(code: .tab, flags: [.maskCommand, .maskShift])
if hasWitch {
emitter.emit(code: .tab, flags: [.maskAlternate, .maskShift])
} else {
emitter.emit(code: .tab, flags: [.maskCommand, .maskShift])
}
return true
case [.l]:
emitter.emit(code: .rightArrow, flags: [.maskControl, .maskSecondaryFn])
return true
case [.n]:
emitter.emit(code: .f1, flags: [.maskCommand])
if hasWitch {
emitter.emit(code: .tab, flags: [.maskControl, .maskAlternate])
} else {
emitter.emit(code: .f1, flags: [.maskCommand])
}
return true
case [.b]:
emitter.emit(code: .f1, flags: [.maskCommand, .maskShift])
case [.b], [.p]:
if hasWitch {
emitter.emit(code: .tab, flags: [.maskControl, .maskAlternate, .maskShift])
} else {
emitter.emit(code: .f1, flags: [.maskCommand, .maskShift])
}
return true
case [.m]:
showOrHideApplication("com.apple.exposelauncher")
Expand Down

0 comments on commit 824d543

Please sign in to comment.