move NiriIpc and PowerProfileService singletons to services/
This commit is contained in:
parent
63e93f5de0
commit
0160e4a1fb
10 changed files with 18 additions and 19 deletions
74
shell/services/NiriIpc.qml
Normal file
74
shell/services/NiriIpc.qml
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
pragma Singleton
|
||||
|
||||
import QtQuick
|
||||
import Quickshell.Io
|
||||
|
||||
QtObject {
|
||||
id: root
|
||||
|
||||
signal workspacesChanged(var workspaces)
|
||||
signal workspaceActivated(int id, bool focused)
|
||||
signal windowFocusChanged(var windowId)
|
||||
signal windowOpenedOrChanged(var window)
|
||||
|
||||
property bool available: false
|
||||
|
||||
property string focusedTitle: ""
|
||||
property string focusedAppId: ""
|
||||
property bool overviewOpen: false
|
||||
|
||||
property var _focusedProc: Process {
|
||||
running: true
|
||||
command: ["niri", "msg", "--json", "focused-window"]
|
||||
stdout: StdioCollector {
|
||||
onStreamFinished: {
|
||||
try {
|
||||
const w = JSON.parse(text);
|
||||
if (w) {
|
||||
root.focusedTitle = w.title || "";
|
||||
root.focusedAppId = w.app_id || "";
|
||||
} else {
|
||||
root.focusedTitle = "";
|
||||
root.focusedAppId = "";
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
property var _eventStream: Process {
|
||||
running: true
|
||||
command: ["niri", "msg", "--json", "event-stream"]
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: line => {
|
||||
try {
|
||||
const ev = JSON.parse(line);
|
||||
root.available = true;
|
||||
if (ev.WorkspacesChanged !== undefined)
|
||||
root.workspacesChanged(ev.WorkspacesChanged.workspaces);
|
||||
else if (ev.WorkspaceActivated !== undefined)
|
||||
root.workspaceActivated(ev.WorkspaceActivated.id, ev.WorkspaceActivated.focused);
|
||||
else if (ev.WindowFocusChanged !== undefined) {
|
||||
root.windowFocusChanged(ev.WindowFocusChanged.id);
|
||||
if (ev.WindowFocusChanged.id !== null)
|
||||
root._focusedProc.running = true;
|
||||
else {
|
||||
root.focusedTitle = "";
|
||||
root.focusedAppId = "";
|
||||
}
|
||||
} else if (ev.OverviewOpenedOrClosed !== undefined) {
|
||||
root.overviewOpen = ev.OverviewOpenedOrClosed.is_open;
|
||||
} else if (ev.WindowOpenedOrChanged !== undefined) {
|
||||
root.windowOpenedOrChanged(ev.WindowOpenedOrChanged.window);
|
||||
const w = ev.WindowOpenedOrChanged.window;
|
||||
if (w.is_focused) {
|
||||
root.focusedTitle = w.title || "";
|
||||
root.focusedAppId = w.app_id || "";
|
||||
}
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue