Skip to content

Commit

Permalink
Reimplement MenuBarAppearancePanel (#14)
Browse files Browse the repository at this point in the history
* Begin implementing new MenuBarAppearancePanel

* Tweaks

* Only update a control item's window frame when it intersects with its screen

* Update MenuBarAppearancePanel.swift

* Refactoring

* Prevent MenuBarAppearancePanel from showing again if ordered out

* Refactoring

* Update MenuBarAppearancePanel.swift

* Workaround for full screen

* Better workaround for full screen

* Refactoring

* Make new appearance panel work with `MenuBarShapeKind.none`

* Update MenuBarAppearancePanel.swift

* Update MenuBarAppearancePanel.swift

* Remove old appearance panel and its subtypes

* A comment

* Move ScreenshotManager functionality to ScreenCaptureManager

* Update MenuBarAppearancePanel.swift

* Minor tweaks

* Fix for multiple appearance panels appearing on the same screen

* Update MenuBarAppearancePanel.swift

* Remove unnecessary redundancy
  • Loading branch information
jordanbaird authored Feb 16, 2024
1 parent 3850bc8 commit 815f491
Show file tree
Hide file tree
Showing 10 changed files with 1,066 additions and 944 deletions.
44 changes: 20 additions & 24 deletions Ice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
1725FC6A2AED973800A59081 /* AppState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1725FC692AED973800A59081 /* AppState.swift */; };
1736F77C2ADBBF340073428E /* CustomGradientPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1736F77B2ADBBF340073428E /* CustomGradientPicker.swift */; };
1736F7802ADBC02B0073428E /* CustomGradient.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1736F77F2ADBC02B0073428E /* CustomGradient.swift */; };
174AA5D62B71D97100E3FE74 /* MenuBarAppearancePanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AA5D52B71D97100E3FE74 /* MenuBarAppearancePanel.swift */; };
174AA5F52B730A0B00E3FE74 /* ScreenCaptureManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 174AA5F42B730A0B00E3FE74 /* ScreenCaptureManager.swift */; };
175061912B1543DD003144CD /* LaunchAtLogin in Frameworks */ = {isa = PBXBuildFile; productRef = 175061902B1543DD003144CD /* LaunchAtLogin */; };
1750850E2B683A4C00CFF13A /* StateView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1750850D2B683A4C00CFF13A /* StateView.swift */; };
175085132B69C4C100CFF13A /* CustomTabBuilder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 175085122B69C4C100CFF13A /* CustomTabBuilder.swift */; };
Expand All @@ -31,9 +33,6 @@
1773546A2B1BBACF001CF731 /* MenuBarAppearanceTab.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177354692B1BBACF001CF731 /* MenuBarAppearanceTab.swift */; };
1773546C2B1BBBA1001CF731 /* MenuBarShapePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1773546B2B1BBBA1001CF731 /* MenuBarShapePicker.swift */; };
177354702B1BFF65001CF731 /* HorizontalEdge+cgRectEdge.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1773546F2B1BFF65001CF731 /* HorizontalEdge+cgRectEdge.swift */; };
177354792B1F533F001CF731 /* MenuBarOverlayPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177354782B1F533F001CF731 /* MenuBarOverlayPanel.swift */; };
1773547B2B1F539A001CF731 /* MenuBarBackingPanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1773547A2B1F539A001CF731 /* MenuBarBackingPanel.swift */; };
177354812B1F5F38001CF731 /* ScreenshotManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177354802B1F5F38001CF731 /* ScreenshotManager.swift */; };
177354842B1F9AF9001CF731 /* NSBezierPath+union.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177354832B1F9AF9001CF731 /* NSBezierPath+union.swift */; };
177386F32B092A0700448BBF /* ControlItemImage.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177386F22B092A0700448BBF /* ControlItemImage.swift */; };
177386F52B0A654D00448BBF /* ControlItemImageSet.swift in Sources */ = {isa = PBXBuildFile; fileRef = 177386F42B0A654D00448BBF /* ControlItemImageSet.swift */; };
Expand All @@ -44,12 +43,12 @@
1787C4342B16AECF002F50DF /* PermissionsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1787C4332B16AECF002F50DF /* PermissionsView.swift */; };
1787C4362B17A9EB002F50DF /* Acknowledgements.pdf in Resources */ = {isa = PBXBuildFile; fileRef = 1787C4352B17A9EB002F50DF /* Acknowledgements.pdf */; };
1787C43B2B187187002F50DF /* MenuBarTintKind.swift in Sources */ = {isa = PBXBuildFile; fileRef = 1787C43A2B187187002F50DF /* MenuBarTintKind.swift */; };
178B36692AE6EC2E00AA7B35 /* MenuBarAppearancePanel.swift in Sources */ = {isa = PBXBuildFile; fileRef = 178B36682AE6EC2E00AA7B35 /* MenuBarAppearancePanel.swift */; };
17928F1A2AC5DF9C0016C615 /* Defaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17928F192AC5DF9C0016C615 /* Defaults.swift */; };
179F3C432ACE746700A76EE8 /* RemoveSidebarToggle.swift in Sources */ = {isa = PBXBuildFile; fileRef = 179F3C422ACE746700A76EE8 /* RemoveSidebarToggle.swift */; };
17B380F32ADCBC8A0002C9C3 /* OnKeyDown.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B380F22ADCBC8A0002C9C3 /* OnKeyDown.swift */; };
17B380F52ADCBE090002C9C3 /* LocalEventMonitorModifier.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B380F42ADCBE090002C9C3 /* LocalEventMonitorModifier.swift */; };
17B7F32B2B264C1800CDCF49 /* MenuBarAppearanceManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17B7F32A2B264C1800CDCF49 /* MenuBarAppearanceManager.swift */; };
17C3C5F72B75A36100B9648C /* NSScreen+displayID.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17C3C5F62B75A36100B9648C /* NSScreen+displayID.swift */; };
17DFF4AC2AD5FB3300B5177A /* MenuBarSettingsPane.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DFF4AB2AD5FB3300B5177A /* MenuBarSettingsPane.swift */; };
17DFF4C02AD8DBC500B5177A /* CodableColor.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17DFF4BF2AD8DBC500B5177A /* CodableColor.swift */; };
17EC6B582AE0C34A0065F260 /* Comparable+clamped.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17EC6B572AE0C34A0065F260 /* Comparable+clamped.swift */; };
Expand Down Expand Up @@ -101,6 +100,8 @@
1726A3F82B3378B8008B09DD /* Acknowledgements.rtf */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.rtf; path = Acknowledgements.rtf; sourceTree = "<group>"; };
1736F77B2ADBBF340073428E /* CustomGradientPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomGradientPicker.swift; sourceTree = "<group>"; };
1736F77F2ADBC02B0073428E /* CustomGradient.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomGradient.swift; sourceTree = "<group>"; };
174AA5D52B71D97100E3FE74 /* MenuBarAppearancePanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarAppearancePanel.swift; sourceTree = "<group>"; };
174AA5F42B730A0B00E3FE74 /* ScreenCaptureManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenCaptureManager.swift; sourceTree = "<group>"; };
1750850D2B683A4C00CFF13A /* StateView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StateView.swift; sourceTree = "<group>"; };
175085122B69C4C100CFF13A /* CustomTabBuilder.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTabBuilder.swift; sourceTree = "<group>"; };
175085142B69C50C00CFF13A /* CustomTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CustomTab.swift; sourceTree = "<group>"; };
Expand All @@ -113,9 +114,6 @@
177354692B1BBACF001CF731 /* MenuBarAppearanceTab.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarAppearanceTab.swift; sourceTree = "<group>"; };
1773546B2B1BBBA1001CF731 /* MenuBarShapePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarShapePicker.swift; sourceTree = "<group>"; };
1773546F2B1BFF65001CF731 /* HorizontalEdge+cgRectEdge.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HorizontalEdge+cgRectEdge.swift"; sourceTree = "<group>"; };
177354782B1F533F001CF731 /* MenuBarOverlayPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarOverlayPanel.swift; sourceTree = "<group>"; };
1773547A2B1F539A001CF731 /* MenuBarBackingPanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarBackingPanel.swift; sourceTree = "<group>"; };
177354802B1F5F38001CF731 /* ScreenshotManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenshotManager.swift; sourceTree = "<group>"; };
177354832B1F9AF9001CF731 /* NSBezierPath+union.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSBezierPath+union.swift"; sourceTree = "<group>"; };
177386F22B092A0700448BBF /* ControlItemImage.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlItemImage.swift; sourceTree = "<group>"; };
177386F42B0A654D00448BBF /* ControlItemImageSet.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ControlItemImageSet.swift; sourceTree = "<group>"; };
Expand All @@ -125,13 +123,13 @@
1787C4332B16AECF002F50DF /* PermissionsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PermissionsView.swift; sourceTree = "<group>"; };
1787C4352B17A9EB002F50DF /* Acknowledgements.pdf */ = {isa = PBXFileReference; lastKnownFileType = image.pdf; path = Acknowledgements.pdf; sourceTree = "<group>"; };
1787C43A2B187187002F50DF /* MenuBarTintKind.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarTintKind.swift; sourceTree = "<group>"; };
178B36682AE6EC2E00AA7B35 /* MenuBarAppearancePanel.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarAppearancePanel.swift; sourceTree = "<group>"; };
17928F192AC5DF9C0016C615 /* Defaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Defaults.swift; sourceTree = "<group>"; };
179F3C422ACE746700A76EE8 /* RemoveSidebarToggle.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = RemoveSidebarToggle.swift; sourceTree = "<group>"; };
17B380F22ADCBC8A0002C9C3 /* OnKeyDown.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OnKeyDown.swift; sourceTree = "<group>"; };
17B380F42ADCBE090002C9C3 /* LocalEventMonitorModifier.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocalEventMonitorModifier.swift; sourceTree = "<group>"; };
17B7F32A2B264C1800CDCF49 /* MenuBarAppearanceManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarAppearanceManager.swift; sourceTree = "<group>"; };
17C261E22B5AC03C0076F129 /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
17C3C5F62B75A36100B9648C /* NSScreen+displayID.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSScreen+displayID.swift"; sourceTree = "<group>"; };
17DFF4AB2AD5FB3300B5177A /* MenuBarSettingsPane.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MenuBarSettingsPane.swift; sourceTree = "<group>"; };
17DFF4BF2AD8DBC500B5177A /* CodableColor.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CodableColor.swift; sourceTree = "<group>"; };
17EC6B572AE0C34A0065F260 /* Comparable+clamped.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Comparable+clamped.swift"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -287,16 +285,6 @@
path = HorizontalEdge;
sourceTree = "<group>";
};
177354772B1F530B001CF731 /* MenuBarAppearancePanel */ = {
isa = PBXGroup;
children = (
178B36682AE6EC2E00AA7B35 /* MenuBarAppearancePanel.swift */,
1773547A2B1F539A001CF731 /* MenuBarBackingPanel.swift */,
177354782B1F533F001CF731 /* MenuBarOverlayPanel.swift */,
);
path = MenuBarAppearancePanel;
sourceTree = "<group>";
};
177354822B1F9AE1001CF731 /* NSBezierPath */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -370,6 +358,14 @@
path = Main;
sourceTree = "<group>";
};
17C3C5F52B75A35000B9648C /* NSScreen */ = {
isa = PBXGroup;
children = (
17C3C5F62B75A36100B9648C /* NSScreen+displayID.swift */,
);
path = NSScreen;
sourceTree = "<group>";
};
17EC6B522AE0C09F0065F260 /* Pickers */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -491,7 +487,7 @@
17928F192AC5DF9C0016C615 /* Defaults.swift */,
170CF88D2B0EDD780073F982 /* LocalizedErrorBox.swift */,
71008DEF2AB907B00036B1F3 /* ObjectAssociation.swift */,
177354802B1F5F38001CF731 /* ScreenshotManager.swift */,
174AA5F42B730A0B00E3FE74 /* ScreenCaptureManager.swift */,
170749CB2B120951009DDF73 /* EventMonitors */,
71D36C492A88EDD200D89CD5 /* Swizzling */,
);
Expand All @@ -508,6 +504,7 @@
716683442A76811C006ABF84 /* Logger */,
7133ED5F2A855ADA000A7E1B /* NSApplication */,
177354822B1F9AE1001CF731 /* NSBezierPath */,
17C3C5F52B75A35000B9648C /* NSScreen */,
716683462A76811C006ABF84 /* NSStatusItem */,
);
path = Extensions;
Expand All @@ -533,12 +530,12 @@
isa = PBXGroup;
children = (
17B7F32A2B264C1800CDCF49 /* MenuBarAppearanceManager.swift */,
174AA5D52B71D97100E3FE74 /* MenuBarAppearancePanel.swift */,
7166834F2A7681AF006ABF84 /* MenuBarManager.swift */,
7162406E2AA0A323003EC671 /* MenuBarSection.swift */,
177354652B1B8502001CF731 /* MenuBarShape.swift */,
1787C43A2B187187002F50DF /* MenuBarTintKind.swift */,
177386F62B0A656100448BBF /* ControlItem */,
177354772B1F530B001CF731 /* MenuBarAppearancePanel */,
);
path = MenuBar;
sourceTree = "<group>";
Expand Down Expand Up @@ -688,7 +685,6 @@
716683502A7681AF006ABF84 /* MenuBarManager.swift in Sources */,
1780ED0E2B43D132000AED1C /* BoxObject.swift in Sources */,
175085132B69C4C100CFF13A /* CustomTabBuilder.swift in Sources */,
177354812B1F5F38001CF731 /* ScreenshotManager.swift in Sources */,
176B23F42ADB76A1008AE86B /* CustomColorPicker.swift in Sources */,
17540BD82B20C0DA00A0F965 /* NSBezierPath+drawShadow.swift in Sources */,
177354842B1F9AF9001CF731 /* NSBezierPath+union.swift in Sources */,
Expand All @@ -697,7 +693,6 @@
1773546A2B1BBACF001CF731 /* MenuBarAppearanceTab.swift in Sources */,
17B7F32B2B264C1800CDCF49 /* MenuBarAppearanceManager.swift in Sources */,
7150A7B12AA427F80045EA68 /* Hotkey+Key.swift in Sources */,
178B36692AE6EC2E00AA7B35 /* MenuBarAppearancePanel.swift in Sources */,
175584152B541D6F00EDC9D3 /* MenuBarLayoutTab.swift in Sources */,
1736F7802ADBC02B0073428E /* CustomGradient.swift in Sources */,
7166834C2A76811C006ABF84 /* NSStatusItem+showMenu.swift in Sources */,
Expand All @@ -716,9 +711,10 @@
17DFF4C02AD8DBC500B5177A /* CodableColor.swift in Sources */,
71839BD82A997DC200250044 /* Edge+cgRectEdge.swift in Sources */,
714BB9BB2AAB1D690057FB1D /* AboutSettingsPane.swift in Sources */,
177354792B1F533F001CF731 /* MenuBarOverlayPanel.swift in Sources */,
174AA5F52B730A0B00E3FE74 /* ScreenCaptureManager.swift in Sources */,
71623BD32A8B6744002FD331 /* CustomButtonStyle.swift in Sources */,
7133ED712A85AE6A000A7E1B /* SettingsNavigationItem.swift in Sources */,
174AA5D62B71D97100E3FE74 /* MenuBarAppearancePanel.swift in Sources */,
71008DF02AB907B00036B1F3 /* ObjectAssociation.swift in Sources */,
179F3C432ACE746700A76EE8 /* RemoveSidebarToggle.swift in Sources */,
17DFF4AC2AD5FB3300B5177A /* MenuBarSettingsPane.swift in Sources */,
Expand All @@ -730,8 +726,8 @@
170CF88C2B0ED4FA0073F982 /* HotkeyRecordingFailure.swift in Sources */,
170CF88E2B0EDD780073F982 /* LocalizedErrorBox.swift in Sources */,
7166832E2A767E6A006ABF84 /* IceApp.swift in Sources */,
1773547B2B1F539A001CF731 /* MenuBarBackingPanel.swift in Sources */,
71FEA2502A8D5D590048341A /* HotkeyRecorder.swift in Sources */,
17C3C5F72B75A36100B9648C /* NSScreen+displayID.swift in Sources */,
7133ED5E2A853FCF000A7E1B /* Constants.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
15 changes: 15 additions & 0 deletions Ice/Extensions/NSScreen/NSScreen+displayID.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// NSScreen+displayID.swift
// Ice
//

import Cocoa

extension NSScreen {
/// The display identifier of the screen.
var displayID: CGDirectDisplayID {
// deviceDescription is guaranteed to always have an NSScreenNumber key, so a force unwrap here is okay
let screenNumber = deviceDescription[NSDeviceDescriptionKey("NSScreenNumber")]! // swiftlint:disable:this force_unwrapping
return screenNumber as! CGDirectDisplayID // swiftlint:disable:this force_cast
}
}
11 changes: 9 additions & 2 deletions Ice/MenuBar/ControlItem/ControlItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -242,8 +242,15 @@ final class ControlItem: ObservableObject {

if let window = statusItem.button?.window {
window.publisher(for: \.frame)
.sink { [weak self] frame in
self?.windowFrame = frame
.sink { [weak self, weak window] frame in
guard
let self,
let screen = window?.screen,
screen.frame.intersects(frame)
else {
return
}
windowFrame = frame
}
.store(in: &c)

Expand Down
Loading

0 comments on commit 815f491

Please sign in to comment.