213 lines
7.5 KiB
QML
213 lines
7.5 KiB
QML
pragma ComponentBehavior: Bound
|
|
|
|
import "popouts" as BarPopouts
|
|
import "components"
|
|
import "components/workspaces"
|
|
import QtQuick
|
|
import QtQuick.Layouts
|
|
import Quickshell
|
|
import Caelestia.Config
|
|
import qs.components
|
|
import qs.services
|
|
|
|
ColumnLayout {
|
|
id: root
|
|
|
|
required property ShellScreen screen
|
|
required property DrawerVisibilities visibilities
|
|
required property BarPopouts.Wrapper popouts
|
|
required property bool fullscreen
|
|
readonly property int vPadding: Tokens.padding.large
|
|
|
|
function closeTray(): void {
|
|
if (!Config.bar.tray.compact)
|
|
return;
|
|
|
|
for (let i = 0; i < repeater.count; i++) {
|
|
const loader = repeater.itemAt(i) as WrappedLoader;
|
|
if (loader?.enabled && loader.id === "tray") {
|
|
(loader.item as Tray).expanded = false;
|
|
}
|
|
}
|
|
}
|
|
|
|
function checkPopout(y: real): void {
|
|
const ch = childAt(width / 2, y) as WrappedLoader;
|
|
|
|
if (ch?.id !== "tray")
|
|
closeTray();
|
|
|
|
if (!ch) {
|
|
popouts.hasCurrent = false;
|
|
return;
|
|
}
|
|
|
|
const id = ch.id;
|
|
const top = ch.y;
|
|
|
|
if (id === "statusIcons" && Config.bar.popouts.statusIcons) {
|
|
const items = (ch.item as StatusIcons).items;
|
|
const icon = items.childAt(items.width / 2, mapToItem(items, 0, y).y);
|
|
if (icon) {
|
|
popouts.currentName = icon.name;
|
|
popouts.currentCenter = Qt.binding(() => icon.mapToItem(root, 0, icon.implicitHeight / 2).y);
|
|
popouts.hasCurrent = true;
|
|
}
|
|
} else if (id === "tray" && Config.bar.popouts.tray) {
|
|
const tray = ch.item as Tray;
|
|
if (!Config.bar.tray.compact || (tray.expanded && !tray.expandIcon.contains(mapToItem(tray.expandIcon, tray.implicitWidth / 2, y)))) {
|
|
const index = Math.floor(((y - top - tray.padding * 2 + tray.spacing) / tray.layout.implicitHeight) * tray.items.count);
|
|
const trayItem = tray.items.itemAt(index);
|
|
if (trayItem) {
|
|
popouts.currentName = `traymenu${index}`;
|
|
popouts.currentCenter = Qt.binding(() => trayItem.mapToItem(root, 0, trayItem.implicitHeight / 2).y);
|
|
popouts.hasCurrent = true;
|
|
} else {
|
|
popouts.hasCurrent = false;
|
|
}
|
|
} else {
|
|
popouts.hasCurrent = false;
|
|
tray.expanded = true;
|
|
}
|
|
} else if (id === "activeWindow" && Config.bar.popouts.activeWindow && Config.bar.activeWindow.showOnHover) {
|
|
popouts.currentName = id.toLowerCase();
|
|
popouts.currentCenter = (ch.item as Item).mapToItem(root, 0, (ch.item as Item).implicitHeight / 2).y ?? 0;
|
|
popouts.hasCurrent = true;
|
|
}
|
|
}
|
|
|
|
function handleWheel(y: real, angleDelta: point): void {
|
|
const ch = childAt(width / 2, y) as WrappedLoader;
|
|
if (ch?.id === "workspaces" && Config.bar.scrollActions.workspaces) {
|
|
// Workspace scroll
|
|
const mon = (Config.bar.workspaces.perMonitorWorkspaces ? Hypr.monitorFor(screen) : Hypr.focusedMonitor);
|
|
const specialWs = mon?.lastIpcObject.specialWorkspace.name;
|
|
if (specialWs?.length > 0)
|
|
Hypr.dispatch(`togglespecialworkspace ${specialWs.slice(8)}`);
|
|
else if (angleDelta.y < 0 || (Config.bar.workspaces.perMonitorWorkspaces ? mon.activeWorkspace?.id : Hypr.activeWsId) > 1)
|
|
Hypr.dispatch(`workspace r${angleDelta.y > 0 ? "-" : "+"}1`);
|
|
} else if (y < screen.height / 2 && Config.bar.scrollActions.volume) {
|
|
// Volume scroll on top half
|
|
if (angleDelta.y > 0)
|
|
Audio.incrementVolume();
|
|
else if (angleDelta.y < 0)
|
|
Audio.decrementVolume();
|
|
} else if (Config.bar.scrollActions.brightness) {
|
|
// Brightness scroll on bottom half
|
|
const monitor = Brightness.getMonitorForScreen(screen);
|
|
if (angleDelta.y > 0)
|
|
monitor.setBrightness(monitor.brightness + Config.services.brightnessIncrement);
|
|
else if (angleDelta.y < 0)
|
|
monitor.setBrightness(monitor.brightness - Config.services.brightnessIncrement);
|
|
}
|
|
}
|
|
|
|
spacing: Tokens.spacing.normal
|
|
|
|
Repeater {
|
|
id: repeater
|
|
|
|
model: Config.bar.entries
|
|
|
|
DelegateChooser {
|
|
role: "id"
|
|
|
|
DelegateChoice {
|
|
roleValue: "spacer"
|
|
delegate: WrappedLoader {
|
|
Layout.fillHeight: enabled
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "logo"
|
|
delegate: WrappedLoader {
|
|
sourceComponent: OsIcon {}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "workspaces"
|
|
delegate: WrappedLoader {
|
|
sourceComponent: Workspaces {
|
|
screen: root.screen
|
|
fullscreen: root.fullscreen
|
|
}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "activeWindow"
|
|
delegate: WrappedLoader {
|
|
Layout.fillWidth: true
|
|
visible: !root.fullscreen
|
|
sourceComponent: ActiveWindow {
|
|
bar: root
|
|
monitor: Brightness.getMonitorForScreen(root.screen)
|
|
}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "tray"
|
|
delegate: WrappedLoader {
|
|
visible: !root.fullscreen
|
|
sourceComponent: Tray {}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "clock"
|
|
delegate: WrappedLoader {
|
|
visible: !root.fullscreen
|
|
sourceComponent: Clock {}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "statusIcons"
|
|
delegate: WrappedLoader {
|
|
visible: !root.fullscreen
|
|
sourceComponent: StatusIcons {}
|
|
}
|
|
}
|
|
DelegateChoice {
|
|
roleValue: "power"
|
|
delegate: WrappedLoader {
|
|
sourceComponent: Power {
|
|
visibilities: root.visibilities
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
component WrappedLoader: Loader {
|
|
required enabled
|
|
required property string id
|
|
required property int index
|
|
|
|
function findFirstEnabled(): Item {
|
|
const count = repeater.count;
|
|
for (let i = 0; i < count; i++) {
|
|
const item = repeater.itemAt(i);
|
|
if (item?.enabled)
|
|
return item;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function findLastEnabled(): Item {
|
|
for (let i = repeater.count - 1; i >= 0; i--) {
|
|
const item = repeater.itemAt(i);
|
|
if (item?.enabled)
|
|
return item;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
asynchronous: true
|
|
Layout.alignment: Qt.AlignHCenter
|
|
|
|
// Cursed ahh thing to add padding to first and last enabled components
|
|
Layout.topMargin: findFirstEnabled() === this ? root.vPadding : 0
|
|
Layout.bottomMargin: findLastEnabled() === this ? root.vPadding : 0
|
|
|
|
visible: enabled
|
|
active: enabled
|
|
}
|
|
}
|