Skip to content

Commit

Permalink
feat: easier back-cycling shortcut (#420)
Browse files Browse the repository at this point in the history
fix: correct layout for right-to-left languages
  • Loading branch information
lwouis committed Jul 20, 2020
1 parent 961b7e5 commit a14b3fa
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/logic/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Preferences {
"fontHeight": "15",
"holdShortcut": "",
"nextWindowShortcut": "",
"previousWindowShortcut": "",
"previousWindowShortcut": "",
"cancelShortcut": "",
"closeWindowShortcut": "W",
"minDeminWindowShortcut": "M",
Expand Down
10 changes: 5 additions & 5 deletions src/ui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ class App: NSApplication, NSApplicationDelegate {

@objc func showUi() {
appIsBeingUsed = true
DispatchQueue.main.async { () -> () in self.showUiOrCycleSelection(.neutral) }
DispatchQueue.main.async { () -> () in self.showUiOrCycleSelection() }
}

func cycleSelection(_ direction: Direction) {
Expand Down Expand Up @@ -215,8 +215,8 @@ class App: NSApplication, NSApplicationDelegate {
}
}

func showUiOrCycleSelection(_ direction: Direction) {
debugPrint("showUiOrCycleSelection", direction)
func showUiOrCycleSelection() {
debugPrint("showUiOrCycleSelection")
if isFirstSummon {
debugPrint("showUiOrCycleSelection: isFirstSummon")
isFirstSummon = false
Expand All @@ -234,12 +234,12 @@ class App: NSApplication, NSApplicationDelegate {
Windows.refreshWhichWindowsToShowTheUser(screen)
if (!Windows.list.contains { $0.shouldShowTheUser }) { hideUi(); return }
Windows.updateFocusedWindowIndex(0)
Windows.cycleFocusedWindowIndex(direction.step())
Windows.cycleFocusedWindowIndex(1)
DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + Preferences.windowDisplayDelay) { () -> () in
self.rebuildUi()
}
} else {
cycleSelection(direction)
cycleSelection(.leading)
}
}

Expand Down
11 changes: 3 additions & 8 deletions src/ui/main-window/ThumbnailsView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -231,24 +231,19 @@ class FlippedView: NSView {
}

enum Direction {
case neutral
case left
case right
case left
case leading
case trailing
case up
case down

func step() -> Int {
if self == .left {
return -1
return App.shared.userInterfaceLayoutDirection == .leftToRight ? -1 : 1
} else if self == .right {
return 1
} else if self == .leading {
return App.shared.userInterfaceLayoutDirection == .leftToRight ? 1 : -1
} else if self == .trailing {
return App.shared.userInterfaceLayoutDirection == .leftToRight ? -1 : 1
}
return 0
return self == .leading ? 1 : -1
}
}
23 changes: 14 additions & 9 deletions src/ui/preferences-window/tabs/GeneralTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ class GeneralTab: NSViewController, PreferencePane {
static var shortcutsDependentOnHoldShortcut = [NSControl]()
static var shortcutsActionsBlocks = [
"holdShortcut": { App.app.focusTarget() },
"nextWindowShortcut": { App.app.showUiOrCycleSelection(.right) },
"previousWindowShortcut": { App.app.showUiOrCycleSelection(.left) },
"": { App.app.cycleSelection(.leading) },
"": { App.app.cycleSelection(.trailing) },
"nextWindowShortcut": { App.app.showUiOrCycleSelection() },
"previousWindowShortcut": { App.app.cycleSelection(.trailing) },
"": { App.app.cycleSelection(.right) },
"": { App.app.cycleSelection(.left) },
"": { App.app.cycleSelection(.up) },
"": { App.app.cycleSelection(.down) },
"cancelShortcut": { App.app.hideUi() },
Expand All @@ -28,7 +28,7 @@ class GeneralTab: NSViewController, PreferencePane {
let startAtLogin = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Start at login:", comment: ""), "startAtLogin", extraAction: startAtLoginCallback)
let hideMenubarIcon = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Hide menubar icon:", comment: ""), "hideMenubarIcon", extraAction: hideMenubarIconCallback)
var holdShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hold", comment: ""), "holdShortcut", Preferences.holdShortcut, false, labelPosition: .leftWithoutSeparator)
holdShortcut.append(LabelAndControl.makeLabel(NSLocalizedString("then press:", comment: "")))
holdShortcut.append(LabelAndControl.makeLabel(NSLocalizedString("and press:", comment: "")))
let nextWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select next window", comment: ""), "nextWindowShortcut", Preferences.nextWindowShortcut, labelPosition: .right)
let previousWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select previous window", comment: ""), "previousWindowShortcut", Preferences.previousWindowShortcut, labelPosition: .right)
let cancelShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Cancel and hide", comment: ""), "cancelShortcut", Preferences.cancelShortcut, labelPosition: .right)
Expand All @@ -47,7 +47,10 @@ class GeneralTab: NSViewController, PreferencePane {
let showFullscreenWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Fullscreen", comment: ""), "showFullscreenWindows", labelPosition: .right))
let showMinimizedWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Minimized", comment: ""), "showMinimizedWindows", labelPosition: .right))
let showHiddenWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Hidden", comment: ""), "showHiddenWindows", labelPosition: .right))
let shortcuts = StackView([nextWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
let shortcuts = StackView([previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
let thenRelease = LabelAndControl.makeLabel(NSLocalizedString("then release:", comment: ""))
let orPress = LabelAndControl.makeLabel(NSLocalizedString("or press:", comment: ""))
let focusSelectedWindow = LabelAndControl.makeLabel(NSLocalizedString("Focus selected window", comment: ""))
let toShowDropdowns = StackView([appsToShow, spacesToShow, screensToShow], .vertical)
let toShowCheckboxes = StackView([showMinimizedWindows, showHiddenWindows, showFullscreenWindows], .vertical)
let toShowExplanations = LabelAndControl.makeLabel(NSLocalizedString("Show the following windows:", comment: ""))
Expand All @@ -56,12 +59,14 @@ class GeneralTab: NSViewController, PreferencePane {
let grid = GridView([
startAtLogin,
hideMenubarIcon,
[holdAndPress, shortcuts],
[holdAndPress, StackView(nextWindowShortcut)],
[thenRelease, focusSelectedWindow],
[orPress, shortcuts],
[checkboxesExplanations, checkboxes],
[toShowExplanations, toShow],
])
grid.column(at: 0).xPlacement = .trailing
[2, 3, 4].forEach { grid.row(at: $0).topPadding = GridView.interPadding }
[2, 5, 6].forEach { grid.row(at: $0).topPadding = GridView.interPadding }
grid.fit()

GeneralTab.shortcutsDependentOnHoldShortcut.append(contentsOf: [enableArrows[0] as! NSControl] +
Expand All @@ -81,7 +86,7 @@ class GeneralTab: NSViewController, PreferencePane {
private static func addShortcut(_ type: KeyEventType, _ shortcut: Shortcut, _ controlId: String) {
removeShortcutIfExists(controlId, type) // remove the previous shortcut
shortcutActions[controlId] = ShortcutAction(shortcut: shortcut, actionHandler: { _ in
let isShortcutInitiatingTheApp = ["previousWindowShortcut", "nextWindowShortcut"].contains(controlId)
let isShortcutInitiatingTheApp = controlId == "nextWindowShortcut"
if isShortcutInitiatingTheApp {
App.app.appIsBeingUsed = true
}
Expand Down

0 comments on commit a14b3fa

Please sign in to comment.