quickshell-toki-night/modules/session/Content.qml

131 lines
3.2 KiB
QML

pragma ComponentBehavior: Bound
import qs.config
import qs.custom
import qs.services
import qs.util
import Quickshell
import QtQuick
Row {
id: root
required property PersistentProperties uiState
padding: 12
spacing: 12
SessionButton {
id: sleep
icon: "bedtime"
iconColor: Config.colors.violet
command: Config.session.sleep
KeyNavigation.right: lock
Component.onCompleted: forceActiveFocus()
}
SessionButton {
id: lock
icon: "lock"
iconColor: Config.colors.brown
command: Config.session.lock
KeyNavigation.left: sleep
KeyNavigation.right: logout
}
SessionButton {
id: logout
icon: "logout"
iconColor: Config.colors.cyan
command: Config.session.logout
KeyNavigation.left: lock
KeyNavigation.right: reboot
}
SessionButton {
id: reboot
icon: "cached"
iconColor: Config.colors.yellow
command: Config.session.reboot
KeyNavigation.left: logout
KeyNavigation.right: shutdown
}
SessionButton {
id: shutdown
icon: "power_settings_new"
iconColor: Config.colors.red
command: Config.session.shutdown
KeyNavigation.left: reboot
}
component SessionButton: CustomRect {
id: button
required property string icon
required property color iconColor
required property list<string> command
implicitWidth: Config.session.buttonSize
implicitHeight: Config.session.buttonSize
radius: 22
color: button.activeFocus ? Config.colors.containerAlt : Config.colors.container
Behavior on color {
CAnim {}
}
Keys.onEnterPressed: layer.onClicked()
Keys.onReturnPressed: layer.onClicked()
Keys.onPressed: event => {
if (event.modifiers & Qt.ControlModifier) {
if (event.key === Qt.Key_L && KeyNavigation.right) {
KeyNavigation.right.focus = true;
event.accepted = true;
} else if (event.key === Qt.Key_H && KeyNavigation.left) {
KeyNavigation.left.focus = true;
event.accepted = true;
}
} else if (event.key === Qt.Key_Tab && KeyNavigation.right) {
KeyNavigation.right.focus = true;
event.accepted = true;
} else if (event.key === Qt.Key_Backtab || (event.key === Qt.Key_Tab && (event.modifiers & Qt.ShiftModifier))) {
if (KeyNavigation.left) {
KeyNavigation.left.focus = true;
event.accepted = true;
}
}
}
StateLayer {
id: layer
anchors.fill: parent
radius: parent.radius
function onClicked(): void {
root.uiState.session = false;
Quickshell.execDetached(button.command);
}
}
MaterialIcon {
anchors.centerIn: parent
text: button.icon
color: button.iconColor
font.pointSize: Config.font.size.largest
font.weight: 500
}
}
}