From 9f8d774efdfe3f0ffb758a6ce06744d352c1c5dc Mon Sep 17 00:00:00 2001 From: Hannes Date: Sat, 22 Aug 2026 21:35:43 +0200 Subject: [PATCH] rework of IdleButton --- config/Config.qml | 2 +- modules/bar/Bar.qml | 2 +- modules/bar/scripts/Idle.sh | 14 ------------- modules/bar/states/Idle/IdleState.qml | 22 ++------------------ modules/bar/widgets/IdleButton.qml | 30 +++++++++++++++++---------- modules/bar/widgets/Workspaces.qml | 1 + 6 files changed, 24 insertions(+), 47 deletions(-) delete mode 100755 modules/bar/scripts/Idle.sh diff --git a/config/Config.qml b/config/Config.qml index fa23597..eca7844 100644 --- a/config/Config.qml +++ b/config/Config.qml @@ -24,7 +24,7 @@ QtObject { readonly property int border_width: 2 readonly property string font: "CodeNewRoman Nerd Font" - readonly property string jfont: "CodeNewRoman Nerd Font" + readonly property string jfont: "Noto Sans JP" function big_font_size(value) { return value * 0.6 diff --git a/modules/bar/Bar.qml b/modules/bar/Bar.qml index 0fd8b7d..686659a 100644 --- a/modules/bar/Bar.qml +++ b/modules/bar/Bar.qml @@ -70,7 +70,7 @@ PanelWindow { Tray{} Battery{} Network {} - IdleButton {} + IdleButton { panelWindow: panel } PowerButton {} } diff --git a/modules/bar/scripts/Idle.sh b/modules/bar/scripts/Idle.sh deleted file mode 100755 index 06ecf05..0000000 --- a/modules/bar/scripts/Idle.sh +++ /dev/null @@ -1,14 +0,0 @@ -if [ "$1" = "--status" ]; then - if pgrep -x "hypridle" >/dev/null; then - echo 1 - else - echo 0 - fi - exit 0 -fi - -if pgrep -x "hypridle" >/dev/null; then - killall hypridle -else - hypridle & -fi \ No newline at end of file diff --git a/modules/bar/states/Idle/IdleState.qml b/modules/bar/states/Idle/IdleState.qml index 980b28f..8717311 100644 --- a/modules/bar/states/Idle/IdleState.qml +++ b/modules/bar/states/Idle/IdleState.qml @@ -5,24 +5,6 @@ import Quickshell.Io import "../../../../config" Item { - property int idle: 0 - - Process { - id: statusScript - command: ["sh", "-c", Config.configDir + "/modules/bar/scripts/Idle.sh --status"] - running: true - stdout: StdioCollector { - onStreamFinished: { - idle = this.text.trim() === "0" ? 1 : 0 - } - } - } - - Timer { - interval: 5000 - running: true - repeat: true - triggeredOnStart: true - onTriggered: statusScript.running = true - } + // true = inhibit idle (prevent hypridle/lock/dpms), false = allow idle + property bool idle: false } \ No newline at end of file diff --git a/modules/bar/widgets/IdleButton.qml b/modules/bar/widgets/IdleButton.qml index 30d801d..44f93de 100644 --- a/modules/bar/widgets/IdleButton.qml +++ b/modules/bar/widgets/IdleButton.qml @@ -1,6 +1,7 @@ import QtQuick import Quickshell import Quickshell.Hyprland +import Quickshell.Wayland import Quickshell.Io import "../../../config" import "../states/Idle" @@ -12,16 +13,29 @@ MouseArea { hoverEnabled: true cursorShape: Qt.PointingHandCursor + required property PanelWindow panelWindow + + IdleInhibitor { + id: idleInhibitor + window: panelWindow + enabled: IdleState.idle + } + + IdleMonitor { + id: idleMonitor + enabled: true + timeout: 30 + respectInhibitors: true + } + onClicked: { - var newState = IdleState.idle ? 0 : 1 - console.log("[IdleButton] Toggling idle: " + (newState ? "enabled" : "disabled")) - idleToggleProc.startDetached() - IdleState.idle = newState + IdleState.idle = !IdleState.idle + console.log("[IdleButton] Toggling idle: " + (IdleState.idle ? "enabled" : "disabled")) } Rectangle { anchors.fill: parent - color: idleButton.containsMouse ? Colors.tertiary : Qt.alpha(Colors.tertiaryContainer, 0.25) + color: idleButton.containsMouse ? Colors.tertiary : idleMonitor.isIdle ? Qt.alpha(Colors.secondary, 0.25) : Qt.alpha(Colors.tertiaryContainer, 0.25) radius: Config.radius_fun(idleButton.height) border.width: Config.border_width border.color: ( @@ -42,10 +56,4 @@ MouseArea { ) } } - - Process { - id: idleToggleProc - command: ["sh", "-c", Config.configDir + "/modules/bar/scripts/Idle.sh"] - running: false - } } \ No newline at end of file diff --git a/modules/bar/widgets/Workspaces.qml b/modules/bar/widgets/Workspaces.qml index 601d528..80625fc 100644 --- a/modules/bar/widgets/Workspaces.qml +++ b/modules/bar/widgets/Workspaces.qml @@ -74,6 +74,7 @@ Rectangle { } else { Hyprland.dispatch("workspace " + workspaceData.id) } + Hyprland.refreshWorkspaces() } Row {