Skip to content

Commit

Permalink
Restore Ice Bar location picker
Browse files Browse the repository at this point in the history
Closes #308
  • Loading branch information
jordanbaird committed Aug 10, 2024
1 parent 83d6f50 commit ead794b
Show file tree
Hide file tree
Showing 5 changed files with 78 additions and 7 deletions.
4 changes: 4 additions & 0 deletions Ice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,7 @@
718152C32C34E595005564AA /* NSScreen+screenWithMouse.swift in Sources */ = {isa = PBXBuildFile; fileRef = 718152C22C34E595005564AA /* NSScreen+screenWithMouse.swift */; };
71829E0A2C2FDCC200503604 /* NSScreen+getMenuBarHeight.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71829E092C2FDCC200503604 /* NSScreen+getMenuBarHeight.swift */; };
71839C162A9B6A0D00250044 /* OnFrameChange.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71839C152A9B6A0D00250044 /* OnFrameChange.swift */; };
718E3F782C679F680029B835 /* IceBarLocation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 718E3F772C679F680029B835 /* IceBarLocation.swift */; };
71C400322AAD76A8006FDB1C /* ReadWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71C400312AAD76A8006FDB1C /* ReadWindow.swift */; };
71D2B02E2AAFDD5C0002B6C8 /* Bundle+versionString.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71D2B02D2AAFDD5C0002B6C8 /* Bundle+versionString.swift */; };
71D36C4F2A88FE4900D89CD5 /* SettingsWindow.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71D36C4E2A88FE4900D89CD5 /* SettingsWindow.swift */; };
Expand Down Expand Up @@ -256,6 +257,7 @@
718152C22C34E595005564AA /* NSScreen+screenWithMouse.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSScreen+screenWithMouse.swift"; sourceTree = "<group>"; };
71829E092C2FDCC200503604 /* NSScreen+getMenuBarHeight.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSScreen+getMenuBarHeight.swift"; sourceTree = "<group>"; };
71839C152A9B6A0D00250044 /* OnFrameChange.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnFrameChange.swift; sourceTree = "<group>"; };
718E3F772C679F680029B835 /* IceBarLocation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IceBarLocation.swift; sourceTree = "<group>"; };
71C400312AAD76A8006FDB1C /* ReadWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ReadWindow.swift; sourceTree = "<group>"; };
71D2B02D2AAFDD5C0002B6C8 /* Bundle+versionString.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Bundle+versionString.swift"; sourceTree = "<group>"; };
71D36C4E2A88FE4900D89CD5 /* SettingsWindow.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SettingsWindow.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -455,6 +457,7 @@
children = (
17BE3DCF2C1A45B3008B98EF /* IceBar.swift */,
71287C5F2C3189AC0028706E /* IceBarColorManager.swift */,
718E3F772C679F680029B835 /* IceBarLocation.swift */,
);
path = IceBar;
sourceTree = "<group>";
Expand Down Expand Up @@ -969,6 +972,7 @@
17540BDC2B23BD5700A0F965 /* NSBezierPath+intersects.swift in Sources */,
17F998512C16D02E00D75EC0 /* LayoutBarScrollView.swift in Sources */,
179AC2FC2C1146EF0051E7B0 /* RemoveSidebarToggle.swift in Sources */,
718E3F782C679F680029B835 /* IceBarLocation.swift in Sources */,
17B7F32B2B264C1800CDCF49 /* MenuBarAppearanceManager.swift in Sources */,
17F9984D2C16CD8E00D75EC0 /* MenuBarItemsSettingsPane.swift in Sources */,
71F428152C3B5F3D0025706C /* AppNavigationState.swift in Sources */,
Expand Down
8 changes: 2 additions & 6 deletions Ice/IceBar/IceBar.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,6 @@ class IceBarPanel: NSPanel {
}

private func updateOrigin(for screen: NSScreen) {
enum IceBarLocation {
case dynamic, mousePointer, iceIcon
}

guard let appState else {
return
}
Expand All @@ -114,7 +110,7 @@ class IceBarPanel: NSPanel {
}

switch iceBarLocation {
case .dynamic:
case .default:
if appState.eventManager.isMouseInsideEmptyMenuBarSpace {
return getOrigin(for: .mousePointer)
}
Expand Down Expand Up @@ -151,7 +147,7 @@ class IceBarPanel: NSPanel {
}
}

setFrameOrigin(getOrigin(for: .dynamic))
setFrameOrigin(getOrigin(for: appState.settingsManager.generalSettingsManager.iceBarLocation))
}

func show(section: MenuBarSection.Name, on screen: NSScreen) async {
Expand Down
29 changes: 29 additions & 0 deletions Ice/IceBar/IceBarLocation.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
//
// IceBarLocation.swift
// Ice
//

import SwiftUI

/// Locations where the Ice Bar can appear.
enum IceBarLocation: Int, CaseIterable, Identifiable {
/// The Ice Bar will appear in different locations based on context.
case `default` = 0

/// The Ice Bar will appear centered below the mouse pointer.
case mousePointer = 1

/// The Ice Bar will appear centered below the Ice icon.
case iceIcon = 2

var id: Int { rawValue }

/// Localized string key representation.
var localized: LocalizedStringKey {
switch self {
case .default: "Default"
case .mousePointer: "Mouse pointer"
case .iceIcon: "Ice icon"
}
}
}
15 changes: 15 additions & 0 deletions Ice/Settings/SettingsManagers/GeneralSettingsManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ final class GeneralSettingsManager: ObservableObject {
/// in a separate bar below the menu bar.
@Published var useIceBar = false

/// The location where the Ice Bar appears.
@Published var iceBarLocation: IceBarLocation = .default

/// A Boolean value that indicates whether the hidden section
/// should be shown when the mouse pointer clicks in an empty
/// area of the menu bar.
Expand Down Expand Up @@ -80,6 +83,11 @@ final class GeneralSettingsManager: ObservableObject {
Defaults.ifPresent(key: .autoRehide, assign: &autoRehide)
Defaults.ifPresent(key: .rehideInterval, assign: &rehideInterval)

Defaults.ifPresent(key: .iceBarLocation) { rawValue in
if let location = IceBarLocation(rawValue: rawValue) {
iceBarLocation = location
}
}
Defaults.ifPresent(key: .rehideStrategy) { rawValue in
if let strategy = RehideStrategy(rawValue: rawValue) {
rehideStrategy = strategy
Expand Down Expand Up @@ -140,6 +148,13 @@ final class GeneralSettingsManager: ObservableObject {
}
.store(in: &c)

$iceBarLocation
.receive(on: DispatchQueue.main)
.sink { location in
Defaults.set(location.rawValue, forKey: .iceBarLocation)
}
.store(in: &c)

$showOnClick
.receive(on: DispatchQueue.main)
.sink { showOnClick in
Expand Down
29 changes: 28 additions & 1 deletion Ice/Settings/SettingsPanes/GeneralSettingsPane.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct GeneralSettingsPane: View {
iceIconOptions
}
Section {
useIceBar
iceBarOptions
}
Section {
showOnClick
Expand Down Expand Up @@ -137,6 +137,14 @@ struct GeneralSettingsPane: View {
}
}

@ViewBuilder
private var iceBarOptions: some View {
useIceBar
if manager.useIceBar {
iceBarLocationPicker
}
}

@ViewBuilder
private var useIceBar: some View {
Toggle(isOn: manager.bindings.useIceBar) {
Expand All @@ -145,6 +153,25 @@ struct GeneralSettingsPane: View {
}
}

@ViewBuilder
private var iceBarLocationPicker: some View {
Picker(selection: manager.bindings.iceBarLocation) {
ForEach(IceBarLocation.allCases) { location in
Text(location.localized).tag(location)
}
} label: {
Text("Location")
switch manager.iceBarLocation {
case .default:
Text("The Ice Bar's location changes based on context")
case .mousePointer:
Text("The Ice Bar is centered below the mouse pointer")
case .iceIcon:
Text("The Ice Bar is centered below the Ice icon")
}
}
}

@ViewBuilder
private var showOnClick: some View {
Toggle(isOn: manager.bindings.showOnClick) {
Expand Down

0 comments on commit ead794b

Please sign in to comment.