Skip to content

Commit

Permalink
[chore]: Style changes and tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
jordanbaird committed Aug 2, 2024
1 parent 2332b01 commit 5411f32
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 132 deletions.
16 changes: 16 additions & 0 deletions Ice.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,8 @@
17FE5AD32BCA7A7500E4F8D9 /* ScreenStateManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17FE5AD22BCA7A7500E4F8D9 /* ScreenStateManager.swift */; };
17FE5AD52BCA9BE200E4F8D9 /* ScreenState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 17FE5AD42BCA9BE200E4F8D9 /* ScreenState.swift */; };
71008DF02AB907B00036B1F3 /* ObjectAssociation.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71008DEF2AB907B00036B1F3 /* ObjectAssociation.swift */; };
7105CA212C5D2EFF004E439E /* StatusItemDefaults.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7105CA202C5D2EFF004E439E /* StatusItemDefaults.swift */; };
7105CA252C5D2F44004E439E /* StatusItemDefaultsKey.swift in Sources */ = {isa = PBXBuildFile; fileRef = 7105CA242C5D2F44004E439E /* StatusItemDefaultsKey.swift */; };
711535F22AB9F6C1003193AD /* BindingExposable.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711535F12AB9F6C1003193AD /* BindingExposable.swift */; };
711568B02C59ADBF00CDF58F /* NSScreen+frameOfNotch.swift in Sources */ = {isa = PBXBuildFile; fileRef = 711568AF2C59ADBF00CDF58F /* NSScreen+frameOfNotch.swift */; };
71287C602C3189AC0028706E /* IceBarColorManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = 71287C5F2C3189AC0028706E /* IceBarColorManager.swift */; };
Expand Down Expand Up @@ -225,6 +227,8 @@
17FE5AD22BCA7A7500E4F8D9 /* ScreenStateManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenStateManager.swift; sourceTree = "<group>"; };
17FE5AD42BCA9BE200E4F8D9 /* ScreenState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ScreenState.swift; sourceTree = "<group>"; };
71008DEF2AB907B00036B1F3 /* ObjectAssociation.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ObjectAssociation.swift; sourceTree = "<group>"; };
7105CA202C5D2EFF004E439E /* StatusItemDefaults.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemDefaults.swift; sourceTree = "<group>"; };
7105CA242C5D2F44004E439E /* StatusItemDefaultsKey.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = StatusItemDefaultsKey.swift; sourceTree = "<group>"; };
711535F12AB9F6C1003193AD /* BindingExposable.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = BindingExposable.swift; sourceTree = "<group>"; };
711568AF2C59ADBF00CDF58F /* NSScreen+frameOfNotch.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "NSScreen+frameOfNotch.swift"; sourceTree = "<group>"; };
71287C5F2C3189AC0028706E /* IceBarColorManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IceBarColorManager.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -590,6 +594,15 @@
path = ScreenState;
sourceTree = "<group>";
};
7105CA232C5D2F36004E439E /* StatusItemDefaults */ = {
isa = PBXGroup;
children = (
7105CA202C5D2EFF004E439E /* StatusItemDefaults.swift */,
7105CA242C5D2F44004E439E /* StatusItemDefaultsKey.swift */,
);
path = StatusItemDefaults;
sourceTree = "<group>";
};
7133ED5F2A855ADA000A7E1B /* NSApplication */ = {
isa = PBXGroup;
children = (
Expand Down Expand Up @@ -699,6 +712,7 @@
17CC22B42B8A55E7001A0582 /* WindowInfo.swift */,
170749CB2B120951009DDF73 /* EventMonitors */,
17FE5AD62BCA9BEC00E4F8D9 /* ScreenState */,
7105CA232C5D2F36004E439E /* StatusItemDefaults */,
179AC2FD2C1147500051E7B0 /* Swizzling */,
);
path = Utilities;
Expand Down Expand Up @@ -959,6 +973,7 @@
17F9984D2C16CD8E00D75EC0 /* MenuBarItemsSettingsPane.swift in Sources */,
71F428152C3B5F3D0025706C /* AppNavigationState.swift in Sources */,
17D1AC8D2B97BB5900726180 /* MenuBarItem.swift in Sources */,
7105CA212C5D2EFF004E439E /* StatusItemDefaults.swift in Sources */,
71553E372C378BF50083F5BE /* Notifications.swift in Sources */,
173C248C2B8E821C0096F7A1 /* UpdatesSettingsPane.swift in Sources */,
171C6F9C2C0356BC0097A5C8 /* GeneralSettingsPane.swift in Sources */,
Expand All @@ -974,6 +989,7 @@
7166833D2A7680CE006ABF84 /* AppDelegate.swift in Sources */,
17EE695E2C26618F00F778A7 /* AnyInsettableShape.swift in Sources */,
7133ED6A2A85870E000A7E1B /* SettingsView.swift in Sources */,
7105CA252C5D2F44004E439E /* StatusItemDefaultsKey.swift in Sources */,
7133ED652A85811C000A7E1B /* NSApplication+windowWithIdentifier.swift in Sources */,
7150A7B32AA42B640045EA68 /* Modifiers.swift in Sources */,
179AC2FF2C11475F0051E7B0 /* NSSplitViewItem+swizzledCanCollapse.swift in Sources */,
Expand Down
5 changes: 1 addition & 4 deletions Ice/Bridging/Shims/Deprecated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,4 @@ import ApplicationServices

/// Returns a PSN for a given PID.
@_silgen_name("GetProcessForPID")
func GetProcessForPID(
_ pid: pid_t,
_ psn: inout ProcessSerialNumber
) -> OSStatus
func GetProcessForPID(_ pid: pid_t, _ psn: inout ProcessSerialNumber) -> OSStatus
72 changes: 11 additions & 61 deletions Ice/Bridging/Shims/Private.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,93 +37,43 @@ struct CGSSpaceMask: OptionSet {
func CGSMainConnectionID() -> CGSConnectionID

@_silgen_name("CGSCopyConnectionProperty")
func CGSCopyConnectionProperty(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ key: CFString,
_ outValue: inout Unmanaged<CFTypeRef>?
) -> CGError
func CGSCopyConnectionProperty(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ key: CFString, _ outValue: inout Unmanaged<CFTypeRef>?) -> CGError

@_silgen_name("CGSSetConnectionProperty")
func CGSSetConnectionProperty(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ key: CFString,
_ value: CFTypeRef
) -> CGError
func CGSSetConnectionProperty(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ key: CFString, _ value: CFTypeRef) -> CGError

// MARK: - CGSEvent Functions

@_silgen_name("CGSEventIsAppUnresponsive")
func CGSEventIsAppUnresponsive(
_ cid: CGSConnectionID,
_ psn: inout ProcessSerialNumber
) -> Bool
func CGSEventIsAppUnresponsive(_ cid: CGSConnectionID, _ psn: inout ProcessSerialNumber) -> Bool

// MARK: - CGSSpace Functions

@_silgen_name("CGSGetActiveSpace")
func CGSGetActiveSpace(_ cid: CGSConnectionID) -> CGSSpaceID

@_silgen_name("CGSCopySpacesForWindows")
func CGSCopySpacesForWindows(
_ cid: CGSConnectionID,
_ mask: CGSSpaceMask,
_ windowIDs: CFArray
) -> Unmanaged<CFArray>?
func CGSCopySpacesForWindows(_ cid: CGSConnectionID, _ mask: CGSSpaceMask, _ windowIDs: CFArray) -> Unmanaged<CFArray>?

@_silgen_name("CGSSpaceGetType")
func CGSSpaceGetType(
_ cid: CGSConnectionID,
_ sid: CGSSpaceID
) -> CGSSpaceType
func CGSSpaceGetType(_ cid: CGSConnectionID, _ sid: CGSSpaceID) -> CGSSpaceType

// MARK: - CGSWindow Functions

@_silgen_name("CGSGetWindowList")
func CGSGetWindowList(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ count: Int32,
_ list: UnsafeMutablePointer<CGWindowID>,
_ outCount: inout Int32
) -> CGError
func CGSGetWindowList(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ count: Int32, _ list: UnsafeMutablePointer<CGWindowID>, _ outCount: inout Int32) -> CGError

@_silgen_name("CGSGetOnScreenWindowList")
func CGSGetOnScreenWindowList(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ count: Int32,
_ list: UnsafeMutablePointer<CGWindowID>,
_ outCount: inout Int32
) -> CGError
func CGSGetOnScreenWindowList(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ count: Int32, _ list: UnsafeMutablePointer<CGWindowID>, _ outCount: inout Int32) -> CGError

@_silgen_name("CGSGetProcessMenuBarWindowList")
func CGSGetProcessMenuBarWindowList(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ count: Int32,
_ list: UnsafeMutablePointer<CGWindowID>,
_ outCount: inout Int32
) -> CGError
func CGSGetProcessMenuBarWindowList(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ count: Int32, _ list: UnsafeMutablePointer<CGWindowID>, _ outCount: inout Int32) -> CGError

@_silgen_name("CGSGetWindowCount")
func CGSGetWindowCount(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ outCount: inout Int32
) -> CGError
func CGSGetWindowCount(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ outCount: inout Int32) -> CGError

@_silgen_name("CGSGetOnScreenWindowCount")
func CGSGetOnScreenWindowCount(
_ cid: CGSConnectionID,
_ targetCID: CGSConnectionID,
_ outCount: inout Int32
) -> CGError
func CGSGetOnScreenWindowCount(_ cid: CGSConnectionID, _ targetCID: CGSConnectionID, _ outCount: inout Int32) -> CGError

@_silgen_name("CGSGetScreenRectForWindow")
func CGSGetScreenRectForWindow(
_ cid: CGSConnectionID,
_ wid: CGWindowID,
_ outRect: inout CGRect
) -> CGError
func CGSGetScreenRectForWindow(_ cid: CGSConnectionID, _ wid: CGWindowID, _ outRect: inout CGRect) -> CGError
71 changes: 8 additions & 63 deletions Ice/ControlItem/ControlItem.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,13 +101,14 @@ final class ControlItem: ObservableObject {
self.identifier = identifier
self.state = .hideItems

// FIXME: This is a strong candidate for a new macOS release to break, but we need this
// constraint to hide control items when the `ShowSectionDividers` setting is disabled.
// We used to use the status item's `isVisible` property, which was more robust, but would
// completely remove the control item. Now that we have profiles, we need to be able to
// accurately retrieve the items for each section, so we need the control items to always
// be present to act as delimiters. The new solution is to remove the constraint that
// prevents status items from having a length of zero, then resizing the content view.
// This is a strong candidate for a new macOS release to break, but we need this constraint
// to hide control items when the `ShowSectionDividers` setting is disabled. We used to use
// the status item's `isVisible` property, which was more robust, but would completely remove
// the control item. Now that we have profiles, we need to be able to accurately retrieve the
// items for each section, so we need the control items to always be present to act as
// delimiters. The new solution is to remove the constraint that prevents status items from
// having a length of zero, then resize the content view.
// FIXME: Find a replacement for this
if
let button = statusItem.button,
let constraints = button.window?.contentView?.constraintsAffectingLayout(for: .horizontal),
Expand Down Expand Up @@ -542,62 +543,6 @@ final class ControlItem: ObservableObject {
}
}

// MARK: - StatusItemDefaultsKey

/// Keys used to look up user defaults for status items.
struct StatusItemDefaultsKey<Value> {
let rawValue: String
}

extension StatusItemDefaultsKey<CGFloat> {
static let preferredPosition = StatusItemDefaultsKey(rawValue: "Preferred Position")
}

extension StatusItemDefaultsKey<Bool> {
static let isVisible = StatusItemDefaultsKey(rawValue: "Visible")
}

// MARK: - StatusItemDefaults

/// Proxy getters and setters for a status item's user default values.
enum StatusItemDefaults {
private static func stringKey<Value>(
forKey key: StatusItemDefaultsKey<Value>,
autosaveName: String
) -> String {
return "NSStatusItem \(key.rawValue) \(autosaveName)"
}

/// Accesses the value associated with the specified key and autosave name.
static subscript<Value>(
key: StatusItemDefaultsKey<Value>,
autosaveName: String
) -> Value? {
get {
let key = stringKey(forKey: key, autosaveName: autosaveName)
return UserDefaults.standard.object(forKey: key) as? Value
}
set {
let key = stringKey(forKey: key, autosaveName: autosaveName)
UserDefaults.standard.set(newValue, forKey: key)
}
}

/// Migrates the given status item defaults key from an old autosave name
/// to a new autosave name.
static func migrate<Value>(
key: StatusItemDefaultsKey<Value>,
from oldAutosaveName: String,
to newAutosaveName: String
) {
guard newAutosaveName != oldAutosaveName else {
return
}
Self[key, newAutosaveName] = Self[key, oldAutosaveName]
Self[key, oldAutosaveName] = nil
}
}

// MARK: - Logger
private extension Logger {
static let controlItem = Logger(category: "ControlItem")
Expand Down
5 changes: 1 addition & 4 deletions Ice/LayoutBar/LayoutBarContainer.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import Combine
class LayoutBarContainer: NSView {
/// Phases for a dragging session.
enum DraggingPhase {
case entered
case exited
case updated
case ended
case entered, exited, updated, ended
}

/// Cached width constraint for the container view.
Expand Down
34 changes: 34 additions & 0 deletions Ice/Utilities/StatusItemDefaults/StatusItemDefaults.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// StatusItemDefaults.swift
// Ice
//

import Foundation

/// Proxy getters and setters for a status item's user default values.
enum StatusItemDefaults {
private static func stringKey<Value>(forKey key: StatusItemDefaultsKey<Value>, autosaveName: String) -> String {
return "NSStatusItem \(key.rawValue) \(autosaveName)"
}

/// Accesses the value associated with the specified key and autosave name.
static subscript<Value>(key: StatusItemDefaultsKey<Value>, autosaveName: String) -> Value? {
get {
let key = stringKey(forKey: key, autosaveName: autosaveName)
return UserDefaults.standard.object(forKey: key) as? Value
}
set {
let key = stringKey(forKey: key, autosaveName: autosaveName)
UserDefaults.standard.set(newValue, forKey: key)
}
}

/// Migrates the given status item defaults key from an old autosave name to a new autosave name.
static func migrate<Value>(key: StatusItemDefaultsKey<Value>, from oldAutosaveName: String, to newAutosaveName: String) {
guard newAutosaveName != oldAutosaveName else {
return
}
Self[key, newAutosaveName] = Self[key, oldAutosaveName]
Self[key, oldAutosaveName] = nil
}
}
19 changes: 19 additions & 0 deletions Ice/Utilities/StatusItemDefaults/StatusItemDefaultsKey.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// StatusItemDefaultsKey.swift
// Ice
//

import CoreGraphics

/// Keys used to look up user defaults for status items.
struct StatusItemDefaultsKey<Value> {
let rawValue: String
}

extension StatusItemDefaultsKey<CGFloat> {
static let preferredPosition = StatusItemDefaultsKey(rawValue: "Preferred Position")
}

extension StatusItemDefaultsKey<Bool> {
static let isVisible = StatusItemDefaultsKey(rawValue: "Visible")
}

0 comments on commit 5411f32

Please sign in to comment.