repositories / dotfiles
dotfiles
bugabingas dorkfiles
owned by admin
quickshell/nuguland/Bar.qml
Rawpragma ComponentBehavior: Bound
import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Wayland
import "human.js" as Human
PanelWindow {
id: root
required property Theme theme
required property Niri niriService
required property Registry registry
// Only forwarded: PopupHost leaves keyboard focus to an active privilege prompt.
required property Privilege privilegeService
required property SurfaceManager surfaces
required property Usage usageService
required property string orientation
readonly property bool vertical: orientation === "vertical"
// The entry behind a usage-ordered chip: a popup or a toggle entry.
function chipEntry(name: var): FeatureEntry {
return root.registry ? (root.registry.popup(name) || root.registry.toggle(name)) : null;
}
// The bar's one tooltip: the hovered chip's or bar control's full name, at once
// and without a timer, in its own surface beside the bar; a press dismisses it.
property Item hintTarget: null
property string hintText: ""
property bool hintShown: false
function hoverHint(item: Item, text: string, hovered: bool): void {
if (hovered && text.length > 0) {
root.hintTarget = item;
root.hintText = text;
root.hintShown = true;
if (root.theme)
root.theme.toolTipClaimed(hintWindow);
} else if (root.hintTarget === item) {
root.dismissHint();
}
}
function dismissHint(): void {
root.hintShown = false;
}
// A toggle entry's chip records its usage and emits `activated`, without
// touching the popup; any other chip toggles its popup.
function activateChip(name) {
const feature = root.chipEntry(name);
if (feature && feature.kind === "toggle") {
if (root.usageService)
root.usageService.record(feature.name);
feature.activated();
return;
}
root.activatePopup(name);
}
function itemRectInBar(item: Item): rect {
return item.mapToItem(root.contentItem, Qt.rect(0, 0, item.width, item.height));
}
function registerAnchor(name, item) {
// Skip hidden or unsized items: only a laid-out control is an anchor.
if (!root.surfaces || !item || !item.visible || item.width <= 0 || item.height <= 0)
return;
const rect = itemRectInBar(item);
root.surfaces.registerAnchor(name, Qt.rect(Math.round(rect.x), Math.round(rect.y), Math.round(rect.width), Math.round(rect.height)));
}
function activatePopup(name) {
if (!root.surfaces)
return;
const target = String(name);
if (root.surfaces.popupOpen && root.surfaces.popupName === target) {
root.surfaces.closePopup("bar-toggle");
} else {
if (root.usageService)
root.usageService.record(target);
root.surfaces.openRegisteredPopup(target);
}
}
function refreshSurfaceGeometry() {
if (root.surfaces) {
const thickness = Math.round(root.vertical ? root.width : root.height);
let screen = null;
const screens = Quickshell.screens;
for (let i = 0; i < screens.length; i++) {
if (screens[i] === root.screen) {
screen = screens[i];
break;
}
}
root.surfaces.setPopupScreen(Math.round(screen ? screen.width : root.width), Math.round(screen ? screen.height : root.height), thickness, root.orientation);
}
}
// horizontal: width spans (left+right anchored), implicitHeight sets bar
// height. vertical: height spans (top+bottom anchored), implicitWidth sets
// bar thickness from the widest chip content (never a magic constant).
implicitHeight: 34
implicitWidth: root.vertical ? (Math.max(34, widgetsRow.implicitWidth, endSlot.width, workspaceStrip.implicitWidth) + 12) : root.width
color: "transparent"
WlrLayershell.namespace: "nuguland-bar"
WlrLayershell.layer: WlrLayer.Top
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
Component.onCompleted: Qt.callLater(root.refreshSurfaceGeometry)
onSurfacesChanged: Qt.callLater(root.refreshSurfaceGeometry)
onWidthChanged: root.refreshSurfaceGeometry()
onHeightChanged: root.refreshSurfaceGeometry()
anchors {
top: true
left: true
right: !root.vertical
bottom: root.vertical
}
Rectangle {
id: barContent
anchors.fill: parent
color: "transparent"
// accent edge: bottom hairline (horizontal) / right hairline (vertical)
Rectangle {
x: root.vertical ? parent.width - 1 : 0
y: root.vertical ? 0 : parent.height - 1
width: root.vertical ? 1 : parent.width
height: root.vertical ? parent.height : 1
color: root.theme ? root.theme.withAlpha(root.theme.ui.accent, 0.55) : "transparent"
}
// End slot: registry entries with their own bar control (FeatureEntry.barControl).
// Horizontally at the right edge, widgets immediately before it; vertically
// centred, but always 12 px above the widgets.
// A layout, not a Grid: Grid adds trailing spacing after fewer items than columns.
GridLayout {
id: endSlot
columns: root.vertical ? 1 : 99
rowSpacing: 12
columnSpacing: 12
anchors.right: parent.right
anchors.rightMargin: 10
anchors.verticalCenter: parent.verticalCenter
states: State {
when: root.vertical
AnchorChanges {
target: endSlot
anchors.right: undefined
anchors.verticalCenter: undefined
anchors.horizontalCenter: parent.horizontalCenter
}
PropertyChanges {
endSlot.y: Math.min(barContent.height / 2 - endSlot.height / 2, widgetsRow.y - endSlot.height - 12)
}
}
Repeater {
model: root.registry ? root.registry.barControls : []
delegate: BarControlSlot {}
}
}
// Workspaces fill the space before widgets horizontally, or above the
// end slot vertically. Each output keeps its own faint tray.
GridLayout {
id: workspaceStrip
// horizontal base: single row from the left edge up to the widgets,
// centred vertically. Vertical state swaps to a single column from
// the top down to the end slot, centred horizontally.
columns: root.vertical ? 1 : 99
rowSpacing: 8
columnSpacing: 8
clip: true
anchors.left: parent.left
anchors.leftMargin: root.vertical ? 0 : 10
anchors.right: widgetsRow.left
anchors.rightMargin: root.vertical ? 0 : 12
anchors.verticalCenter: parent.verticalCenter
anchors.topMargin: root.vertical ? 10 : 0
anchors.bottomMargin: root.vertical ? 10 : 0
states: State {
when: root.vertical
AnchorChanges {
target: workspaceStrip
anchors.left: undefined
anchors.right: undefined
anchors.verticalCenter: undefined
anchors.top: parent.top
anchors.bottom: endSlot.top
anchors.horizontalCenter: parent.horizontalCenter
}
}
Repeater {
model: root.niriService ? root.niriService.workspaceGroups() : []
// Wrap the group in a plain Item: Qt6 won't inject an array
// model's modelData into a required prop on a delegate root that
// re-declares it for a nested Repeater. The wrapper takes the
// injection and hands it to the tray/pills explicitly.
delegate: Item {
id: groupItem
required property var modelData
implicitWidth: tray.width
implicitHeight: tray.height
Layout.preferredWidth: tray.width
Layout.preferredHeight: tray.height
// pinned to the strip's start edge: left in the horizontal
// row, top in the vertical column (no centred-float gap).
Layout.alignment: root.vertical ? (Qt.AlignHCenter | Qt.AlignTop) : (Qt.AlignLeft | Qt.AlignVCenter)
Rectangle {
id: tray
anchors.centerIn: parent
width: pills.implicitWidth + 12
height: pills.implicitHeight + 12
radius: root.theme ? root.theme.radiusCard : 0
color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.07) : "transparent"
// pills: one output's workspaces. Flow follows the bar —
// a horizontal row, or a vertical stack in vertical mode.
GridLayout {
id: pills
anchors.centerIn: parent
columns: root.vertical ? 1 : 99
rowSpacing: 4
columnSpacing: 4
Repeater {
model: groupItem.modelData.workspaces
delegate: Item {
id: pillWrap
required property var modelData
implicitWidth: workspaceChip.width
implicitHeight: workspaceChip.height
Layout.preferredWidth: workspaceChip.width
Layout.preferredHeight: workspaceChip.height
Layout.alignment: Qt.AlignCenter
Rectangle {
id: workspaceChip
readonly property bool active: !!pillWrap.modelData.is_focused
readonly property string idxStr: String(pillWrap.modelData.shortcut || pillWrap.modelData.idx || pillWrap.modelData.id || "?")
readonly property string nameStr: pillWrap.modelData.name ? String(pillWrap.modelData.name).toLowerCase() : ""
readonly property string abbrName: Human.abbreviate(workspaceChip.nameStr)
anchors.centerIn: parent
width: Math.max(30, workspaceContent.implicitWidth + (root.vertical ? 12 : 16))
height: root.vertical ? (workspaceContent.implicitHeight + 8) : 22
radius: root.theme ? root.theme.radiusControl : 0
color: root.theme ? (active ? root.theme.withAlpha(root.theme.ui.focus, 0.28) : root.theme.withAlpha(root.theme.ui.minor, 0.1)) : "transparent"
border.width: 0
// idx (minor) leads the name (normal): inline in horizontal, stacked in vertical.
GridLayout {
id: workspaceContent
anchors.centerIn: parent
columns: root.vertical ? 1 : 2
rowSpacing: 0
columnSpacing: 4
NuguText {
Layout.alignment: Qt.AlignHCenter
theme: root.theme
variant: "meta"
text: workspaceChip.idxStr
color: !root.theme ? "transparent" : (workspaceChip.active ? root.theme.ui.accent : root.theme.ui.minor)
}
NuguText {
Layout.alignment: Qt.AlignHCenter
visible: text.length > 0
theme: root.theme
variant: "meta"
font.pixelSize: root.vertical ? 10 : 13
text: root.vertical ? workspaceChip.abbrName : workspaceChip.nameStr
color: !root.theme ? "transparent" : (workspaceChip.active ? root.theme.ui.accent : root.theme.ui.normal)
}
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
cursorShape: Qt.PointingHandCursor
onClicked: {
if (root.niriService)
root.niriService.focusWorkspace(pillWrap.modelData.name || pillWrap.modelData.idx || pillWrap.modelData.id);
}
}
}
}
}
}
}
}
}
}
// Widgets keep their natural width before the end slot horizontally,
// or at the bottom edge vertically.
GridLayout {
id: widgetsRow
// horizontal base: single row pinned before the end slot, centred
// vertically. The vertical state swaps to a single column pinned to
// the bottom edge, centred horizontally. AnchorChanges is required
// because clearing an anchor with `undefined` does not reset it.
columns: root.vertical ? 1 : 99
rowSpacing: 4
columnSpacing: 4
anchors.right: endSlot.left
anchors.rightMargin: root.vertical ? 0 : 12
anchors.verticalCenter: parent.verticalCenter
anchors.bottomMargin: root.vertical ? 10 : 0
states: State {
when: root.vertical
AnchorChanges {
target: widgetsRow
anchors.right: undefined
anchors.verticalCenter: undefined
anchors.bottom: parent.bottom
anchors.horizontalCenter: parent.horizontalCenter
}
}
Repeater {
model: root.usageService ? root.usageService.layoutOrder : []
delegate: BarChip {
required property var modelData
popupName: modelData
}
}
}
}
// Another tooltip taking over hides the bar's.
Connections {
target: root.theme
function onToolTipClaimed(tip: QtObject): void {
if (tip !== hintWindow)
root.dismissHint();
}
}
// A transparent output-sized layer surface of its own, since the bar's surface is
// too thin to hold a tooltip; click-through and keyboardless, so it never takes
// input. The bar sits at the output's top left: bar and output coordinates agree.
PanelWindow {
id: hintWindow
readonly property int gap: 6
readonly property var targetRect: root.hintShown && root.hintTarget ? root.itemRectInBar(root.hintTarget) : null
screen: root.screen
visible: hintWindow.targetRect !== null
color: "transparent"
exclusionMode: ExclusionMode.Ignore
WlrLayershell.namespace: "nuguland-bar-hint"
WlrLayershell.layer: WlrLayer.Overlay
WlrLayershell.keyboardFocus: WlrKeyboardFocus.None
mask: Region {}
anchors {
top: true
left: true
right: true
bottom: true
}
// Below a horizontal chip or beside a vertical one, kept on the output.
Rectangle {
id: hintBox
x: !hintWindow.targetRect ? 0 : (root.vertical ? root.width + hintWindow.gap : Math.max(hintWindow.gap, Math.min(hintWindow.width - width - hintWindow.gap, hintWindow.targetRect.x + (hintWindow.targetRect.width - width) / 2)))
y: !hintWindow.targetRect ? 0 : (root.vertical ? Math.max(hintWindow.gap, Math.min(hintWindow.height - height - hintWindow.gap, hintWindow.targetRect.y + (hintWindow.targetRect.height - height) / 2)) : root.height + hintWindow.gap)
width: hintLabel.implicitWidth + 2 * (root.theme ? root.theme.spaceSm : 0)
height: hintLabel.implicitHeight + 2 * (root.theme ? root.theme.spaceSm : 0)
radius: root.theme ? root.theme.radiusControl : 0
color: root.theme ? root.theme.content.backdrop : "transparent"
border.width: 1
border.color: root.theme ? root.theme.withAlpha(root.theme.ui.minor, 0.3) : "transparent"
Text {
id: hintLabel
anchors.centerIn: parent
text: root.hintText
textFormat: Text.PlainText
font.family: "IBM Plex Sans"
font.pixelSize: 13
color: root.theme ? root.theme.content.normal : "transparent"
}
}
}
PopupHost {
theme: root.theme
surfaces: root.surfaces
registry: root.registry
privilegeService: root.privilegeService
barWindow: root
}
component StateLayer: MouseArea {
id: stateLayer
property Theme theme
property bool checked: false
property bool disabled: false
property real hoverOpacity: 0.08
property real pressOpacity: 0.14
property real disabledOpacity: 0.38
property point pressOrigin: Qt.point(width / 2, height / 2)
property real rippleRadius: 0
property real cornerRadius: 0
property real endRadius: Math.sqrt(width * width + height * height) * 1.25
// Tooltip text while hovered: the chip's or control's full name.
property string hint: ""
signal activated
function beginPress(x, y) {
pressOrigin = Qt.point(x, y);
rippleRadius = 0;
rippleAnimation.restart();
}
function keyboardActivate() {
beginPress(width / 2, height / 2);
activated();
}
anchors.fill: parent
clip: true
enabled: !disabled
hoverEnabled: true
acceptedButtons: Qt.LeftButton
cursorShape: disabled ? Qt.ArrowCursor : Qt.PointingHandCursor
activeFocusOnTab: !disabled
onPressed: event => {
root.dismissHint();
return beginPress(event.x, event.y);
}
onContainsMouseChanged: root.hoverHint(stateLayer, stateLayer.hint, stateLayer.containsMouse)
Component.onDestruction: root.hoverHint(stateLayer, "", false)
onClicked: activated()
Keys.onReturnPressed: event => {
event.accepted = true;
keyboardActivate();
}
Keys.onSpacePressed: event => {
event.accepted = true;
keyboardActivate();
}
Rectangle {
anchors.fill: parent
radius: stateLayer.cornerRadius
color: stateLayer.theme ? stateLayer.theme.ui.accent : "white"
opacity: stateLayer.disabled ? stateLayer.disabledOpacity : stateLayer.pressed ? stateLayer.pressOpacity : stateLayer.containsMouse || stateLayer.checked ? stateLayer.hoverOpacity : 0
Behavior on opacity {
NumberAnimation {
duration: stateLayer.theme && stateLayer.theme.lowPowerMode ? 0 : 120
easing.type: Easing.OutCubic
}
}
}
Rectangle {
width: stateLayer.rippleRadius * 2
height: width
x: stateLayer.pressOrigin.x - width / 2
y: stateLayer.pressOrigin.y - height / 2
radius: width / 2
color: stateLayer.theme ? stateLayer.theme.ui.accent : "white"
opacity: stateLayer.pressed ? stateLayer.pressOpacity : 0
Behavior on opacity {
NumberAnimation {
duration: stateLayer.theme && stateLayer.theme.lowPowerMode ? 0 : 160
easing.type: Easing.OutCubic
}
}
}
// Keyboard focus ring, contrast-checked like the popup controls' focus border.
Rectangle {
anchors.fill: parent
visible: stateLayer.activeFocus
radius: stateLayer.cornerRadius
color: "transparent"
border.width: 2
border.color: stateLayer.theme ? stateLayer.theme.content.focus : "white"
}
NumberAnimation {
id: rippleAnimation
target: stateLayer
property: "rippleRadius"
to: stateLayer.endRadius
duration: stateLayer.theme && stateLayer.theme.lowPowerMode ? 0 : 220
easing.type: Easing.OutCubic
}
}
// A registry entry's own bar control (FeatureEntry.barControl) in the end slot:
// Bar binds its inputs, lays the shared state layer over it, toggles the
// entry's popup on activation, and registers the popup anchor.
component BarControlSlot: Loader {
id: slot
required property FeatureEntry modelData
readonly property string controlName: slot.modelData.name
readonly property bool selected: !!root.surfaces && root.surfaces.popupName === slot.controlName
readonly property BarControl control: slot.item as BarControl
function register(): void {
root.registerAnchor(slot.controlName, slot);
}
sourceComponent: slot.modelData.barControl
Component.onCompleted: Qt.callLater(slot.register)
onXChanged: slot.register()
onYChanged: slot.register()
onWidthChanged: slot.register()
onHeightChanged: slot.register()
// The slot sits inside the end slot, which moves with the bar layout.
Connections {
target: endSlot
function onXChanged(): void {
slot.register();
}
function onYChanged(): void {
slot.register();
}
}
Binding {
target: slot.control
property: "label"
value: slot.modelData.barLabel
}
Binding {
target: slot.control
property: "selected"
value: slot.selected
}
Binding {
target: slot.control
property: "vertical"
value: root.vertical
}
StateLayer {
theme: root.theme
cornerRadius: slot.control ? slot.control.radius : 0
checked: slot.selected
hint: slot.modelData.barTitle
z: 1
onActivated: {
if (root.surfaces)
root.activatePopup(slot.controlName);
}
}
}
component BarChip: Rectangle {
id: chip
required property string popupName
readonly property FeatureEntry feature: root.chipEntry(popupName)
readonly property string label: feature ? feature.barLabel : popupName
readonly property string title: feature ? feature.barTitle : popupName
// The vertical bar shows the entry's glyph and badge instead of its label.
readonly property string icon: root.vertical && feature ? feature.barIcon : ""
readonly property string badge: chip.icon.length > 0 && feature ? feature.barBadge : ""
property int preferredWidth: root.vertical ? 52 : Math.max(52, labelText.implicitWidth + 18)
readonly property bool selected: root.surfaces && root.surfaces.popupName === popupName
readonly property bool active: !!feature && feature.barActive
readonly property bool activeStrong: !!feature && feature.barStrong
readonly property bool busy: !!feature && feature.barBusy
readonly property string role: feature ? feature.barRole : "ui.accent"
readonly property color roleColor: !root.theme ? "transparent" : (chip.role === "warning" ? root.theme.warning : root.theme.ui.accent)
readonly property color foregroundColor: !root.theme ? "transparent" : (chip.selected ? root.theme.content.backdrop : (chip.activeStrong ? chip.roleColor : root.theme.content.normal))
Layout.preferredWidth: preferredWidth
Layout.preferredHeight: 26
Layout.alignment: Qt.AlignVCenter
radius: root.theme ? root.theme.radiusControl : 0
color: !root.theme ? "transparent" : (selected ? root.theme.ui.focus : (activeStrong && !selected ? root.theme.withAlpha(chip.roleColor, 0.3) : root.theme.withAlpha(root.theme.ui.minor, 0.1)))
clip: true
border.width: chip.activeStrong && !chip.selected ? 1 : 0
border.color: root.theme && chip.activeStrong ? chip.roleColor : "transparent"
Accessible.role: Accessible.Button
Accessible.name: chip.title
Accessible.description: chip.label
Accessible.onPressAction: root.activateChip(chip.popupName)
Component.onCompleted: Qt.callLater(() => {
return root.registerAnchor(chip.popupName, chip);
})
onXChanged: root.registerAnchor(chip.popupName, chip)
onYChanged: root.registerAnchor(chip.popupName, chip)
onWidthChanged: root.registerAnchor(chip.popupName, chip)
onHeightChanged: root.registerAnchor(chip.popupName, chip)
NuguText {
id: labelText
visible: chip.icon.length === 0
anchors.centerIn: parent
width: Math.max(0, parent.width - 14)
theme: root.theme
variant: "meta"
selected: chip.selected
text: chip.label
font.bold: chip.activeStrong && !chip.selected
horizontalAlignment: Text.AlignHCenter
elide: Text.ElideRight
color: chip.foregroundColor
Accessible.ignored: true
z: 2
}
Row {
visible: chip.icon.length > 0
anchors.centerIn: parent
spacing: 2
z: 2
Text {
objectName: "barIcon"
anchors.verticalCenter: parent.verticalCenter
color: chip.foregroundColor
font.family: "Symbols Nerd Font Mono"
font.pixelSize: 20
text: chip.icon
Accessible.ignored: true
}
Text {
objectName: "barBadge"
visible: chip.badge.length > 0
anchors.verticalCenter: parent.verticalCenter
color: chip.selected ? chip.foregroundColor : chip.roleColor
font.family: "IBM Plex Sans"
font.pixelSize: 12
font.bold: true
text: chip.badge
Accessible.ignored: true
}
}
Rectangle {
id: activeDot
objectName: "activeDot"
visible: chip.active && chip.role !== "warning" && !chip.activeStrong && !chip.selected && !chip.busy && chip.badge.length === 0
width: 5
height: 5
radius: 2.5
anchors.top: parent.top
anchors.right: parent.right
anchors.topMargin: 4
anchors.rightMargin: 5
color: root.theme ? chip.roleColor : "white"
opacity: 0.9
z: 4
Behavior on opacity {
NumberAnimation {
duration: root.theme && root.theme.lowPowerMode ? 0 : 160
easing.type: Easing.OutCubic
}
}
}
// Attention never relies on colour alone: a warning shows an exclamation
// mark where routine activity shows a dot.
Text {
objectName: "warningMark"
visible: chip.active && chip.role === "warning" && !chip.activeStrong && !chip.selected && !chip.busy && chip.badge.length === 0
anchors.top: parent.top
anchors.right: parent.right
anchors.rightMargin: 4
color: chip.roleColor
font.family: "IBM Plex Sans"
font.pixelSize: 11
font.bold: true
text: "!"
Accessible.ignored: true
z: 4
}
Rectangle {
objectName: "busyLine"
visible: chip.busy
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 3
width: Math.max(16, parent.width * 0.42)
height: 2
radius: 1
color: chip.roleColor
opacity: 0.65
z: 4
// A calm pulse while the work lasts: each leg stays within 250 ms.
SequentialAnimation on opacity {
running: chip.busy && !(root.theme && root.theme.lowPowerMode)
loops: Animation.Infinite
NumberAnimation {
to: 0.25
duration: 240
easing.type: Easing.InOutSine
}
NumberAnimation {
to: 0.78
duration: 240
easing.type: Easing.InOutSine
}
PauseAnimation {
duration: 480
}
}
}
StateLayer {
theme: root.theme
cornerRadius: chip.radius
checked: chip.selected
hint: chip.title
z: 3
onActivated: root.activateChip(chip.popupName)
}
}
}