From d2e53592ed58e9019c7dd376b97a19d819bbdba4 Mon Sep 17 00:00:00 2001 From: Ly-sec Date: Thu, 21 Aug 2025 13:21:10 +0200 Subject: [PATCH] Fix ActiveWindow for niri --- Services/CompositorService.qml | 62 ++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/Services/CompositorService.qml b/Services/CompositorService.qml index 682fbcc..a36b1f0 100644 --- a/Services/CompositorService.qml +++ b/Services/CompositorService.qml @@ -281,6 +281,68 @@ Singleton { if (event.WorkspacesChanged) { niriWorkspaceProcess.running = true + } else if (event.WindowOpenedOrChanged) { + try { + const windowData = event.WindowOpenedOrChanged.window + + // Find if this window already exists + const existingIndex = windows.findIndex(w => w.id === windowData.id) + + const newWindow = { + "id": windowData.id, + "title": windowData.title || "", + "appId": windowData.app_id || "", + "workspaceId": windowData.workspace_id || null, + "isFocused": windowData.is_focused === true + } + + if (existingIndex >= 0) { + // Update existing window + windows[existingIndex] = newWindow + } else { + // Add new window + windows.push(newWindow) + windows.sort((a, b) => a.id - b.id) + } + + // Update focused window index if this window is focused + if (newWindow.isFocused) { + focusedWindowIndex = windows.findIndex(w => w.id === windowData.id) + updateFocusedWindowTitle() + activeWindowChanged() + } + + windowListChanged() + } catch (e) { + Logger.error("Compositor", "Error parsing WindowOpenedOrChanged event:", e) + } + } else if (event.WindowClosed) { + try { + const windowId = event.WindowClosed.id + + // Remove the window from the list + const windowIndex = windows.findIndex(w => w.id === windowId) + if (windowIndex >= 0) { + // If this was the focused window, clear focus + if (windowIndex === focusedWindowIndex) { + focusedWindowIndex = -1 + updateFocusedWindowTitle() + activeWindowChanged() + } + + // Remove the window + windows.splice(windowIndex, 1) + + // Adjust focused window index if needed + if (focusedWindowIndex > windowIndex) { + focusedWindowIndex-- + } + + windowListChanged() + } + } catch (e) { + Logger.error("Compositor", "Error parsing WindowClosed event:", e) + } } else if (event.WindowsChanged) { try { const windowsData = event.WindowsChanged.windows