diff --git a/Kit/module/widget.swift b/Kit/module/widget.swift index f574c4da..374b9b98 100644 --- a/Kit/module/widget.swift +++ b/Kit/module/widget.swift @@ -149,6 +149,7 @@ public protocol widget_p: NSView { var position: Int { get set } var widthHandler: (() -> Void)? { get set } + var onClick: (() -> Void)? { get set } func setValues(_ values: [value_t]) func settings() -> NSView @@ -159,6 +160,7 @@ open class WidgetWrapper: NSView, widget_p { public var title: String public var position: Int = -1 public var widthHandler: (() -> Void)? = nil + public var onClick: (() -> Void)? = nil public var shadowSize: CGSize internal var queue: DispatchQueue @@ -216,6 +218,14 @@ open class WidgetWrapper: NSView, widget_p { open func settings() -> NSView { return NSView() } open func setValues(_ values: [value_t]) {} + + open override func mouseDown(with event: NSEvent) { + if let f = self.onClick { + f() + return + } + super.mouseDown(with: event) + } } public class Widget { @@ -430,7 +440,7 @@ public class MenuBar { DispatchQueue.main.async(execute: { s.recalculateWidth() DispatchQueue.main.asyncAfter(deadline: .now() + 0.1) { - s.view.addWidget(w.item, position: w.position) + s.view.addWidget(w.item) s.view.recalculate(s.sortedWidgets) } }) @@ -507,7 +517,7 @@ public class MenuBar { self.callback?() } - @objc private func togglePopup(_ sender: Any) { + @objc private func togglePopup(_ sender: NSEvent) { if let item = self.menuBarItem, let window = item.button?.window { NotificationCenter.default.post(name: .togglePopup, object: nil, userInfo: [ "module": self.moduleName, @@ -560,7 +570,7 @@ public class MenuBarView: NSView { fatalError("init(coder:) has not been implemented") } - public func addWidget(_ view: NSView, position: Int) { + public func addWidget(_ view: NSView) { self.addSubview(view) } diff --git a/Kit/types.swift b/Kit/types.swift index 8a25b60f..0b7d9fe3 100644 --- a/Kit/types.swift +++ b/Kit/types.swift @@ -259,6 +259,7 @@ public extension Notification.Name { static let moduleRearrange = Notification.Name("moduleRearrange") static let pause = Notification.Name("pause") static let toggleFanControl = Notification.Name("toggleFanControl") + static let combinedModulesPopup = Notification.Name("combinedModulesPopup") } public var isARM: Bool { diff --git a/Stats/Views/AppSettings.swift b/Stats/Views/AppSettings.swift index 5e1651dd..7bc64231 100644 --- a/Stats/Views/AppSettings.swift +++ b/Stats/Views/AppSettings.swift @@ -18,29 +18,21 @@ class ApplicationSettings: NSStackView { } private var temperatureUnitsValue: String { - get { - Store.shared.string(key: "temperature_units", defaultValue: "system") - } - set { - Store.shared.set(key: "temperature_units", value: newValue) - } + get { Store.shared.string(key: "temperature_units", defaultValue: "system") } + set { Store.shared.set(key: "temperature_units", value: newValue) } } private var combinedModulesState: Bool { - get { - Store.shared.bool(key: "CombinedModules", defaultValue: false) - } - set { - Store.shared.set(key: "CombinedModules", value: newValue) - } + get { Store.shared.bool(key: "CombinedModules", defaultValue: false) } + set { Store.shared.set(key: "CombinedModules", value: newValue) } } private var combinedModulesSpacing: String { - get { - Store.shared.string(key: "CombinedModules_spacing", defaultValue: "none") - } - set { - Store.shared.set(key: "CombinedModules_spacing", value: newValue) - } + get { Store.shared.string(key: "CombinedModules_spacing", defaultValue: "none") } + set { Store.shared.set(key: "CombinedModules_spacing", value: newValue) } + } + private var combinedModulesPopup: Bool { + get { Store.shared.bool(key: "CombinedModules_popup", defaultValue: true) } + set { Store.shared.set(key: "CombinedModules_popup", value: newValue) } } private let updateWindow: UpdateWindow = UpdateWindow() @@ -268,6 +260,11 @@ class ApplicationSettings: NSStackView { selected: self.combinedModulesSpacing ) ]) + grid.addRow(with: [NSGridCell.emptyContentView, self.toggleView( + action: #selector(self.toggleCombinedModulesPopup), + state: self.combinedModulesPopup, + text: localizedString("Combined details") + )]) view.addArrangedSubview(self.moduleSelector) view.addArrangedSubview(grid) @@ -518,6 +515,11 @@ class ApplicationSettings: NSStackView { @objc private func toggleTelemetry(_ sender: NSButton) { telemetry.isEnabled = sender.state == NSControl.StateValue.on } + + @objc private func toggleCombinedModulesPopup(_ sender: NSButton) { + self.combinedModulesPopup = sender.state == NSControl.StateValue.on + NotificationCenter.default.post(name: .combinedModulesPopup, object: nil, userInfo: nil) + } } private class ModuleSelectorView: NSStackView {