From e1371c647e25b066d89175fd4e0bf7cf3a82ab91 Mon Sep 17 00:00:00 2001 From: Sem Date: Sun, 29 Mar 2026 23:58:48 +0200 Subject: [PATCH] organize files --- quickshell/RandomWallpaper.qml | 2 +- quickshell/SystemStats.qml | 75 ++++++++ quickshell/constants/Constants.qml | 20 +++ quickshell/helpers/WorkspaceHelpers.qml | 22 +++ quickshell/shell.qml | 216 ++---------------------- quickshell/ui/Clock.qml | 28 +++ quickshell/ui/TopBar.qml | 108 ++++++++++++ 7 files changed, 266 insertions(+), 205 deletions(-) create mode 100644 quickshell/SystemStats.qml create mode 100644 quickshell/constants/Constants.qml create mode 100644 quickshell/helpers/WorkspaceHelpers.qml create mode 100644 quickshell/ui/Clock.qml create mode 100644 quickshell/ui/TopBar.qml diff --git a/quickshell/RandomWallpaper.qml b/quickshell/RandomWallpaper.qml index 62b108b..8cb1fc6 100644 --- a/quickshell/RandomWallpaper.qml +++ b/quickshell/RandomWallpaper.qml @@ -37,7 +37,7 @@ Item { var index = Math.floor(Math.random() * wallpapers.length); var path = wallpapers[index]; - console.log("wallpaper set to " + path); + // console.log("wallpaper set to " + path); wallpaperProcess.command = ["awww", "img", path, "--transition-type", "grow", "--transition-fps", "60", "--transition-duration", "0.6"]; diff --git a/quickshell/SystemStats.qml b/quickshell/SystemStats.qml new file mode 100644 index 0000000..e3e4775 --- /dev/null +++ b/quickshell/SystemStats.qml @@ -0,0 +1,75 @@ +import Quickshell +import Quickshell.Io +import QtQuick + +Item { + id: root + + // ===================== + // System stats + // ===================== + property int cpuUsage: 0 + property int memUsage: 0 + + property var lastCpuIdle: 0 + property var lastCpuTotal: 0 + + Process { + id: cpuProc + // get cpu usage, first line of /proc/stat + command: ["cat", "/proc/stat"] + stdout: StdioCollector { + onStreamFinished: { + var line = this.text.split(/\r?\n/)[1].split(" "); + + var user = parseInt(line[1]); + var nice = parseInt(line[2]); + var system = parseInt(line[3]); + var idle = parseInt(line[4]); + var iowait = parseInt(line[5]); + var irq = parseInt(line[6]); + var softirq = parseInt(line[7]); + + var idleAll = idle + iowait; + var total = user + nice + system + idle + iowait + irq + softirq; + + var diffIdle = idleAll - root.lastCpuIdle; + var diffTotal = total - root.lastCpuTotal; + + if (diffTotal > 0) { + root.cpuUsage = Math.round(100 * (1 - diffIdle / diffTotal)); + } + + root.lastCpuIdle = idleAll; + root.lastCpuTotal = total; + } + } + } + + Process { + id: memProc + command: ["sh", "-c", "free | grep Mem"] + stdout: SplitParser { + onRead: data => { + if (!data) + return; + var parts = data.trim().split(/\s+/); + var total = parseInt(parts[1]) || 1; + var used = parseInt(parts[2]) || 0; + memUsage = Math.round(100 * used / total); + } + } + Component.onCompleted: running = true + } + + // Update loop + Timer { + interval: 2000 + running: true + repeat: true + onTriggered: { + cpuProc.running = true; + memProc.running = true; + } + } +} diff --git a/quickshell/constants/Constants.qml b/quickshell/constants/Constants.qml new file mode 100644 index 0000000..15ad5b1 --- /dev/null +++ b/quickshell/constants/Constants.qml @@ -0,0 +1,20 @@ +pragma Singleton + +import QtQuick + +Item { + id: constants + + //font + property string fontFamily: "JetBrainsMono Nerd Font" + property int fontSize: 14 + + //colors + property color backgroundColor: "#1a1b26" + property color colBg: "#1a1b26" + property color colMuted: "#444b6a" + property color colCyan: "#0db9d7" + property color colBlue: "#7aa2f7" + property color colMagenta: "#e528c2" + property color colYellow: "#e0af68" +} diff --git a/quickshell/helpers/WorkspaceHelpers.qml b/quickshell/helpers/WorkspaceHelpers.qml new file mode 100644 index 0000000..699c4da --- /dev/null +++ b/quickshell/helpers/WorkspaceHelpers.qml @@ -0,0 +1,22 @@ +import QtQuick +import Quickshell.Hyprland + +Item { + id: root + + // ===================== + // Helpers + // ===================== + function getWorkspace(id) { + var list = Hyprland.workspaces.values; + for (var i = 0; i < list.length; i++) { + if (list[i].id === id) + return list[i]; + } + return null; + } + + function isWorkspaceActive(id) { + return Hyprland.focusedWorkspace && Hyprland.focusedWorkspace.id === id; + } +} diff --git a/quickshell/shell.qml b/quickshell/shell.qml index dc101f0..d0fc8ef 100644 --- a/quickshell/shell.qml +++ b/quickshell/shell.qml @@ -6,223 +6,31 @@ import QtQuick import QtQuick.Layouts import "." +import "constants" +import "ui" // qmllint disable uncreatable-type PanelWindow { id: root - // ===================== - // System stats - // ===================== - property int cpuUsage: 0 - property int memUsage: 0 - - property var lastCpuIdle: 0 - property var lastCpuTotal: 0 - - RandomWallpaper {} - - Process { - id: cpuProc - // get cpu usage, first line of /proc/stat - command: ["cat", "/proc/stat"] - stdout: StdioCollector { - onStreamFinished: { - var line = this.text.split(/\r?\n/)[1].split(" "); - - var user = parseInt(line[1]); - var nice = parseInt(line[2]); - var system = parseInt(line[3]); - var idle = parseInt(line[4]); - var iowait = parseInt(line[5]); - var irq = parseInt(line[6]); - var softirq = parseInt(line[7]); - - var idleAll = idle + iowait; - var total = user + nice + system + idle + iowait + irq + softirq; - - var diffIdle = idleAll - root.lastCpuIdle; - var diffTotal = total - root.lastCpuTotal; - - if (diffTotal > 0) { - root.cpuUsage = Math.round(100 * (1 - diffIdle / diffTotal)); - } - - root.lastCpuIdle = idleAll; - root.lastCpuTotal = total; - } - } - } - - Process { - id: memProc - command: ["sh", "-c", "free | grep Mem"] - stdout: SplitParser { - onRead: data => { - if (!data) - return; - var parts = data.trim().split(/\s+/); - var total = parseInt(parts[1]) || 1; - var used = parseInt(parts[2]) || 0; - memUsage = Math.round(100 * used / total); - } - } - Component.onCompleted: running = true - } - - // Update loop - Timer { - interval: 2000 - running: true - repeat: true - onTriggered: { - cpuProc.running = true; - memProc.running = true; - } - } - - // ===================== - // Theme - // ===================== - property color colBg: "#1a1b26" - property color colMuted: "#444b6a" - property color colCyan: "#0db9d7" - property color colBlue: "#7aa2f7" - property color colMagenta: "#e528c2" - property color colYellow: "#e0af68" - - property string fontFamily: "JetBrainsMono Nerd Font" - property int fontSize: 14 - - // ===================== - // Helpers - // ===================== - function getWorkspace(id) { - var list = Hyprland.workspaces.values; - for (var i = 0; i < list.length; i++) { - if (list[i].id === id) - return list[i]; - } - return null; - } - - function isWorkspaceActive(id) { - return Hyprland.focusedWorkspace && Hyprland.focusedWorkspace.id === id; - } - // ===================== // Layout // ===================== anchors.top: true anchors.left: true anchors.right: true - implicitHeight: 30 - color: root.colBg + implicitHeight: 25 + color: Constants.colBg - RowLayout { + RandomWallpaper {} + + SystemStats { + id: stats + } + TopBar { anchors.fill: parent - anchors.margins: 8 - // ===================== - // LEFT: Workspaces - // ===================== - RowLayout { - spacing: 6 - - Repeater { - model: 9 - - Text { - required property int index - - property int wsId: index + 1 - property var ws: root.getWorkspace(wsId) - - text: wsId - - color: root.isWorkspaceActive(wsId) ? root.colCyan : (ws ? root.colMagenta : root.colMuted) - - font { - family: root.fontFamily - pixelSize: root.fontSize - bold: true - } - - MouseArea { - anchors.fill: parent - onClicked: Hyprland.dispatch("workspace " + wsId) - } - } - } - } - - // Spacer - Item { - Layout.fillWidth: true - } - - // ===================== - // RIGHT: System info - // ===================== - RowLayout { - spacing: 10 - - // CPU (placeholder, hook later) - Text { - id: cpuText - text: "CPU: " + cpuUsage + "%" - color: root.colYellow - font.pixelSize: root.fontSize - font.family: root.fontFamily - font.bold: true - } - - Rectangle { - width: 1 - height: 16 - color: root.colMuted - } - - // Memory (placeholder) - Text { - id: memText - text: "Mem: " + memUsage + "%" - color: root.colCyan - font.pixelSize: root.fontSize - font.family: root.fontFamily - font.bold: true - } - - Rectangle { - width: 1 - height: 16 - color: root.colMuted - } - - // Clock - Text { - id: clock - color: root.colBlue - - font { - family: root.fontFamily - pixelSize: root.fontSize - bold: true - } - - function updateTime() { - text = Qt.formatDateTime(new Date(), "ddd, MMM dd - HH:mm"); - } - - Component.onCompleted: updateTime() - - Timer { - interval: 1000 - running: true - repeat: true - onTriggered: clock.updateTime() - } - } - } + cpuUsage: stats.cpuUsage + memUsage: stats.memUsage } } diff --git a/quickshell/ui/Clock.qml b/quickshell/ui/Clock.qml new file mode 100644 index 0000000..5cbc42e --- /dev/null +++ b/quickshell/ui/Clock.qml @@ -0,0 +1,28 @@ +import QtQuick +import "../constants" + +// Clock + +Text { + id: clock + color: Constants.colBlue + + font { + family: Constants.fontFamily + pixelSize: Constants.fontSize + bold: true + } + + function updateTime() { + text = Qt.formatDateTime(new Date(), "ddd, MMM dd - HH:mm"); + } + + Component.onCompleted: updateTime() + + Timer { + interval: 1000 + running: true + repeat: true + onTriggered: clock.updateTime() + } +} diff --git a/quickshell/ui/TopBar.qml b/quickshell/ui/TopBar.qml new file mode 100644 index 0000000..eb9d3c8 --- /dev/null +++ b/quickshell/ui/TopBar.qml @@ -0,0 +1,108 @@ +pragma ComponentBehavior: Bound + +import Quickshell +import Quickshell.Wayland +import Quickshell.Hyprland +import Quickshell.Io +import QtQuick +import QtQuick.Layouts + +import "../constants" +import "../helpers" +import "." + +Item { + id: root + + property int cpuUsage: 0 + property int memUsage: 0 + + RowLayout { + anchors.fill: parent + // anchors.centerIn: verticalCenter + anchors.leftMargin: 8 + anchors.rightMargin: 8 + + WorkspaceHelpers { + id: workspaceHelpers + } + + // ===================== + // LEFT: Workspaces + // ===================== + RowLayout { + spacing: 10 + + Repeater { + model: 9 + + Text { + required property int index + + property int wsId: index + 1 + property var ws: workspaceHelpers.getWorkspace(wsId) + + text: wsId + + color: workspaceHelpers.isWorkspaceActive(wsId) ? Constants.colCyan : (ws ? Constants.colMagenta : Constants.colMuted) + + font { + family: Constants.fontFamily + pixelSize: Constants.fontSize + bold: true + } + + MouseArea { + anchors.fill: parent + onClicked: Hyprland.dispatch("workspace " + wsId) + } + } + } + } + + // Spacer + Item { + Layout.fillWidth: true + } + + // ===================== + // RIGHT: System info + // ===================== + RowLayout { + spacing: 10 + + //TODO put this in separate component + Text { + id: cpuText + text: "CPU: " + cpuUsage + "%" + color: Constants.colYellow + font.pixelSize: Constants.fontSize + font.family: Constants.fontFamily + font.bold: true + } + + Rectangle { + width: 1 + height: 16 + color: Constants.colMuted + } + + Text { + id: memText + text: "Mem: " + memUsage + "%" + color: Constants.colCyan + font.pixelSize: Constants.fontSize + font.family: Constants.fontFamily + font.bold: true + } + + Rectangle { + width: 1 + height: 16 + color: Constants.colMuted + } + + Clock {} + } + } +}