From 80017cbeb91c37865f02b160c91f54d4b4fba39c Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Sun, 13 Apr 2025 23:11:12 +1000
Subject: navbar: add mediadisplay toggle

Also better error message for visualiser
---
 src/modules/navbar.tsx | 42 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

(limited to 'src/modules/navbar.tsx')

diff --git a/src/modules/navbar.tsx b/src/modules/navbar.tsx
index 3e2b1c9..35d3900 100644
--- a/src/modules/navbar.tsx
+++ b/src/modules/navbar.tsx
@@ -2,12 +2,15 @@ import type { Monitor } from "@/services/monitors";
 import { capitalize } from "@/utils/strings";
 import type { AstalWidget } from "@/utils/types";
 import { bind, execAsync, Variable } from "astal";
-import { Astal, Gtk } from "astal/gtk3";
+import { App, Astal, Gtk } from "astal/gtk3";
 import { navbar as config } from "config";
 import AstalHyprland from "gi://AstalHyprland";
 import Pango from "gi://Pango";
 import SideBar, { awaitSidebar, paneNames, switchPane, type PaneName } from "./sidebar";
 
+const layerNames = ["mediadisplay"] as const;
+type LayerName = `${(typeof layerNames)[number]}${number}`;
+
 const specialWsNames = ["sysmon", "communication", "music", "todo"] as const;
 type SpecialWsName = (typeof specialWsNames)[number];
 
@@ -20,6 +23,10 @@ const getPaneIcon = (name: PaneName) => {
     return "date_range";
 };
 
+const getLayerIcon = (name: LayerName) => {
+    return "graphic_eq";
+};
+
 const getSpecialWsIcon = (name: SpecialWsName) => {
     if (name === "sysmon") return "speed";
     if (name === "communication") return "communication";
@@ -76,6 +83,36 @@ const PaneButton = ({
     </button>
 );
 
+const LayerButton = ({ name }: { name: LayerName }) => (
+    <button
+        cursor="pointer"
+        onClicked={() => App.toggle_window(name)}
+        setup={self =>
+            self.hook(App, "window-toggled", (_, window) => {
+                if (window.name === name) self.toggleClassName("current", window.visible);
+            })
+        }
+    >
+        <box vertical className="nav-button">
+            <label className="icon" label={getLayerIcon(name)} />
+            <revealer
+                transitionType={Gtk.RevealerTransitionType.SLIDE_DOWN}
+                transitionDuration={150}
+                setup={self => {
+                    let visible = false;
+                    self.hook(config.showLabels, (_, v) => self.toggleClassName(v && visible));
+                    self.hook(App, "window-toggled", (_, window) => {
+                        if (window.name === name)
+                            self.toggleClassName("current", config.showLabels.get() && window.visible);
+                    });
+                }}
+            >
+                <label truncate wrapMode={Pango.WrapMode.WORD_CHAR} className="label" label={capitalize(name)} />
+            </revealer>
+        </box>
+    </button>
+);
+
 const SpecialWsButton = ({ name }: { name: SpecialWsName }) => {
     const revealChild = Variable.derive(
         [config.showLabels, bind(AstalHyprland.get_default(), "focusedClient")],
@@ -152,6 +189,9 @@ export default ({ monitor }: { monitor: Monitor }) => {
                     {paneNames.map(n => (
                         <PaneButton monitor={monitor} name={n} sidebar={sidebar} />
                     ))}
+                    {layerNames.map(n => (
+                        <LayerButton name={`${n}${monitor.id}`} />
+                    ))}
                     <box vexpand />
                     {specialWsNames.map(n => (
                         <SpecialWsButton name={n} />
-- 
cgit v1.2.3-freya

