mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-27 23:12:49 -05:00
Add systemd-inhibit widget
This commit is contained in:
73
Modules/TopBar/IdleInhibitor.qml
Normal file
73
Modules/TopBar/IdleInhibitor.qml
Normal file
@@ -0,0 +1,73 @@
|
||||
import QtQuick
|
||||
import QtQuick.Controls
|
||||
import Quickshell
|
||||
import qs.Common
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property string section: "right"
|
||||
property var popupTarget: null
|
||||
property var parentScreen: null
|
||||
|
||||
width: 40
|
||||
height: 30
|
||||
radius: Theme.cornerRadius
|
||||
color: {
|
||||
const baseColor = mouseArea.containsMouse
|
||||
? Theme.primaryPressed
|
||||
: (IdleInhibitorService.idleInhibited ? Theme.primaryHover : Theme.secondaryHover)
|
||||
return Qt.rgba(baseColor.r, baseColor.g, baseColor.b,
|
||||
baseColor.a * Theme.widgetTransparency)
|
||||
}
|
||||
|
||||
DankIcon {
|
||||
anchors.centerIn: parent
|
||||
name: IdleInhibitorService.idleInhibited ? "motion_sensor_active" : "motion_sensor_idle"
|
||||
size: Theme.iconSize - 6
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouseArea
|
||||
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
|
||||
onClicked: {
|
||||
IdleInhibitorService.toggleIdleInhibit()
|
||||
}
|
||||
}
|
||||
|
||||
ToolTip {
|
||||
visible: mouseArea.containsMouse
|
||||
delay: 1000
|
||||
text: IdleInhibitorService.idleInhibited
|
||||
? "Screen timeout disabled\nClick to enable"
|
||||
: "Screen timeout enabled\nClick to disable"
|
||||
|
||||
contentItem: Text {
|
||||
text: parent.text || ""
|
||||
font.family: Theme.fontFamily || "Sans"
|
||||
font.pixelSize: Theme.fontSize - 2
|
||||
color: Theme.surfaceText
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
color: Theme.surfaceContainer
|
||||
radius: Theme.cornerRadius
|
||||
border.color: Theme.outline
|
||||
border.width: 1
|
||||
}
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.shortDuration
|
||||
easing.type: Theme.standardEasing
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -312,6 +312,8 @@ PanelWindow {
|
||||
return true
|
||||
case "controlCenterButton":
|
||||
return true
|
||||
case "idleInhibitor":
|
||||
return true
|
||||
case "spacer":
|
||||
return true
|
||||
case "separator":
|
||||
@@ -355,6 +357,8 @@ PanelWindow {
|
||||
return batteryComponent
|
||||
case "controlCenterButton":
|
||||
return controlCenterButtonComponent
|
||||
case "idleInhibitor":
|
||||
return idleInhibitorComponent
|
||||
case "spacer":
|
||||
return spacerComponent
|
||||
case "separator":
|
||||
@@ -953,6 +957,23 @@ PanelWindow {
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: idleInhibitorComponent
|
||||
|
||||
IdleInhibitor {
|
||||
section: {
|
||||
if (parent && parent.parent === leftSection)
|
||||
return "left"
|
||||
if (parent && parent.parent === rightSection)
|
||||
return "right"
|
||||
if (parent && parent.parent === centerSection)
|
||||
return "center"
|
||||
return "right"
|
||||
}
|
||||
parentScreen: root.screen
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: spacerComponent
|
||||
|
||||
|
||||
Reference in New Issue
Block a user