| 1 | import QtQuick |
| 2 | import QtQuick.Layouts |
| 3 | import Quickshell |
| 4 | import Quickshell.Io |
| 5 | import Quickshell.Wayland |
| 6 | import Quickshell.Hyprland |
| 7 | import Quickshell.Services.Pipewire |
| 8 | |
| 9 | ShellRoot { |
| 10 | id: root |
| 11 | property bool opened: false |
| 12 | property int tab: 0 |
| 13 | readonly property var tabNames: ["home", "audio", "net", "bt"] |
| 14 | |
| 15 | function openTab(name) { |
| 16 | var i = tabNames.indexOf(name) |
| 17 | if (i >= 0) tab = i |
| 18 | opened = true |
| 19 | } |
| 20 | |
| 21 | // keep every pipewire node bound so volume / mute / properties are readable |
| 22 | PwObjectTracker { objects: Pipewire.nodes.values } |
| 23 | |
| 24 | PanelWindow { |
| 25 | id: panel |
| 26 | visible: root.opened |
| 27 | anchors { top: true; right: true } |
| 28 | margins { top: 2 ; right: 2 } |
| 29 | implicitWidth: 430 |
| 30 | implicitHeight: 590 |
| 31 | exclusiveZone: 0 |
| 32 | color: "transparent" |
| 33 | WlrLayershell.layer: WlrLayer.Overlay |
| 34 | WlrLayershell.namespace: "wal-control" |
| 35 | WlrLayershell.keyboardFocus: WlrKeyboardFocus.OnDemand |
| 36 | |
| 37 | Rectangle { |
| 38 | anchors.fill: parent |
| 39 | color: Theme.bgA |
| 40 | border.width: 2 |
| 41 | border.color: Theme.accent |
| 42 | focus: true |
| 43 | Keys.onEscapePressed: root.opened = false |
| 44 | |
| 45 | ColumnLayout { |
| 46 | anchors.fill: parent |
| 47 | anchors.margins: 12 |
| 48 | spacing: 10 |
| 49 | |
| 50 | RowLayout { |
| 51 | Layout.fillWidth: true |
| 52 | spacing: 2 |
| 53 | Repeater { |
| 54 | model: [ |
| 55 | { icon: Theme.iHome, name: "home" }, |
| 56 | { icon: Theme.iVolHigh, name: "audio" }, |
| 57 | { icon: Theme.iWifi, name: "net" }, |
| 58 | { icon: Theme.iBt, name: "bt" } |
| 59 | ] |
| 60 | delegate: Rectangle { |
| 61 | id: tabBtn |
| 62 | required property var modelData |
| 63 | required property int index |
| 64 | implicitWidth: lbl.implicitWidth + 22 |
| 65 | implicitHeight: 28 |
| 66 | color: root.tab === index ? Theme.accent : (tm.containsMouse ? Theme.surfaceHi : "transparent") |
| 67 | Text { |
| 68 | id: lbl |
| 69 | anchors.centerIn: parent |
| 70 | text: tabBtn.modelData.icon + " " + tabBtn.modelData.name |
| 71 | color: root.tab === tabBtn.index ? Theme.bg : Theme.fg |
| 72 | font.family: Theme.font |
| 73 | font.pixelSize: Theme.fontSize |
| 74 | } |
| 75 | MouseArea { |
| 76 | id: tm |
| 77 | anchors.fill: parent |
| 78 | hoverEnabled: true |
| 79 | cursorShape: Qt.PointingHandCursor |
| 80 | onClicked: root.tab = tabBtn.index |
| 81 | } |
| 82 | } |
| 83 | } |
| 84 | Item { Layout.fillWidth: true } |
| 85 | IconBtn { icon: Theme.iClose; height: 28; onClicked: root.opened = false } |
| 86 | } |
| 87 | |
| 88 | Rectangle { Layout.fillWidth: true; Layout.preferredHeight: 1; color: Theme.line } |
| 89 | |
| 90 | StackLayout { |
| 91 | Layout.fillWidth: true |
| 92 | Layout.fillHeight: true |
| 93 | currentIndex: root.tab |
| 94 | |
| 95 | HomePage { onCloseRequested: root.opened = false } |
| 96 | AudioPage {} |
| 97 | NetPage { active: root.opened && root.tab === 2 } |
| 98 | BtPage { active: root.opened && root.tab === 3 } |
| 99 | } |
| 100 | } |
| 101 | } |
| 102 | } |
| 103 | |
| 104 | // clicking anywhere outside the panel closes it |
| 105 | HyprlandFocusGrab { |
| 106 | windows: [panel] |
| 107 | active: root.opened |
| 108 | onCleared: root.opened = false |
| 109 | } |
| 110 | |
| 111 | IpcHandler { |
| 112 | target: "control" |
| 113 | function toggle(): void { root.opened = !root.opened } |
| 114 | function open(): void { root.opened = true } |
| 115 | function close(): void { root.opened = false } |
| 116 | function show(name: string): void { root.openTab(name) } |
| 117 | } |
| 118 | } |