navbar: add special workspace toggles

This commit is contained in:
2 * r + 2 * t 2025-04-08 16:52:38 +10:00
parent 276b207cf1
commit 10290bc427
2 changed files with 49 additions and 18 deletions

View file

@ -21,36 +21,37 @@
} }
&.current { &.current {
.pane-button { .nav-button {
background-color: scheme.$primary; background-color: scheme.$primary;
color: color.change(scheme.$base, $alpha: 1); color: color.change(scheme.$base, $alpha: 1);
} }
&:hover .pane-button, &:hover .nav-button,
&:focus .pane-button { &:focus .nav-button {
background-color: color.mix(scheme.$primary, scheme.$base, 80%); background-color: color.mix(scheme.$primary, scheme.$base, 80%);
} }
&:active .pane-button { &:active .nav-button {
background-color: color.mix(scheme.$primary, scheme.$base, 70%); background-color: color.mix(scheme.$primary, scheme.$base, 70%);
} }
} }
&:first-child .pane-button { &:first-child .nav-button {
margin-top: lib.s(10); margin-top: lib.s(10);
} }
&:last-child .pane-button { &:last-child .nav-button {
margin-bottom: lib.s(10); margin-bottom: lib.s(10);
} }
} }
.pane-button { .nav-button {
@include lib.rounded(20); @include lib.rounded(20);
@include lib.element-decel; @include lib.element-decel;
padding: lib.s(10) lib.s(8); padding: lib.s(10) lib.s(8);
margin: lib.s(5) lib.s(8); margin: lib.s(5) lib.s(8);
min-width: lib.s(40);
.icon { .icon {
font-size: lib.s(28); font-size: lib.s(28);

View file

@ -1,11 +1,16 @@
import type { Monitor } from "@/services/monitors"; import type { Monitor } from "@/services/monitors";
import { capitalize } from "@/utils/strings";
import type { AstalWidget } from "@/utils/types"; import type { AstalWidget } from "@/utils/types";
import { Variable } from "astal"; import { bind, execAsync, Variable } from "astal";
import { Astal, Gtk } from "astal/gtk3"; import { Astal, Gtk } from "astal/gtk3";
import { navbar as config } from "config"; import { navbar as config } from "config";
import AstalHyprland from "gi://AstalHyprland"; import AstalHyprland from "gi://AstalHyprland";
import Pango from "gi://Pango";
import SideBar, { awaitSidebar, paneNames, switchPane, type PaneName } from "./sidebar"; import SideBar, { awaitSidebar, paneNames, switchPane, type PaneName } from "./sidebar";
const specialWsNames = ["sysmon", "communication", "music", "todo"] as const;
type SpecialWsName = (typeof specialWsNames)[number];
const getPaneIcon = (name: PaneName) => { const getPaneIcon = (name: PaneName) => {
if (name === "dashboard") return "dashboard"; if (name === "dashboard") return "dashboard";
if (name === "audio") return "tune"; if (name === "audio") return "tune";
@ -15,13 +20,11 @@ const getPaneIcon = (name: PaneName) => {
return "date_range"; return "date_range";
}; };
const getPaneName = (name: PaneName) => { const getSpecialWsIcon = (name: SpecialWsName) => {
if (name === "dashboard") return "Dash"; if (name === "sysmon") return "speed";
if (name === "audio") return "Audio"; if (name === "communication") return "communication";
if (name === "connectivity") return "Conn"; if (name === "music") return "music_note";
if (name === "packages") return "Pkgs"; return "checklist";
if (name === "notifpane") return "Alrts";
return "Time";
}; };
const hookIsCurrent = ( const hookIsCurrent = (
@ -50,17 +53,40 @@ const PaneButton = ({
}) => ( }) => (
<button <button
cursor="pointer" cursor="pointer"
onClick={() => switchPane(monitor, name)} onClicked={() => switchPane(monitor, name)}
setup={self => hookIsCurrent(self, sidebar, name, c => self.toggleClassName("current", c))} setup={self => hookIsCurrent(self, sidebar, name, c => self.toggleClassName("current", c))}
> >
<box vertical className="pane-button"> <box vertical className="nav-button">
<label className="icon" label={getPaneIcon(name)} /> <label className="icon" label={getPaneIcon(name)} />
<revealer <revealer
transitionType={Gtk.RevealerTransitionType.SLIDE_DOWN} transitionType={Gtk.RevealerTransitionType.SLIDE_DOWN}
transitionDuration={150} transitionDuration={150}
setup={self => hookIsCurrent(self, sidebar, name, c => self.set_reveal_child(c))} setup={self => hookIsCurrent(self, sidebar, name, c => self.set_reveal_child(c))}
> >
<label className="label" label={getPaneName(name)} /> <label truncate wrapMode={Pango.WrapMode.WORD_CHAR} className="label" label={capitalize(name)} />
</revealer>
</box>
</button>
);
const SpecialWsButton = ({ name }: { name: SpecialWsName }) => (
<button
className={bind(AstalHyprland.get_default(), "focusedClient").as(c =>
c?.get_workspace().get_name() === `special:${name}` ? "current" : ""
)}
cursor="pointer"
onClicked={() => execAsync(`caelestia toggle ${name}`).catch(console.error)}
>
<box vertical className="nav-button">
<label className="icon" label={getSpecialWsIcon(name)} />
<revealer
transitionType={Gtk.RevealerTransitionType.SLIDE_DOWN}
transitionDuration={150}
revealChild={bind(AstalHyprland.get_default(), "focusedClient").as(
c => c?.get_workspace().get_name() === `special:${name}`
)}
>
<label truncate wrapMode={Pango.WrapMode.WORD_CHAR} className="label" label={capitalize(name)} />
</revealer> </revealer>
</box> </box>
</button> </button>
@ -113,6 +139,10 @@ export default ({ monitor }: { monitor: Monitor }) => {
{paneNames.map(n => ( {paneNames.map(n => (
<PaneButton monitor={monitor} name={n} sidebar={sidebar} /> <PaneButton monitor={monitor} name={n} sidebar={sidebar} />
))} ))}
<box vexpand />
{specialWsNames.map(n => (
<SpecialWsButton name={n} />
))}
</box> </box>
</eventbox> </eventbox>
</window> </window>