move NiriIpc and PowerProfileService singletons to services/

This commit is contained in:
Damocles 2026-04-17 23:11:46 +02:00
commit 0160e4a1fb
10 changed files with 18 additions and 19 deletions

View file

@ -145,7 +145,7 @@ PanelWindow {
id: _windowTitleGroup
Layout.minimumWidth: 0
clip: true
visible: S.Modules.windowTitle.enable && M.NiriIpc.focusedTitle !== ""
visible: S.Modules.windowTitle.enable && S.NiriIpc.focusedTitle !== ""
M.WindowTitleModule {
id: _windowTitle
readonly property real _maxWidth: Math.max(0, centerSection.x - _windowTitleGroup.x - 2 * S.Theme.groupPadding - S.Theme.groupSpacing)

View file

@ -10,7 +10,7 @@ PanelWindow {
required property var screen
visible: M.NotifService.popups.length > 0 && !M.NiriIpc.overviewOpen
visible: M.NotifService.popups.length > 0 && !S.NiriIpc.overviewOpen
color: "transparent"
WlrLayershell.layer: WlrLayer.Overlay

View file

@ -24,6 +24,6 @@ PanelWindow {
C.HexWaveBackground {
anchors.fill: parent
running: M.NiriIpc.overviewOpen
running: S.NiriIpc.overviewOpen
}
}

View file

@ -4,16 +4,16 @@ import "../services" as S
M.BarIcon {
id: root
tooltip: "Power profile: " + (M.PowerProfileService.profile || "unknown")
tooltip: "Power profile: " + (S.PowerProfileService.profile || "unknown")
color: M.PowerProfileService.profile === "performance" ? S.Theme.base09 : M.PowerProfileService.profile === "power-saver" ? S.Theme.base0B : root.accentColor
color: S.PowerProfileService.profile === "performance" ? S.Theme.base09 : S.PowerProfileService.profile === "power-saver" ? S.Theme.base0B : root.accentColor
icon: {
if (M.PowerProfileService.profile === "performance")
if (S.PowerProfileService.profile === "performance")
return "\uF0E7";
if (M.PowerProfileService.profile === "power-saver")
if (S.PowerProfileService.profile === "power-saver")
return "\uF06C";
if (M.PowerProfileService.profile === "balanced")
if (S.PowerProfileService.profile === "balanced")
return "\uF24E";
return "\uF0E7";
}
@ -23,8 +23,8 @@ M.BarIcon {
cursorShape: Qt.PointingHandCursor
onClicked: {
const cycle = ["performance", "balanced", "power-saver"];
const idx = cycle.indexOf(M.PowerProfileService.profile);
M.PowerProfileService.set(cycle[(idx + 1) % cycle.length]);
const idx = cycle.indexOf(S.PowerProfileService.profile);
S.PowerProfileService.set(cycle[(idx + 1) % cycle.length]);
}
}
}

View file

@ -8,12 +8,12 @@ import "../services" as S
M.BarSection {
id: root
spacing: S.Theme.moduleSpacing
tooltip: M.NiriIpc.focusedAppId ? M.NiriIpc.focusedAppId + "\n" + M.NiriIpc.focusedTitle : M.NiriIpc.focusedTitle
tooltip: S.NiriIpc.focusedAppId ? S.NiriIpc.focusedAppId + "\n" + S.NiriIpc.focusedTitle : S.NiriIpc.focusedTitle
readonly property string _iconSource: {
if (!M.NiriIpc.focusedAppId)
if (!S.NiriIpc.focusedAppId)
return "";
const entry = DesktopEntries.heuristicLookup(M.NiriIpc.focusedAppId);
const entry = DesktopEntries.heuristicLookup(S.NiriIpc.focusedAppId);
return entry ? Quickshell.iconPath(entry.icon) : "";
}
@ -37,7 +37,7 @@ M.BarSection {
M.BarLabel {
id: _label
label: M.NiriIpc.focusedTitle
label: S.NiriIpc.focusedTitle
color: root.accentColor
elide: Text.ElideRight
anchors.verticalCenter: parent.verticalCenter

View file

@ -36,7 +36,7 @@ Row {
// Live updates via shared NiriIpc singleton
Connections {
target: M.NiriIpc
target: S.NiriIpc
function onWorkspacesChanged(workspaces) {
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
}

View file

@ -30,8 +30,6 @@ WeatherModule 1.0 WeatherModule.qml
PowerProfileModule 1.0 PowerProfileModule.qml
IdleInhibitorModule 1.0 IdleInhibitorModule.qml
NotificationsModule 1.0 NotificationsModule.qml
singleton NiriIpc 1.0 NiriIpc.qml
singleton PowerProfileService 1.0 PowerProfileService.qml
ProcessList 1.0 ProcessList.qml
singleton NotifService 1.0 NotifService.qml
NotifItem 1.0 NotifItem.qml

View 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) {}
}
}
}
}

View file

@ -0,0 +1,53 @@
pragma Singleton
import QtQuick
import Quickshell.Io
import "." as S
QtObject {
id: root
property string profile: ""
readonly property bool powerSaver: profile === "power-saver"
property var _proc: Process {
running: S.Modules.powerProfile.enable
command: ["powerprofilesctl", "get"]
stdout: StdioCollector {
onStreamFinished: root.profile = text.trim()
}
}
property var _monitor: Process {
running: S.Modules.powerProfile.enable
command: ["sh", "-c", "dbus-monitor --system \"interface='org.freedesktop.DBus.Properties',member='PropertiesChanged',path='/net/hadess/PowerProfiles'\" 2>/dev/null"]
stdout: SplitParser {
splitMarker: "\n"
onRead: _debounce.restart()
}
}
property var _debounce: Timer {
interval: 300
onTriggered: root._proc.running = true
}
property var _poll: Timer {
interval: 60000
running: S.Modules.powerProfile.enable
repeat: true
onTriggered: root._proc.running = true
}
function set(p) {
_setter.next = p;
_setter.running = true;
}
property var _setter: Process {
property string next: ""
command: ["powerprofilesctl", "set", next]
onRunningChanged: if (!running && next !== "")
root._proc.running = true
}
}

View file

@ -2,3 +2,5 @@ module services
singleton Theme 1.0 Theme.qml
singleton SystemStats 1.0 SystemStats.qml
singleton Modules 1.0 Modules.qml
singleton NiriIpc 1.0 NiriIpc.qml
singleton PowerProfileService 1.0 PowerProfileService.qml