mirror of
https://github.com/AquaMorph/dotfiles.git
synced 2026-09-29 20:04:21 +00:00
refactor(quickshell): centralize hardware status polling
This commit is contained in:
@@ -1,42 +1,16 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
|
||||||
import Quickshell.Io
|
|
||||||
|
|
||||||
Block {
|
Block {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property int percentage: -1
|
required property var service
|
||||||
|
|
||||||
visible: percentage >= 0
|
visible: service.brightness >= 0
|
||||||
blockColor: "#2980b9"
|
blockColor: "#2980b9"
|
||||||
interactive: true
|
interactive: true
|
||||||
text: "\uf185 " + percentage + "%"
|
text: "\uf185 " + service.brightness + "%"
|
||||||
onWheel: wheel => {
|
onWheel: wheel => {
|
||||||
const change = wheel.angleDelta.y > 0 ? "+5%" : "5%-";
|
const change = wheel.angleDelta.y > 0 ? "+5%" : "5%-";
|
||||||
Quickshell.execDetached(["brightnessctl", "set", change]);
|
service.setBrightness(change);
|
||||||
refreshTimer.restart();
|
|
||||||
}
|
|
||||||
|
|
||||||
Process {
|
|
||||||
id: brightnessQuery
|
|
||||||
command: ["brightnessctl", "-m"]
|
|
||||||
running: true
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
const fields = text.trim().split(",");
|
|
||||||
root.percentage = fields.length >= 4
|
|
||||||
? parseInt(fields[3].replace("%", ""))
|
|
||||||
: -1;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
id: refreshTimer
|
|
||||||
interval: 500
|
|
||||||
repeat: true
|
|
||||||
running: true
|
|
||||||
onTriggered: brightnessQuery.running = true
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ PanelWindow {
|
|||||||
property var sink: Pipewire.defaultAudioSink
|
property var sink: Pipewire.defaultAudioSink
|
||||||
property var source: Pipewire.defaultAudioSource
|
property var source: Pipewire.defaultAudioSource
|
||||||
property var battery: UPower.displayDevice
|
property var battery: UPower.displayDevice
|
||||||
|
property var hardware
|
||||||
|
|
||||||
anchors {
|
anchors {
|
||||||
top: true
|
top: true
|
||||||
@@ -150,8 +151,8 @@ PanelWindow {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Network {}
|
Network { service: bar.hardware }
|
||||||
Backlight {}
|
Backlight { service: bar.hardware }
|
||||||
|
|
||||||
Block {
|
Block {
|
||||||
property int percentage: Math.round(bar.battery.percentage * 100)
|
property int percentage: Math.round(bar.battery.percentage * 100)
|
||||||
|
|||||||
@@ -0,0 +1,79 @@
|
|||||||
|
import QtQuick
|
||||||
|
import Quickshell
|
||||||
|
import Quickshell.Io
|
||||||
|
|
||||||
|
Scope {
|
||||||
|
id: root
|
||||||
|
|
||||||
|
property string connection: "Disconnected"
|
||||||
|
property int brightness: -1
|
||||||
|
|
||||||
|
function setBrightness(change) {
|
||||||
|
Quickshell.execDetached(["brightnessctl", "set", change]);
|
||||||
|
brightnessRefresh.restart();
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: networkQuery
|
||||||
|
command: ["nmcli", "-t", "-f", "TYPE,NAME", "connection", "show", "--active"]
|
||||||
|
running: true
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
const lines = text.trim().split("\n");
|
||||||
|
for (let line of lines) {
|
||||||
|
const separator = line.indexOf(":");
|
||||||
|
const type = line.slice(0, separator);
|
||||||
|
if (type === "802-11-wireless" || type === "wifi") {
|
||||||
|
root.connection = line.slice(separator + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (let line of lines) {
|
||||||
|
const separator = line.indexOf(":");
|
||||||
|
const type = line.slice(0, separator);
|
||||||
|
if (type === "802-3-ethernet" || type === "ethernet") {
|
||||||
|
root.connection = line.slice(separator + 1);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
root.connection = "Disconnected";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 5000
|
||||||
|
repeat: true
|
||||||
|
running: true
|
||||||
|
onTriggered: networkQuery.running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Process {
|
||||||
|
id: brightnessQuery
|
||||||
|
command: ["brightnessctl", "-m"]
|
||||||
|
running: true
|
||||||
|
|
||||||
|
stdout: StdioCollector {
|
||||||
|
onStreamFinished: {
|
||||||
|
const fields = text.trim().split(",");
|
||||||
|
root.brightness = fields.length >= 4
|
||||||
|
? parseInt(fields[3].replace("%", ""))
|
||||||
|
: -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
interval: 2000
|
||||||
|
repeat: true
|
||||||
|
running: true
|
||||||
|
onTriggered: brightnessQuery.running = true
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: brightnessRefresh
|
||||||
|
interval: 250
|
||||||
|
onTriggered: brightnessQuery.running = true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,51 +1,14 @@
|
|||||||
import QtQuick
|
import QtQuick
|
||||||
import Quickshell
|
import Quickshell
|
||||||
import Quickshell.Io
|
|
||||||
|
|
||||||
Block {
|
Block {
|
||||||
id: root
|
id: root
|
||||||
|
|
||||||
property string connection: "Disconnected"
|
required property var service
|
||||||
property bool connected: connection !== "Disconnected"
|
property bool connected: service.connection !== "Disconnected"
|
||||||
|
|
||||||
blockColor: connected ? "#2980b9" : "#e91e63"
|
blockColor: connected ? "#2980b9" : "#e91e63"
|
||||||
interactive: true
|
interactive: true
|
||||||
text: connected ? "\uf1eb " + connection : "Disconnected !"
|
text: connected ? "\uf1eb " + service.connection : "Disconnected !"
|
||||||
onClicked: Quickshell.execDetached(["nm-connection-editor"])
|
onClicked: Quickshell.execDetached(["nm-connection-editor"])
|
||||||
|
|
||||||
Process {
|
|
||||||
id: networkQuery
|
|
||||||
command: ["nmcli", "-t", "-f", "TYPE,NAME", "connection", "show", "--active"]
|
|
||||||
running: true
|
|
||||||
|
|
||||||
stdout: StdioCollector {
|
|
||||||
onStreamFinished: {
|
|
||||||
const lines = text.trim().split("\n");
|
|
||||||
for (let line of lines) {
|
|
||||||
const separator = line.indexOf(":");
|
|
||||||
const type = line.slice(0, separator);
|
|
||||||
if (type === "802-11-wireless" || type === "wifi") {
|
|
||||||
root.connection = line.slice(separator + 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (let line of lines) {
|
|
||||||
const separator = line.indexOf(":");
|
|
||||||
const type = line.slice(0, separator);
|
|
||||||
if (type === "802-3-ethernet" || type === "ethernet") {
|
|
||||||
root.connection = line.slice(separator + 1);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
root.connection = "Disconnected";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Timer {
|
|
||||||
interval: 5000
|
|
||||||
repeat: true
|
|
||||||
running: true
|
|
||||||
onTriggered: networkQuery.running = true
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
import Quickshell
|
import Quickshell
|
||||||
|
|
||||||
ShellRoot {
|
ShellRoot {
|
||||||
|
HardwareService {
|
||||||
|
id: hardwareService
|
||||||
|
}
|
||||||
|
|
||||||
Variants {
|
Variants {
|
||||||
model: Quickshell.screens
|
model: Quickshell.screens
|
||||||
|
|
||||||
Bar {
|
Bar {
|
||||||
required property var modelData
|
required property var modelData
|
||||||
screen: modelData
|
screen: modelData
|
||||||
|
hardware: hardwareService
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user