Possible fix for QS crash on single monitor wake
This commit is contained in:
parent
aed728ec9c
commit
88447fbcef
7 changed files with 70 additions and 25 deletions
42
Commons/Icons.qml
Normal file
42
Commons/Icons.qml
Normal 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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -43,9 +43,9 @@ Loader {
|
||||||
}
|
}
|
||||||
|
|
||||||
margins {
|
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
|
&& 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
|
&& Settings.data.bar.position === "bottom" ? Math.floor(Style.barHeight * scaling) : 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -49,13 +49,7 @@ Row {
|
||||||
if (!focusedWindow || !focusedWindow.appId)
|
if (!focusedWindow || !focusedWindow.appId)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
// DesktopEntries.byId may return null for unknown apps; guard accordingly
|
return Icons.iconForAppId(focusedWindow.appId)
|
||||||
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 || ""
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// A hidden text element to safely measure the full title width
|
// A hidden text element to safely measure the full title width
|
||||||
|
|
|
||||||
|
|
@ -10,24 +10,30 @@ Item {
|
||||||
|
|
||||||
width: pill.width
|
width: pill.width
|
||||||
height: pill.height
|
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
|
// Used to avoid opening the pill on Quickshell startup
|
||||||
property bool firstBrightnessReceived: false
|
property bool firstBrightnessReceived: false
|
||||||
|
|
||||||
|
function getMonitor() {
|
||||||
|
return BrightnessService.getMonitorForScreen(screen) || null
|
||||||
|
}
|
||||||
|
|
||||||
function getIcon() {
|
function getIcon() {
|
||||||
var brightness = BrightnessService.getMonitorForScreen(screen).brightness
|
var monitor = getMonitor()
|
||||||
return brightness <= 0 ? "brightness_1" : brightness < 0.33 ? "brightness_low" : brightness
|
var brightness = monitor ? monitor.brightness : 0
|
||||||
< 0.66 ? "brightness_medium" : "brightness_high"
|
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
|
// Connection used to open the pill when brightness changes
|
||||||
Connections {
|
Connections {
|
||||||
target: BrightnessService.getMonitorForScreen(screen)
|
target: getMonitor()
|
||||||
|
ignoreUnknownSignals: true
|
||||||
function onBrightnessUpdated() {
|
function onBrightnessUpdated() {
|
||||||
Logger.log("Bar-Brightness", "OnBrightnessUpdated")
|
Logger.log("Bar-Brightness", "OnBrightnessUpdated")
|
||||||
|
var monitor = getMonitor()
|
||||||
var monitor = BrightnessService.getMonitorForScreen(screen)
|
if (!monitor)
|
||||||
|
return
|
||||||
var currentBrightness = monitor.brightness
|
var currentBrightness = monitor.brightness
|
||||||
|
|
||||||
// Ignore if this is the first time or if brightness hasn't actually changed
|
// Ignore if this is the first time or if brightness hasn't actually changed
|
||||||
|
|
@ -52,15 +58,19 @@ Item {
|
||||||
iconCircleColor: Color.mPrimary
|
iconCircleColor: Color.mPrimary
|
||||||
collapsedIconColor: Color.mOnSurface
|
collapsedIconColor: Color.mOnSurface
|
||||||
autoHide: false // Important to be false so we can hover as long as we want
|
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: {
|
tooltipText: {
|
||||||
var monitor = BrightnessService.getMonitorForScreen(screen)
|
var monitor = getMonitor()
|
||||||
return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method
|
if (!monitor) return ""
|
||||||
+ "\nLeft click for advanced settings.\nScroll up/down to change brightness."
|
return "Brightness: " + Math.round(monitor.brightness * 100) + "%\nMethod: " + monitor.method + "\nLeft click for advanced settings.\nScroll up/down to change brightness."
|
||||||
}
|
}
|
||||||
|
|
||||||
onWheel: function (angle) {
|
onWheel: function (angle) {
|
||||||
var monitor = BrightnessService.getMonitorForScreen(screen)
|
var monitor = getMonitor()
|
||||||
|
if (!monitor) return
|
||||||
if (angle > 0) {
|
if (angle > 0) {
|
||||||
monitor.increaseBrightness()
|
monitor.increaseBrightness()
|
||||||
} else if (angle < 0) {
|
} else if (angle < 0) {
|
||||||
|
|
|
||||||
|
|
@ -159,8 +159,7 @@ Loader {
|
||||||
function getAppIcon(toplevel: Toplevel): string {
|
function getAppIcon(toplevel: Toplevel): string {
|
||||||
if (!toplevel)
|
if (!toplevel)
|
||||||
return ""
|
return ""
|
||||||
let icon = Quickshell.iconPath(DesktopEntries.byId(toplevel.appId?.toLowerCase()).icon)
|
return Icons.iconForAppId(toplevel.appId?.toLowerCase())
|
||||||
return icon || Quickshell.iconPath("application-x-executable", true)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Row {
|
Row {
|
||||||
|
|
|
||||||
|
|
@ -418,7 +418,7 @@ NPanel {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
anchors.margins: Style.marginXS * scaling
|
anchors.margins: Style.marginXS * scaling
|
||||||
asynchronous: true
|
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)
|
visible: (modelData.isCalculator || modelData.isClipboard || modelData.isCommand || parent.iconLoaded)
|
||||||
&& modelData.type !== 'image'
|
&& modelData.type !== 'image'
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -134,7 +134,7 @@ ColumnLayout {
|
||||||
|
|
||||||
NToggle {
|
NToggle {
|
||||||
label: "Show Battery Percentage"
|
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
|
checked: Settings.data.bar.alwaysShowBatteryPercentage
|
||||||
onToggled: checked => {
|
onToggled: checked => {
|
||||||
Settings.data.bar.alwaysShowBatteryPercentage = checked
|
Settings.data.bar.alwaysShowBatteryPercentage = checked
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue