From b51e6a5e7323f7fe30ee3529ddc2d4dd9636c333 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Tue, 19 Aug 2025 14:39:20 +0200 Subject: [PATCH] Fix Hyprland active window --- Services/CompositorService.qml | 50 ++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) diff --git a/Services/CompositorService.qml b/Services/CompositorService.qml index b9bd2ab..8cf2bba 100644 --- a/Services/CompositorService.qml +++ b/Services/CompositorService.qml @@ -43,12 +43,23 @@ Singleton { } } + Connections { + target: Hyprland.toplevels + enabled: isHyprland + function onValuesChanged() { + updateHyprlandWindows() + windowListChanged() + } + } + Connections { target: Hyprland enabled: isHyprland function onRawEvent(event) { updateHyprlandWorkspaces() workspaceChanged() + updateHyprlandWindows() + windowListChanged() } } @@ -85,7 +96,9 @@ Singleton { function initHyprland() { try { Hyprland.refreshWorkspaces() + Hyprland.refreshToplevels() updateHyprlandWorkspaces() + updateHyprlandWindows() setupHyprlandConnections() Logger.log("Compositor", "Hyprland initialized successfully") } catch (e) { @@ -125,6 +138,43 @@ Singleton { } } + function updateHyprlandWindows() { + if (!isHyprland) + return + + try { + const hlToplevels = Hyprland.toplevels.values + const windowsList = [] + + for (var i = 0; i < hlToplevels.length; i++) { + const toplevel = hlToplevels[i] + windowsList.push({ + "id": toplevel.address || "", + "title": toplevel.title || "", + "appId": toplevel.class || toplevel.initialClass || "", + "workspaceId": toplevel.workspace?.id || null, + "isFocused": Hyprland.activeToplevel && Hyprland.activeToplevel.address === toplevel.address + }) + } + + windows = windowsList + + // Update focused window index + focusedWindowIndex = -1 + for (var j = 0; j < windowsList.length; j++) { + if (windowsList[j].isFocused) { + focusedWindowIndex = j + break + } + } + + updateFocusedWindowTitle() + activeWindowChanged() + } catch (e) { + Logger.error("Compositor", "Error updating Hyprland windows:", e) + } + } + // Niri integration function initNiri() { try {