Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add option to minimize other windows when switching #2290

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/logic/ATShortcut.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ class ATShortcut {
App.app.appIsBeingUsed = true
return true
}
if triggerPhase == .up && App.app.appIsBeingUsed && (index == nil || index == App.app.shortcutIndex) && Preferences.shortcutStyle[App.app.shortcutIndex] == .focusOnRelease {
if triggerPhase == .up && App.app.appIsBeingUsed && (index == nil || index == App.app.shortcutIndex) && Preferences.shortcutStyle[App.app.shortcutIndex] != .doNothingOnRelease {
return true
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/logic/Preferences.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Preferences {
"minDeminWindowShortcut": "M",
"quitAppShortcut": "Q",
"hideShowAppShortcut": "H",
"minimizeOtherWindowsShortcut": "1",
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think adding the option to minimize other windows is not adding much noise in the existing dropdown "on release:". However, as a secondary shortcut like quit/hide/etc, I think it's too niche to have such a prominent UI in the preferences. This shortcut 1 would also conflict with #210. I think the feature is a bit too niche to have a dedicated shortcut as such.

"arrowKeysEnabled": "true",
"mouseHoverEnabled": "true",
"cursorFollowFocusEnabled": "false",
Expand Down Expand Up @@ -117,6 +118,7 @@ class Preferences {
static var minDeminWindowShortcut: String { defaults.string("minDeminWindowShortcut") }
static var quitAppShortcut: String { defaults.string("quitAppShortcut") }
static var hideShowAppShortcut: String { defaults.string("hideShowAppShortcut") }
static var minimizeOtherWindowsShortcut: String { defaults.string("minimizeOtherWindowsShortcut") }
static var arrowKeysEnabled: Bool { defaults.bool("arrowKeysEnabled") }
static var mouseHoverEnabled: Bool { defaults.bool("mouseHoverEnabled") }
static var cursorFollowFocusEnabled: Bool { defaults.bool("cursorFollowFocusEnabled") }
Expand Down Expand Up @@ -458,11 +460,13 @@ enum MenubarIconPreference: String, CaseIterable, MacroPreference {
enum ShortcutStylePreference: String, CaseIterable, MacroPreference {
case focusOnRelease = "0"
case doNothingOnRelease = "1"
case minimizeOthersOnRelease = "2"

var localizedString: LocalizedString {
switch self {
case .focusOnRelease: return NSLocalizedString("Focus selected window", comment: "")
case .doNothingOnRelease: return NSLocalizedString("Do nothing", comment: "")
case .minimizeOthersOnRelease: return NSLocalizedString("Minimize other windows", comment: "")
}
}
}
Expand Down
8 changes: 8 additions & 0 deletions src/logic/Windows.swift
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,14 @@ class Windows {
return list.count > focusedWindowIndex ? list[focusedWindowIndex] : nil
}

static func minimizeOtherWindows() {
Windows.list.enumerated().forEach {
if $0.offset != focusedWindowIndex && !$0.element.isMinimized && !$0.element.isWindowlessApp && $0.element.shouldShowTheUser {
$0.element.minDemin()
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You check shouldShowTheUser here. Is it what the user would expect though? Let's imagine I use the command+` shortcut. It shows me only windows of the active app. When I set it to "minimize other windows" on release, I think I expect that every other window on my screen will minimize, except the one I just focused, no? Here it will only minimize the other windows of the active app.

Same logic will keep some windows on-screen, depending on the shortcut filtereing logic behind shouldShowTheUser.

Another point: I wonder if people will expect this single-window mode to be per-Space and/or per-Screen. I'm not sure users expect windows in every Space and on every Screen to minimize when they go for this type of workflow. Maybe they would like to have a "main window" per Screen?

What do you think?

}
}
}

static func cycleFocusedWindowIndex(_ step: Int) {
let nextIndex = windowIndexAfterCycling(step)
if ((step > 0 && nextIndex < focusedWindowIndex) || (step < 0 && nextIndex > focusedWindowIndex)) &&
Expand Down
15 changes: 15 additions & 0 deletions src/ui/App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -149,10 +149,25 @@ class App: AppCenterApplication, NSApplicationDelegate {
Windows.focusedWindow()?.application.hideOrShow()
}

func minimizeOtherWindows() {
debugPrint("minimizeOtherWindows")
Windows.minimizeOtherWindows()
}

func focusTarget() {
debugPrint("focusTarget")
focusSelectedWindow(Windows.focusedWindow())
}

func handleHold(_ shortcutIndex: Int) {
let shortcutStyle = Preferences.shortcutStyle[shortcutIndex]
if shortcutStyle == .focusOnRelease {
focusTarget()
} else if shortcutStyle == .minimizeOthersOnRelease {
minimizeOtherWindows()
focusTarget()
}
}

@objc func checkForUpdatesNow(_ sender: NSMenuItem) {
PoliciesTab.checkForUpdatesNow(sender)
Expand Down
14 changes: 8 additions & 6 deletions src/ui/preferences-window/tabs/ControlsTab.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ class ControlsTab {
static var shortcuts = [String: ATShortcut]()
static var shortcutControls = [String: (CustomRecorderControl, String)]()
static var shortcutsActions = [
"holdShortcut": { App.app.focusTarget() },
"holdShortcut2": { App.app.focusTarget() },
"holdShortcut3": { App.app.focusTarget() },
"holdShortcut4": { App.app.focusTarget() },
"holdShortcut5": { App.app.focusTarget() },
"holdShortcut": { App.app.handleHold(0) },
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure about the name of this function, but I can't think of a better one :-)

"holdShortcut2": { App.app.handleHold(1) },
"holdShortcut3": { App.app.handleHold(2) },
"holdShortcut4": { App.app.handleHold(3) },
"holdShortcut5": { App.app.handleHold(4) },
"focusWindowShortcut": { App.app.focusTarget() },
"nextWindowShortcut": { App.app.showUiOrCycleSelection(0) },
"nextWindowShortcut2": { App.app.showUiOrCycleSelection(1) },
Expand All @@ -26,6 +26,7 @@ class ControlsTab {
"minDeminWindowShortcut": { App.app.minDeminSelectedWindow() },
"quitAppShortcut": { App.app.quitSelectedApp() },
"hideShowAppShortcut": { App.app.hideShowSelectedApp() },
"minimizeOtherWindowsShortcut": { App.app.minimizeOtherWindows() },
]
static var arrowKeysCheckbox: NSButton!

Expand All @@ -37,6 +38,7 @@ class ControlsTab {
let minDeminWindowShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Minimize/Deminimize window", comment: ""), "minDeminWindowShortcut", Preferences.minDeminWindowShortcut, labelPosition: .right)
let quitAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Quit app", comment: ""), "quitAppShortcut", Preferences.quitAppShortcut, labelPosition: .right)
let hideShowAppShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Hide/Show app", comment: ""), "hideShowAppShortcut", Preferences.hideShowAppShortcut, labelPosition: .right)
let minimizeOtherWindowsShortcut = LabelAndControl.makeLabelWithRecorder(NSLocalizedString("Minimize other windows", comment: ""), "minimizeOtherWindowsShortcut", Preferences.minimizeOtherWindowsShortcut, labelPosition: .right)
let enableArrows = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Arrow keys", comment: ""), "arrowKeysEnabled", extraAction: ControlsTab.arrowKeysEnabledCallback, labelPosition: .right)
arrowKeysCheckbox = enableArrows[0] as? NSButton
let enableMouse = LabelAndControl.makeLabelWithCheckbox(NSLocalizedString("Mouse hover", comment: ""), "mouseHoverEnabled", labelPosition: .right)
Expand All @@ -45,7 +47,7 @@ class ControlsTab {
let selectWindowCheckboxes = StackView([StackView(enableArrows), StackView(enableMouse)], .vertical)
let miscCheckboxesExplanations = LabelAndControl.makeLabel(NSLocalizedString("Miscellaneous:", comment: ""))
let miscCheckboxes = StackView([StackView(enableCursorFollowFocus)], .vertical)
let shortcuts = StackView([focusWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
let shortcuts = StackView([focusWindowShortcut, previousWindowShortcut, cancelShortcut, closeWindowShortcut, minDeminWindowShortcut, quitAppShortcut, hideShowAppShortcut, minimizeOtherWindowsShortcut].map { (view: [NSView]) in StackView(view) }, .vertical)
let orPress = LabelAndControl.makeLabel(NSLocalizedString("While open, press:", comment: ""), shouldFit: false)
let (holdShortcut, nextWindowShortcut, tab1View) = toShowSection(0)
let (holdShortcut2, nextWindowShortcut2, tab2View) = toShowSection(1)
Expand Down