Build the Panama Hyprland desktop
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
// One tile in the power menu: big glyph, label underneath.
|
||||
//
|
||||
// Anything that ends the session arms on the first press and only fires on the
|
||||
// second, with the label swapping to "Confirm" — an accidental Ctrl+Alt+Delete
|
||||
// should never be one click away from losing everything that is open.
|
||||
|
||||
import QtQuick
|
||||
import qs.config
|
||||
|
||||
Rectangle {
|
||||
id: root
|
||||
|
||||
property string glyph: ""
|
||||
property string label: ""
|
||||
// Tint red on hover and require the two-step confirm.
|
||||
property bool destructive: false
|
||||
// Highlighted by keyboard navigation.
|
||||
property bool selected: false
|
||||
|
||||
signal activated
|
||||
|
||||
readonly property bool armed: confirmTimer.running
|
||||
|
||||
implicitWidth: 136
|
||||
implicitHeight: 136
|
||||
radius: Theme.cardRadius + 6
|
||||
border.width: 0
|
||||
|
||||
readonly property color accentFor: root.destructive ? Theme.danger : Theme.accent
|
||||
|
||||
color: {
|
||||
if (root.armed)
|
||||
return Theme.alpha(Theme.danger, 0.32);
|
||||
if (mouse.pressed)
|
||||
return Theme.alpha(root.accentFor, 0.3);
|
||||
if (mouse.containsMouse || root.selected)
|
||||
return Theme.alpha(root.accentFor, 0.18);
|
||||
return Theme.alpha(Theme.fg, 0.07);
|
||||
}
|
||||
|
||||
Behavior on color {
|
||||
ColorAnimation {
|
||||
duration: Theme.durFast
|
||||
}
|
||||
}
|
||||
|
||||
// Keyboard focus ring.
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
radius: parent.radius
|
||||
color: "transparent"
|
||||
border.width: root.selected ? 2 : 0
|
||||
border.color: root.accentFor
|
||||
visible: root.selected
|
||||
}
|
||||
|
||||
Column {
|
||||
anchors.centerIn: parent
|
||||
spacing: 10
|
||||
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: root.glyph
|
||||
color: root.armed ? Theme.danger : Theme.fg
|
||||
font.family: Theme.fontMono
|
||||
font.pixelSize: 40
|
||||
}
|
||||
|
||||
Text {
|
||||
anchors.horizontalCenter: parent.horizontalCenter
|
||||
text: root.armed ? "Confirm" : root.label
|
||||
color: root.armed ? Theme.danger : Theme.fg
|
||||
font.family: Theme.fontFamily
|
||||
font.pixelSize: Theme.fontSize
|
||||
font.weight: Font.Medium
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger from a click or from Enter while keyboard-selected.
|
||||
function trigger(): void {
|
||||
if (root.destructive && !root.armed) {
|
||||
confirmTimer.restart();
|
||||
return;
|
||||
}
|
||||
confirmTimer.stop();
|
||||
root.activated();
|
||||
}
|
||||
|
||||
function disarm(): void {
|
||||
confirmTimer.stop();
|
||||
}
|
||||
|
||||
// Arming is not sticky: walk away and the button forgets.
|
||||
Timer {
|
||||
id: confirmTimer
|
||||
interval: 4000
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
id: mouse
|
||||
anchors.fill: parent
|
||||
hoverEnabled: true
|
||||
cursorShape: Qt.PointingHandCursor
|
||||
onClicked: root.trigger()
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,169 @@
|
||||
// Replaces GNOME's power-off dialog. Opened by Ctrl+Alt+Delete and from the
|
||||
// quick-settings footer.
|
||||
//
|
||||
// Log Out, Restart and Power Off arm on the first press and fire on the second
|
||||
// (see PowerButton); Lock and Suspend are one press because neither loses work.
|
||||
|
||||
import Quickshell
|
||||
import Quickshell.Wayland
|
||||
import QtQuick
|
||||
import qs.config
|
||||
import qs.services
|
||||
|
||||
PanelWindow {
|
||||
id: win
|
||||
|
||||
visible: ShellState.powerMenuOpen
|
||||
color: "transparent"
|
||||
|
||||
anchors {
|
||||
top: true
|
||||
bottom: true
|
||||
left: true
|
||||
right: true
|
||||
}
|
||||
|
||||
exclusiveZone: 0
|
||||
|
||||
WlrLayershell.namespace: "qs-popover-power"
|
||||
WlrLayershell.layer: WlrLayer.Overlay
|
||||
WlrLayershell.keyboardFocus: WlrKeyboardFocus.Exclusive
|
||||
|
||||
property int currentIndex: 0
|
||||
|
||||
// The session is uwsm-managed, so logging out means stopping the uwsm unit
|
||||
// rather than killing the compositor; the hyprctl branch is only there for
|
||||
// a session started without it.
|
||||
readonly property string logoutScript: 'if command -v uwsm >/dev/null 2>&1; then exec uwsm stop; else exec hyprctl dispatch "hl.dsp.exit()"; fi'
|
||||
|
||||
readonly property var entries: [
|
||||
{
|
||||
glyph: "",
|
||||
label: "Lock",
|
||||
destructive: false,
|
||||
cmd: ["loginctl", "lock-session"]
|
||||
},
|
||||
{
|
||||
glyph: "",
|
||||
label: "Log Out",
|
||||
destructive: true,
|
||||
cmd: ["sh", "-c", win.logoutScript]
|
||||
},
|
||||
{
|
||||
glyph: "",
|
||||
label: "Suspend",
|
||||
destructive: false,
|
||||
cmd: ["systemctl", "suspend"]
|
||||
},
|
||||
{
|
||||
glyph: "",
|
||||
label: "Restart",
|
||||
destructive: true,
|
||||
cmd: ["systemctl", "reboot"]
|
||||
},
|
||||
{
|
||||
glyph: "",
|
||||
label: "Power Off",
|
||||
destructive: true,
|
||||
cmd: ["systemctl", "poweroff"]
|
||||
}
|
||||
]
|
||||
|
||||
onVisibleChanged: {
|
||||
if (!win.visible)
|
||||
return;
|
||||
// Never reopen with a destructive button still armed from last time.
|
||||
win.currentIndex = 0;
|
||||
for (let i = 0; i < rep.count; i++)
|
||||
rep.itemAt(i).disarm();
|
||||
keys.forceActiveFocus();
|
||||
}
|
||||
|
||||
function run(index: int): void {
|
||||
ShellState.close();
|
||||
Quickshell.execDetached(win.entries[index].cmd);
|
||||
}
|
||||
|
||||
function move(step: int): void {
|
||||
// Moving away disarms, so Enter can never fire a button the user only
|
||||
// meant to walk past.
|
||||
rep.itemAt(win.currentIndex).disarm();
|
||||
win.currentIndex = (win.currentIndex + step + win.entries.length) % win.entries.length;
|
||||
}
|
||||
|
||||
FocusScope {
|
||||
id: keys
|
||||
anchors.fill: parent
|
||||
focus: true
|
||||
|
||||
Keys.onPressed: event => {
|
||||
switch (event.key) {
|
||||
case Qt.Key_Escape:
|
||||
ShellState.close();
|
||||
break;
|
||||
case Qt.Key_Left:
|
||||
win.move(-1);
|
||||
break;
|
||||
case Qt.Key_Right:
|
||||
win.move(1);
|
||||
break;
|
||||
case Qt.Key_Return:
|
||||
case Qt.Key_Enter:
|
||||
case Qt.Key_Space:
|
||||
rep.itemAt(win.currentIndex).trigger();
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
event.accepted = true;
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.fill: parent
|
||||
color: Theme.alpha(Theme.bgDark, Theme.overlayAlpha)
|
||||
border.width: 0
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
onClicked: ShellState.close()
|
||||
}
|
||||
}
|
||||
|
||||
Rectangle {
|
||||
anchors.centerIn: parent
|
||||
implicitWidth: row.implicitWidth + 2 * 24
|
||||
implicitHeight: row.implicitHeight + 2 * 24
|
||||
radius: Theme.popoverRadius + 8
|
||||
border.width: 0
|
||||
color: Theme.alpha(Theme.bgPopover, Theme.popoverAlpha)
|
||||
|
||||
// Swallow clicks that land on the panel but miss a tile, so the
|
||||
// outside-click handler underneath doesn't close the menu.
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
}
|
||||
|
||||
Row {
|
||||
id: row
|
||||
anchors.centerIn: parent
|
||||
spacing: 14
|
||||
|
||||
Repeater {
|
||||
id: rep
|
||||
model: win.entries
|
||||
|
||||
PowerButton {
|
||||
required property var modelData
|
||||
required property int index
|
||||
|
||||
glyph: modelData.glyph
|
||||
label: modelData.label
|
||||
destructive: modelData.destructive
|
||||
selected: index === win.currentIndex
|
||||
onActivated: win.run(index)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user