PowerPanel polishing

This commit is contained in:
quadbyte 2025-08-20 19:34:33 -04:00
parent 6538ef1459
commit 3de8c0af13
5 changed files with 112 additions and 109 deletions

View file

@ -5,7 +5,7 @@
"mSecondary": "#9ccfd8", "mSecondary": "#9ccfd8",
"mOnSecondary": "#191724", "mOnSecondary": "#191724",
"mTertiary": "#31748f", "mTertiary": "#31748f",
"mOnTertiary": "#e0def4", "mOnTertiary": "#191724",
"mError": "#eb6f92", "mError": "#eb6f92",
"mOnError": "#1f1d2e", "mOnError": "#1f1d2e",
"mSurface": "#191724", "mSurface": "#191724",

View file

@ -238,16 +238,11 @@ NPanel {
bottomPadding: 0 bottomPadding: 0
font.bold: true font.bold: true
Component.onCompleted: { Component.onCompleted: {
// contentItem.cursorColor = Color.mOnSurface
// contentItem.verticalAlignment = TextInput.AlignVCenter
// Focus the search bar by default // Focus the search bar by default
Qt.callLater(() => { Qt.callLater(() => {
searchInput.forceActiveFocus() searchInput.forceActiveFocus()
}) })
} }
//onActiveFocusChanged: contentItem.cursorColor = Color.mOnSurface
Keys.onDownPressed: selectNext() Keys.onDownPressed: selectNext()
Keys.onUpPressed: selectPrev() Keys.onUpPressed: selectPrev()
Keys.onEnterPressed: activateSelected() Keys.onEnterPressed: activateSelected()

View file

@ -12,12 +12,12 @@ import qs.Widgets
NPanel { NPanel {
id: root id: root
panelWidth: 420 * scaling panelWidth: 440 * scaling
panelHeight: 370 * scaling panelHeight: 380 * scaling
panelAnchorCentered: true panelAnchorCentered: true
// Timer properties // Timer properties
property int timerDuration: 5000 // 5 seconds property int timerDuration: 9000 // 9 seconds
property string pendingAction: "" property string pendingAction: ""
property bool timerActive: false property bool timerActive: false
property int timeRemaining: 0 property int timeRemaining: 0
@ -60,16 +60,16 @@ NPanel {
} }
break break
case "suspend": case "suspend":
suspendProcess.running = true CompositorService.suspend()
break break
case "reboot": case "reboot":
rebootProcess.running = true CompositorService.reboot()
break break
case "logout": case "logout":
CompositorService.logout() CompositorService.logout()
break break
case "shutdown": case "shutdown":
shutdownProcess.running = true CompositorService.shutdown()
break break
} }
@ -78,25 +78,6 @@ NPanel {
root.close() root.close()
} }
// System processes
Process {
id: shutdownProcess
command: ["shutdown", "-h", "now"]
running: false
}
Process {
id: rebootProcess
command: ["reboot"]
running: false
}
Process {
id: suspendProcess
command: ["systemctl", "suspend"]
running: false
}
// Countdown timer // Countdown timer
Timer { Timer {
id: countdownTimer id: countdownTimer
@ -127,18 +108,21 @@ NPanel {
Layout.preferredHeight: Style.baseWidgetSize * 0.8 * scaling Layout.preferredHeight: Style.baseWidgetSize * 0.8 * scaling
NText { NText {
text: timerActive ? `${pendingAction.charAt(0).toUpperCase() + pendingAction.slice(1)} in ${Math.ceil(timeRemaining / 1000)}s` : "Power Options" text: timerActive ? `${pendingAction.charAt(0).toUpperCase() + pendingAction.slice(1)} in ${Math.ceil(
timeRemaining / 1000)} seconds...` : "Power Options"
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
font.pointSize: Style.fontSizeM * scaling font.pointSize: Style.fontSizeL * scaling
color: timerActive ? Color.mPrimary : Color.mOnSurface color: timerActive ? Color.mPrimary : Color.mOnSurface
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
} }
Item { Layout.fillWidth: true } Item {
Layout.fillWidth: true
}
NIconButton { NIconButton {
icon: timerActive ? "block" : "close" icon: timerActive ? "back_hand" : "close"
tooltipText: timerActive ? "Cancel Timer" : "Close" tooltipText: timerActive ? "Cancel Timer" : "Close"
Layout.alignment: Qt.AlignVCenter Layout.alignment: Qt.AlignVCenter
colorBg: timerActive ? Color.applyOpacity(Color.mError, "20") : Color.transparent colorBg: timerActive ? Color.applyOpacity(Color.mError, "20") : Color.transparent
@ -154,8 +138,6 @@ NPanel {
} }
} }
// Power options // Power options
ColumnLayout { ColumnLayout {
Layout.fillWidth: true Layout.fillWidth: true
@ -165,7 +147,7 @@ NPanel {
PowerButton { PowerButton {
Layout.fillWidth: true Layout.fillWidth: true
icon: "lock_outline" icon: "lock_outline"
title: "Lock Screen" title: "Lock"
subtitle: "Lock your session" subtitle: "Lock your session"
onClicked: startTimer("lock") onClicked: startTimer("lock")
pending: timerActive && pendingAction === "lock" pending: timerActive && pendingAction === "lock"
@ -212,8 +194,6 @@ NPanel {
isShutdown: true isShutdown: true
} }
} }
} }
} }
@ -227,26 +207,30 @@ NPanel {
property bool pending: false property bool pending: false
property bool isShutdown: false property bool isShutdown: false
signal clicked() signal clicked
height: Style.baseWidgetSize * 1.5 * scaling height: Style.baseWidgetSize * 1.6 * scaling
radius: Style.radiusS * scaling radius: Style.radiusS * scaling
color: { color: {
if (pending) return Color.applyOpacity(Color.mPrimary, "20") if (pending)
if (mouseArea.containsMouse) return Color.mSurfaceVariant return Color.applyOpacity(Color.mPrimary, "20")
if (mouseArea.containsMouse)
return Color.mTertiary
return Color.transparent return Color.transparent
} }
border.width: pending ? 2 * scaling : (mouseArea.containsMouse ? 1 * scaling : 0) border.width: pending ? Math.max(Style.borderM * scaling) : 0
border.color: pending ? Color.mPrimary : Color.mOutline border.color: pending ? Color.mPrimary : Color.mOutline
Behavior on color { Behavior on color {
ColorAnimation { duration: 150 } ColorAnimation {
duration: Style.animationFast
}
} }
Item { Item {
anchors.fill: parent anchors.fill: parent
anchors.margins: Style.marginM * scaling anchors.margins: Style.marginL * scaling
// Icon on the left // Icon on the left
NIcon { NIcon {
@ -255,18 +239,24 @@ NPanel {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
text: buttonRoot.icon text: buttonRoot.icon
color: { color: {
if (buttonRoot.pending) return Color.mPrimary
if (buttonRoot.isShutdown && mouseArea.containsMouse) return Color.mError if (buttonRoot.pending)
if (mouseArea.containsMouse) return Color.mPrimary return Color.mPrimary
if (buttonRoot.isShutdown && !mouseArea.containsMouse)
return Color.mError
if (mouseArea.containsMouse)
return Color.mOnTertiary
return Color.mOnSurface return Color.mOnSurface
} }
font.pointSize: Style.fontSizeL * scaling font.pointSize: Style.fontSizeXXXL * scaling
width: Style.baseWidgetSize * 0.6 * scaling width: Style.baseWidgetSize * 0.6 * scaling
horizontalAlignment: Text.AlignHCenter horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter verticalAlignment: Text.AlignVCenter
Behavior on color { Behavior on color {
ColorAnimation { duration: 150 } ColorAnimation {
duration: Style.animationFast
}
} }
} }
@ -275,23 +265,28 @@ NPanel {
anchors.left: iconElement.right anchors.left: iconElement.right
anchors.right: pendingIndicator.visible ? pendingIndicator.left : parent.right anchors.right: pendingIndicator.visible ? pendingIndicator.left : parent.right
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
anchors.leftMargin: Style.marginM * scaling anchors.leftMargin: Style.marginXL * scaling
anchors.rightMargin: pendingIndicator.visible ? Style.marginM * scaling : 0 anchors.rightMargin: pendingIndicator.visible ? Style.marginM * scaling : 0
spacing: 2 * scaling spacing: 0
NText { NText {
text: buttonRoot.title text: buttonRoot.title
font.weight: Style.fontWeightMedium font.weight: Style.fontWeightMedium
font.pointSize: Style.fontSizeS * scaling font.pointSize: Style.fontSizeM * scaling
color: { color: {
if (buttonRoot.pending) return Color.mPrimary if (buttonRoot.pending)
if (buttonRoot.isShutdown && mouseArea.containsMouse) return Color.mError return Color.mPrimary
if (mouseArea.containsMouse) return Color.mPrimary if (buttonRoot.isShutdown && !mouseArea.containsMouse)
return Color.mError
if (mouseArea.containsMouse)
return Color.mOnTertiary
return Color.mOnSurface return Color.mOnSurface
} }
Behavior on color { Behavior on color {
ColorAnimation { duration: 150 } ColorAnimation {
duration: Style.animationFast
}
} }
} }
@ -304,10 +299,15 @@ NPanel {
} }
font.pointSize: Style.fontSizeXS * scaling font.pointSize: Style.fontSizeXS * scaling
color: { color: {
if (buttonRoot.pending) return Color.mPrimary if (buttonRoot.pending)
return Color.mPrimary
if (buttonRoot.isShutdown && !mouseArea.containsMouse)
return Color.mError
if (mouseArea.containsMouse)
return Color.mOnTertiary
return Color.mOnSurfaceVariant return Color.mOnSurfaceVariant
} }
opacity: 0.8 opacity: Style.opacityHeavy
wrapMode: Text.WordWrap wrapMode: Text.WordWrap
} }
} }
@ -319,22 +319,20 @@ NPanel {
anchors.verticalCenter: parent.verticalCenter anchors.verticalCenter: parent.verticalCenter
width: 24 * scaling width: 24 * scaling
height: 24 * scaling height: 24 * scaling
radius: 12 * scaling radius: width * 0.5
color: Color.mPrimary color: Color.mPrimary
visible: buttonRoot.pending visible: buttonRoot.pending
NText { NText {
anchors.centerIn: parent anchors.centerIn: parent
text: Math.ceil(timeRemaining / 1000) text: Math.ceil(timeRemaining / 1000)
font.pointSize: Style.fontSizeXS * scaling font.pointSize: Style.fontSizeS * scaling
font.weight: Style.fontWeightBold font.weight: Style.fontWeightBold
color: Color.mOnPrimary color: Color.mOnPrimary
} }
} }
} }
MouseArea { MouseArea {
id: mouseArea id: mouseArea
anchors.fill: parent anchors.fill: parent

View file

@ -86,8 +86,6 @@ NBox {
} }
} }
// ---------------------------------- // ----------------------------------
// Uptime // Uptime
Timer { Timer {

View file

@ -396,6 +396,25 @@ Singleton {
} }
} }
// Get current workspace
function getCurrentWorkspace() {
for (var i = 0; i < workspaces.count; i++) {
const ws = workspaces.get(i)
if (ws.isFocused) {
return ws
}
}
return null
}
// Get focused window
function getFocusedWindow() {
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length) {
return windows[focusedWindowIndex]
}
return null
}
// Generic logout/shutdown commands // Generic logout/shutdown commands
function logout() { function logout() {
if (isHyprland) { if (isHyprland) {
@ -415,22 +434,15 @@ Singleton {
} }
} }
// Get current workspace function shutdown() {
function getCurrentWorkspace() { Quickshell.execDetached(["shutdown", "-h", "now"])
for (var i = 0; i < workspaces.count; i++) {
const ws = workspaces.get(i)
if (ws.isFocused) {
return ws
}
}
return null
} }
// Get focused window function reboot() {
function getFocusedWindow() { Quickshell.execDetached(["reboot"])
if (focusedWindowIndex >= 0 && focusedWindowIndex < windows.length) {
return windows[focusedWindowIndex]
} }
return null
function suspend() {
Quickshell.execDetached(["systemctl", "suspend"])
} }
} }