hyprland: use qs hyprland service
Also use models
This commit is contained in:
parent
c2e78cc11c
commit
588e7fcffc
2 changed files with 50 additions and 120 deletions
3
.vscode/settings.json
vendored
Normal file
3
.vscode/settings.json
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"editor.defaultFormatter": "theqtcompany.qt-qml"
|
||||||
|
}
|
||||||
|
|
@ -1,5 +1,4 @@
|
||||||
pragma Singleton
|
pragma Singleton
|
||||||
pragma ComponentBehavior: Bound
|
|
||||||
|
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
import Quickshell.Io
|
||||||
|
|
@ -9,151 +8,79 @@ import QtQuick
|
||||||
Singleton {
|
Singleton {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property list<var> clients: []
|
readonly property ListModel clients: ListModel {}
|
||||||
property list<var> monitors: []
|
readonly property var workspaces: Hyprland.workspaces
|
||||||
property list<var> workspaces: []
|
readonly property var monitors: Hyprland.monitors
|
||||||
property var activeClient: null
|
property var activeClient: null
|
||||||
property var activeWorkspace: null
|
property HyprlandWorkspace activeWorkspace: null
|
||||||
property var focusedMonitor: null
|
property HyprlandMonitor focusedMonitor: Hyprland.monitors.values.find(m => m.lastIpcObject.focused) ?? null
|
||||||
|
|
||||||
|
Component.onCompleted: reload()
|
||||||
|
|
||||||
function reload() {
|
function reload() {
|
||||||
|
Hyprland.refreshWorkspaces();
|
||||||
|
Hyprland.refreshMonitors();
|
||||||
getClients.running = true;
|
getClients.running = true;
|
||||||
getMonitors.running = true;
|
|
||||||
getWorkspaces.running = true;
|
|
||||||
getActiveClient.running = true;
|
getActiveClient.running = true;
|
||||||
getActiveWorkspace.running = true;
|
getActiveWorkspace.running = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: reload()
|
function dispatch(request: string): void {
|
||||||
|
Hyprland.dispatch(request);
|
||||||
|
}
|
||||||
|
|
||||||
Connections {
|
Connections {
|
||||||
target: Hyprland
|
target: Hyprland
|
||||||
function onRawEvent(event: string): void {
|
|
||||||
if (!event.endsWith("v2"))
|
function onRawEvent(event: HyprlandEvent): void {
|
||||||
|
if (!event.name.endsWith("v2"))
|
||||||
root.reload();
|
root.reload();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
component HyprData: Process {
|
Process {
|
||||||
id: proc
|
id: getClients
|
||||||
|
command: ["bash", "-c", "hyprctl -j clients | jq -c"]
|
||||||
required property string type
|
|
||||||
property string prop: type
|
|
||||||
property bool array: true
|
|
||||||
function transform(data) {
|
|
||||||
return data;
|
|
||||||
}
|
|
||||||
|
|
||||||
command: ["bash", "-c", `hyprctl -j ${type} | jq -c`]
|
|
||||||
stdout: SplitParser {
|
stdout: SplitParser {
|
||||||
onRead: data => {
|
onRead: data => {
|
||||||
root[proc.prop] = proc.array ? JSON.parse(data).map(proc.transform) : proc.transform(JSON.parse(data));
|
const clients = JSON.parse(data);
|
||||||
if (proc.type === "monitors")
|
root.clients.clear();
|
||||||
root.focusedMonitor = root.monitors.find(m => m.focused);
|
for (const client of clients) {
|
||||||
|
root.clients.append({
|
||||||
|
lastIpcObject: client,
|
||||||
|
address: client.address,
|
||||||
|
class: client.class,
|
||||||
|
title: client.title
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function transformClient(client) {
|
|
||||||
if (!client.address)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return {
|
|
||||||
address: client.address,
|
|
||||||
x: client.at[0],
|
|
||||||
y: client.at[1],
|
|
||||||
width: client.size[0],
|
|
||||||
height: client.size[1],
|
|
||||||
workspace: transformWorkspace(client.workspace),
|
|
||||||
floating: client.floating,
|
|
||||||
monitor: client.monitor,
|
|
||||||
wmClass: client.class,
|
|
||||||
title: client.title,
|
|
||||||
initialClass: client.initialClass,
|
|
||||||
initialTitle: client.initialTitle,
|
|
||||||
pid: client.pid,
|
|
||||||
xwayland: client.xwayland,
|
|
||||||
pinned: client.pinned,
|
|
||||||
fullscreen: client.fullscreen,
|
|
||||||
focusHistoryId: client.focusHistoryID,
|
|
||||||
inhibitingIdle: client.inhibitingIdle
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformMonitor(monitor) {
|
|
||||||
return {
|
|
||||||
id: monitor.id,
|
|
||||||
name: monitor.name,
|
|
||||||
description: monitor.description,
|
|
||||||
make: monitor.make,
|
|
||||||
model: monitor.model,
|
|
||||||
serial: monitor.serial,
|
|
||||||
x: monitor.x,
|
|
||||||
y: monitor.y,
|
|
||||||
width: monitor.width,
|
|
||||||
height: monitor.height,
|
|
||||||
refreshRate: monitor.refreshRate,
|
|
||||||
activeWorkspace: transformWorkspace(monitor.activeWorkspace),
|
|
||||||
specialWorkspace: transformWorkspace(monitor.specialWorkspace),
|
|
||||||
reserved: monitor.reserved,
|
|
||||||
scale: monitor.scale,
|
|
||||||
transform: monitor.transform,
|
|
||||||
focused: monitor.focused,
|
|
||||||
dpms: monitor.dpms,
|
|
||||||
vrr: monitor.vrr,
|
|
||||||
disabled: monitor.disabled
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
function transformWorkspace(workspace) {
|
|
||||||
return {
|
|
||||||
id: workspace.id,
|
|
||||||
name: workspace.name,
|
|
||||||
special: workspace.name.startsWith("special:")
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
HyprData {
|
Process {
|
||||||
id: getClients
|
|
||||||
type: "clients"
|
|
||||||
function transform(client) {
|
|
||||||
return transformClient(client);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprData {
|
|
||||||
id: getMonitors
|
|
||||||
type: "monitors"
|
|
||||||
function transform(monitor) {
|
|
||||||
return transformMonitor(monitor);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprData {
|
|
||||||
id: getWorkspaces
|
|
||||||
type: "workspaces"
|
|
||||||
function transform(workspace) {
|
|
||||||
return transformWorkspace(workspace);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
HyprData {
|
|
||||||
id: getActiveClient
|
id: getActiveClient
|
||||||
type: "activewindow"
|
command: ["bash", "-c", "hyprctl -j activewindow | jq -c"]
|
||||||
prop: "activeClient"
|
stdout: SplitParser {
|
||||||
array: false
|
onRead: data => {
|
||||||
function transform(client) {
|
const client = JSON.parse(data);
|
||||||
return transformClient(client);
|
root.activeClient = {
|
||||||
|
lastIpcObject: client,
|
||||||
|
address: client.address,
|
||||||
|
class: client.class,
|
||||||
|
title: client.title
|
||||||
|
};
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
HyprData {
|
Process {
|
||||||
id: getActiveWorkspace
|
id: getActiveWorkspace
|
||||||
type: "activeworkspace"
|
command: ["bash", "-c", "hyprctl -j activeworkspace | jq -c"]
|
||||||
prop: "activeWorkspace"
|
stdout: SplitParser {
|
||||||
array: false
|
onRead: data => {
|
||||||
function transform(workspace) {
|
const ws = JSON.parse(data);
|
||||||
return transformWorkspace(workspace);
|
root.activeWorkspace = root.workspaces.values.find(w => w.id === ws.id) ?? null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue