Skip to content

Commit

Permalink
Add UserSettings.autoCompactDisplayCount
Browse files Browse the repository at this point in the history
  • Loading branch information
tekezo committed Feb 20, 2025
1 parent c28699d commit 7f98cfe
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/TrueWidget/swift/DisplayMonitor.swift
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class DisplayMonitor: ObservableObject {
}

private let callback: CGDisplayReconfigurationCallBack = { _, flags, userInfo in
if !flags.intersection([.addFlag, .removeFlag]).isEmpty {
if flags.isDisjoint(with: [.addFlag, .removeFlag]) {
guard let opaque = userInfo else {
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/TrueWidget/swift/TrueWidgetApp.swift
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ struct TrueWidgetApp: App {
},
label: {
checkmarkLabel(
title: "Auto Compact",
title: "Auto compact",
checked: userSettings.widgetAppearance == WidgetAppearance.autoCompact.rawValue)
}
)
Expand Down
6 changes: 6 additions & 0 deletions src/TrueWidget/swift/UserSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,10 @@ final class UserSettings: ObservableObject {
@AppStorage("compactLocalTimeSecondsFontSize") var compactLocalTimeSecondsFontSize: Double = 12.0
@AppStorage("compactShowCPUUsage") var compactShowCPUUsage: Bool = true
@AppStorage("compactCPUUsageFontSize") var compactCPUUsageFontSize: Double = 12.0

//
// Auto compact
//

@AppStorage("autoCompactDisplayCount") var autoCompactDisplayCount: Int = 1
}
2 changes: 1 addition & 1 deletion src/TrueWidget/swift/Views/ContentView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ struct ContentView: View {
case WidgetAppearance.compact.rawValue:
return true
case WidgetAppearance.autoCompact.rawValue:
if displayMonitor.displayCount == 1 {
if displayMonitor.displayCount <= userSettings.autoCompactDisplayCount {
return true
}
return false
Expand Down
19 changes: 19 additions & 0 deletions src/TrueWidget/swift/Views/Settings/SettingsCompactView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ struct SettingsCompactView: View {
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}

GroupBox(label: Text("Auto compact")) {
VStack(alignment: .leading) {
HStack {
Text("Automatically switch to compact mode if the display count is ")

Picker("", selection: $userSettings.autoCompactDisplayCount) {
ForEach(1...16, id: \.self) { number in
Text("\(number)").tag(number)
}
}
.frame(width: 60)

Text("or less")
}
}
.padding()
.frame(maxWidth: .infinity, alignment: .leading)
}
}
}
}
2 changes: 1 addition & 1 deletion src/TrueWidget/swift/Views/Settings/SettingsMainView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ struct SettingsMainView: View {
Picker("", selection: $userSettings.widgetAppearance) {
Text("Normal").tag(WidgetAppearance.normal.rawValue)
Text("Compact").tag(WidgetAppearance.compact.rawValue)
Text("Auto Compact").tag(WidgetAppearance.autoCompact.rawValue)
Text("Auto compact").tag(WidgetAppearance.autoCompact.rawValue)
Text("Hidden").tag(WidgetAppearance.hidden.rawValue)
}
.pickerStyle(.radioGroup)
Expand Down

0 comments on commit 7f98cfe

Please sign in to comment.