From a4137c57c11b4ebaea6e4a631bb5edcd7c9e8c4b Mon Sep 17 00:00:00 2001 From: bbedward Date: Thu, 19 Feb 2026 20:45:50 -0500 Subject: [PATCH] running apps: fix ordering on niri --- .../Modules/DankBar/Widgets/RunningApps.qml | 12 +- quickshell/Services/NiriService.qml | 139 ++++++------------ 2 files changed, 46 insertions(+), 105 deletions(-) diff --git a/quickshell/Modules/DankBar/Widgets/RunningApps.qml b/quickshell/Modules/DankBar/Widgets/RunningApps.qml index 95ace37c..98bab579 100644 --- a/quickshell/Modules/DankBar/Widgets/RunningApps.qml +++ b/quickshell/Modules/DankBar/Widgets/RunningApps.qml @@ -138,15 +138,13 @@ BasePill { readonly property real iconCellSize: Theme.barIconSize(root.barThickness, undefined, root.barConfig?.noBackground) + 6 readonly property string focusedAppId: { - const toplevels = CompositorService.sortedToplevels; - if (!toplevels) + if (!sortedToplevels || sortedToplevels.length === 0) return ""; - let result = ""; - for (let i = 0; i < toplevels.length; i++) { - if (toplevels[i].activated) - result = toplevels[i].appId || ""; + for (let i = 0; i < sortedToplevels.length; i++) { + if (sortedToplevels[i].activated) + return sortedToplevels[i].appId || ""; } - return result; + return ""; } visible: windowCount > 0 diff --git a/quickshell/Services/NiriService.qml b/quickshell/Services/NiriService.qml index 8a90f123..be695f3a 100644 --- a/quickshell/Services/NiriService.qml +++ b/quickshell/Services/NiriService.qml @@ -963,48 +963,34 @@ Singleton { return enrichedToplevels; } - function filterCurrentWorkspace(toplevels, screenName) { - let currentWorkspaceId = null; - - for (var i = 0; i < allWorkspaces.length; i++) { - const ws = allWorkspaces[i]; - if (ws.output === screenName && ws.is_active) { - currentWorkspaceId = ws.id; - break; - } - } - - if (currentWorkspaceId === null) - return toplevels; - - const workspaceWindows = windows.filter(niriWindow => niriWindow.workspace_id === currentWorkspaceId); + function _matchAndEnrichToplevels(toplevels, niriWindows) { const usedToplevels = new Set(); const result = []; - for (const niriWindow of workspaceWindows) { + for (const niriWindow of niriWindows) { let bestMatch = null; let bestScore = -1; for (const toplevel of toplevels) { if (usedToplevels.has(toplevel)) continue; - if (toplevel.appId === niriWindow.app_id) { - let score = 1; + if (toplevel.appId !== niriWindow.app_id) + continue; - if (niriWindow.title && toplevel.title) { - if (toplevel.title === niriWindow.title) { - score = 3; - } else if (toplevel.title.includes(niriWindow.title) || niriWindow.title.includes(toplevel.title)) { - score = 2; - } + let score = 1; + if (niriWindow.title && toplevel.title) { + if (toplevel.title === niriWindow.title) { + score = 3; + } else if (toplevel.title.includes(niriWindow.title) || niriWindow.title.includes(toplevel.title)) { + score = 2; } + } - if (score > bestScore) { - bestScore = score; - bestMatch = toplevel; - if (score === 3) - break; - } + if (score > bestScore) { + bestScore = score; + bestMatch = toplevel; + if (score === 3) + break; } } @@ -1025,17 +1011,15 @@ Singleton { return NiriService.focusWindow(niriWindow.id); }, "close": function () { - if (bestMatch.close) { + if (bestMatch.close) return bestMatch.close(); - } return false; } }; for (let prop in bestMatch) { - if (!(prop in enrichedToplevel)) { + if (!(prop in enrichedToplevel)) enrichedToplevel[prop] = bestMatch[prop]; - } } result.push(enrichedToplevel); @@ -1044,6 +1028,26 @@ Singleton { return result; } + function filterCurrentWorkspace(toplevels, screenName) { + let currentWorkspaceId = null; + + for (var i = 0; i < allWorkspaces.length; i++) { + const ws = allWorkspaces[i]; + if (ws.output === screenName && ws.is_active) { + currentWorkspaceId = ws.id; + break; + } + } + + if (currentWorkspaceId === null) + return toplevels; + + if (toplevels.length > 0 && toplevels[0].niriWorkspaceId !== undefined) + return toplevels.filter(t => t.niriWorkspaceId === currentWorkspaceId); + + return _matchAndEnrichToplevels(toplevels, windows.filter(nw => nw.workspace_id === currentWorkspaceId)); + } + function filterCurrentDisplay(toplevels, screenName) { if (!toplevels || toplevels.length === 0 || !screenName) return toplevels; @@ -1058,71 +1062,10 @@ Singleton { if (outputWorkspaceIds.size === 0) return toplevels; - const displayWindows = windows.filter(niriWindow => outputWorkspaceIds.has(niriWindow.workspace_id)); - const usedToplevels = new Set(); - const result = []; + if (toplevels.length > 0 && toplevels[0].niriWorkspaceId !== undefined) + return toplevels.filter(t => outputWorkspaceIds.has(t.niriWorkspaceId)); - for (const niriWindow of displayWindows) { - let bestMatch = null; - let bestScore = -1; - - for (const toplevel of toplevels) { - if (usedToplevels.has(toplevel)) - continue; - if (toplevel.appId === niriWindow.app_id) { - let score = 1; - - if (niriWindow.title && toplevel.title) { - if (toplevel.title === niriWindow.title) { - score = 3; - } else if (toplevel.title.includes(niriWindow.title) || niriWindow.title.includes(toplevel.title)) { - score = 2; - } - } - - if (score > bestScore) { - bestScore = score; - bestMatch = toplevel; - if (score === 3) - break; - } - } - } - - if (!bestMatch) - continue; - usedToplevels.add(bestMatch); - - const workspace = workspaces[niriWindow.workspace_id]; - const isFocused = niriWindow.is_focused ?? (workspace && workspace.active_window_id === niriWindow.id) ?? false; - - const enrichedToplevel = { - "appId": bestMatch.appId, - "title": bestMatch.title, - "activated": isFocused, - "niriWindowId": niriWindow.id, - "niriWorkspaceId": niriWindow.workspace_id, - "activate": function () { - return NiriService.focusWindow(niriWindow.id); - }, - "close": function () { - if (bestMatch.close) { - return bestMatch.close(); - } - return false; - } - }; - - for (let prop in bestMatch) { - if (!(prop in enrichedToplevel)) { - enrichedToplevel[prop] = bestMatch[prop]; - } - } - - result.push(enrichedToplevel); - } - - return result; + return _matchAndEnrichToplevels(toplevels, windows.filter(nw => outputWorkspaceIds.has(nw.workspace_id))); } function generateNiriLayoutConfig() {