powermenu wip

This commit is contained in:
quadbyte 2025-08-20 11:40:33 -04:00
parent 778f934010
commit fe3818d531
2 changed files with 90 additions and 79 deletions

View file

@ -70,7 +70,7 @@ NBox {
icon: "power_settings_new" icon: "power_settings_new"
tooltipText: "Power Menu" tooltipText: "Power Menu"
onClicked: { onClicked: {
powerMenu.show() powerMenu.open(screen)
} }
} }
} }
@ -78,9 +78,6 @@ NBox {
PowerMenu { PowerMenu {
id: powerMenu id: powerMenu
// TBC
// anchors.top: powerButton.bottom
// anchors.right: powerButton.right
} }
// ---------------------------------- // ----------------------------------

View file

@ -4,26 +4,94 @@ import QtQuick.Layouts
import Quickshell import Quickshell
import Quickshell.Io import Quickshell.Io
import Quickshell.Widgets import Quickshell.Widgets
import Quickshell.Wayland
import qs.Commons import qs.Commons
import qs.Services import qs.Services
import qs.Widgets import qs.Widgets
import qs.Modules.LockScreen import qs.Modules.LockScreen
NPanel { PanelWindow {
id: powerMenu id: root
anchors.top: true
anchors.left: true
anchors.right: true
anchors.bottom: true
visible: false visible: false
color: "#3300FF00"
screen: screen
onVisibleChanged: {
if (visible) {
console.log("Oh Yeah")
Qt.callLater(() => forceActiveFocus())
}
}
function open() {
visible = true
}
function close() {
visible = false
}
// Clicking outside of the rectangle to close
MouseArea {
anchors.fill: parent
onClicked: root.close()
}
// ----------------------------------
// System functions
function logout() {
CompositorService.logout()
}
function suspend() {
suspendProcess.running = true
}
function shutdown() {
shutdownProcess.running = true
}
function reboot() {
rebootProcess.running = true
}
Process {
id: shutdownProcess
command: ["shutdown", "-h", "now"]
running: false
}
Process {
id: rebootProcess
command: ["reboot"]
running: false
}
Process {
id: suspendProcess
command: ["systemctl", "suspend"]
running: false
}
Process {
id: logoutProcess
command: ["loginctl", "terminate-user", Quickshell.env("USER")]
running: false
}
property var entriesCount: 5 property var entriesCount: 5
property var entryHeight: Style.baseWidgetSize * scaling property var entryHeight: Style.baseWidgetSize * scaling
// Anchors will be set by the parent component
function show() {
visible = true
}
function hide() {
visible = false
}
Rectangle { Rectangle {
width: 160 * scaling width: 160 * scaling
@ -41,13 +109,10 @@ NPanel {
anchors.rightMargin: Style.marginL * scaling anchors.rightMargin: Style.marginL * scaling
anchors.topMargin: 86 * scaling anchors.topMargin: 86 * scaling
// Prevent closing when clicking in the panel bg Component.onCompleted: {
MouseArea { console.log("oncompleted")
anchors.fill: parent Qt.callLater(() => forceActiveFocus())
onClicked: { }
}
}
ColumnLayout { ColumnLayout {
anchors.fill: parent anchors.fill: parent
@ -102,9 +167,9 @@ NPanel {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
Logger.log("PowerMenu", "Lock screen requested") Logger.log("PowerMenu", "Lock screen requested")
// Lock the screen // // Lock the screen
lockScreen.isLoaded = true // lockScreen.isLoaded = true
powerMenu.visible = false // root.close()
} }
} }
} }
@ -157,7 +222,7 @@ NPanel {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
suspend() suspend()
powerMenu.visible = false root.close()
} }
} }
} }
@ -210,7 +275,7 @@ NPanel {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
reboot() reboot()
powerMenu.visible = false root.close()
} }
} }
} }
@ -263,7 +328,7 @@ NPanel {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
logout() logout()
powerMenu.visible = false root.close()
} }
} }
} }
@ -316,61 +381,10 @@ NPanel {
cursorShape: Qt.PointingHandCursor cursorShape: Qt.PointingHandCursor
onClicked: { onClicked: {
shutdown() shutdown()
powerMenu.visible = false root.close()
} }
} }
} }
} }
} }
// ----------------------------------
// System functions
function logout() {
CompositorService.logout()
}
function suspend() {
suspendProcess.running = true
}
function shutdown() {
shutdownProcess.running = true
}
function reboot() {
rebootProcess.running = true
}
Process {
id: shutdownProcess
command: ["shutdown", "-h", "now"]
running: false
}
Process {
id: rebootProcess
command: ["reboot"]
running: false
}
Process {
id: suspendProcess
command: ["systemctl", "suspend"]
running: false
}
Process {
id: logoutProcess
command: ["loginctl", "terminate-user", Quickshell.env("USER")]
running: false
}
// LockScreen instance
LockScreen {
id: lockScreen
}
} }