Possible hyprland active window crash fix

This commit is contained in:
Ly-sec 2025-08-19 23:09:18 +02:00
parent d753788d8a
commit 8ffd2ab8ac

View file

@ -36,37 +36,49 @@ Singleton {
// Hyprland connections // Hyprland connections
Connections { Connections {
target: Hyprland.workspaces target: Hyprland.workspaces
enabled: isHyprland enabled: isHyprland && Hyprland && Hyprland.workspaces
function onValuesChanged() { function onValuesChanged() {
try {
updateHyprlandWorkspaces() updateHyprlandWorkspaces()
workspaceChanged() workspaceChanged()
} catch (e) {
Logger.error("Compositor", "Error in workspaces valuesChanged:", e)
}
} }
} }
Connections { Connections {
target: Hyprland.toplevels target: Hyprland.toplevels
enabled: isHyprland enabled: isHyprland && Hyprland && Hyprland.toplevels
function onValuesChanged() { function onValuesChanged() {
try {
updateHyprlandWindows() updateHyprlandWindows()
windowListChanged() windowListChanged()
} catch (e) {
Logger.error("Compositor", "Error in toplevels valuesChanged:", e)
}
} }
} }
Connections { Connections {
target: Hyprland target: Hyprland
enabled: isHyprland enabled: isHyprland && Hyprland
function onRawEvent(event) { function onRawEvent(event) {
try {
updateHyprlandWorkspaces() updateHyprlandWorkspaces()
workspaceChanged() workspaceChanged()
updateHyprlandWindows() updateHyprlandWindows()
windowListChanged() windowListChanged()
} catch (e) {
Logger.error("Compositor", "Error in rawEvent:", e)
}
} }
} }
function detectCompositor() { function detectCompositor() {
try { try {
// Try Hyprland first // Try Hyprland first - add extra safety checks
if (Hyprland.eventSocketPath) { if (Hyprland && Hyprland.eventSocketPath) {
compositorType = "hyprland" compositorType = "hyprland"
isHyprland = true isHyprland = true
isNiri = false isNiri = false
@ -74,7 +86,7 @@ Singleton {
return return
} }
} catch (e) { } catch (e) {
Logger.warn("Compositor", "Hyprland detection failed:", e)
// Hyprland not available // Hyprland not available
} }
@ -117,16 +129,31 @@ Singleton {
workspaces.clear() workspaces.clear()
try { try {
// Add null checks for Hyprland objects
if (!Hyprland || !Hyprland.workspaces || !Hyprland.workspaces.values) {
Logger.warn("Compositor", "Hyprland workspaces not available")
return
}
const hlWorkspaces = Hyprland.workspaces.values const hlWorkspaces = Hyprland.workspaces.values
for (var i = 0; i < hlWorkspaces.length; i++) { for (var i = 0; i < hlWorkspaces.length; i++) {
const ws = hlWorkspaces[i] const ws = hlWorkspaces[i]
// Add null checks for workspace properties
if (!ws) {
continue
}
// Only append workspaces with id >= 1 // Only append workspaces with id >= 1
if (ws.id >= 1) { if (ws.id >= 1) {
// Safe property access with proper null checks
const monitorName = ws.monitor && ws.monitor.name ? ws.monitor.name : ""
workspaces.append({ workspaces.append({
"id": i, "id": i,
"idx": ws.id, "idx": ws.id,
"name": ws.name || "", "name": ws.name || "",
"output": ws.monitor?.name || "", "output": monitorName,
"isActive": ws.active === true, "isActive": ws.active === true,
"isFocused": ws.focused === true, "isFocused": ws.focused === true,
"isUrgent": ws.urgent === true "isUrgent": ws.urgent === true
@ -143,17 +170,43 @@ Singleton {
return return
try { try {
// Add null checks for Hyprland objects
if (!Hyprland || !Hyprland.toplevels || !Hyprland.toplevels.values) {
Logger.warn("Compositor", "Hyprland toplevels not available")
return
}
const hlToplevels = Hyprland.toplevels.values const hlToplevels = Hyprland.toplevels.values
const windowsList = [] const windowsList = []
for (var i = 0; i < hlToplevels.length; i++) { for (var i = 0; i < hlToplevels.length; i++) {
const toplevel = hlToplevels[i] const toplevel = hlToplevels[i]
// Add null checks for toplevel properties
if (!toplevel) {
continue
}
// Safe property access with proper null checks
const workspaceId = toplevel.workspace && toplevel.workspace.id !== undefined ? toplevel.workspace.id : null
// Extra safety for activeToplevel access - this is often the source of crashes
let isFocused = false
try {
if (Hyprland && Hyprland.activeToplevel && toplevel.address) {
isFocused = Hyprland.activeToplevel.address === toplevel.address
}
} catch (e) {
// activeToplevel access failed, default to false
isFocused = false
}
windowsList.push({ windowsList.push({
"id": toplevel.address || "", "id": toplevel.address || "",
"title": toplevel.title || "", "title": toplevel.title || "",
"appId": toplevel.class || toplevel.initialClass || "", "appId": toplevel.class || toplevel.initialClass || "",
"workspaceId": toplevel.workspace?.id || null, "workspaceId": workspaceId,
"isFocused": Hyprland.activeToplevel && Hyprland.activeToplevel.address === toplevel.address "isFocused": isFocused
}) })
} }
@ -172,6 +225,10 @@ Singleton {
activeWindowChanged() activeWindowChanged()
} catch (e) { } catch (e) {
Logger.error("Compositor", "Error updating Hyprland windows:", e) Logger.error("Compositor", "Error updating Hyprland windows:", e)
// Reset to safe state on error
windows = []
focusedWindowIndex = -1
updateFocusedWindowTitle()
} }
} }