From 2a9c33b0780c2b8f4e23ef2d050f7e4da56f1e2e Mon Sep 17 00:00:00 2001 From: Louis Pontoise Date: Sat, 5 Sep 2020 02:35:15 +0900 Subject: [PATCH] feat: allow per-shortcut release action preference (closes #573) --- resources/l10n/Localizable.strings | 2 +- resources/l10n/ar.lproj/Localizable.strings | 2 +- resources/l10n/de.lproj/Localizable.strings | 2 +- resources/l10n/en.lproj/Localizable.strings | 2 +- resources/l10n/es.lproj/Localizable.strings | 2 +- resources/l10n/fi.lproj/Localizable.strings | 2 +- resources/l10n/fr.lproj/Localizable.strings | 2 +- resources/l10n/hu.lproj/Localizable.strings | 2 +- resources/l10n/id.lproj/Localizable.strings | 2 +- resources/l10n/it.lproj/Localizable.strings | 2 +- resources/l10n/ja.lproj/Localizable.strings | 2 +- resources/l10n/ko.lproj/Localizable.strings | 2 +- resources/l10n/lb.lproj/Localizable.strings | 2 +- resources/l10n/nl.lproj/Localizable.strings | 2 +- resources/l10n/no.lproj/Localizable.strings | 2 +- resources/l10n/pl.lproj/Localizable.strings | 2 +- resources/l10n/pt-BR.lproj/Localizable.strings | 2 +- resources/l10n/pt.lproj/Localizable.strings | 2 +- resources/l10n/ru.lproj/Localizable.strings | 2 +- resources/l10n/tr.lproj/Localizable.strings | 2 +- resources/l10n/zh-CN.lproj/Localizable.strings | 2 +- resources/l10n/zh-TW.lproj/Localizable.strings | 2 +- src/logic/Preferences.swift | 3 ++- src/logic/events/KeyboardEvents.swift | 4 ++-- src/ui/preferences-window/tabs/ControlsTab.swift | 4 ++-- 25 files changed, 28 insertions(+), 27 deletions(-) diff --git a/resources/l10n/Localizable.strings b/resources/l10n/Localizable.strings index d2438989..e26715b3 100644 --- a/resources/l10n/Localizable.strings +++ b/resources/l10n/Localizable.strings @@ -299,7 +299,7 @@ "Theme:" = "Theme:"; /* No comment provided by engineer. */ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /* No comment provided by engineer. */ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/ar.lproj/Localizable.strings b/resources/l10n/ar.lproj/Localizable.strings index ac12d3cc..e1bcb475 100644 --- a/resources/l10n/ar.lproj/Localizable.strings +++ b/resources/l10n/ar.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "المظهر:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/de.lproj/Localizable.strings b/resources/l10n/de.lproj/Localizable.strings index b5143e79..ee43382f 100644 --- a/resources/l10n/de.lproj/Localizable.strings +++ b/resources/l10n/de.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Thema:"; /*No comment provided by engineer.*/ -"then release:" = "dann loslassen:"; +"Then release:" = "Dann loslassen:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Diese Erlaubnis ist nötig um Fenster nach dem Drücken des Tastenkürzels anzuzeigen"; diff --git a/resources/l10n/en.lproj/Localizable.strings b/resources/l10n/en.lproj/Localizable.strings index bf635db0..040b0cdb 100644 --- a/resources/l10n/en.lproj/Localizable.strings +++ b/resources/l10n/en.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Theme:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/es.lproj/Localizable.strings b/resources/l10n/es.lproj/Localizable.strings index bbd61c6b..c76e99a0 100644 --- a/resources/l10n/es.lproj/Localizable.strings +++ b/resources/l10n/es.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/fi.lproj/Localizable.strings b/resources/l10n/fi.lproj/Localizable.strings index 5b600eae..6b433126 100644 --- a/resources/l10n/fi.lproj/Localizable.strings +++ b/resources/l10n/fi.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Teema:"; /*No comment provided by engineer.*/ -"then release:" = "sitten päästä:"; +"Then release:" = "Sitten päästä:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Tarvitaan ikkunoiden valitsemiseksi"; diff --git a/resources/l10n/fr.lproj/Localizable.strings b/resources/l10n/fr.lproj/Localizable.strings index 5ba8e7dd..a29d660e 100644 --- a/resources/l10n/fr.lproj/Localizable.strings +++ b/resources/l10n/fr.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Thème :"; /*No comment provided by engineer.*/ -"then release:" = "puis relâcher :"; +"Then release:" = "Puis relâcher :"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Cette permission est nécessaire pour afficher la fenêtre après le relâchement du raccourci clavier"; diff --git a/resources/l10n/hu.lproj/Localizable.strings b/resources/l10n/hu.lproj/Localizable.strings index 8cc7a3e3..44f9223e 100644 --- a/resources/l10n/hu.lproj/Localizable.strings +++ b/resources/l10n/hu.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Téma:"; /*No comment provided by engineer.*/ -"then release:" = "majd engedje fel:"; +"Then release:" = "Majd engedje fel:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Ez a jogosultság ahhoz szükséges hogy az ablak fókuszba kerüljön miután a parancsikont elengedte"; diff --git a/resources/l10n/id.lproj/Localizable.strings b/resources/l10n/id.lproj/Localizable.strings index dcb0e729..678ecafe 100644 --- a/resources/l10n/id.lproj/Localizable.strings +++ b/resources/l10n/id.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "lalu lepaskan:"; +"Then release:" = "Lalu lepaskan:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Izin ini diperlukan untuk memfokuskan jendela setelah Anda melepaskan pintasan"; diff --git a/resources/l10n/it.lproj/Localizable.strings b/resources/l10n/it.lproj/Localizable.strings index c9fdae29..01b38708 100644 --- a/resources/l10n/it.lproj/Localizable.strings +++ b/resources/l10n/it.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/ja.lproj/Localizable.strings b/resources/l10n/ja.lproj/Localizable.strings index 5d5d38b2..3a52b018 100644 --- a/resources/l10n/ja.lproj/Localizable.strings +++ b/resources/l10n/ja.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "テーマ:"; /*No comment provided by engineer.*/ -"then release:" = "離した時の動作:"; +"Then release:" = "離した時の動作:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "こちらの許可は、ショートカットキーを離した後、ウィンドウにフォーカスするのに必要です。"; diff --git a/resources/l10n/ko.lproj/Localizable.strings b/resources/l10n/ko.lproj/Localizable.strings index c563d2fd..1541e5c7 100644 --- a/resources/l10n/ko.lproj/Localizable.strings +++ b/resources/l10n/ko.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "테마:"; /*No comment provided by engineer.*/ -"then release:" = "그리고 놓으면:"; +"Then release:" = "그리고 놓으면:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "이 권한은 단축키를 사용했을 때 원하는 윈도우로 이동할 수 있게 해줍니다"; diff --git a/resources/l10n/lb.lproj/Localizable.strings b/resources/l10n/lb.lproj/Localizable.strings index e293a063..6808a45c 100644 --- a/resources/l10n/lb.lproj/Localizable.strings +++ b/resources/l10n/lb.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Theme:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/nl.lproj/Localizable.strings b/resources/l10n/nl.lproj/Localizable.strings index fa9cae25..21c27712 100644 --- a/resources/l10n/nl.lproj/Localizable.strings +++ b/resources/l10n/nl.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Thema:"; /*No comment provided by engineer.*/ -"then release:" = "doe dan:"; +"Then release:" = "Doe dan:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Deze permissie is nodig om vensters te focussen na het uitvoeren van de snelkoppeling"; diff --git a/resources/l10n/no.lproj/Localizable.strings b/resources/l10n/no.lproj/Localizable.strings index 1803cd13..6794fa5e 100644 --- a/resources/l10n/no.lproj/Localizable.strings +++ b/resources/l10n/no.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "så slipp:"; +"Then release:" = "Så slipp:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Denne tillatelsen er nødvendig for å kunne fokusere på vindu når du slipper hurtigtasten"; diff --git a/resources/l10n/pl.lproj/Localizable.strings b/resources/l10n/pl.lproj/Localizable.strings index 9d15fa54..e5fce369 100644 --- a/resources/l10n/pl.lproj/Localizable.strings +++ b/resources/l10n/pl.lproj/Localizable.strings @@ -304,7 +304,7 @@ "Theme:" = "Motyw:"; /*No comment provided by engineer.*/ -"then release:" = "po czym wypuść:"; +"Then release:" = "Po czym wypuść:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "To uprawnienie jest potrzebne, aby aktywować okna po zwolnieniu skrótu"; diff --git a/resources/l10n/pt-BR.lproj/Localizable.strings b/resources/l10n/pt-BR.lproj/Localizable.strings index 9f01d6cb..7e2dc165 100644 --- a/resources/l10n/pt-BR.lproj/Localizable.strings +++ b/resources/l10n/pt-BR.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "Ao soltar:"; +"Then release:" = "Ao soltar:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Esta permissão é necessária para focar a janela após acionar o atalho"; diff --git a/resources/l10n/pt.lproj/Localizable.strings b/resources/l10n/pt.lproj/Localizable.strings index fffa832c..ace3b4b8 100644 --- a/resources/l10n/pt.lproj/Localizable.strings +++ b/resources/l10n/pt.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "depois soltar:"; +"Then release:" = "Depois soltar:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Esta permissão é necessária para dar foco em janelas após carregar nos atalhos"; diff --git a/resources/l10n/ru.lproj/Localizable.strings b/resources/l10n/ru.lproj/Localizable.strings index 12b27683..bb066845 100644 --- a/resources/l10n/ru.lproj/Localizable.strings +++ b/resources/l10n/ru.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Тема:"; /*No comment provided by engineer.*/ -"then release:" = "затем отпустить:"; +"Then release:" = "Затем отпустить:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "Это разрешение нужно для фокусировки окна после отпускания комбинации клавиш"; diff --git a/resources/l10n/tr.lproj/Localizable.strings b/resources/l10n/tr.lproj/Localizable.strings index 85b05047..c41e4843 100644 --- a/resources/l10n/tr.lproj/Localizable.strings +++ b/resources/l10n/tr.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "Tema:"; /*No comment provided by engineer.*/ -"then release:" = "then release:"; +"Then release:" = "Then release:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "This permission is needed to focus windows after you release the shortcut"; diff --git a/resources/l10n/zh-CN.lproj/Localizable.strings b/resources/l10n/zh-CN.lproj/Localizable.strings index 9ce089b8..880a73fd 100644 --- a/resources/l10n/zh-CN.lproj/Localizable.strings +++ b/resources/l10n/zh-CN.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "主题:"; /*No comment provided by engineer.*/ -"then release:" = "然后松开:"; +"Then release:" = "然后松开:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "需要此权限在释放快捷键后切换鼠标焦点"; diff --git a/resources/l10n/zh-TW.lproj/Localizable.strings b/resources/l10n/zh-TW.lproj/Localizable.strings index 281bf7f8..53655adb 100644 --- a/resources/l10n/zh-TW.lproj/Localizable.strings +++ b/resources/l10n/zh-TW.lproj/Localizable.strings @@ -303,7 +303,7 @@ "Theme:" = "主題:"; /*No comment provided by engineer.*/ -"then release:" = "然後放開:"; +"Then release:" = "然後放開:"; /*No comment provided by engineer.*/ "This permission is needed to focus windows after you release the shortcut" = "需要取得此權限,才能在放開快速鍵後聚焦視窗"; diff --git a/src/logic/Preferences.swift b/src/logic/Preferences.swift index 9bd9eccd..c352a339 100644 --- a/src/logic/Preferences.swift +++ b/src/logic/Preferences.swift @@ -58,6 +58,7 @@ class Preferences { "minCellsPerRow": defaultsDependingOnScreenRatio_["minCellsPerRow"]!, "maxCellsPerRow": defaultsDependingOnScreenRatio_["maxCellsPerRow"]!, "shortcutStyle": "0", + "shortcutStyle2": "0", "hideAppBadges": "false", "hideWindowlessApps": "false", "hideThumbnails": "false", @@ -116,7 +117,7 @@ class Preferences { static var appsToShow: [AppsToShowPreference] { ["appsToShow", "appsToShow2"].map { defaults.macroPref($0, AppsToShowPreference.allCases) } } static var spacesToShow: [SpacesToShowPreference] { ["spacesToShow", "spacesToShow2"].map { defaults.macroPref($0, SpacesToShowPreference.allCases) } } static var screensToShow: [ScreensToShowPreference] { ["screensToShow", "screensToShow2"].map { defaults.macroPref($0, ScreensToShowPreference.allCases) } } - static var shortcutStyle: ShortcutStylePreference { defaults.macroPref("shortcutStyle", ShortcutStylePreference.allCases) } + static var shortcutStyle: [ShortcutStylePreference] { ["shortcutStyle", "shortcutStyle2"].map { defaults.macroPref($0, ShortcutStylePreference.allCases) } } static var menubarIcon: MenubarIconPreference { defaults.macroPref("menubarIcon", MenubarIconPreference.allCases) } // derived values diff --git a/src/logic/events/KeyboardEvents.swift b/src/logic/events/KeyboardEvents.swift index 96c1282c..63ab6d12 100644 --- a/src/logic/events/KeyboardEvents.swift +++ b/src/logic/events/KeyboardEvents.swift @@ -118,7 +118,7 @@ fileprivate func handleHotModifier(_ modifiers: UInt32) -> Bool { let otherKey = key == "holdShortcut" ? "holdShortcut2" : "holdShortcut" KeyboardEvents.holdShortcutWasDown[key] = false } - if Preferences.shortcutStyle == .focusOnRelease && handleHotAny(key, shortcutIndex) { + if Preferences.shortcutStyle[App.app.shortcutIndex] == .focusOnRelease && handleHotAny(key, shortcutIndex) { return true } } @@ -151,7 +151,7 @@ fileprivate func localShortcutThatMatches(_ event: NSEvent) -> String? { if shortcutId.hasPrefix("holdShortcut") { let postfix = App.app.shortcutIndex == 0 ? "" : "2" if event.sr_keyEventType == .up && event.type == .flagsChanged && shortcut.keyCode == .none && event.modifierFlags.isDisjoint(with: shortcut.modifierFlags) && - shortcutId == "holdShortcut" + postfix && App.app.appIsBeingUsed && Preferences.shortcutStyle == .focusOnRelease { + shortcutId == "holdShortcut" + postfix && App.app.appIsBeingUsed && Preferences.shortcutStyle[App.app.shortcutIndex] == .focusOnRelease { return shortcutId } } else if event.sr_keyEventType == .down && (shortcut.keyCode == .none || event.keyCode == shortcut.carbonKeyCode) && diff --git a/src/ui/preferences-window/tabs/ControlsTab.swift b/src/ui/preferences-window/tabs/ControlsTab.swift index 9ece4dfc..1d05edb5 100644 --- a/src/ui/preferences-window/tabs/ControlsTab.swift +++ b/src/ui/preferences-window/tabs/ControlsTab.swift @@ -24,7 +24,6 @@ class ControlsTab { ] static func initTab() -> NSView { - let shortcutStyle = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("then release:", comment: ""), "shortcutStyle", ShortcutStylePreference.allCases) let focusWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Focus selected window", comment: ""), "focusWindowShortcut", Preferences.focusWindowShortcut, 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) @@ -47,7 +46,6 @@ class ControlsTab { let grid = GridView([ [tabView], - shortcutStyle, [orPress, shortcuts], [checkboxesExplanations, checkboxes], ]) @@ -81,12 +79,14 @@ class ControlsTab { let showHiddenWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Hidden", comment: ""), "showHiddenWindows" + postfix, labelPosition: .right)) let showFullscreenWindows = StackView(LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Fullscreen", comment: ""), "showFullscreenWindows" + postfix, labelPosition: .right)) let nextWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Select next window", comment: ""), "nextWindowShortcut" + postfix, Preferences.nextWindowShortcut[postfix == "" ? 0 : 1], labelPosition: .right) + let shortcutStyle = LabelAndControl.makeLabelWithDropdown(NSLocalizedString("Then release:", comment: ""), "shortcutStyle" + postfix, ShortcutStylePreference.allCases) let toShowDropdowns = StackView([appsToShow, spacesToShow, screensToShow, showMinimizedWindows, showHiddenWindows, showFullscreenWindows], .vertical, false) toShowDropdowns.spacing = TabView.padding toShowDropdowns.fit() let tab = GridView([ [toShowExplanations, toShowDropdowns], [holdAndPress, StackView(nextWindowShortcut)], + shortcutStyle, ], TabView.padding) tab.column(at: 0).xPlacement = .trailing tab.fit()