refactor: consolidate niri event-stream into NiriIpc singleton
This commit is contained in:
parent
cc44bd1c0e
commit
71a843e0f3
4 changed files with 59 additions and 44 deletions
34
modules/NiriIpc.qml
Normal file
34
modules/NiriIpc.qml
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
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 var _eventStream: Process {
|
||||
running: true
|
||||
command: ["niri", "msg", "--json", "event-stream"]
|
||||
stdout: SplitParser {
|
||||
splitMarker: "\n"
|
||||
onRead: line => {
|
||||
try {
|
||||
const ev = JSON.parse(line);
|
||||
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);
|
||||
else if (ev.WindowOpenedOrChanged !== undefined)
|
||||
root.windowOpenedOrChanged(ev.WindowOpenedOrChanged.window);
|
||||
} catch (e) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue