Files
glassMxrph/quickshell/bar/Bar.qml
T
mxandClaude Opus 5.5 bc197339fa Add bar spots beside the notch, and Caffeine and Night Light modules
Notch mode gets two more module lists, notch.innerLeft and
notch.innerRight: spots right beside the notch at the same distance on
both sides. They follow the notch's edges as it springs wider for media,
never draw pills (plugins and the tray drop theirs there), and fade out
while the notch is open or widened. Picking a module for one of the four
side spots in Settings -> Notch moves it there from the others.

Caffeine and Night Light are now bar modules too; Night Light polls its
state every 30 s while only the bar watches it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-29 23:27:01 +01:00

200 lines
9.5 KiB
QML

import QtQuick
import QtQuick.Shapes
import Quickshell
import Quickshell.Hyprland
import Quickshell.Wayland
import "../components"
import "../notch"
import "../core"
import "../services"
import "../theme"
// Quickshell selects the concrete PanelWindow implementation at runtime.
// qmllint disable uncreatable-type
PanelWindow {
// qmllint enable uncreatable-type
id: root
required property var modelData
screen: modelData
anchors { top: true; left: true; right: true }
readonly property int outerMargin: BarDrawers.margin
// The window reaches below the bar (input is masked to the bar) so the
// HyprGlass layer edge is not on the bar's bottom edge, where drawers join.
// While the launcher is open in the notch, the window is tall enough for
// it to grow down; input stays masked to the shapes.
readonly property bool tall: notch && (notchPill.searching || notchPill.height > BarDrawers.bottom + 1)
implicitHeight: tall ? Math.ceil(BarDrawers.bottom + notchPill.maxBodyHeight + 40) : BarDrawers.bottom + BarDrawers.overhang
// Notch mode splits the bar into a left island, the centre notch and a
// right island; only those take input.
readonly property bool notch: ShellState.notchMode
// The islands share the notch's centre line (the notch runs from the top
// edge to the bar's bottom), so they line up with its clock.
readonly property int islandY: Math.round((BarDrawers.bottom - BarDrawers.height) / 2)
mask: Region {
item: root.notch ? leftIsland : panel
Region { item: root.notch ? notchPill : null; intersection: Intersection.Combine }
Region { item: root.notch ? rightIsland : null; intersection: Intersection.Combine }
Region { item: root.notch && innerLeft.shown ? innerLeft : null; intersection: Intersection.Combine }
Region { item: root.notch && innerRight.shown ? innerRight : null; intersection: Intersection.Combine }
}
color: Theme.transparent
// Reserve the bar itself (margin + height), not the overhang below it, so
// windows tile beneath the bar instead of under it.
exclusionMode: ExclusionMode.Normal
exclusiveZone: BarDrawers.bottom
WlrLayershell.namespace: "glassMxrph-bar"
// The notch's search takes the keyboard while it is open on this screen;
// a click anywhere else closes it.
readonly property bool searching: notch && ShellState.notchLauncher && ScreenService.current(ShellState.launcherScreen) === screen
WlrLayershell.keyboardFocus: searching ? WlrKeyboardFocus.Exclusive : WlrKeyboardFocus.None
// The grab starts once the bar holds the keyboard; started together with
// the focus change, Hyprland clears it at once and the search closes.
property bool grabbing: false
onSearchingChanged: {
grabbing = false;
if (searching)
grabStart.restart();
}
Timer {
id: grabStart
interval: 150
onTriggered: root.grabbing = root.searching
}
HyprlandFocusGrab {
windows: [root]
active: root.grabbing
onCleared: if (root.grabbing)
ShellState.launcherOpen = false
}
Component.onCompleted: TrayService.registerBar(root)
Component.onDestruction: TrayService.unregisterBar(root)
GlassPanel {
id: panel
visible: !root.notch
x: root.outerMargin; y: root.outerMargin
width: root.width - 2 * root.outerMargin
height: BarDrawers.height
radius: BarDrawers.radius
border.width: 0
// In notch mode the side rows move into their islands; the notch replaces the centre.
// Notch mode unloads these; its islands carry their own module lists.
ModuleRow { position: "left"; active: !root.notch; barScreen: root.screen; anchors.left: parent.left; anchors.leftMargin: 6; anchors.verticalCenter: parent.verticalCenter }
ModuleRow { position: "center"; active: !root.notch; barScreen: root.screen; anchors.centerIn: parent }
ModuleRow { position: "right"; active: !root.notch; barScreen: root.screen; anchors.right: parent.right; anchors.rightMargin: 6; anchors.verticalCenter: parent.verticalCenter }
}
// Outline with openings where drawers hang from the bar.
Shape {
id: outline
visible: !root.notch
x: panel.x
y: panel.y
width: panel.width
height: panel.height
preferredRendererType: Shape.CurveRenderer
readonly property var gaps: BarDrawers.gapsFor(root.screen ? root.screen.name : "").map(g => [g.x0 - panel.x, g.x1 - panel.x]).sort((a, b) => b[0] - a[0])
ShapePath {
fillColor: "transparent"
strokeColor: Theme.border
strokeWidth: 1
PathSvg {
path: {
const W = panel.width - 1, H = panel.height - 0.5, r = Math.max(0, panel.radius - 0.5), o = 0.5;
let d = `M ${r + o} ${o} L ${W - r} ${o} A ${r} ${r} 0 0 1 ${W} ${r + o} L ${W} ${H - r} A ${r} ${r} 0 0 1 ${W - r} ${H}`;
// Bottom edge right to left, skipping each drawer's span.
for (const g of outline.gaps)
d += ` L ${Math.min(W - r, Math.max(r, g[1]))} ${H} M ${Math.max(r, Math.min(W - r, g[0]))} ${H}`;
return d + ` L ${r + o} ${H} A ${r} ${r} 0 0 1 ${o} ${H - r} L ${o} ${r + o} A ${r} ${r} 0 0 1 ${r + o} ${o}`;
}
}
}
}
// Notch mode -------------------------------------------------------------
// Side islands: "float" leaves the modules on the wallpaper, "pill" puts
// them on rounded pills and "notch" hangs them from the top edge like the
// centre notch. Both use the notch's fill.
readonly property string islandStyle: ConfigService.ready ? ConfigService.data.notch.islandStyle : "float"
component Island: GlassPanel {
id: island
property alias row: islandRow
property string side
readonly property bool hanging: root.islandStyle === "notch"
color: root.islandStyle === "pill" ? Theme.notchFill : Theme.transparent
border.width: root.islandStyle === "pill" ? 1 : 0
plain: true
visible: root.notch && ConfigService.ready && ConfigService.data.notch[side].length > 0
// Hanging islands keep their ears on screen.
x: {
const inset = root.outerMargin + (hanging ? BarDrawers.ear : 0);
return side === "left" ? inset : root.width - inset - width;
}
y: root.islandY
width: islandRow.implicitWidth + (root.islandStyle === "float" ? 12 : 24)
height: BarDrawers.height
radius: root.islandStyle === "pill" ? height / 2 : BarDrawers.radius
DrawerShape {
z: -1
visible: island.hanging
x: -BarDrawers.ear
y: -island.y
bodyWidth: island.width
bodyHeight: BarDrawers.bottom
ear: BarDrawers.ear
radius: Math.min(Theme.radius, BarDrawers.bottom / 2)
fillColor: Theme.notchFill
}
ModuleRow {
id: islandRow
position: island.side
active: root.notch
modules: BarLayout.notchModules(root.screen ? root.screen.name : "", island.side)
barScreen: root.screen
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
}
}
Island { id: leftIsland; side: "left" }
Island { id: rightIsland; side: "right" }
// Spots right beside the notch, one each side at the same distance. Always
// bare (no pill), they ride the notch's edges as it springs wider for media,
// and step aside while it is opened or widened for the launcher or a banner.
readonly property int innerGap: 10
readonly property bool notchBusy: ShellState.notchOpen || notchPill.searching || notchPill.showing
component InnerSlot: Item {
id: slot
property string side
readonly property bool used: root.notch && ConfigService.ready && (ConfigService.data.notch[side] || []).length > 0
readonly property bool shown: used && opacity > 0.01
visible: shown
opacity: used && !root.notchBusy ? 1 : 0
Behavior on opacity {
NumberAnimation {
duration: Theme.duration
easing.type: Easing.OutCubic
}
}
x: side === "innerLeft" ? notchPill.x - root.innerGap - width : notchPill.x + notchPill.width + root.innerGap
y: root.islandY
width: slotRow.implicitWidth
height: BarDrawers.height
ModuleRow {
id: slotRow
position: slot.side === "innerLeft" ? "left" : "right"
active: slot.used
modules: BarLayout.notchModules(root.screen ? root.screen.name : "", slot.side)
barScreen: root.screen
anchors.verticalCenter: parent.verticalCenter
}
}
InnerSlot { id: innerLeft; side: "innerLeft" }
InnerSlot { id: innerRight; side: "innerRight" }
NotchPill {
id: notchPill
barScreen: root.screen
x: Math.round((root.width - width) / 2)
y: 0
width: implicitWidth
height: implicitHeight
// The open notch window draws over this spot on its own screen.
visible: root.notch && !(ShellState.notchWindow && ShellState.notchWindow.visible && ShellState.notchWindow.screen === root.screen) && !(ShellState.wallpaperWindow && ShellState.wallpaperWindow.visible && ShellState.wallpaperWindow.screen === root.screen)
}
}