Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013ZYoSQwwYWhJHLX6VBCGnF
291 lines
9.6 KiB
QML
291 lines
9.6 KiB
QML
import QtQuick
|
|
import Quickshell
|
|
import Quickshell.Wayland
|
|
import Quickshell.Hyprland
|
|
import Quickshell.Io
|
|
import Quickshell.Services.UPower
|
|
import "../Shared"
|
|
|
|
PanelWindow {
|
|
id: barWindow
|
|
|
|
// Reference to global state
|
|
property QtObject rootState
|
|
// Shared overlay window that renders tray icon hover tooltips (see
|
|
// TrayTooltip.qml) so this bar's own surface can stay exactly as tall
|
|
// as the pill itself.
|
|
property QtObject trayTooltip
|
|
|
|
anchors {
|
|
top: true
|
|
left: true
|
|
right: true
|
|
}
|
|
|
|
// Matches hyprland.lua's general.gaps_out (20) so the gap above the bar
|
|
// (this margin) and the gap below it (added by Hyprland once the
|
|
// exclusiveZone ends) read as the same size.
|
|
readonly property int hyprGapsOut: 20
|
|
|
|
margins {
|
|
top: hyprGapsOut
|
|
left: hyprGapsOut
|
|
right: hyprGapsOut
|
|
}
|
|
|
|
// No separate bottom buffer here — Hyprland's gaps_out already adds its
|
|
// own gap between the reserved zone and the tiled window below.
|
|
exclusiveZone: implicitHeight + margins.top
|
|
|
|
implicitHeight: 40
|
|
color: "transparent"
|
|
|
|
WlrLayershell.layer: WlrLayer.Top
|
|
WlrLayershell.namespace: "quickshell-bar"
|
|
|
|
// Left Pill (Workspaces + Battery)
|
|
Rectangle {
|
|
id: leftPill
|
|
anchors.left: parent.left
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
height: parent.height
|
|
width: leftPillRow.width + Theme.geometry.padding * 2
|
|
radius: Theme.geometry.pillRadius
|
|
color: Theme.colors.surface
|
|
border.color: Theme.colors.border
|
|
border.width: 1
|
|
|
|
Row {
|
|
id: leftPillRow
|
|
anchors.centerIn: parent
|
|
spacing: Theme.geometry.spacing
|
|
|
|
// Workspaces
|
|
Row {
|
|
spacing: Theme.geometry.spacing
|
|
Repeater {
|
|
model: Hyprland.workspaces.values
|
|
|
|
delegate: Rectangle {
|
|
width: 24
|
|
height: 24
|
|
radius: Theme.geometry.radiusTiny
|
|
color: modelData.active ? Theme.colors.primary : Theme.colors.surfaceHover
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: modelData.id
|
|
color: modelData.active ? Theme.colors.background : Theme.colors.text
|
|
font.family: Theme.font.family
|
|
font.pixelSize: 12
|
|
font.bold: modelData.active
|
|
}
|
|
|
|
MouseArea {
|
|
anchors.fill: parent
|
|
cursorShape: Qt.PointingHandCursor
|
|
onClicked: modelData.activate()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// Center Pill (Clock)
|
|
Rectangle {
|
|
id: centerPill
|
|
anchors.horizontalCenter: parent.horizontalCenter
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
height: parent.height
|
|
width: clockText.width + Theme.geometry.padding * 4
|
|
radius: Theme.geometry.pillRadius
|
|
color: Theme.colors.surface
|
|
border.color: Theme.colors.border
|
|
border.width: 1
|
|
|
|
SystemClock {
|
|
id: clock
|
|
precision: SystemClock.Minutes
|
|
}
|
|
|
|
Text {
|
|
id: clockText
|
|
anchors.centerIn: parent
|
|
text: Qt.formatDateTime(clock.date, "dddd, MMMM d · hh:mm")
|
|
color: Theme.colors.text
|
|
font.family: Theme.font.family
|
|
font.bold: true
|
|
}
|
|
}
|
|
|
|
// Right Pill (System tray: WiFi, Bluetooth, Battery)
|
|
// Hidden entirely when none of the tray icons have anything to show.
|
|
Rectangle {
|
|
id: rightPill
|
|
visible: wifiPoll.connected || bluetoothPoll.connectedDevices.length > 0 || battery.isPresent
|
|
anchors.right: parent.right
|
|
anchors.verticalCenter: parent.verticalCenter
|
|
height: parent.height
|
|
width: rightPillRow.width + Theme.geometry.padding * 2
|
|
radius: Theme.geometry.pillRadius
|
|
color: Theme.colors.surface
|
|
border.color: Theme.colors.border
|
|
border.width: 1
|
|
|
|
Row {
|
|
id: rightPillRow
|
|
anchors.centerIn: parent
|
|
spacing: Theme.geometry.spacing
|
|
|
|
TrayIcon {
|
|
glyph: "" // nf-fa-wifi
|
|
active: wifiPoll.connected
|
|
tooltip: "WiFi: " + wifiPoll.ssid
|
|
visible: wifiPoll.connected
|
|
tooltipWindow: barWindow.trayTooltip
|
|
}
|
|
|
|
TrayIcon {
|
|
glyph: "" // nf-fa-bluetooth_b
|
|
active: true
|
|
tooltip: "Bluetooth: " + bluetoothPoll.connectedDevices
|
|
visible: bluetoothPoll.connectedDevices.length > 0
|
|
tooltipWindow: barWindow.trayTooltip
|
|
}
|
|
|
|
TrayIcon {
|
|
glyph: {
|
|
let p = battery.percentage;
|
|
if (!battery.isPresent) return ""; // nf-fa-plug (desktop/no battery)
|
|
if (p >= 0.9) return "";
|
|
if (p >= 0.65) return "";
|
|
if (p >= 0.4) return "";
|
|
if (p >= 0.15) return "";
|
|
return "";
|
|
}
|
|
active: battery.state === UPowerDeviceState.Charging
|
|
tooltip: battery.isPresent
|
|
? "Battery: " + Math.round(battery.percentage * 100) + "%"
|
|
+ (battery.state === UPowerDeviceState.Charging ? " (charging)" : "")
|
|
: "No battery"
|
|
visible: battery.isPresent
|
|
tooltipWindow: barWindow.trayTooltip
|
|
}
|
|
}
|
|
}
|
|
|
|
property QtObject battery: UPower.displayDevice
|
|
|
|
// --- WiFi status (polled via nmcli; requires NetworkManager) ---
|
|
QtObject {
|
|
id: wifiPoll
|
|
property bool connected: false
|
|
property string ssid: ""
|
|
}
|
|
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: wifiProcess.restart()
|
|
}
|
|
|
|
Process {
|
|
id: wifiProcess
|
|
command: ["bash", "-c", "nmcli -t -f ACTIVE,SSID dev wifi 2>/dev/null | awk -F: '$1==\"yes\"{print $2; exit}'"]
|
|
running: false
|
|
function restart() { running = false; running = true; }
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
let ssid = this.text.trim();
|
|
wifiPoll.connected = ssid.length > 0;
|
|
wifiPoll.ssid = ssid;
|
|
}
|
|
}
|
|
}
|
|
|
|
// --- Bluetooth status (polled via bluetoothctl) ---
|
|
QtObject {
|
|
id: bluetoothPoll
|
|
property bool available: true
|
|
property bool powered: false
|
|
property string connectedDevices: ""
|
|
}
|
|
|
|
Timer {
|
|
interval: 5000
|
|
running: true
|
|
repeat: true
|
|
triggeredOnStart: true
|
|
onTriggered: bluetoothProcess.restart()
|
|
}
|
|
|
|
Process {
|
|
id: bluetoothProcess
|
|
command: ["bash", "-c", "powered=$(bluetoothctl show 2>/dev/null | awk -F': ' '/Powered/{print $2}'); devices=$(bluetoothctl devices Connected 2>/dev/null | sed -E 's/^Device [0-9A-F:]+ //' | paste -sd, -); echo \"$powered|$devices\""]
|
|
running: false
|
|
function restart() { running = false; running = true; }
|
|
stdout: StdioCollector {
|
|
onStreamFinished: {
|
|
let parts = this.text.trim().split("|");
|
|
if (parts[0] === undefined || parts[0] === "") {
|
|
bluetoothPoll.available = false;
|
|
return;
|
|
}
|
|
bluetoothPoll.available = true;
|
|
bluetoothPoll.powered = parts[0] === "yes";
|
|
bluetoothPoll.connectedDevices = parts[1] || "";
|
|
}
|
|
}
|
|
}
|
|
|
|
// Inline component for a hoverable tray icon. The tooltip itself is
|
|
// rendered by the shared TrayTooltip overlay window (see tooltipWindow)
|
|
// so it isn't clipped by this bar's small surface.
|
|
component TrayIcon: Item {
|
|
id: trayIcon
|
|
property string glyph: ""
|
|
property string tooltip: ""
|
|
property bool active: false
|
|
property QtObject tooltipWindow
|
|
|
|
width: 24
|
|
height: 24
|
|
|
|
Rectangle {
|
|
anchors.fill: parent
|
|
radius: Theme.geometry.radiusTiny
|
|
color: hoverArea.containsMouse
|
|
? Theme.colors.surfaceHover
|
|
: (trayIcon.active ? Qt.alpha(Theme.colors.primary, 0.15) : "transparent")
|
|
|
|
Text {
|
|
anchors.centerIn: parent
|
|
text: trayIcon.glyph
|
|
font.family: Theme.font.family
|
|
font.pixelSize: 13
|
|
color: trayIcon.active ? Theme.colors.primary : Theme.colors.text
|
|
}
|
|
}
|
|
|
|
MouseArea {
|
|
id: hoverArea
|
|
anchors.fill: parent
|
|
hoverEnabled: true
|
|
onEntered: {
|
|
if (trayIcon.tooltipWindow && trayIcon.tooltip.length > 0) {
|
|
// Anchor on the icon's horizontal center; the tooltip
|
|
// window centers its bubble under this point itself.
|
|
let pos = trayIcon.mapToGlobal(trayIcon.width / 2, trayIcon.height + Theme.geometry.spacing / 2);
|
|
trayIcon.tooltipWindow.showAt(pos.x, pos.y, trayIcon.tooltip);
|
|
}
|
|
}
|
|
onExited: {
|
|
if (trayIcon.tooltipWindow) trayIcon.tooltipWindow.hide();
|
|
}
|
|
}
|
|
}
|
|
}
|