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

42
Commons/Icons.qml Normal file
View file

@ -0,0 +1,42 @@
pragma Singleton
import QtQuick
import Quickshell
Singleton {
id: icons
function iconFromName(iconName, fallbackName) {
const fallback = fallbackName || "application-x-executable"
try {
if (iconName && typeof Quickshell !== 'undefined' && Quickshell.iconPath) {
const p = Quickshell.iconPath(iconName, fallback)
if (p && p !== "") return p
}
} catch (e) {
// ignore and fall back
}
try {
return Quickshell.iconPath ? (Quickshell.iconPath(fallback, true) || "") : ""
} catch (e2) {
return ""
}
}
// Resolve icon path for a DesktopEntries appId - safe on missing entries
function iconForAppId(appId, fallbackName) {
const fallback = fallbackName || "application-x-executable"
if (!appId) return iconFromName(fallback, fallback)
try {
if (typeof DesktopEntries === 'undefined' || !DesktopEntries.byId)
return iconFromName(fallback, fallback)
const entry = DesktopEntries.byId(appId)
const name = entry && entry.icon ? entry.icon : ""
return iconFromName(name || fallback, fallback)
} catch (e) {
return iconFromName(fallback, fallback)
}
}
}

View file

@ -43,9 +43,9 @@ Loader {
}
margins {
top: (Settings.data.bar.monitors.includes(modelData.name) || (Settings.data.bar.monitors.length === 0))
top: ((modelData && Settings.data.bar.monitors.includes(modelData.name)) || (Settings.data.bar.monitors.length === 0))
&& Settings.data.bar.position === "top" ? Math.floor(Style.barHeight * scaling) : 0
bottom: (Settings.data.bar.monitors.includes(modelData.name) || (Settings.data.bar.monitors.length === 0))
bottom: ((modelData && Settings.data.bar.monitors.includes(modelData.name)) || (Settings.data.bar.monitors.length === 0))
&& Settings.data.bar.position === "bottom" ? Math.floor(Style.barHeight * scaling) : 0
}

View file

@ -49,13 +49,7 @@ Row {
if (!focusedWindow || !focusedWindow.appId)
return ""
// DesktopEntries.byId may return null for unknown apps; guard accordingly
if (typeof DesktopEntries === 'undefined' || !DesktopEntries.byId)
return ""
const entry = DesktopEntries.byId(focusedWindow.appId)
const iconName = entry && entry.icon ? entry.icon : ""
const iconPath = iconName ? Quickshell.iconPath(iconName) : ""
return iconPath || ""
return Icons.iconForAppId(focusedWindow.appId)
}
// A hidden text element to safely measure the full title width

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) {

View file

@ -159,8 +159,7 @@ Loader {
function getAppIcon(toplevel: Toplevel): string {
if (!toplevel)
return ""
let icon = Quickshell.iconPath(DesktopEntries.byId(toplevel.appId?.toLowerCase()).icon)
return icon || Quickshell.iconPath("application-x-executable", true)
return Icons.iconForAppId(toplevel.appId?.toLowerCase())
}
Row {

View file

@ -418,7 +418,7 @@ NPanel {
anchors.fill: parent
anchors.margins: Style.marginXS * scaling
asynchronous: true
source: modelData.isCalculator ? "" : modelData.isClipboard ? "" : modelData.isCommand ? modelData.icon : (modelData.icon ? Quickshell.iconPath(modelData.icon, "application-x-executable") : "")
source: modelData.isCalculator ? "" : modelData.isClipboard ? "" : modelData.isCommand ? modelData.icon : Icons.iconFromName(modelData.icon, "application-x-executable")
visible: (modelData.isCalculator || modelData.isClipboard || modelData.isCommand || parent.iconLoaded)
&& modelData.type !== 'image'
}

View file

@ -134,7 +134,7 @@ ColumnLayout {
NToggle {
label: "Show Battery Percentage"
description: "Show battery percentage at all times (otherwise only when charging or low)."
description: "Show battery percentage at all times."
checked: Settings.data.bar.alwaysShowBatteryPercentage
onToggled: checked => {
Settings.data.bar.alwaysShowBatteryPercentage = checked