extract shared PopupPanel for animated tray/power menus
This commit is contained in:
parent
77ce83462d
commit
b8ec39f2c9
6 changed files with 249 additions and 302 deletions
|
|
@ -1,152 +1,73 @@
|
|||
import QtQuick
|
||||
import Quickshell
|
||||
import Quickshell.Io
|
||||
import Quickshell.Wayland
|
||||
import "." as M
|
||||
|
||||
PanelWindow {
|
||||
M.PopupPanel {
|
||||
id: menuWindow
|
||||
|
||||
required property var screen
|
||||
required property real anchorX
|
||||
panelWidth: 180
|
||||
|
||||
signal menuClosed
|
||||
signal runCommand(var cmd)
|
||||
|
||||
readonly property bool _isNiri: Quickshell.env("NIRI_SOCKET") !== ""
|
||||
|
||||
function _run(cmd) {
|
||||
runCommand(cmd);
|
||||
menuClosed();
|
||||
dismiss();
|
||||
}
|
||||
|
||||
visible: true
|
||||
color: "transparent"
|
||||
Repeater {
|
||||
model: [
|
||||
{ label: "Lock", icon: "\uF023", cmd: ["loginctl", "lock-session"], color: M.Theme.base0D },
|
||||
{ label: "Suspend", icon: "\uF186", cmd: ["systemctl", "suspend"], color: M.Theme.base0E },
|
||||
{ label: "Logout", icon: "\uF2F5", cmd: menuWindow._isNiri ? ["niri", "msg", "action", "quit"] : ["loginctl", "terminate-user", ""], color: M.Theme.base0A },
|
||||
{ label: "Reboot", icon: "\uF021", cmd: ["systemctl", "reboot"], color: M.Theme.base09 },
|
||||
{ label: "Shutdown", icon: "\uF011", cmd: ["systemctl", "poweroff"], color: M.Theme.base08 }
|
||||
]
|
||||
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.exclusiveZone: 0
|
||||
WlrLayershell.namespace: "nova-powermenu"
|
||||
delegate: Item {
|
||||
id: entry
|
||||
|
||||
anchors.top: true
|
||||
anchors.left: true
|
||||
anchors.right: true
|
||||
anchors.bottom: true
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: menuWindow.menuClosed()
|
||||
}
|
||||
width: menuWindow.panelWidth
|
||||
height: 32
|
||||
|
||||
Item {
|
||||
id: panel
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 4
|
||||
anchors.rightMargin: 4
|
||||
color: entryArea.containsMouse ? M.Theme.base02 : "transparent"
|
||||
radius: M.Theme.radius
|
||||
}
|
||||
|
||||
x: Math.max(0, Math.min(Math.round(menuWindow.anchorX - menuCol.width / 2), menuWindow.width - menuCol.width))
|
||||
y: 0
|
||||
Text {
|
||||
id: entryIcon
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
text: entry.modelData.icon
|
||||
color: entry.modelData.color
|
||||
font.pixelSize: M.Theme.fontSize + 1
|
||||
font.family: M.Theme.iconFontFamily
|
||||
}
|
||||
|
||||
width: menuCol.width
|
||||
height: menuCol.height
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: entryIcon.right
|
||||
anchors.leftMargin: 10
|
||||
text: entry.modelData.label
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: M.Theme.base01
|
||||
opacity: Math.max(M.Theme.barOpacity, 0.85)
|
||||
topLeftRadius: 0
|
||||
topRightRadius: 0
|
||||
bottomLeftRadius: M.Theme.radius
|
||||
bottomRightRadius: M.Theme.radius
|
||||
}
|
||||
|
||||
Column {
|
||||
id: menuCol
|
||||
|
||||
width: 180
|
||||
topPadding: 4
|
||||
bottomPadding: 4
|
||||
spacing: 2
|
||||
|
||||
Repeater {
|
||||
model: [
|
||||
{
|
||||
label: "Lock",
|
||||
icon: "\uF023",
|
||||
cmd: ["loginctl", "lock-session"],
|
||||
color: M.Theme.base0D
|
||||
},
|
||||
{
|
||||
label: "Suspend",
|
||||
icon: "\uF186",
|
||||
cmd: ["systemctl", "suspend"],
|
||||
color: M.Theme.base0E
|
||||
},
|
||||
{
|
||||
label: "Logout",
|
||||
icon: "\uF2F5",
|
||||
cmd: menuWindow._isNiri ? ["niri", "msg", "action", "quit"] : ["loginctl", "terminate-user", ""],
|
||||
color: M.Theme.base0A
|
||||
},
|
||||
{
|
||||
label: "Reboot",
|
||||
icon: "\uF021",
|
||||
cmd: ["systemctl", "reboot"],
|
||||
color: M.Theme.base09
|
||||
},
|
||||
{
|
||||
label: "Shutdown",
|
||||
icon: "\uF011",
|
||||
cmd: ["systemctl", "poweroff"],
|
||||
color: M.Theme.base08
|
||||
}
|
||||
]
|
||||
|
||||
delegate: Item {
|
||||
id: entry
|
||||
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
width: menuCol.width
|
||||
height: 32
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
anchors.leftMargin: 4
|
||||
anchors.rightMargin: 4
|
||||
color: entryArea.containsMouse ? M.Theme.base02 : "transparent"
|
||||
radius: M.Theme.radius
|
||||
}
|
||||
|
||||
Text {
|
||||
id: entryIcon
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: parent.left
|
||||
anchors.leftMargin: 12
|
||||
text: entry.modelData.icon
|
||||
color: entry.modelData.color
|
||||
font.pixelSize: M.Theme.fontSize + 1
|
||||
font.family: M.Theme.iconFontFamily
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.verticalCenter: parent.verticalCenter
|
||||
anchors.left: entryIcon.right
|
||||
anchors.leftMargin: 10
|
||||
text: entry.modelData.label
|
||||
color: M.Theme.base05
|
||||
font.pixelSize: M.Theme.fontSize
|
||||
font.family: M.Theme.fontFamily
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: entryArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onClicked: menuWindow._run(entry.modelData.cmd)
|
||||
}
|
||||
}
|
||||
MouseArea {
|
||||
id: entryArea
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
onClicked: menuWindow._run(entry.modelData.cmd)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue