From 1f2b56496e0d78b7595d57b2b8fef26bbc09760e Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Thu, 16 Jan 2025 13:14:22 +1100 Subject: bar: use trayitem about_to_show + scroll events Scroll brightness on left, volume on right --- modules/bar.tsx | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) (limited to 'modules/bar.tsx') diff --git a/modules/bar.tsx b/modules/bar.tsx index 94b057e..5ed309e 100644 --- a/modules/bar.tsx +++ b/modules/bar.tsx @@ -6,6 +6,7 @@ import AstalHyprland from "gi://AstalHyprland"; import AstalNetwork from "gi://AstalNetwork"; import AstalNotifd from "gi://AstalNotifd"; import AstalTray from "gi://AstalTray"; +import AstalWp01 from "gi://AstalWp"; import { bar as config } from "../config"; import type { Monitor } from "../services/monitors"; import Players from "../services/players"; @@ -122,22 +123,22 @@ const Workspace = ({ idx }: { idx: number }) => { valign={Gtk.Align.CENTER} onClicked={() => hyprland.dispatch("workspace", String(wsId))} setup={self => { - const update = () => { + const update = () => self.toggleClassName( "occupied", hyprland.clients.some(c => c.workspace.id === wsId) ); - self.toggleClassName("focused", hyprland.focusedWorkspace.id === wsId); - }; self.hook(hyprland, "notify::focused-workspace", () => { wsId = Math.floor((hyprland.focusedWorkspace.id - 1) / config.wsPerGroup) * config.wsPerGroup + idx; + self.toggleClassName("focused", hyprland.focusedWorkspace.id === wsId); update(); }); self.hook(hyprland, "client-added", update); self.hook(hyprland, "client-moved", update); self.hook(hyprland, "client-removed", update); + self.toggleClassName("focused", hyprland.focusedWorkspace.id === wsId); update(); }} /> @@ -163,15 +164,24 @@ const Workspaces = () => ( @register() class TrayItemMenu extends astalify(Gtk.Menu) { + readonly item: AstalTray.TrayItem; + constructor(props: ConstructProps & { item: AstalTray.TrayItem }) { const { item, ...sProps } = props; super(sProps as any); + this.item = item; + this.hook(item, "notify::menu-model", () => this.bind_model(item.menuModel, null, true)); this.hook(item, "notify::action-group", () => this.insert_action_group("dbusmenu", item.actionGroup)); this.bind_model(item.menuModel, null, true); this.insert_action_group("dbusmenu", item.actionGroup); } + + popup_at_widget_bottom(widget: Gtk.Widget) { + this.item.about_to_show(); + this.popup_at_widget(widget, Gdk.Gravity.SOUTH, Gdk.Gravity.NORTH, null); + } } const TrayItem = (item: AstalTray.TrayItem) => { @@ -180,10 +190,9 @@ const TrayItem = (item: AstalTray.TrayItem) => {