Files
quickshell/modules/bar/widgets/IdleButton.qml
T

70 lines
2.2 KiB
QML

import QtQuick
import Quickshell
import Quickshell.Hyprland
import Quickshell.Io
import "../../../colors"
import "../states" 1.0 as Global
MouseArea {
id: idleButton
width: Math.max(idleText.width + parent.spacing*2, bar.height)
height: bar.height
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
Component.onCompleted: {
idleStatusScript.running = true
}
Rectangle {
anchors.fill: parent
color: idleButton.containsMouse ? Colors.tertiary : Qt.alpha(Colors.tertiaryContainer, 0.25)
radius: 6
border.width: 2
border.color: idleButton.containsMouse ? Colors.tertiaryContainer_fg
: Colors.secondaryContainer_fg
Item {
anchors.fill: parent
Process {
id: idleScript
command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Idle.sh"]
stdout: StdioCollector {
onStreamFinished: Global.IdleState.idle ? console.log(`Disabling Idle`) : console.log(`Enabling Idle`)
}
}
MouseArea {
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
anchors.fill: parent
onClicked: {
console.log("Running Idle Script")
idleScript.startDetached()
Global.IdleState.idle = !Global.IdleState.idle
console.log("Current Idle State: " + Global.IdleState.idle)
}
}
}
Text {
id: idleText
anchors.centerIn: parent
text: Global.IdleState.idle ? "" : ""
font.pixelSize: 26
font.family: "Nerd Font"
color: idleButton.containsMouse ? Colors.tertiary_fg : idleText.text == "" ? Colors.primary : Colors.tertiary
}
}
Process {
id: idleStatusScript
command: ["sh", "-c", Quickshell.env("HOME") + "/.config/quickshell/modules/bar/scripts/Idle.sh" + " --status"]
stdout: StdioCollector {
onStreamFinished: {
Global.IdleState.idle = this.text.trim() === "0" ? 1 : 0
}
}
}
}