From 2b1c64b21a3261a1c14a6295acacf88f05c3439e Mon Sep 17 00:00:00 2001 From: matt1432 Date: Fri, 15 Nov 2024 22:07:59 -0500 Subject: [PATCH] feat(ags): only show icon of current client on binto --- nixosModules/ags/config/widgets/bar/binto.tsx | 11 +--- .../config/widgets/bar/items/current-icon.tsx | 66 +++++++++++++++++++ 2 files changed, 69 insertions(+), 8 deletions(-) create mode 100644 nixosModules/ags/config/widgets/bar/items/current-icon.tsx diff --git a/nixosModules/ags/config/widgets/bar/binto.tsx b/nixosModules/ags/config/widgets/bar/binto.tsx index 982f8bac..f53540b3 100644 --- a/nixosModules/ags/config/widgets/bar/binto.tsx +++ b/nixosModules/ags/config/widgets/bar/binto.tsx @@ -2,11 +2,10 @@ import { Astal, Gtk } from 'astal/gtk3'; import Audio from './items/audio'; import Clock from './items/clock'; -import CurrentClient from './items/current-client'; +import CurrentIcon from './items/current-icon'; import Network from './items/network'; import NotifButton from './items/notif-button'; import SysTray from './items/tray'; -import Workspaces from './items/workspaces'; import BarRevealer from './fullscreen'; import Separator from '../misc/separator'; @@ -25,11 +24,11 @@ export default () => ( > - + - + @@ -39,10 +38,6 @@ export default () => ( - - - - diff --git a/nixosModules/ags/config/widgets/bar/items/current-icon.tsx b/nixosModules/ags/config/widgets/bar/items/current-icon.tsx new file mode 100644 index 00000000..7d66facd --- /dev/null +++ b/nixosModules/ags/config/widgets/bar/items/current-icon.tsx @@ -0,0 +1,66 @@ +import { bind, Variable } from 'astal'; + +import AstalApps from 'gi://AstalApps'; +const Applications = AstalApps.Apps.new(); + +import AstalHyprland from 'gi://AstalHyprland'; +const Hyprland = AstalHyprland.get_default(); + +import { hyprMessage } from '../../../lib'; + + +export default () => { + const visibleIcon = Variable(false); + const focusedIcon = Variable(''); + + let lastFocused: string | undefined; + + const updateVars = ( + client: AstalHyprland.Client | null = Hyprland.get_focused_client(), + ) => { + lastFocused = client?.get_address(); + const app = Applications.fuzzy_query( + client?.get_class() ?? '', + )[0]; + + const icon = app?.iconName; + + if (icon) { + visibleIcon.set(true); + focusedIcon.set(icon); + } + else { + visibleIcon.set(false); + } + + const id = client?.connect('notify::title', (c) => { + if (c.get_address() !== lastFocused) { + c.disconnect(id); + } + }); + }; + + updateVars(); + Hyprland.connect('notify::focused-client', () => updateVars()); + Hyprland.connect('client-removed', () => updateVars()); + Hyprland.connect('client-added', async() => { + try { + updateVars(Hyprland.get_client(JSON.parse(await hyprMessage('j/activewindow')).address)); + } + catch (e) { + console.log(e); + } + }); + + return ( + + + + ); +};