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
|
|
@ -145,7 +145,7 @@ PanelWindow {
|
||||||
id: _windowTitleGroup
|
id: _windowTitleGroup
|
||||||
Layout.minimumWidth: 0
|
Layout.minimumWidth: 0
|
||||||
clip: true
|
clip: true
|
||||||
visible: S.Modules.windowTitle.enable && M.NiriIpc.focusedTitle !== ""
|
visible: S.Modules.windowTitle.enable && S.NiriIpc.focusedTitle !== ""
|
||||||
M.WindowTitleModule {
|
M.WindowTitleModule {
|
||||||
id: _windowTitle
|
id: _windowTitle
|
||||||
readonly property real _maxWidth: Math.max(0, centerSection.x - _windowTitleGroup.x - 2 * S.Theme.groupPadding - S.Theme.groupSpacing)
|
readonly property real _maxWidth: Math.max(0, centerSection.x - _windowTitleGroup.x - 2 * S.Theme.groupPadding - S.Theme.groupSpacing)
|
||||||
|
|
|
||||||
|
|
@ -10,7 +10,7 @@ PanelWindow {
|
||||||
|
|
||||||
required property var screen
|
required property var screen
|
||||||
|
|
||||||
visible: M.NotifService.popups.length > 0 && !M.NiriIpc.overviewOpen
|
visible: M.NotifService.popups.length > 0 && !S.NiriIpc.overviewOpen
|
||||||
color: "transparent"
|
color: "transparent"
|
||||||
|
|
||||||
WlrLayershell.layer: WlrLayer.Overlay
|
WlrLayershell.layer: WlrLayer.Overlay
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,6 @@ PanelWindow {
|
||||||
|
|
||||||
C.HexWaveBackground {
|
C.HexWaveBackground {
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
running: M.NiriIpc.overviewOpen
|
running: S.NiriIpc.overviewOpen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -4,16 +4,16 @@ import "../services" as S
|
||||||
|
|
||||||
M.BarIcon {
|
M.BarIcon {
|
||||||
id: root
|
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: {
|
icon: {
|
||||||
if (M.PowerProfileService.profile === "performance")
|
if (S.PowerProfileService.profile === "performance")
|
||||||
return "\uF0E7";
|
return "\uF0E7";
|
||||||
if (M.PowerProfileService.profile === "power-saver")
|
if (S.PowerProfileService.profile === "power-saver")
|
||||||
return "\uF06C";
|
return "\uF06C";
|
||||||
if (M.PowerProfileService.profile === "balanced")
|
if (S.PowerProfileService.profile === "balanced")
|
||||||
return "\uF24E";
|
return "\uF24E";
|
||||||
return "\uF0E7";
|
return "\uF0E7";
|
||||||
}
|
}
|
||||||
|
|
@ -23,8 +23,8 @@ M.BarIcon {
|
||||||
cursorShape: Qt.PointingHandCursor
|
cursorShape: Qt.PointingHandCursor
|
||||||
onClicked: {
|
onClicked: {
|
||||||
const cycle = ["performance", "balanced", "power-saver"];
|
const cycle = ["performance", "balanced", "power-saver"];
|
||||||
const idx = cycle.indexOf(M.PowerProfileService.profile);
|
const idx = cycle.indexOf(S.PowerProfileService.profile);
|
||||||
M.PowerProfileService.set(cycle[(idx + 1) % cycle.length]);
|
S.PowerProfileService.set(cycle[(idx + 1) % cycle.length]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,12 +8,12 @@ import "../services" as S
|
||||||
M.BarSection {
|
M.BarSection {
|
||||||
id: root
|
id: root
|
||||||
spacing: S.Theme.moduleSpacing
|
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: {
|
readonly property string _iconSource: {
|
||||||
if (!M.NiriIpc.focusedAppId)
|
if (!S.NiriIpc.focusedAppId)
|
||||||
return "";
|
return "";
|
||||||
const entry = DesktopEntries.heuristicLookup(M.NiriIpc.focusedAppId);
|
const entry = DesktopEntries.heuristicLookup(S.NiriIpc.focusedAppId);
|
||||||
return entry ? Quickshell.iconPath(entry.icon) : "";
|
return entry ? Quickshell.iconPath(entry.icon) : "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -37,7 +37,7 @@ M.BarSection {
|
||||||
|
|
||||||
M.BarLabel {
|
M.BarLabel {
|
||||||
id: _label
|
id: _label
|
||||||
label: M.NiriIpc.focusedTitle
|
label: S.NiriIpc.focusedTitle
|
||||||
color: root.accentColor
|
color: root.accentColor
|
||||||
elide: Text.ElideRight
|
elide: Text.ElideRight
|
||||||
anchors.verticalCenter: parent.verticalCenter
|
anchors.verticalCenter: parent.verticalCenter
|
||||||
|
|
|
||||||
|
|
@ -36,7 +36,7 @@ Row {
|
||||||
|
|
||||||
// Live updates via shared NiriIpc singleton
|
// Live updates via shared NiriIpc singleton
|
||||||
Connections {
|
Connections {
|
||||||
target: M.NiriIpc
|
target: S.NiriIpc
|
||||||
function onWorkspacesChanged(workspaces) {
|
function onWorkspacesChanged(workspaces) {
|
||||||
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
|
root._allWorkspaces = workspaces.sort((a, b) => a.idx - b.idx);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,8 +30,6 @@ WeatherModule 1.0 WeatherModule.qml
|
||||||
PowerProfileModule 1.0 PowerProfileModule.qml
|
PowerProfileModule 1.0 PowerProfileModule.qml
|
||||||
IdleInhibitorModule 1.0 IdleInhibitorModule.qml
|
IdleInhibitorModule 1.0 IdleInhibitorModule.qml
|
||||||
NotificationsModule 1.0 NotificationsModule.qml
|
NotificationsModule 1.0 NotificationsModule.qml
|
||||||
singleton NiriIpc 1.0 NiriIpc.qml
|
|
||||||
singleton PowerProfileService 1.0 PowerProfileService.qml
|
|
||||||
ProcessList 1.0 ProcessList.qml
|
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
|
||||||
|
|
|
||||||
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) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
53
shell/services/PowerProfileService.qml
Normal file
53
shell/services/PowerProfileService.qml
Normal 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -2,3 +2,5 @@ module services
|
||||||
singleton Theme 1.0 Theme.qml
|
singleton Theme 1.0 Theme.qml
|
||||||
singleton SystemStats 1.0 SystemStats.qml
|
singleton SystemStats 1.0 SystemStats.qml
|
||||||
singleton Modules 1.0 Modules.qml
|
singleton Modules 1.0 Modules.qml
|
||||||
|
singleton NiriIpc 1.0 NiriIpc.qml
|
||||||
|
singleton PowerProfileService 1.0 PowerProfileService.qml
|
||||||
|
|
|
||||||
Reference in a new issue