Another possible hyprland active window fix

This commit is contained in:
Ly-sec 2025-08-19 23:18:28 +02:00
parent 8ffd2ab8ac
commit a9fceee62d
2 changed files with 61 additions and 14 deletions

View file

@ -29,18 +29,27 @@ Row {
Connections { Connections {
target: CompositorService target: CompositorService
function onActiveWindowChanged() { function onActiveWindowChanged() {
try {
// Check if window actually changed // Check if window actually changed
if (CompositorService.focusedWindowIndex !== lastWindowIndex) { if (CompositorService.focusedWindowIndex !== lastWindowIndex) {
lastWindowIndex = CompositorService.focusedWindowIndex lastWindowIndex = CompositorService.focusedWindowIndex
showingFullTitle = true showingFullTitle = true
fullTitleTimer.restart() fullTitleTimer.restart()
} }
} catch (e) {
console.error("ActiveWindow: Error in activeWindowChanged:", e)
}
} }
} }
function getTitle() { function getTitle() {
try {
const focusedWindow = CompositorService.getFocusedWindow() const focusedWindow = CompositorService.getFocusedWindow()
return focusedWindow ? (focusedWindow.title || focusedWindow.appId || "") : "" return focusedWindow ? (focusedWindow.title || focusedWindow.appId || "") : ""
} catch (e) {
console.error("ActiveWindow: Error getting title:", e)
return ""
}
} }
// A hidden text element to safely measure the full title width // A hidden text element to safely measure the full title width

View file

@ -28,6 +28,18 @@ Singleton {
signal overviewStateChanged signal overviewStateChanged
signal windowListChanged signal windowListChanged
// Throttle timer to prevent too frequent window updates
Timer {
id: windowUpdateTimer
interval: 100 // 100ms debounce
repeat: false
onTriggered: {
if (isHyprland) {
updateHyprlandWindows()
}
}
}
// Compositor detection // Compositor detection
Component.onCompleted: { Component.onCompleted: {
detectCompositor() detectCompositor()
@ -52,7 +64,8 @@ Singleton {
enabled: isHyprland && Hyprland && Hyprland.toplevels enabled: isHyprland && Hyprland && Hyprland.toplevels
function onValuesChanged() { function onValuesChanged() {
try { try {
updateHyprlandWindows() // Use throttled update to prevent rapid-fire updates causing crashes
windowUpdateTimer.restart()
windowListChanged() windowListChanged()
} catch (e) { } catch (e) {
Logger.error("Compositor", "Error in toplevels valuesChanged:", e) Logger.error("Compositor", "Error in toplevels valuesChanged:", e)
@ -65,10 +78,12 @@ Singleton {
enabled: isHyprland && Hyprland enabled: isHyprland && Hyprland
function onRawEvent(event) { function onRawEvent(event) {
try { try {
// Only update workspaces on raw events, not windows (too frequent)
updateHyprlandWorkspaces() updateHyprlandWorkspaces()
workspaceChanged() workspaceChanged()
updateHyprlandWindows() // Remove automatic window updates on raw events to prevent crashes
windowListChanged() // updateHyprlandWindows()
// windowListChanged()
} catch (e) { } catch (e) {
Logger.error("Compositor", "Error in rawEvent:", e) Logger.error("Compositor", "Error in rawEvent:", e)
} }
@ -107,8 +122,26 @@ Singleton {
// Hyprland integration // Hyprland integration
function initHyprland() { function initHyprland() {
try { try {
Logger.log("Compositor", "Starting Hyprland initialization...")
// Add safety checks before calling refresh functions
if (!Hyprland) {
throw new Error("Hyprland object is null")
}
if (typeof Hyprland.refreshWorkspaces === 'function') {
Hyprland.refreshWorkspaces() Hyprland.refreshWorkspaces()
} else {
Logger.warn("Compositor", "Hyprland.refreshWorkspaces not available")
}
if (typeof Hyprland.refreshToplevels === 'function') {
Hyprland.refreshToplevels() Hyprland.refreshToplevels()
} else {
Logger.warn("Compositor", "Hyprland.refreshToplevels not available")
}
// Update with safety checks
updateHyprlandWorkspaces() updateHyprlandWorkspaces()
updateHyprlandWindows() updateHyprlandWindows()
setupHyprlandConnections() setupHyprlandConnections()
@ -117,6 +150,7 @@ Singleton {
Logger.error("Compositor", "Error initializing Hyprland:", e) Logger.error("Compositor", "Error initializing Hyprland:", e)
compositorType = "unknown" compositorType = "unknown"
isHyprland = false isHyprland = false
isNiri = false
} }
} }
@ -485,9 +519,13 @@ Singleton {
// Get focused window // Get focused window
function getFocusedWindow() { function getFocusedWindow() {
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length) { try {
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length && windows) {
return windows[focusedWindowIndex] return windows[focusedWindowIndex]
} }
} catch (e) {
Logger.error("Compositor", "Error getting focused window:", e)
}
return null return null
} }
} }