From 655cc825a9bf90e73fe8fc0c1083505ac6ecc172 Mon Sep 17 00:00:00 2001
From: waydabber <37590873+waydabber@users.noreply.github.com>
Date: Mon, 2 Aug 2021 21:07:58 +0200
Subject: [PATCH] Replace slider titles in menu with icons on macOS Big Sur and
above.
---
MonitorControl/Info.plist | 2 +-
MonitorControl/Support/Utils.swift | 50 +++++++++++++++++++++---------
MonitorControlHelper/Info.plist | 2 +-
3 files changed, 38 insertions(+), 16 deletions(-)
diff --git a/MonitorControl/Info.plist b/MonitorControl/Info.plist
index 5d53bf0..5b54e84 100644
--- a/MonitorControl/Info.plist
+++ b/MonitorControl/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 1155
+ 1221
LSApplicationCategoryType
public.app-category.utilities
LSMinimumSystemVersion
diff --git a/MonitorControl/Support/Utils.swift b/MonitorControl/Support/Utils.swift
index 87c794c..3352646 100644
--- a/MonitorControl/Support/Utils.swift
+++ b/MonitorControl/Support/Utils.swift
@@ -21,22 +21,44 @@ class Utils: NSObject {
let slider = NSSlider(value: 0, minValue: 0, maxValue: 100, target: handler, action: #selector(SliderHandler.valueChanged))
slider.isEnabled = false
- slider.frame.size.width = 180
- slider.frame.origin = NSPoint(x: 15, y: 5)
-
handler.slider = slider
- let view = NSView(frame: NSRect(x: 0, y: 0, width: slider.frame.width + 30, height: slider.frame.height + 10))
- view.addSubview(slider)
-
- item.view = view
-
- let sliderHeaderItem = NSMenuItem()
- let attrs: [NSAttributedString.Key: Any] = [.foregroundColor: NSColor.systemGray, .font: NSFont.systemFont(ofSize: 12)]
- sliderHeaderItem.attributedTitle = NSAttributedString(string: title, attributes: attrs)
-
- menu.insertItem(item, at: 0)
- menu.insertItem(sliderHeaderItem, at: 0)
+ if #available(macOS 11.0, *) {
+ slider.frame.size.width = 160
+ slider.frame.origin = NSPoint(x: 35, y: 5)
+ let view = NSView(frame: NSRect(x: 0, y: 0, width: slider.frame.width + 47, height: slider.frame.height + 14))
+ view.frame.origin = NSPoint(x: 12, y: 0)
+ let icon = NSImageView(image: NSImage(systemSymbolName: "circle.dotted", accessibilityDescription: title)!)
+ icon.frame = view.frame
+ icon.wantsLayer = true
+ icon.alphaValue = 0.7
+ icon.imageAlignment = NSImageAlignment.alignLeft
+ switch command {
+ case .audioSpeakerVolume:
+ icon.image = NSImage(systemSymbolName: "speaker.wave.2", accessibilityDescription: title)!
+ case .brightness:
+ icon.image = NSImage(systemSymbolName: "sun.max", accessibilityDescription: title)!
+ case .contrast:
+ icon.image = NSImage(systemSymbolName: "circle.lefthalf.filled", accessibilityDescription: title)!
+ default:
+ break
+ }
+ view.addSubview(icon)
+ view.addSubview(slider)
+ item.view = view
+ menu.insertItem(item, at: 0)
+ } else {
+ slider.frame.size.width = 180
+ slider.frame.origin = NSPoint(x: 15, y: 5)
+ let view = NSView(frame: NSRect(x: 0, y: 0, width: slider.frame.width + 30, height: slider.frame.height + 10))
+ let sliderHeaderItem = NSMenuItem()
+ let attrs: [NSAttributedString.Key: Any] = [.foregroundColor: NSColor.systemGray, .font: NSFont.systemFont(ofSize: 12)]
+ sliderHeaderItem.attributedTitle = NSAttributedString(string: title, attributes: attrs)
+ view.addSubview(slider)
+ item.view = view
+ menu.insertItem(item, at: 0)
+ menu.insertItem(sliderHeaderItem, at: 0)
+ }
var values: (UInt16, UInt16)?
let delay = display.needsLongerDelay ? UInt64(40 * kMillisecondScale) : nil
diff --git a/MonitorControlHelper/Info.plist b/MonitorControlHelper/Info.plist
index e4d1444..d10e3df 100644
--- a/MonitorControlHelper/Info.plist
+++ b/MonitorControlHelper/Info.plist
@@ -19,7 +19,7 @@
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
- 1155
+ 1221
LSApplicationCategoryType
public.app-category.utilities
LSBackgroundOnly