From d65f2205309d3e4ee461acf3f7672f00336b2964 Mon Sep 17 00:00:00 2001 From: lwouis Date: Mon, 9 Dec 2024 18:21:19 +0100 Subject: [PATCH] feat: decrease shortcuts from 5 to 3 --- src/logic/Preferences.swift | 42 ++++++------------- src/logic/events/KeyboardEventsTestable.swift | 4 -- src/logic/events/TrackpadEvents.swift | 4 +- .../tabs/controls/ControlsTab.swift | 18 +++----- unit-tests/Mocks.swift | 4 +- 5 files changed, 20 insertions(+), 52 deletions(-) diff --git a/src/logic/Preferences.swift b/src/logic/Preferences.swift index 23884540..ae996ce9 100644 --- a/src/logic/Preferences.swift +++ b/src/logic/Preferences.swift @@ -8,13 +8,9 @@ class Preferences { "holdShortcut": "⌥", "holdShortcut2": "⌥", "holdShortcut3": "⌥", - "holdShortcut4": "⌥", - "holdShortcut5": "⌥", "nextWindowShortcut": "⇥", "nextWindowShortcut2": keyAboveTabDependingOnInputSource(), "nextWindowShortcut3": "", - "nextWindowShortcut4": "", - "nextWindowShortcut5": "", "nextWindowGesture": GesturePreference.disabled.indexAsString, "focusWindowShortcut": "Space", "previousWindowShortcut": "⇧", @@ -32,26 +28,18 @@ class Preferences { "showMinimizedWindows2": ShowHowPreference.show.indexAsString, "showMinimizedWindows3": ShowHowPreference.show.indexAsString, "showMinimizedWindows4": ShowHowPreference.show.indexAsString, - "showMinimizedWindows5": ShowHowPreference.show.indexAsString, - "showMinimizedWindows6": ShowHowPreference.show.indexAsString, "showHiddenWindows": ShowHowPreference.show.indexAsString, "showHiddenWindows2": ShowHowPreference.show.indexAsString, "showHiddenWindows3": ShowHowPreference.show.indexAsString, "showHiddenWindows4": ShowHowPreference.show.indexAsString, - "showHiddenWindows5": ShowHowPreference.show.indexAsString, - "showHiddenWindows6": ShowHowPreference.show.indexAsString, "showFullscreenWindows": ShowHowPreference.show.indexAsString, "showFullscreenWindows2": ShowHowPreference.show.indexAsString, "showFullscreenWindows3": ShowHowPreference.show.indexAsString, "showFullscreenWindows4": ShowHowPreference.show.indexAsString, - "showFullscreenWindows5": ShowHowPreference.show.indexAsString, - "showFullscreenWindows6": ShowHowPreference.show.indexAsString, "windowOrder": WindowOrderPreference.recentlyFocused.indexAsString, "windowOrder2": WindowOrderPreference.recentlyFocused.indexAsString, "windowOrder3": WindowOrderPreference.recentlyFocused.indexAsString, "windowOrder4": WindowOrderPreference.recentlyFocused.indexAsString, - "windowOrder5": WindowOrderPreference.recentlyFocused.indexAsString, - "windowOrder6": WindowOrderPreference.recentlyFocused.indexAsString, "showTabsAsWindows": "false", "hideColoredCircles": "false", "windowDisplayDelay": "100", @@ -69,20 +57,14 @@ class Preferences { "appsToShow2": AppsToShowPreference.active.indexAsString, "appsToShow3": AppsToShowPreference.all.indexAsString, "appsToShow4": AppsToShowPreference.all.indexAsString, - "appsToShow5": AppsToShowPreference.all.indexAsString, - "appsToShow6": AppsToShowPreference.all.indexAsString, "spacesToShow": SpacesToShowPreference.all.indexAsString, "spacesToShow2": SpacesToShowPreference.all.indexAsString, "spacesToShow3": SpacesToShowPreference.all.indexAsString, "spacesToShow4": SpacesToShowPreference.all.indexAsString, - "spacesToShow5": SpacesToShowPreference.all.indexAsString, - "spacesToShow6": SpacesToShowPreference.all.indexAsString, "screensToShow": ScreensToShowPreference.all.indexAsString, "screensToShow2": ScreensToShowPreference.all.indexAsString, "screensToShow3": ScreensToShowPreference.all.indexAsString, "screensToShow4": ScreensToShowPreference.all.indexAsString, - "screensToShow5": ScreensToShowPreference.all.indexAsString, - "screensToShow6": ScreensToShowPreference.all.indexAsString, "fadeOutAnimation": "false", "hideSpaceNumberLabels": "false", "hideStatusIcons": "false", @@ -97,8 +79,6 @@ class Preferences { "shortcutStyle2": ShortcutStylePreference.focusOnRelease.indexAsString, "shortcutStyle3": ShortcutStylePreference.focusOnRelease.indexAsString, "shortcutStyle4": ShortcutStylePreference.focusOnRelease.indexAsString, - "shortcutStyle5": ShortcutStylePreference.focusOnRelease.indexAsString, - "shortcutStyle6": ShortcutStylePreference.focusOnRelease.indexAsString, "hideAppBadges": "false", "hideWindowlessApps": "false", "hideThumbnails": "false", @@ -113,8 +93,8 @@ class Preferences { // not exposed as preferences now but may be in the future, probably through macro preferences // persisted values - static var holdShortcut: [String] { ["holdShortcut", "holdShortcut2", "holdShortcut3", "holdShortcut4", "holdShortcut5"].map { UserDefaults.standard.string($0) } } - static var nextWindowShortcut: [String] { ["nextWindowShortcut", "nextWindowShortcut2", "nextWindowShortcut3", "nextWindowShortcut4", "nextWindowShortcut5"].map { UserDefaults.standard.string($0) } } + static var holdShortcut: [String] { ["holdShortcut", "holdShortcut2", "holdShortcut3"].map { UserDefaults.standard.string($0) } } + static var nextWindowShortcut: [String] { ["nextWindowShortcut", "nextWindowShortcut2", "nextWindowShortcut3"].map { UserDefaults.standard.string($0) } } static var nextWindowGesture: GesturePreference { UserDefaults.standard.macroPref("nextWindowGesture", GesturePreference.allCases) } static var focusWindowShortcut: String { UserDefaults.standard.string("focusWindowShortcut") } static var previousWindowShortcut: String { UserDefaults.standard.string("previousWindowShortcut") } @@ -158,18 +138,20 @@ class Preferences { static var showTitles: ShowTitlesPreference { UserDefaults.standard.macroPref("showTitles", ShowTitlesPreference.allCases) } static var updatePolicy: UpdatePolicyPreference { UserDefaults.standard.macroPref("updatePolicy", UpdatePolicyPreference.allCases) } static var crashPolicy: CrashPolicyPreference { UserDefaults.standard.macroPref("crashPolicy", CrashPolicyPreference.allCases) } - static var appsToShow: [AppsToShowPreference] { ["appsToShow", "appsToShow2", "appsToShow3", "appsToShow4", "appsToShow5", "appsToShow6"].map { UserDefaults.standard.macroPref($0, AppsToShowPreference.allCases) } } - static var spacesToShow: [SpacesToShowPreference] { ["spacesToShow", "spacesToShow2", "spacesToShow3", "spacesToShow4", "spacesToShow5", "spacesToShow6"].map { UserDefaults.standard.macroPref($0, SpacesToShowPreference.allCases) } } - static var screensToShow: [ScreensToShowPreference] { ["screensToShow", "screensToShow2", "screensToShow3", "screensToShow4", "screensToShow5", "screensToShow6"].map { UserDefaults.standard.macroPref($0, ScreensToShowPreference.allCases) } } - static var showMinimizedWindows: [ShowHowPreference] { ["showMinimizedWindows", "showMinimizedWindows2", "showMinimizedWindows3", "showMinimizedWindows4", "showMinimizedWindows5", "showMinimizedWindows6"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } - static var showHiddenWindows: [ShowHowPreference] { ["showHiddenWindows", "showHiddenWindows2", "showHiddenWindows3", "showHiddenWindows4", "showHiddenWindows5", "showHiddenWindows6"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } - static var showFullscreenWindows: [ShowHowPreference] { ["showFullscreenWindows", "showFullscreenWindows2", "showFullscreenWindows3", "showFullscreenWindows4", "showFullscreenWindows5", "showFullscreenWindows6"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } - static var windowOrder: [WindowOrderPreference] { ["windowOrder", "windowOrder2", "windowOrder3", "windowOrder4", "windowOrder5", "windowOrder6"].map { UserDefaults.standard.macroPref($0, WindowOrderPreference.allCases) } } - static var shortcutStyle: [ShortcutStylePreference] { ["shortcutStyle", "shortcutStyle2", "shortcutStyle3", "shortcutStyle4", "shortcutStyle5", "shortcutStyle6"].map { UserDefaults.standard.macroPref($0, ShortcutStylePreference.allCases) } } + static var appsToShow: [AppsToShowPreference] { ["appsToShow", "appsToShow2", "appsToShow3", "appsToShow4"].map { UserDefaults.standard.macroPref($0, AppsToShowPreference.allCases) } } + static var spacesToShow: [SpacesToShowPreference] { ["spacesToShow", "spacesToShow2", "spacesToShow3", "spacesToShow4"].map { UserDefaults.standard.macroPref($0, SpacesToShowPreference.allCases) } } + static var screensToShow: [ScreensToShowPreference] { ["screensToShow", "screensToShow2", "screensToShow3", "screensToShow4"].map { UserDefaults.standard.macroPref($0, ScreensToShowPreference.allCases) } } + static var showMinimizedWindows: [ShowHowPreference] { ["showMinimizedWindows", "showMinimizedWindows2", "showMinimizedWindows3", "showMinimizedWindows4"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } + static var showHiddenWindows: [ShowHowPreference] { ["showHiddenWindows", "showHiddenWindows2", "showHiddenWindows3", "showHiddenWindows4"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } + static var showFullscreenWindows: [ShowHowPreference] { ["showFullscreenWindows", "showFullscreenWindows2", "showFullscreenWindows3", "showFullscreenWindows4"].map { UserDefaults.standard.macroPref($0, ShowHowPreference.allCases) } } + static var windowOrder: [WindowOrderPreference] { ["windowOrder", "windowOrder2", "windowOrder3", "windowOrder4"].map { UserDefaults.standard.macroPref($0, WindowOrderPreference.allCases) } } + static var shortcutStyle: [ShortcutStylePreference] { ["shortcutStyle", "shortcutStyle2", "shortcutStyle3", "shortcutStyle4"].map { UserDefaults.standard.macroPref($0, ShortcutStylePreference.allCases) } } static var menubarIcon: MenubarIconPreference { UserDefaults.standard.macroPref("menubarIcon", MenubarIconPreference.allCases) } static var menubarIconShown: Bool { UserDefaults.standard.bool("menubarIconShown") } static var language: LanguagePreference { UserDefaults.standard.macroPref("language", LanguagePreference.allCases) } + static let gestureIndex = 3 + static func initialize() { removeCorruptedPreferences() migratePreferences() diff --git a/src/logic/events/KeyboardEventsTestable.swift b/src/logic/events/KeyboardEventsTestable.swift index 649431c5..8bcd07eb 100644 --- a/src/logic/events/KeyboardEventsTestable.swift +++ b/src/logic/events/KeyboardEventsTestable.swift @@ -5,13 +5,9 @@ class KeyboardEventsTestable { "nextWindowShortcut": 0, "nextWindowShortcut2": 1, "nextWindowShortcut3": 2, - "nextWindowShortcut4": 3, - "nextWindowShortcut5": 4, "holdShortcut": 5, "holdShortcut2": 6, "holdShortcut3": 7, - "holdShortcut4": 8, - "holdShortcut5": 9, ] } diff --git a/src/logic/events/TrackpadEvents.swift b/src/logic/events/TrackpadEvents.swift index e07ec704..56dc1dab 100644 --- a/src/logic/events/TrackpadEvents.swift +++ b/src/logic/events/TrackpadEvents.swift @@ -67,7 +67,7 @@ private func touchEventHandler(_ cgEvent: CGEvent) -> Bool { let requiredFingers = Preferences.nextWindowGesture == .fourFingerSwipe ? 4 : 3 if touches.allSatisfy({ $0.phase == .ended }) || touches.count != requiredFingers { clearState() - if App.app.appIsBeingUsed && touches.count < requiredFingers && App.app.shortcutIndex == 5 + if App.app.appIsBeingUsed && touches.count < requiredFingers && App.app.shortcutIndex == Preferences.gestureIndex && Preferences.shortcutStyle[App.app.shortcutIndex] == .focusOnRelease { DispatchQueue.main.async { App.app.focusTarget() } return true @@ -86,7 +86,7 @@ private func touchEventHandler(_ cgEvent: CGEvent) -> Bool { // the SHOW_UI_THRESHOLD is much less then the CYCLE_THRESHOLD // so for consistency when swiping, extend the threshold for the next horizontal swipe extendNextXThreshold = true - DispatchQueue.main.async { App.app.showUiOrCycleSelection(5) } + DispatchQueue.main.async { App.app.showUiOrCycleSelection(Preferences.gestureIndex) } return true } return false diff --git a/src/ui/preferences-window/tabs/controls/ControlsTab.swift b/src/ui/preferences-window/tabs/controls/ControlsTab.swift index 504603d8..81d6960c 100644 --- a/src/ui/preferences-window/tabs/controls/ControlsTab.swift +++ b/src/ui/preferences-window/tabs/controls/ControlsTab.swift @@ -8,14 +8,10 @@ class ControlsTab { "holdShortcut": { App.app.focusTarget() }, "holdShortcut2": { App.app.focusTarget() }, "holdShortcut3": { App.app.focusTarget() }, - "holdShortcut4": { App.app.focusTarget() }, - "holdShortcut5": { App.app.focusTarget() }, "focusWindowShortcut": { App.app.focusTarget() }, "nextWindowShortcut": { App.app.showUiOrCycleSelection(0) }, "nextWindowShortcut2": { App.app.showUiOrCycleSelection(1) }, "nextWindowShortcut3": { App.app.showUiOrCycleSelection(2) }, - "nextWindowShortcut4": { App.app.showUiOrCycleSelection(3) }, - "nextWindowShortcut5": { App.app.showUiOrCycleSelection(4) }, "previousWindowShortcut": { App.app.previousWindowShortcutWithRepeatingKey() }, "→": { App.app.cycleSelection(.right) }, "←": { App.app.cycleSelection(.left) }, @@ -44,13 +40,11 @@ class ControlsTab { let (holdShortcut, nextWindowShortcut, tab1View) = shortcutTab(0) let (holdShortcut2, nextWindowShortcut2, tab2View) = shortcutTab(1) let (holdShortcut3, nextWindowShortcut3, tab3View) = shortcutTab(2) - let (holdShortcut4, nextWindowShortcut4, tab4View) = shortcutTab(3) - let (holdShortcut5, nextWindowShortcut5, tab5View) = shortcutTab(4) - let tab6View = gestureTab(5) - tableGroupViews = [tab1View, tab2View, tab3View, tab4View, tab5View, tab6View] + let tab6View = gestureTab(Preferences.gestureIndex) + tableGroupViews = [tab1View, tab2View, tab3View, tab6View] // trigger shortcutChanged for these shortcuts to trigger .restrictModifiers - [holdShortcut, holdShortcut2, holdShortcut3, holdShortcut4, holdShortcut5].forEach { ControlsTab.shortcutChangedCallback($0[1] as! NSControl) } - [nextWindowShortcut, nextWindowShortcut2, nextWindowShortcut3, nextWindowShortcut4, nextWindowShortcut5].forEach { ControlsTab.shortcutChangedCallback($0[0] as! NSControl) } + [holdShortcut, holdShortcut2, holdShortcut3].forEach { ControlsTab.shortcutChangedCallback($0[1] as! NSControl) } + [nextWindowShortcut, nextWindowShortcut2, nextWindowShortcut3].forEach { ControlsTab.shortcutChangedCallback($0[0] as! NSControl) } let tabs = StackView(tableGroupViews, .vertical) tabs.translatesAutoresizingMaskIntoConstraints = false @@ -61,8 +55,6 @@ class ControlsTab { NSLocalizedString("Shortcut 1", comment: ""), NSLocalizedString("Shortcut 2", comment: ""), NSLocalizedString("Shortcut 3", comment: ""), - NSLocalizedString("Shortcut 4", comment: ""), - NSLocalizedString("Shortcut 5", comment: ""), NSLocalizedString("Gesture", comment: ""), ], trackingMode: .selectOne, target: self, action: #selector(switchTab(_:))) tab.selectedSegment = 0 @@ -73,7 +65,7 @@ class ControlsTab { let additionalControlsButton = NSButton(title: NSLocalizedString("Additional controls…", comment: ""), target: self, action: #selector(ControlsTab.showAdditionalControlsSettings)) let shortcutsButton = NSButton(title: NSLocalizedString("Shortcuts when active…", comment: ""), target: self, action: #selector(ControlsTab.showShortcutsSettings)) let tools = StackView([additionalControlsButton, shortcutsButton], .horizontal) - let view = TableGroupSetView(originalViews: [table, tab1View, tab2View, tab3View, tab4View, tab5View, tab6View], toolsViews: [tools], toolsAlignment: .trailing) + let view = TableGroupSetView(originalViews: [table, tab1View, tab2View, tab3View, tab6View], toolsViews: [tools], toolsAlignment: .trailing) view.translatesAutoresizingMaskIntoConstraints = false shortcutsWhenActiveSheet = ShortcutsWhenActiveSheet() diff --git a/unit-tests/Mocks.swift b/unit-tests/Mocks.swift index 5fdfc811..ec58dfeb 100644 --- a/unit-tests/Mocks.swift +++ b/unit-tests/Mocks.swift @@ -13,8 +13,6 @@ class ControlsTab { "holdShortcut": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut", .global, .up, 0), "holdShortcut2": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut2", .global, .up, 1), "holdShortcut3": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut3", .global, .up, 2), - "holdShortcut4": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut4", .global, .up, 3), - "holdShortcut5": ATShortcut(Shortcut(keyEquivalent: "⌥")!, "holdShortcut5", .global, .up, 4), "nextWindowShortcut": ATShortcut(Shortcut(keyEquivalent: "⇥")!, "nextWindowShortcut", .global, .down), "nextWindowShortcut2": ATShortcut(Shortcut(keyEquivalent: "`")!, "nextWindowShortcut2", .global, .down), "→": ATShortcut(Shortcut(keyEquivalent: "→")!, "→", .local, .down), @@ -62,7 +60,7 @@ class Logger { } class Preferences { - static var shortcutStyle: [ShortcutStylePreference] = [.focusOnRelease, .focusOnRelease, .focusOnRelease, .focusOnRelease, .focusOnRelease] + static var shortcutStyle: [ShortcutStylePreference] = [.focusOnRelease, .focusOnRelease, .focusOnRelease, .focusOnRelease] static func indexToName(_ baseName: String, _ index: Int) -> String { return baseName + (index == 0 ? "" : String(index + 1))