Possibly fix sizing issue
This commit is contained in:
@@ -11,119 +11,102 @@ Singleton {
|
||||
id: root
|
||||
|
||||
readonly property string hyprlandSignature: Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")
|
||||
|
||||
readonly property var focusedMon: Hyprland.focusedMonitor
|
||||
|
||||
property var hasFullscreen: false
|
||||
property var isScreencasting: false
|
||||
|
||||
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 bool hasFullscreen: false
|
||||
property bool isScreencasting: false
|
||||
|
||||
property ListModel sortedDesktopApplicationsModel: ListModel {}
|
||||
|
||||
onSortedTopLevelsChanged: updateSortedDesktopApplications()
|
||||
// Derived property of sorted toplevels
|
||||
property var sortedTopLevels: {
|
||||
const topLevels = Array.from(Hyprland.toplevels?.values ?? []);
|
||||
const sorted = 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?.at && b.lastIpcObject?.at) {
|
||||
const xCompare = a.lastIpcObject.at[0] - b.lastIpcObject.at[0];
|
||||
if (Math.abs(xCompare) > 10) return xCompare;
|
||||
return a.lastIpcObject.at[1] - b.lastIpcObject.at[1];
|
||||
}
|
||||
if (a.title && b.title)
|
||||
return a.title.localeCompare(b.title);
|
||||
return 0;
|
||||
});
|
||||
return sorted.filter(tl => tl.wayland !== null);
|
||||
}
|
||||
|
||||
function updateSortedDesktopApplications() {
|
||||
sortedDesktopApplicationsModel.clear();
|
||||
property var topLevelWorkspaces: {
|
||||
return sortedTopLevels.map(toplevel => toplevel.workspace);
|
||||
}
|
||||
|
||||
for (const topLevel of sortedTopLevels) {
|
||||
const entry = DesktopEntries.heuristicLookup(topLevel.wayland.appId);
|
||||
sortedDesktopApplicationsModel.append({
|
||||
topLevel: topLevel,
|
||||
desktopEntry: entry
|
||||
});
|
||||
onSortedTopLevelsChanged: refreshSortedDesktopApplications()
|
||||
|
||||
Timer {
|
||||
id: retryTimer
|
||||
interval: 300
|
||||
repeat: false
|
||||
onTriggered: refreshSortedDesktopApplications()
|
||||
}
|
||||
|
||||
function refreshSortedDesktopApplications() {
|
||||
if (!Hyprland.toplevels || Hyprland.toplevels.size === 0)
|
||||
return;
|
||||
|
||||
try {
|
||||
sortedDesktopApplicationsModel.clear();
|
||||
|
||||
for (const topLevel of sortedTopLevels) {
|
||||
const entry = DesktopEntries.heuristicLookup(topLevel.wayland.appId);
|
||||
if (!entry) {
|
||||
retryTimer.restart();
|
||||
return;
|
||||
}
|
||||
sortedDesktopApplicationsModel.append({
|
||||
topLevel: topLevel,
|
||||
desktopEntry: entry
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
} catch (err) {
|
||||
retryTimer.restart();
|
||||
}
|
||||
}
|
||||
|
||||
function workspaceApps(workspaceIndexAlign) {
|
||||
const list = [];
|
||||
const model = sortedDesktopApplicationsModel;
|
||||
for (let i = 0; i < model.count; i++) {
|
||||
const item = model.get(i);
|
||||
for (let i = 0; i < sortedDesktopApplicationsModel.count; i++) {
|
||||
const item = sortedDesktopApplicationsModel.get(i);
|
||||
if (item.topLevel.workspace.id === workspaceIndexAlign)
|
||||
list.push(item.desktopEntry);
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
// Hyprland socket listener
|
||||
Socket {
|
||||
path: `${Quickshell.env("XDG_RUNTIME_DIR")}/hypr/${Quickshell.env("HYPRLAND_INSTANCE_SIGNATURE")}/.socket2.sock`
|
||||
path: `${Quickshell.env("XDG_RUNTIME_DIR")}/hypr/${root.hyprlandSignature}/.socket2.sock`
|
||||
connected: true
|
||||
|
||||
parser: SplitParser {
|
||||
property var fullscreenRegex: new RegExp("fullscreen>>.")
|
||||
property var screencastRegex: new RegExp("screencast>>.*")
|
||||
|
||||
property var fullscreenRegex: /fullscreen>>./
|
||||
property var screencastRegex: /screencast>>.*/
|
||||
onRead: msg => {
|
||||
let match = fullscreenRegex.exec(msg);
|
||||
if (match != null) {
|
||||
if (msg.split(">>")[1] === "1") {
|
||||
root.hasFullscreen = true;
|
||||
} else {
|
||||
root.hasFullscreen = false;
|
||||
}
|
||||
if (fullscreenRegex.test(msg)) {
|
||||
root.hasFullscreen = msg.split(">>")[1] === "1";
|
||||
}
|
||||
match = screencastRegex.exec(msg);
|
||||
if (match != null) {
|
||||
if (msg.split(">>")[1].split(',')[0] === "1") {
|
||||
root.isScreencasting = true;
|
||||
} else {
|
||||
root.isScreencasting = false;
|
||||
}
|
||||
if (screencastRegex.test(msg)) {
|
||||
root.isScreencasting = msg.split(">>")[1].split(',')[0] === "1";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user