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) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -39,32 +39,21 @@ M.BarSection {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Live updates via event stream
|
// Live updates via shared NiriIpc singleton
|
||||||
Process {
|
Connections {
|
||||||
id: eventStream
|
target: M.NiriIpc
|
||||||
running: true
|
function onWindowFocusChanged(windowId) {
|
||||||
command: ["niri", "msg", "--json", "event-stream"]
|
if (windowId !== null)
|
||||||
stdout: SplitParser {
|
initProc.running = true;
|
||||||
splitMarker: "\n"
|
else {
|
||||||
onRead: line => {
|
root._title = "";
|
||||||
try {
|
root._appId = "";
|
||||||
const ev = JSON.parse(line);
|
}
|
||||||
if (ev.WindowFocusChanged !== undefined) {
|
}
|
||||||
// WindowFocusChanged only gives id, re-query for full info
|
function onWindowOpenedOrChanged(window) {
|
||||||
if (ev.WindowFocusChanged.id !== null)
|
if (window.is_focused) {
|
||||||
initProc.running = true;
|
root._title = window.title || "";
|
||||||
else {
|
root._appId = window.app_id || "";
|
||||||
root._title = "";
|
|
||||||
root._appId = "";
|
|
||||||
}
|
|
||||||
} else if (ev.WindowOpenedOrChanged !== undefined) {
|
|
||||||
const w = ev.WindowOpenedOrChanged.window;
|
|
||||||
if (w.is_focused) {
|
|
||||||
root._title = w.title || "";
|
|
||||||
root._appId = w.app_id || "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,24 +33,15 @@ Row {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Live updates
|
// Live updates via shared NiriIpc singleton
|
||||||
Process {
|
Connections {
|
||||||
id: eventStream
|
target: M.NiriIpc
|
||||||
running: true
|
function onWorkspacesChanged(workspaces) {
|
||||||
command: ["niri", "msg", "--json", "event-stream"]
|
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
|
||||||
stdout: SplitParser {
|
}
|
||||||
splitMarker: "\n"
|
function onWorkspaceActivated(id, focused) {
|
||||||
onRead: line => {
|
if (focused)
|
||||||
try {
|
root._activeId = id;
|
||||||
const ev = JSON.parse(line);
|
|
||||||
if (ev.WorkspacesChanged !== undefined) {
|
|
||||||
root._allWorkspaces = ev.WorkspacesChanged.workspaces.sort((a, b) => a.idx - b.idx);
|
|
||||||
} else if (ev.WorkspaceActivated !== undefined) {
|
|
||||||
if (ev.WorkspaceActivated.focused)
|
|
||||||
root._activeId = ev.WorkspaceActivated.id;
|
|
||||||
}
|
|
||||||
} catch (e) {}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -32,6 +32,7 @@ Weather 1.0 Weather.qml
|
||||||
PowerProfile 1.0 PowerProfile.qml
|
PowerProfile 1.0 PowerProfile.qml
|
||||||
IdleInhibitor 1.0 IdleInhibitor.qml
|
IdleInhibitor 1.0 IdleInhibitor.qml
|
||||||
Notifications 1.0 Notifications.qml
|
Notifications 1.0 Notifications.qml
|
||||||
|
singleton NiriIpc 1.0 NiriIpc.qml
|
||||||
singleton ProcessList 1.0 ProcessList.qml
|
singleton ProcessList 1.0 ProcessList.qml
|
||||||
singleton NotifService 1.0 NotifService.qml
|
singleton NotifService 1.0 NotifService.qml
|
||||||
NotifItem 1.0 NotifItem.qml
|
NotifItem 1.0 NotifItem.qml
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue