92 lines
4.3 KiB
QML
92 lines
4.3 KiB
QML
pragma Singleton
|
|
|
|
import Quickshell
|
|
import Quickshell.Hyprland
|
|
import Quickshell.Wayland
|
|
|
|
Singleton {
|
|
|
|
readonly property string hyprlandSignature: Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")
|
|
|
|
property var sortedTopLevels: {
|
|
if (!ToplevelManager.toplevels || !ToplevelManager.toplevels.values) {
|
|
return []
|
|
}
|
|
|
|
const topLevels = Array.from(Hyprland.toplevels.values)
|
|
const sortedHyprland = topLevels.sort((a, b) => {
|
|
if (a.monitor && b.monitor) {
|
|
const monitorCompare = a.monitor.name.localeCompare(b.monitor.name)
|
|
if (monitorCompare !== 0) {
|
|
return monitorCompare
|
|
}
|
|
}
|
|
|
|
if (a.workspace && b.workspace) {
|
|
const workspaceCompare = a.workspace.id - b.workspace.id
|
|
if (workspaceCompare !== 0) {
|
|
return workspaceCompare
|
|
}
|
|
}
|
|
|
|
if (a.lastIpcObject && b.lastIpcObject && a.lastIpcObject.at && b.lastIpcObject.at) {
|
|
const aX = a.lastIpcObject.at[0]
|
|
const bX = b.lastIpcObject.at[0]
|
|
const aY = a.lastIpcObject.at[1]
|
|
const bY = b.lastIpcObject.at[1]
|
|
|
|
const xCompare = aX - bX
|
|
if (Math.abs(xCompare) > 10) {
|
|
return xCompare
|
|
}
|
|
return aY - bY
|
|
}
|
|
|
|
if (a.lastIpcObject && !b.lastIpcObject) {
|
|
return -1
|
|
}
|
|
if (!a.lastIpcObject && b.lastIpcObject) {
|
|
return 1
|
|
}
|
|
|
|
if (a.title && b.title) {
|
|
return a.title.localeCompare(b.title)
|
|
}
|
|
|
|
return 0
|
|
})
|
|
return sortedHyprland.filter(tl => tl.wayland !== null)
|
|
|
|
}
|
|
|
|
property var topLevelWorkspaces: {
|
|
return sortedTopLevels.map(topLevel => topLevel.workspace)
|
|
}
|
|
|
|
property var sortedDesktopApplications: {
|
|
const sortedWayland = sortedTopLevels.map(topLevel => topLevel.wayland).filter(wayland=> wayland !== null)
|
|
|
|
const desktopEntries = sortedWayland.map( topLevel => {
|
|
return DesktopEntries.heuristicLookup(topLevel.appId)
|
|
})
|
|
const workspace = sortedTopLevels.map( topLevel => {
|
|
return topLevel.workspace.id
|
|
})
|
|
const workspaceDesktopEntries = new Map()
|
|
|
|
|
|
for (let i = 0; i < workspace.length; i++) {
|
|
const key = workspace[i];
|
|
const value = desktopEntries[i];
|
|
|
|
if (workspaceDesktopEntries.has(key)) {
|
|
workspaceDesktopEntries.get(key).push(value);
|
|
} else {
|
|
workspaceDesktopEntries.set(key, [value]);
|
|
}
|
|
}
|
|
return workspaceDesktopEntries
|
|
|
|
}
|
|
|
|
} |