mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-29 07:52:50 -05:00
fix some sorting of niri toplevels
This commit is contained in:
@@ -527,51 +527,62 @@ Singleton {
|
|||||||
return [...toplevels]
|
return [...toplevels]
|
||||||
}
|
}
|
||||||
|
|
||||||
return [...toplevels].sort((a, b) => {
|
const usedToplevels = new Set()
|
||||||
const aNiri = findNiriWindow(a)
|
const enrichedToplevels = []
|
||||||
const bNiri = findNiriWindow(b)
|
|
||||||
|
|
||||||
if (!aNiri && !bNiri) {
|
for (const niriWindow of sortWindowsByLayout(windows)) {
|
||||||
return 0
|
let bestMatch = null
|
||||||
}
|
|
||||||
if (!aNiri) {
|
|
||||||
return 1
|
|
||||||
}
|
|
||||||
if (!bNiri) {
|
|
||||||
return -1
|
|
||||||
}
|
|
||||||
|
|
||||||
const aWindow = aNiri.niriWindow
|
for (const toplevel of toplevels) {
|
||||||
const bWindow = bNiri.niriWindow
|
if (usedToplevels.has(toplevel)) continue
|
||||||
const aWorkspace = allWorkspaces.find(ws => ws.id === aWindow.workspace_id)
|
|
||||||
const bWorkspace = allWorkspaces.find(ws => ws.id === bWindow.workspace_id)
|
|
||||||
|
|
||||||
if (aWorkspace && bWorkspace) {
|
if (toplevel.appId === niriWindow.app_id) {
|
||||||
if (aWorkspace.output !== bWorkspace.output) {
|
if (niriWindow.title && toplevel.title === niriWindow.title) {
|
||||||
return aWorkspace.output.localeCompare(bWorkspace.output)
|
bestMatch = toplevel
|
||||||
}
|
break
|
||||||
|
} else if (!niriWindow.title && !bestMatch) {
|
||||||
|
bestMatch = toplevel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (aWorkspace.output === bWorkspace.output && aWorkspace.idx !== bWorkspace.idx) {
|
if (bestMatch) {
|
||||||
return aWorkspace.idx - bWorkspace.idx
|
usedToplevels.add(bestMatch)
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (aWindow.workspace_id === bWindow.workspace_id && aWindow.layout && bWindow.layout && aWindow.layout.pos_in_scrolling_layout && bWindow.layout.pos_in_scrolling_layout) {
|
const enrichedToplevel = {
|
||||||
const aPos = aWindow.layout.pos_in_scrolling_layout
|
appId: bestMatch.appId,
|
||||||
const bPos = bWindow.layout.pos_in_scrolling_layout
|
title: bestMatch.title,
|
||||||
|
activated: bestMatch.activated,
|
||||||
|
niriWindowId: niriWindow.id,
|
||||||
|
niriWorkspaceId: niriWindow.workspace_id,
|
||||||
|
activate: function() {
|
||||||
|
return NiriService.focusWindow(niriWindow.id)
|
||||||
|
},
|
||||||
|
close: function() {
|
||||||
|
if (bestMatch.close) {
|
||||||
|
return bestMatch.close()
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (aPos.length > 1 && bPos.length > 1) {
|
for (let prop in bestMatch) {
|
||||||
if (aPos[0] !== bPos[0]) {
|
if (!(prop in enrichedToplevel)) {
|
||||||
return aPos[0] - bPos[0]
|
enrichedToplevel[prop] = bestMatch[prop]
|
||||||
}
|
}
|
||||||
if (aPos[1] !== bPos[1]) {
|
}
|
||||||
return aPos[1] - bPos[1]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return aWindow.id - bWindow.id
|
enrichedToplevels.push(enrichedToplevel)
|
||||||
})
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const toplevel of toplevels) {
|
||||||
|
if (!usedToplevels.has(toplevel)) {
|
||||||
|
enrichedToplevels.push(toplevel)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return enrichedToplevels
|
||||||
}
|
}
|
||||||
|
|
||||||
function filterCurrentWorkspace(toplevels, screenName) {
|
function filterCurrentWorkspace(toplevels, screenName) {
|
||||||
@@ -588,10 +599,57 @@ Singleton {
|
|||||||
return toplevels
|
return toplevels
|
||||||
}
|
}
|
||||||
|
|
||||||
return toplevels.filter(toplevel => {
|
const workspaceWindows = windows.filter(niriWindow => niriWindow.workspace_id === currentWorkspaceId)
|
||||||
const niriMatch = findNiriWindow(toplevel)
|
const usedToplevels = new Set()
|
||||||
return niriMatch && niriMatch.niriWindow.workspace_id === currentWorkspaceId
|
const result = []
|
||||||
})
|
|
||||||
|
for (const niriWindow of workspaceWindows) {
|
||||||
|
let bestMatch = null
|
||||||
|
|
||||||
|
for (const toplevel of toplevels) {
|
||||||
|
if (usedToplevels.has(toplevel)) continue
|
||||||
|
|
||||||
|
if (toplevel.appId === niriWindow.app_id) {
|
||||||
|
if (niriWindow.title && toplevel.title === niriWindow.title) {
|
||||||
|
bestMatch = toplevel
|
||||||
|
break
|
||||||
|
} else if (!niriWindow.title && !bestMatch) {
|
||||||
|
bestMatch = toplevel
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (bestMatch) {
|
||||||
|
usedToplevels.add(bestMatch)
|
||||||
|
|
||||||
|
const enrichedToplevel = {
|
||||||
|
appId: bestMatch.appId,
|
||||||
|
title: bestMatch.title,
|
||||||
|
activated: bestMatch.activated,
|
||||||
|
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
|
||||||
}
|
}
|
||||||
|
|
||||||
Timer {
|
Timer {
|
||||||
|
|||||||
Reference in New Issue
Block a user