From 74065af3d2aa576e8b183d720033c3eece3deb70 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Sat, 25 Jan 2025 00:24:15 -0800 Subject: [PATCH] Window client title now updates appropriately. (#741) * Window client title now updates appropriately. * Update src/components/bar/modules/window_title/helpers/title.ts --- .../bar/modules/window_title/helpers/title.ts | 22 +++++++++++++++++++ .../bar/modules/window_title/index.tsx | 3 ++- 2 files changed, 24 insertions(+), 1 deletion(-) diff --git a/src/components/bar/modules/window_title/helpers/title.ts b/src/components/bar/modules/window_title/helpers/title.ts index 8bf7e6a..c8cb4f7 100644 --- a/src/components/bar/modules/window_title/helpers/title.ts +++ b/src/components/bar/modules/window_title/helpers/title.ts @@ -1,6 +1,28 @@ import options from 'src/options'; import { capitalizeFirstLetter } from 'src/lib/utils'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; +import { hyprlandService } from 'src/lib/constants/services'; +import { bind, Variable } from 'astal'; + +export const clientTitle = Variable(''); +let clientBinding: Variable | undefined; + +function trackClientUpdates(client: AstalHyprland.Client): void { + clientBinding?.drop(); + clientBinding = undefined; + + if (!client) { + return; + } + + clientBinding = Variable.derive([bind(client, 'title')], (currentTitle) => { + clientTitle.set(currentTitle); + }); +} + +Variable.derive([bind(hyprlandService, 'focusedClient')], (client) => { + trackClientUpdates(client); +}); /** * Retrieves the matching window title details for a given window. diff --git a/src/components/bar/modules/window_title/index.tsx b/src/components/bar/modules/window_title/index.tsx index c77e797..348ecaa 100644 --- a/src/components/bar/modules/window_title/index.tsx +++ b/src/components/bar/modules/window_title/index.tsx @@ -5,7 +5,7 @@ import { hyprlandService } from 'src/lib/constants/services'; import AstalHyprland from 'gi://AstalHyprland?version=0.1'; import { onMiddleClick, onPrimaryClick, onScroll, onSecondaryClick } from 'src/lib/shared/eventHandlers'; import { bind, Variable } from 'astal'; -import { getTitle, getWindowMatch, truncateTitle } from './helpers/title'; +import { clientTitle, getTitle, getWindowMatch, truncateTitle } from './helpers/title'; import { Astal } from 'astal/gtk3'; const { leftClick, rightClick, middleClick, scrollDown, scrollUp } = options.bar.windowtitle; @@ -55,6 +55,7 @@ const ClientTitle = (): BarBoxChild => { bind(icon), bind(truncation), bind(truncation_size), + bind(clientTitle), ], ( client: AstalHyprland.Client,