Possible fix for QS crash on single monitor wake

This commit is contained in:
Ly-sec 2025-08-21 16:29:42 +02:00
parent aed728ec9c
commit 88447fbcef
7 changed files with 70 additions and 25 deletions

View file

@ -10,24 +10,30 @@ Item {
width: pill.width
height: pill.height
visible: Settings.data.bar.showBrightness && firstBrightnessReceived
visible: Settings.data.bar.showBrightness && firstBrightnessReceived && getMonitor() !== null
// Used to avoid opening the pill on Quickshell startup
property bool firstBrightnessReceived: false
function getMonitor() {
return BrightnessService.getMonitorForScreen(screen) || null
}
function getIcon() {
var brightness = BrightnessService.getMonitorForScreen(screen).brightness
return brightness <= 0 ? "brightness_1" : brightness < 0.33 ? "brightness_low" : brightness
< 0.66 ? "brightness_medium" : "brightness_high"
var monitor = getMonitor()
var brightness = monitor ? monitor.brightness : 0
return brightness <= 0 ? "brightness_1" : brightness < 0.33 ? "brightness_low" : brightness < 0.66 ? "brightness_medium" : "brightness_high"
}
// Connection used to open the pill when brightness changes
Connections {
target: BrightnessService.getMonitorForScreen(screen)
target: getMonitor()
ignoreUnknownSignals: true
function onBrightnessUpdated() {
Logger.log("Bar-Brightness", "OnBrightnessUpdated")
var monitor = BrightnessService.getMonitorForScreen(screen)
var monitor = getMonitor()
if (!monitor)
return
var currentBrightness = monitor.brightness
// Ignore if this is the first time or if brightness hasn't actually changed
@ -52,15 +58,19 @@ Item {
iconCircleColor: Color.mPrimary
collapsedIconColor: Color.mOnSurface
autoHide: false // Important to be false so we can hover as long as we want
text: Math.round(BrightnessService.getMonitorForScreen(screen).brightness * 100) + "%"
text: {
var monitor = getMonitor()
return monitor ? (Math.round(monitor.brightness * 100) + "%") : ""
}
tooltipText: {
var monitor = BrightnessService.getMonitorForScreen(screen)
return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method
+ "\nLeft click for advanced settings.\nScroll up/down to change brightness."
var monitor = getMonitor()
if (!monitor) return ""
return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method + "\nLeft click for advanced settings.\nScroll up/down to change brightness."
}
onWheel: function (angle) {
var monitor = BrightnessService.getMonitorForScreen(screen)
var monitor = getMonitor()
if (!monitor) return
if (angle > 0) {
monitor.increaseBrightness()
} else if (angle < 0) {