From b4401968cac353c011f9f3071a87e6ce5b0b3f9b Mon Sep 17 00:00:00 2001 From: Lemmy Date: Thu, 18 Dec 2025 19:13:29 -0500 Subject: [PATCH] Workspace: avoid a bleep of the indicator when switching window focus on the same workspace + Fix a bug where you could have two active windows indicator after the first switch. --- Modules/Bar/Widgets/Workspace.qml | 3 +-- Services/Compositor/NiriService.qml | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/Modules/Bar/Widgets/Workspace.qml b/Modules/Bar/Widgets/Workspace.qml index 16e47861c..219c7823e 100644 --- a/Modules/Bar/Widgets/Workspace.qml +++ b/Modules/Bar/Widgets/Workspace.qml @@ -178,7 +178,7 @@ Item { } } function onActiveWindowChanged() { - if (showApplications || showLabelsOnlyWhenOccupied) { + if (showApplications) { refreshWorkspaces(); } } @@ -450,7 +450,6 @@ Item { return Qt.alpha(Color.mSecondary, 0.3); } - scale: model.isActive ? 1.0 : 0.9 z: 0 MouseArea { diff --git a/Services/Compositor/NiriService.qml b/Services/Compositor/NiriService.qml index 1607aef96..dd91c5d6f 100644 --- a/Services/Compositor/NiriService.qml +++ b/Services/Compositor/NiriService.qml @@ -285,9 +285,10 @@ Item { windows = toSortedWindowList(windowsList); windowListChanged(); + // Find focused window index in the SORTED windows array focusedWindowIndex = -1; - for (var i = 0; i < windowsList.length; i++) { - if (windowsList[i].isFocused) { + for (var i = 0; i < windows.length; i++) { + if (windows[i].isFocused) { focusedWindowIndex = i; break; } @@ -301,6 +302,9 @@ Item { const existingIndex = windows.findIndex(w => w.id === windowData.id); const newWindow = getWindowData(windowData); + // Find the previously focused window ID before any modifications + const previouslyFocusedId = focusedWindowIndex >= 0 && focusedWindowIndex < windows.length ? windows[focusedWindowIndex].id : null; + if (existingIndex >= 0) { windows[existingIndex] = newWindow; } else { @@ -309,15 +313,16 @@ Item { windows = toSortedWindowList(windows); if (newWindow.isFocused) { - const oldFocusedIndex = focusedWindowIndex; focusedWindowIndex = windows.findIndex(w => w.id === windowData.id); - if (oldFocusedIndex !== focusedWindowIndex) { - if (oldFocusedIndex >= 0 && oldFocusedIndex < windows.length) { - windows[oldFocusedIndex].isFocused = false; + // Clear focus on the previously focused window by ID (not index, since list was re-sorted) + if (previouslyFocusedId !== null && previouslyFocusedId !== windowData.id) { + const oldFocusedWindow = windows.find(w => w.id === previouslyFocusedId); + if (oldFocusedWindow) { + oldFocusedWindow.isFocused = false; } - activeWindowChanged(); } + activeWindowChanged(); } windowListChanged();