From 9f0deefec4a6e5cc28b63cd49d66e611ffca849d Mon Sep 17 00:00:00 2001 From: end-4 <97237370+end-4@users.noreply.github.com> Date: Mon, 14 Apr 2025 12:18:33 +0200 Subject: [PATCH] per-monitor handling of sidebar opening --- .../quickshell/modules/common/Appearance.qml | 6 +++ .../quickshell/modules/common/DateTime.qml | 31 +++++++++++ .../modules/common/ResourceUsage.qml | 2 +- .../quickshell/modules/common/SystemInfo.qml | 51 +++++++++++++++++++ .../modules/sidebarRight/SidebarRight.qml | 40 +++++++++------ 5 files changed, 113 insertions(+), 17 deletions(-) create mode 100644 .config/quickshell/modules/common/SystemInfo.qml diff --git a/.config/quickshell/modules/common/Appearance.qml b/.config/quickshell/modules/common/Appearance.qml index e65a5419..6190a3ac 100644 --- a/.config/quickshell/modules/common/Appearance.qml +++ b/.config/quickshell/modules/common/Appearance.qml @@ -16,6 +16,12 @@ Singleton { return Qt.rgba(percentage * c1.r + (1 - percentage) * c2.r, percentage * c1.g + (1 - percentage) * c2.g, percentage * c1.b + (1 - percentage) * c2.b, percentage * c1.a + (1 - percentage) * c2.a); } + // Transparentize + function transparentize(color, percentage) { + var c = Qt.color(color); + return Qt.rgba(c.r, c.g, c.b, c.a * (1 - percentage)); + } + m3colors: QtObject { property bool darkmode: false property bool transparent: false diff --git a/.config/quickshell/modules/common/DateTime.qml b/.config/quickshell/modules/common/DateTime.qml index ddeec093..bbcedfb5 100644 --- a/.config/quickshell/modules/common/DateTime.qml +++ b/.config/quickshell/modules/common/DateTime.qml @@ -6,6 +6,7 @@ pragma Singleton Singleton { property string time: Qt.formatDateTime(clock.date, "hh:mm") property string date: Qt.formatDateTime(clock.date, "dddd, dd/MM") + property string uptime: "0h, 0m" SystemClock { id: clock @@ -13,4 +14,34 @@ Singleton { precision: SystemClock.Minutes } + Timer { + interval: 10 + running: true + repeat: true + onTriggered: { + fileUptime.reload() + const textUptime = fileUptime.text() + const uptimeSeconds = Number(textUptime.split(" ")[0] ?? 0) + + // Convert seconds to days, hours, and minutes + const days = Math.floor(uptimeSeconds / 86400) + const hours = Math.floor((uptimeSeconds % 86400) / 3600) + const minutes = Math.floor((uptimeSeconds % 3600) / 60) + + // Build the formatted uptime string + let formatted = "" + if (days > 0) formatted += `${days}d` + if (hours > 0) formatted += `${formatted ? ", " : ""}${hours}h` + if (minutes > 0 || !formatted) formatted += `${formatted ? ", " : ""}${minutes}m` + uptime = formatted + interval = ConfigOptions.resources.updateInterval; + } + } + + FileView { + id: fileUptime + + path: "/proc/uptime" + } + } diff --git a/.config/quickshell/modules/common/ResourceUsage.qml b/.config/quickshell/modules/common/ResourceUsage.qml index 898abbb3..6326bace 100644 --- a/.config/quickshell/modules/common/ResourceUsage.qml +++ b/.config/quickshell/modules/common/ResourceUsage.qml @@ -16,7 +16,7 @@ Singleton { property var previousCpuStats Timer { - interval: 50 + interval: 10 running: true repeat: true onTriggered: { diff --git a/.config/quickshell/modules/common/SystemInfo.qml b/.config/quickshell/modules/common/SystemInfo.qml new file mode 100644 index 00000000..3db1237c --- /dev/null +++ b/.config/quickshell/modules/common/SystemInfo.qml @@ -0,0 +1,51 @@ +import QtQuick +import Quickshell +import Quickshell.Io +pragma Singleton + +Singleton { + property string distroName: "Unknown" + property string distroId: "unknown" + property string distroIcon: "linux-symbolic" + + Timer { + interval: 1 + running: true + repeat: false + onTriggered: { + fileOsRelease.reload() + const textOsRelease = fileOsRelease.text() + + // Extract the friendly name (PRETTY_NAME field, fallback to NAME) + const prettyNameMatch = textOsRelease.match(/^PRETTY_NAME="(.+?)"/m) + const nameMatch = textOsRelease.match(/^NAME="(.+?)"/m) + distroName = prettyNameMatch ? prettyNameMatch[1] : (nameMatch ? nameMatch[1].replace(/Linux/i, "").trim() : "Unknown") + + // Extract the ID (LOGO field, fallback to "unknown") + const logoMatch = textOsRelease.match(/^LOGO=(.+)$/m) + distroId = logoMatch ? logoMatch[1].replace(/"/g, "") : "unknown" + + // Update the distroIcon property based on distroId + switch (distroId) { + case "arch": distroIcon = "arch-symbolic"; break; + case "endeavouros": distroIcon = "endeavouros-symbolic"; break; + case "cachyos": distroIcon = "cachyos-symbolic"; break; + case "nixos": distroIcon = "nixos-symbolic"; break; + case "fedora": distroIcon = "fedora-symbolic"; break; + case "linuxmint": + case "ubuntu": + case "zorin": + case "popos": distroIcon = "ubuntu-symbolic"; break; + case "debian": + case "raspbian": + case "kali": distroIcon = "debian-symbolic"; break; + default: distroIcon = "linux-symbolic"; break; + } + } + } + + FileView { + id: fileOsRelease + path: "/etc/os-release" + } +} \ No newline at end of file diff --git a/.config/quickshell/modules/sidebarRight/SidebarRight.qml b/.config/quickshell/modules/sidebarRight/SidebarRight.qml index 8b6b6494..f6643c89 100644 --- a/.config/quickshell/modules/sidebarRight/SidebarRight.qml +++ b/.config/quickshell/modules/sidebarRight/SidebarRight.qml @@ -6,6 +6,8 @@ import QtQuick.Layouts import Quickshell.Io import Quickshell import Quickshell.Wayland +import Quickshell.Hyprland +import Qt5Compat.GraphicalEffects Scope { id: bar @@ -13,6 +15,7 @@ Scope { readonly property int sidebarWidth: Appearance.sizes.sidebarWidth Variants { + id: sidebarVariants model: Quickshell.screens PanelWindow { @@ -45,26 +48,31 @@ Scope { } // Shadow - // DropShadow { - // anchors.fill: sideRightBackground - // horizontalOffset: 0 - // verticalOffset: 2 - // radius: 3 - // samples: 17 - // color: Appearance.m3colors.m3shadow - // source: sideRightBackground - // } - - IpcHandler { - target: "sidebarRight" - - function toggle(): void { - sidebarRoot.visible = !sidebarRoot.visible - } + DropShadow { + anchors.fill: sidebarRightBackground + horizontalOffset: 0 + verticalOffset: 2 + radius: Appearance.sizes.elevationMargin + samples: Appearance.sizes.elevationMargin * 2 + 1 // Ideally should be 2 * radius + 1, see qt docs + color: Appearance.transparentize(Appearance.m3colors.m3shadow, 0.55) + source: sidebarRightBackground } } } + IpcHandler { + target: "sidebarRight" + + function toggle(): void { + for (let i = 0; i < sidebarVariants.instances.length; i++) { + let panelWindow = sidebarVariants.instances[i]; + if (panelWindow.modelData.name == Hyprland.focusedMonitor.name) { + panelWindow.visible = !panelWindow.visible; + } + } + } + } + }