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

Implements autounhide when screen is wider than set width #413

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Prev Previous commit
Next Next commit
When showing items due to wide screen, always show inline and never h…
…ide.
  • Loading branch information
lgarron committed Nov 23, 2024
commit bc7c50dd5ca77a6368483c40197ea5f4c35f6686
23 changes: 22 additions & 1 deletion Ice/MenuBar/MenuBarManagement/MenuBarSection.swift
Original file line number Diff line number Diff line change
@@ -127,6 +127,23 @@ final class MenuBarSection {
self.init(name: name, controlItem: controlItem, appState: appState)
}

func forceShowDueToWideScreen() -> Bool {
// TODO: deduplicate with `MenuBarAutoExpander`.
guard
let appState
else {
return false
}
let advancedSettingsManager = appState.settingsManager.advancedSettingsManager;
guard let mainScreen = NSScreen.main else {
return false
}

let mainScreenWidth = mainScreen.frame.width;
let setting = advancedSettingsManager.showHiddenSectionWhenWidthGreaterThan;
return mainScreenWidth >= setting;
}

/// Shows the section.
func show() {
guard
@@ -140,8 +157,9 @@ final class MenuBarSection {
// TODO: Can we use isEnabled for this check?
return
}
let useIceBarExceptOnWideScreen = useIceBar && !self.forceShowDueToWideScreen();
switch name {
case .visible where useIceBar, .hidden where useIceBar:
case .visible where useIceBarExceptOnWideScreen, .hidden where useIceBarExceptOnWideScreen:
Task {
if let screenForIceBar {
await iceBarPanel?.show(section: .hidden, on: screenForIceBar)
@@ -196,6 +214,9 @@ final class MenuBarSection {
else {
return
}
if self.forceShowDueToWideScreen() {
return;
}
iceBarPanel?.close()
switch name {
case _ where useIceBar:
2 changes: 1 addition & 1 deletion Ice/Settings/SettingsPanes/AdvancedSettingsPane.swift
Original file line number Diff line number Diff line change
@@ -147,6 +147,7 @@ struct AdvancedSettingsPane: View {
@ViewBuilder
private var activeScreenWidthToggle: some View {
Toggle("Automatically unhide when active screen width is higher than the value below", isOn: manager.bindings.showHiddenSectionWhenWidthGreaterThanEnabled)
.annotation("This will always show the items in the menu bar (ignoring the \"Use Ice Bar\" setting.")
Copy link

Choose a reason for hiding this comment

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

Looks like I forgot a closing paren here.

Suggested change
.annotation("This will always show the items in the menu bar (ignoring the \"Use Ice Bar\" setting.")
.annotation("This will always show the items in the menu bar (ignoring the \"Use Ice Bar\" setting).")

}

@ViewBuilder
@@ -167,7 +168,6 @@ struct AdvancedSettingsPane: View {
maxSliderLabelWidth = max(maxSliderLabelWidth, frame.width)
}
}
.annotation("You may want to disable automatically rehide in General.")
}
}
}