From b4654909720882ab27a6a9ec092c03f5d6849fea Mon Sep 17 00:00:00 2001 From: Serhiy Mytrovtsiy Date: Fri, 14 Oct 2022 17:24:35 +0200 Subject: [PATCH] feat: added an option to group CPU clusters in the Bar Chart widget (#1110) --- Modules/CPU/main.swift | 10 ++++ Modules/CPU/settings.swift | 53 +++++++++++++++++-- .../bg.lproj/Localizable.strings | 1 + .../ca.lproj/Localizable.strings | 1 + .../cs.lproj/Localizable.strings | 1 + .../da.lproj/Localizable.strings | 1 + .../de.lproj/Localizable.strings | 1 + .../el.lproj/Localizable.strings | 1 + .../en.lproj/Localizable.strings | 1 + .../es.lproj/Localizable.strings | 1 + .../fr.lproj/Localizable.strings | 1 + .../he.lproj/Localizable.strings | 1 + .../hr.lproj/Localizable.strings | 1 + .../hu.lproj/Localizable.strings | 1 + .../id.lproj/Localizable.strings | 1 + .../it.lproj/Localizable.strings | 1 + .../ja.lproj/Localizable.strings | 1 + .../ko.lproj/Localizable.strings | 1 + .../nb.lproj/Localizable.strings | 1 + .../nl.lproj/Localizable.strings | 1 + .../pl.lproj/Localizable.strings | 1 + .../pt-BR.lproj/Localizable.strings | 1 + .../pt-PT.lproj/Localizable.strings | 1 + .../ro.lproj/Localizable.strings | 1 + .../ru.lproj/Localizable.strings | 1 + .../sl.lproj/Localizable.strings | 1 + .../sv.lproj/Localizable.strings | 1 + .../tr.lproj/Localizable.strings | 1 + .../uk.lproj/Localizable.strings | 1 + .../vi.lproj/Localizable.strings | 1 + .../zh-Hans.lproj/Localizable.strings | 1 + .../zh-Hant.lproj/Localizable.strings | 1 + 32 files changed, 89 insertions(+), 4 deletions(-) diff --git a/Modules/CPU/main.swift b/Modules/CPU/main.swift index d6db7945..00658704 100644 --- a/Modules/CPU/main.swift +++ b/Modules/CPU/main.swift @@ -56,6 +56,11 @@ public class CPU: Module { return Store.shared.bool(key: "\(self.config.name)_splitValue", defaultValue: false) } } + private var groupByClustersState: Bool { + get { + return Store.shared.bool(key: "\(self.config.name)_clustersGroup", defaultValue: false) + } + } private var notificationLevel: String { get { return Store.shared.string(key: "\(self.config.name)_notificationLevel", defaultValue: "Disabled") @@ -179,6 +184,11 @@ public class CPU: Module { ColorValue(value.systemLoad, color: NSColor.systemRed), ColorValue(value.userLoad, color: NSColor.systemBlue) ]] + } else if self.groupByClustersState, let e = value.usageECores, let p = value.usagePCores { + val = [ + [ColorValue(e, color: NSColor.systemTeal)], + [ColorValue(p, color: NSColor.systemBlue)] + ] } widget.setValue(val) case let widget as PieChart: diff --git a/Modules/CPU/settings.swift b/Modules/CPU/settings.swift index 9f85c887..f13fae30 100644 --- a/Modules/CPU/settings.swift +++ b/Modules/CPU/settings.swift @@ -21,6 +21,7 @@ internal class Settings: NSStackView, Settings_v { private var updateTopIntervalValue: Int = 1 private var numberOfProcesses: Int = 8 private var notificationLevel: String = "Disabled" + private var clustersGroupState: Bool = false private let title: String private var hasHyperthreadingCores = false @@ -33,6 +34,8 @@ internal class Settings: NSStackView, Settings_v { private var hyperthreadView: NSView? = nil private var splitValueView: NSView? = nil + private var usagePerCoreView: NSView? = nil + private var groupByClustersView: NSView? = nil public init(_ title: String) { self.title = title @@ -48,6 +51,7 @@ internal class Settings: NSStackView, Settings_v { self.hyperthreadState = false } self.hasHyperthreadingCores = sysctlByName("hw.physicalcpu") != sysctlByName("hw.logicalcpu") + self.clustersGroupState = Store.shared.bool(key: "\(self.title)_clustersGroup", defaultValue: self.clustersGroupState) super.init(frame: NSRect(x: 0, y: 0, width: 0, height: 0)) @@ -92,11 +96,19 @@ internal class Settings: NSStackView, Settings_v { )) if !widgets.filter({ $0 == .barChart }).isEmpty { - self.addArrangedSubview(toggleSettingRow( + self.usagePerCoreView = toggleSettingRow( title: localizedString("Show usage per core"), action: #selector(toggleUsagePerCore), state: self.usagePerCoreState - )) + ) + self.addArrangedSubview(self.usagePerCoreView!) + + self.groupByClustersView = toggleSettingRow( + title: localizedString("Cluster grouping"), + action: #selector(toggleClustersGroup), + state: self.clustersGroupState + ) + self.addArrangedSubview(self.groupByClustersView!) if self.hasHyperthreadingCores { self.hyperthreadView = toggleSettingRow( @@ -116,13 +128,14 @@ internal class Settings: NSStackView, Settings_v { action: #selector(toggleSplitValue), state: self.splitValueState ) - if self.usagePerCoreState { + if self.usagePerCoreState || self.clustersGroupState { findAndToggleEnableNSControlState(self.splitValueView, state: false) findAndToggleNSControlState(self.splitValueView, state: .off) } self.addArrangedSubview(self.splitValueView!) } + #if arch(x86_64) if hasIPG { self.addArrangedSubview(toggleSettingRow( title: "\(localizedString("CPU frequency")) (IPG)", @@ -130,6 +143,7 @@ internal class Settings: NSStackView, Settings_v { state: self.IPGState )) } + #endif self.addArrangedSubview(selectSettingsRowV1( title: localizedString("Number of top processes"), @@ -183,7 +197,7 @@ internal class Settings: NSStackView, Settings_v { self.callback() findAndToggleEnableNSControlState(self.hyperthreadView, state: self.usagePerCoreState) - findAndToggleEnableNSControlState(self.splitValueView, state: !self.usagePerCoreState) + findAndToggleEnableNSControlState(self.splitValueView, state: !(self.usagePerCoreState || self.clustersGroupState)) if !self.usagePerCoreState { self.hyperthreadState = false @@ -194,6 +208,12 @@ internal class Settings: NSStackView, Settings_v { Store.shared.set(key: "\(self.title)_splitValue", value: self.splitValueState) findAndToggleNSControlState(self.splitValueView, state: .off) } + + if self.clustersGroupState && self.usagePerCoreState { + self.clustersGroupState = false + Store.shared.set(key: "\(self.title)_clustersGroup", value: self.clustersGroupState) + findAndToggleNSControlState(self.groupByClustersView, state: .off) + } } @objc func toggleMultithreading(_ sender: NSControl) { @@ -244,4 +264,29 @@ internal class Settings: NSStackView, Settings_v { Store.shared.set(key: "\(self.title)_notificationLevel", value: "\(value/100)") } } + + @objc func toggleClustersGroup(_ sender: NSControl) { + var state: NSControl.StateValue? = nil + if #available(OSX 10.15, *) { + state = sender is NSSwitch ? (sender as! NSSwitch).state: nil + } else { + state = sender is NSButton ? (sender as! NSButton).state: nil + } + + self.clustersGroupState = state! == .on ? true : false + Store.shared.set(key: "\(self.title)_clustersGroup", value: self.clustersGroupState) + + findAndToggleEnableNSControlState(self.splitValueView, state: !(self.usagePerCoreState || self.clustersGroupState)) + + if self.clustersGroupState && self.usagePerCoreState { + if #available(macOS 10.15, *) { + findAndToggleNSControlState(self.usagePerCoreView, state: .off) + let toggle: NSSwitch = NSSwitch() + toggle.state = .off + self.toggleUsagePerCore(toggle) + } + } + + self.callback() + } } diff --git a/Stats/Supporting Files/bg.lproj/Localizable.strings b/Stats/Supporting Files/bg.lproj/Localizable.strings index 5d076f4a..01eee0a5 100644 --- a/Stats/Supporting Files/bg.lproj/Localizable.strings +++ b/Stats/Supporting Files/bg.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "Показване на графична карта"; diff --git a/Stats/Supporting Files/ca.lproj/Localizable.strings b/Stats/Supporting Files/ca.lproj/Localizable.strings index 501c65b5..8c1595a0 100644 --- a/Stats/Supporting Files/ca.lproj/Localizable.strings +++ b/Stats/Supporting Files/ca.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU a mostrar"; diff --git a/Stats/Supporting Files/cs.lproj/Localizable.strings b/Stats/Supporting Files/cs.lproj/Localizable.strings index 5e0e33a3..7a7df35e 100644 --- a/Stats/Supporting Files/cs.lproj/Localizable.strings +++ b/Stats/Supporting Files/cs.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU k zobrazení"; diff --git a/Stats/Supporting Files/da.lproj/Localizable.strings b/Stats/Supporting Files/da.lproj/Localizable.strings index 57bb3de3..7f482e98 100644 --- a/Stats/Supporting Files/da.lproj/Localizable.strings +++ b/Stats/Supporting Files/da.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU der vises"; diff --git a/Stats/Supporting Files/de.lproj/Localizable.strings b/Stats/Supporting Files/de.lproj/Localizable.strings index a044d806..911cfe64 100644 --- a/Stats/Supporting Files/de.lproj/Localizable.strings +++ b/Stats/Supporting Files/de.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU auswählen"; diff --git a/Stats/Supporting Files/el.lproj/Localizable.strings b/Stats/Supporting Files/el.lproj/Localizable.strings index 4a5c450a..2b16ae66 100644 --- a/Stats/Supporting Files/el.lproj/Localizable.strings +++ b/Stats/Supporting Files/el.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU προς εμφάνιση"; diff --git a/Stats/Supporting Files/en.lproj/Localizable.strings b/Stats/Supporting Files/en.lproj/Localizable.strings index 7e8b2390..f38e30bc 100644 --- a/Stats/Supporting Files/en.lproj/Localizable.strings +++ b/Stats/Supporting Files/en.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU to show"; diff --git a/Stats/Supporting Files/es.lproj/Localizable.strings b/Stats/Supporting Files/es.lproj/Localizable.strings index d08a254c..60953480 100644 --- a/Stats/Supporting Files/es.lproj/Localizable.strings +++ b/Stats/Supporting Files/es.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU a mostrar"; diff --git a/Stats/Supporting Files/fr.lproj/Localizable.strings b/Stats/Supporting Files/fr.lproj/Localizable.strings index 432f2e0b..cd99badb 100644 --- a/Stats/Supporting Files/fr.lproj/Localizable.strings +++ b/Stats/Supporting Files/fr.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU à afficher"; diff --git a/Stats/Supporting Files/he.lproj/Localizable.strings b/Stats/Supporting Files/he.lproj/Localizable.strings index 180905e0..216c325f 100644 --- a/Stats/Supporting Files/he.lproj/Localizable.strings +++ b/Stats/Supporting Files/he.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "להראות GPU"; diff --git a/Stats/Supporting Files/hr.lproj/Localizable.strings b/Stats/Supporting Files/hr.lproj/Localizable.strings index c0b81f82..39974c70 100644 --- a/Stats/Supporting Files/hr.lproj/Localizable.strings +++ b/Stats/Supporting Files/hr.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "Grafički procesor"; diff --git a/Stats/Supporting Files/hu.lproj/Localizable.strings b/Stats/Supporting Files/hu.lproj/Localizable.strings index 1f8618db..1ef4e039 100644 --- a/Stats/Supporting Files/hu.lproj/Localizable.strings +++ b/Stats/Supporting Files/hu.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "Megjelenítendő GPU"; diff --git a/Stats/Supporting Files/id.lproj/Localizable.strings b/Stats/Supporting Files/id.lproj/Localizable.strings index 7bdb8d78..d4a87766 100644 --- a/Stats/Supporting Files/id.lproj/Localizable.strings +++ b/Stats/Supporting Files/id.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU yang ditampilkan"; diff --git a/Stats/Supporting Files/it.lproj/Localizable.strings b/Stats/Supporting Files/it.lproj/Localizable.strings index 081ec01b..c1694b60 100644 --- a/Stats/Supporting Files/it.lproj/Localizable.strings +++ b/Stats/Supporting Files/it.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU da mostrare"; diff --git a/Stats/Supporting Files/ja.lproj/Localizable.strings b/Stats/Supporting Files/ja.lproj/Localizable.strings index 3ef87232..b5bf3e5b 100644 --- a/Stats/Supporting Files/ja.lproj/Localizable.strings +++ b/Stats/Supporting Files/ja.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "表示する GPU"; diff --git a/Stats/Supporting Files/ko.lproj/Localizable.strings b/Stats/Supporting Files/ko.lproj/Localizable.strings index 5b740069..1f8969c6 100644 --- a/Stats/Supporting Files/ko.lproj/Localizable.strings +++ b/Stats/Supporting Files/ko.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "표시할 GPU"; diff --git a/Stats/Supporting Files/nb.lproj/Localizable.strings b/Stats/Supporting Files/nb.lproj/Localizable.strings index e61719b8..21ae4650 100644 --- a/Stats/Supporting Files/nb.lproj/Localizable.strings +++ b/Stats/Supporting Files/nb.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU å vise"; diff --git a/Stats/Supporting Files/nl.lproj/Localizable.strings b/Stats/Supporting Files/nl.lproj/Localizable.strings index 512e4d42..5ba55166 100644 --- a/Stats/Supporting Files/nl.lproj/Localizable.strings +++ b/Stats/Supporting Files/nl.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU om te laten zien"; diff --git a/Stats/Supporting Files/pl.lproj/Localizable.strings b/Stats/Supporting Files/pl.lproj/Localizable.strings index 7a50cec8..75634669 100644 --- a/Stats/Supporting Files/pl.lproj/Localizable.strings +++ b/Stats/Supporting Files/pl.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "Kolor systemu"; "User color" = "Kolor użytkownika"; "Idle color" = "Nieaktywny kolor"; +"Cluster grouping" = "Grupowanie klastrów"; // GPU "GPU to show" = "GPU do wyświetlenia"; diff --git a/Stats/Supporting Files/pt-BR.lproj/Localizable.strings b/Stats/Supporting Files/pt-BR.lproj/Localizable.strings index a29a3c4f..bffb26ec 100644 --- a/Stats/Supporting Files/pt-BR.lproj/Localizable.strings +++ b/Stats/Supporting Files/pt-BR.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU para mostrar"; diff --git a/Stats/Supporting Files/pt-PT.lproj/Localizable.strings b/Stats/Supporting Files/pt-PT.lproj/Localizable.strings index 6b4c49ac..2c7d9242 100644 --- a/Stats/Supporting Files/pt-PT.lproj/Localizable.strings +++ b/Stats/Supporting Files/pt-PT.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU para mostrar"; diff --git a/Stats/Supporting Files/ro.lproj/Localizable.strings b/Stats/Supporting Files/ro.lproj/Localizable.strings index 4d9a6d45..007ba302 100644 --- a/Stats/Supporting Files/ro.lproj/Localizable.strings +++ b/Stats/Supporting Files/ro.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "Placa video să fie arătată"; diff --git a/Stats/Supporting Files/ru.lproj/Localizable.strings b/Stats/Supporting Files/ru.lproj/Localizable.strings index 318f7aaf..65fcda24 100644 --- a/Stats/Supporting Files/ru.lproj/Localizable.strings +++ b/Stats/Supporting Files/ru.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "Системный цвет"; "User color" = "Пользовательский цвет"; "Idle color" = "Холостой цвет"; +"Cluster grouping" = "Кластерная группировка"; // GPU "GPU to show" = "Активный графический процессор"; diff --git a/Stats/Supporting Files/sl.lproj/Localizable.strings b/Stats/Supporting Files/sl.lproj/Localizable.strings index 9cfeb8ac..f5a709f4 100644 --- a/Stats/Supporting Files/sl.lproj/Localizable.strings +++ b/Stats/Supporting Files/sl.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPE na ogled"; diff --git a/Stats/Supporting Files/sv.lproj/Localizable.strings b/Stats/Supporting Files/sv.lproj/Localizable.strings index 3fcc436c..c2a699db 100644 --- a/Stats/Supporting Files/sv.lproj/Localizable.strings +++ b/Stats/Supporting Files/sv.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU att visa"; diff --git a/Stats/Supporting Files/tr.lproj/Localizable.strings b/Stats/Supporting Files/tr.lproj/Localizable.strings index 7b5ed819..5abd3d41 100644 --- a/Stats/Supporting Files/tr.lproj/Localizable.strings +++ b/Stats/Supporting Files/tr.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "Gösterilecek GPU"; diff --git a/Stats/Supporting Files/uk.lproj/Localizable.strings b/Stats/Supporting Files/uk.lproj/Localizable.strings index 3b647657..e300b401 100644 --- a/Stats/Supporting Files/uk.lproj/Localizable.strings +++ b/Stats/Supporting Files/uk.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "Системний колір"; "User color" = "Колір користувача"; "Idle color" = "Колір простою"; +"Cluster grouping" = "Кластерне групування"; // GPU "GPU to show" = "Активний графічний процесор"; diff --git a/Stats/Supporting Files/vi.lproj/Localizable.strings b/Stats/Supporting Files/vi.lproj/Localizable.strings index 0cbed55d..b4e43711 100644 --- a/Stats/Supporting Files/vi.lproj/Localizable.strings +++ b/Stats/Supporting Files/vi.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "GPU để hiển thị"; diff --git a/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings b/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings index 125371c8..69bced8d 100644 --- a/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings +++ b/Stats/Supporting Files/zh-Hans.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "显示的 GPU"; diff --git a/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings b/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings index f1e257ac..08cab6a6 100644 --- a/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings +++ b/Stats/Supporting Files/zh-Hant.lproj/Localizable.strings @@ -212,6 +212,7 @@ "System color" = "System color"; "User color" = "User color"; "Idle color" = "Idle color"; +"Cluster grouping" = "Cluster grouping"; // GPU "GPU to show" = "顯示顯示卡";