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 d24389891..e26715b34 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 ac12d3cc2..e1bcb4754 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 b5143e795..ee43382f5 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 bf635db00..040b0cdb6 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 bbd61c6bb..c76e99a07 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 5b600eae9..6b433126f 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 5ba8e7dd9..a29d660ed 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 8cc7a3e3c..44f9223ea 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 dcb0e729b..678ecafef 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 c9fdae29d..01b387083 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 5d5d38b26..3a52b018d 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 c563d2fdc..1541e5c75 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 e293a063c..6808a45cf 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 fa9cae255..21c27712c 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 1803cd136..6794fa5eb 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 9d15fa545..e5fce3691 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 9f01d6cb4..7e2dc1652 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 fffa832c5..ace3b4b8d 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 12b276839..bb0668455 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 85b05047e..c41e48437 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 9ce089b8f..880a73fd1 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 281bf7f80..53655adbb 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 9bd9eccde..c352a3391 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 96c1282cc..63ab6d124 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 9ece4dfc8..1d05edb5b 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()