nova-shell/modules/Bar.qml

215 lines
5.9 KiB
QML

import QtQuick
import QtQuick.Layouts
import Quickshell
import Quickshell.Wayland
import "." as M
PanelWindow {
id: bar
required property var screen
color: "transparent"
WlrLayershell.layer: WlrLayer.Bottom
anchors {
top: true
left: true
right: true
}
implicitHeight: M.Theme.barHeight
exclusiveZone: implicitHeight
Rectangle {
anchors.fill: parent
color: M.Theme.base00
opacity: M.Theme.barOpacity
}
Canvas {
anchors.top: parent.top
anchors.left: parent.left
anchors.right: parent.right
height: Math.max(M.Theme.screenRadius + 2, 4)
onPaint: {
const ctx = getContext("2d");
const w = width;
const r = M.Theme.screenRadius;
const lw = 3;
const hw = lw / 2;
ctx.clearRect(0, 0, w, height);
// Opaque backing behind the stroke so it's not transparent
ctx.fillStyle = M.Theme.base00.toString();
ctx.beginPath();
if (r > lw) {
ctx.moveTo(0, r);
ctx.arc(r, r, r, Math.PI, -Math.PI / 2);
ctx.lineTo(w - r, 0);
ctx.arc(w - r, r, r, -Math.PI / 2, 0);
ctx.lineTo(w, lw);
ctx.lineTo(0, lw);
} else {
ctx.rect(0, 0, w, lw);
}
ctx.fill();
// Gradient stroke
const grad = ctx.createLinearGradient(0, 0, w, 0);
grad.addColorStop(0, M.Theme.base0C.toString());
grad.addColorStop(1, M.Theme.base09.toString());
ctx.strokeStyle = grad;
ctx.lineWidth = lw;
ctx.beginPath();
if (r > lw) {
ctx.moveTo(0, r);
ctx.arc(r, r, r - hw, Math.PI, -Math.PI / 2);
ctx.lineTo(w - r, hw);
ctx.arc(w - r, r, r - hw, -Math.PI / 2, 0);
} else {
ctx.moveTo(0, hw);
ctx.lineTo(w, hw);
}
ctx.stroke();
}
}
Item {
anchors.fill: parent
anchors.leftMargin: Math.max(M.Theme.barPadding, M.Theme.screenRadius)
anchors.rightMargin: Math.max(M.Theme.barPadding, M.Theme.screenRadius)
// ---- center (declared first so left/right can anchor to it) ----
RowLayout {
id: centerSection
anchors.horizontalCenter: parent.horizontalCenter
anchors.verticalCenter: parent.verticalCenter
spacing: M.Theme.barSpacing
M.Privacy {}
M.BarGroup {
borderColor: M.Theme.base0D
M.Clock {
visible: M.Modules.clock.enable
}
M.Notifications {
visible: M.Modules.notifications.enable
}
}
}
// ---- left ----
RowLayout {
anchors.left: parent.left
anchors.right: centerSection.left
anchors.verticalCenter: parent.verticalCenter
spacing: M.Theme.barSpacing
M.BarGroup {
borderColor: M.Theme.base0D
M.Workspaces {
bar: bar
visible: M.Modules.workspaces.enable
}
}
M.BarGroup {
borderColor: M.Theme.base0D
M.Tray {
bar: bar
visible: M.Modules.tray.enable
}
}
M.BarGroup {
borderColor: M.Theme.base0D
M.WindowTitle {
Layout.maximumWidth: 400
visible: M.Modules.windowTitle.enable
}
}
Item {
Layout.fillWidth: true
}
}
// ---- right ----
RowLayout {
anchors.left: centerSection.right
anchors.right: parent.right
anchors.verticalCenter: parent.verticalCenter
spacing: M.Theme.barSpacing
Item {
Layout.fillWidth: true
}
// Media
M.BarGroup {
borderColor: M.Theme.base0E
M.Mpris {
bar: bar
}
M.Volume {
visible: M.Modules.volume.enable
}
}
// Connectivity
M.BarGroup {
borderColor: M.Theme.base0D
M.Network {
bar: bar
visible: M.Modules.network.enable
}
M.Bluetooth {
bar: bar
}
}
// Controls
M.BarGroup {
borderColor: M.Theme.base0A
M.Backlight {}
M.PowerProfile {
visible: M.Modules.powerProfile.enable
}
M.IdleInhibitor {
visible: M.Modules.idleInhibitor.enable
}
}
// Stats
M.BarGroup {
borderColor: M.Theme.base08
M.Cpu {
visible: M.Modules.cpu.enable
}
M.Memory {
visible: M.Modules.memory.enable
}
M.Temperature {
visible: M.Modules.temperature.enable
}
M.Weather {
visible: M.Modules.weather.enable
}
M.Disk {
visible: M.Modules.disk.enable
}
}
// Power
M.BarGroup {
borderColor: M.Theme.base08
M.Battery {}
M.Power {
bar: bar
visible: M.Modules.power.enable
}
}
}
}
}