From 587eb6179e7899b339b607a7b0bb8cdbfffa30d6 Mon Sep 17 00:00:00 2001 From: Tomas Rivera <137088692+Totorile1@users.noreply.github.com> Date: Wed, 11 Mar 2026 16:58:03 +0100 Subject: [PATCH] added a systeminfo module to quickshell --- hosts/laptop/home.nix | 1 + modules/home-manager/zsh.nix | 2 + modules/scripts/QSsysinfo.nix | 31 ++++++ other/quickshell/bar/Bar.qml | 160 +++++++++++++++++------------- other/quickshell/theme/Colors.qml | 3 + 5 files changed, 128 insertions(+), 69 deletions(-) create mode 100644 modules/scripts/QSsysinfo.nix diff --git a/hosts/laptop/home.nix b/hosts/laptop/home.nix index 787d31d..c5526e1 100755 --- a/hosts/laptop/home.nix +++ b/hosts/laptop/home.nix @@ -76,6 +76,7 @@ (pkgs.callPackage ../../modules/scripts/manix.nix {}) (pkgs.callPackage ../../modules/scripts/man.nix {}) (pkgs.callPackage ../../modules/scripts/trimmer.nix {}) + (pkgs.callPackage ../../modules/scripts/QSsysinfo.nix {}) #pkgs pkgs.gruvbox-gtk-theme # # Adds the 'hello' command to your environment. It prints a friendly diff --git a/modules/home-manager/zsh.nix b/modules/home-manager/zsh.nix index 77a4a88..70dad75 100644 --- a/modules/home-manager/zsh.nix +++ b/modules/home-manager/zsh.nix @@ -30,6 +30,8 @@ manix = "custom-manix"; man = "custom-man"; mplayer = "mplayer -volume 5"; + snrt = "git add -A && sudo nixos-rebuild test --flake ~/nixos/#laptop"; + snrs = "git add -A && sudo nixos-rebuild switch --flake ~/nixos/#laptop"; }; }; } diff --git a/modules/scripts/QSsysinfo.nix b/modules/scripts/QSsysinfo.nix new file mode 100644 index 0000000..9519622 --- /dev/null +++ b/modules/scripts/QSsysinfo.nix @@ -0,0 +1,31 @@ +{ + writeShellApplication, + ripgrep, + gawkInteractive, + ... +}: +writeShellApplication { + name = "QS-sysinfo"; + runtimeInputs = [ + ripgrep + gawkInteractive + ]; + text = '' + Pad CPU, MEM, DISK to 2 chars (right-aligned) +cpu=$(awk '/^cpu /{printf("%.0f", ($2+$4)*100/($2+$4+$5))}' /proc/stat) +cpu=$(printf "%2s" "$cpu") + +mem=$(free | awk '/Mem:/ {printf("%.0f",$3/$2*100)}') +mem=$(printf "%2s" "$mem") + +disk=$(df / | awk 'NR==2 {gsub("%",""); print $5}') +disk=$(printf "%2s" "$disk") + +# Pad POWER to 5 chars (XX.XX) +power=$(upower -b | awk -F: '/energy-rate/ {gsub(/^[ \t]+/, "", $2); split($2,a," "); printf("%.2f", a[1])}') +power=$(printf "%5s" "$power") + +# Output JSON +echo "{\"cpu\":\"$cpu\",\"mem\":\"$mem\",\"disk\":\"$disk\",\"power\":\"$power\"}" + ''; +} diff --git a/other/quickshell/bar/Bar.qml b/other/quickshell/bar/Bar.qml index 372dc09..96bb457 100644 --- a/other/quickshell/bar/Bar.qml +++ b/other/quickshell/bar/Bar.qml @@ -3,6 +3,7 @@ import QtQuick.Effects import Quickshell import QtQuick.Layouts import Quickshell.Wayland +import Quickshell.Io import "mpris" as Mpris import "systray" as SysTray import "../theme" as Theme @@ -14,23 +15,24 @@ PanelWindow { property var modelData readonly property var tooltip: tooltip readonly property real tooltipYOffset: root.height + 2 + Tooltip { id: tooltip bar: root } + function boundedY(targetY: real, height: real): real { - return Math.max(bar.anchors.topMargin + height, Math.min(bar.height + bar.anchors.topMargin - height, targetY)); + return Math.max(bar.anchors.topMargin + height, + Math.min(bar.height + bar.anchors.topMargin - height, targetY)); } + function boundedX(targetX: real, width: real): real { - return Math.max(bar.anchors.leftMargin + width, Math.min(bar.width + bar.anchors.leftMargin - width, targetX)); + return Math.max(bar.anchors.leftMargin + width, + Math.min(bar.width + bar.anchors.leftMargin - width, targetX)); } WlrLayershell.namespace: "shell:bar" - anchors { - top: true - left: true - right: true - } + anchors { top: true; left: true; right: true } exclusiveZone: 48 implicitHeight: 72 color: Theme.Colors.barColor1 @@ -44,25 +46,16 @@ PanelWindow { Item { id: bar - - anchors { - top: parent.top - left: parent.left - right: parent.right - } - + anchors { top: parent.top; left: parent.left; right: parent.right } implicitHeight: 48 + // ---------------- LEFT MODULE ---------------- Rectangle { - anchors { - top: parent.top - bottom: parent.bottom - left: parent.left - } - - implicitWidth: left.width + left.anchors.leftMargin + left.anchors.rightMargin - implicitHeight: left.height + id: leftModule + anchors { top: parent.top; bottom: parent.bottom; left: parent.left } color: Theme.Colors.barColor2 + implicitWidth: left.childrenRect.width + 14 + implicitHeight: left.childrenRect.height + 8 Rectangle { z: -1 @@ -70,6 +63,7 @@ PanelWindow { color: Theme.Colors.barColor3 anchors.margins: -4 } + Image { width: 16 * 6 height: 4 * 6 @@ -81,39 +75,87 @@ PanelWindow { RowLayout { id: left - - anchors { - top: parent.top - bottom: parent.bottom - left: parent.left - leftMargin: 7 - rightMargin: 7 - } - + anchors { top: parent.top; bottom: parent.bottom; left: parent.left; leftMargin: 7; rightMargin: 7 } spacing: 12 - //Launcher {} + Workspaces { bar: root } + SysTray.SysTray { bar: root } + } + } - Workspaces { - bar: root + // ---------------- SYSINFO MODULE ---------------- + Rectangle { + id: leftCenterModule + anchors { top: parent.top; bottom: parent.bottom; left: leftModule.right; leftMargin: 30 } + color: Theme.Colors.barColor6 + implicitWidth: sysinfo.childrenRect.width + 16 + implicitHeight: sysinfo.childrenRect.height + 8 + + Rectangle { + z: -1 + anchors.fill: parent + color: Theme.Colors.barColor7 + anchors.margins: -4 + } + + Image { + width: 16 * 6 + height: 4 * 6 + anchors.top: parent.bottom + anchors.left: parent.left + source: "../assets/bar-decor.png" + smooth: false + } + + RowLayout { + id: sysinfo + spacing: 10 + + property int cpu: 0 + property int mem: 0 + property int disk: 0 + property real power: 0 + + Timer { + interval: 2000 + running: true + repeat: true + onTriggered: sysProcess.running = true } - SysTray.SysTray { - bar: root + Process { + id: sysProcess + command: ["QS-sysinfo"] + + stdout: SplitParser { + onRead: function(line) { + try { + var data = JSON.parse(line) + sysinfo.cpu = data.cpu + sysinfo.mem = data.mem + sysinfo.disk = data.disk + sysinfo.power = data.power + } catch(e) {} + } + } + } + + Text { + id: infoText + text: "CPU " + sysinfo.cpu + "% MEM " + sysinfo.mem + "% DSK " + sysinfo.disk + "% PWR " + sysinfo.power + "W" + font.pixelSize: 18 + color: Theme.Colors.barColor8 } } } + // ---------------- RIGHT MODULE ---------------- Rectangle { - anchors { - top: parent.top - bottom: parent.bottom - right: parent.right - } - - implicitWidth: right.width + right.anchors.leftMargin + right.anchors.rightMargin - implicitHeight: right.height + id: rightCenterModule + anchors { top: parent.top; bottom: parent.bottom; right: parent.right } color: Theme.Colors.barColor4 + implicitWidth: right.childrenRect.width + 14 + implicitHeight: right.childrenRect.height + 8 Rectangle { z: -1 @@ -121,6 +163,7 @@ PanelWindow { color: Theme.Colors.barColor5 anchors.margins: -4 } + Image { width: 16 * 6 height: 4 * 6 @@ -133,34 +176,13 @@ PanelWindow { RowLayout { id: right - - anchors { - top: parent.top - bottom: parent.bottom - right: parent.right - leftMargin: 7 - rightMargin: 7 - } - + anchors { top: parent.top; bottom: parent.bottom; right: parent.right; leftMargin: 7; rightMargin: 7 } spacing: 12 Time {} - - Volume { - bar: root - } - - Mpris.Players { - window: root - bar: root - } - - //Theme {} - - Power { - id: power - bar: root - } + Volume { bar: root } + Mpris.Players { window: root; bar: root } + Power { id: power; bar: root } } } } diff --git a/other/quickshell/theme/Colors.qml b/other/quickshell/theme/Colors.qml index 5021268..a201b37 100644 --- a/other/quickshell/theme/Colors.qml +++ b/other/quickshell/theme/Colors.qml @@ -51,6 +51,9 @@ QtObject { readonly property color barColor3: border // Left block bar border original color: "#BE850E" readonly property color barColor4: background // Right block bar background original color: "#3B253F" readonly property color barColor5: border // Right block bar border original color: "#BE850E" + readonly property color barColor6: background // left center block bar background + readonly property color barColor7: border // left center block bar border + readonly property color barColor8: text // left center block bar text color readonly property color powerColor1: black // Battery indicator empty color original color: "black" readonly property color powerColor2: red // original color: "red" readonly property color powerColor3: accentYellow // Battery indicator normal color original color: "#EEA939"