From 45cb701b3b42dfbebf4c36406fdc3214c67db837 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Fri, 27 Dec 2024 01:03:40 -0800 Subject: [PATCH] Hyprland clients are now fetched from a binding instead of get_clients(). (#642) * Get clients from bindings. * Active workspaces now show properly on all workspace configurations. * Filter clients by current workspace. --- .../bar/modules/workspaces/helpers/utils.ts | 14 +++++++------- .../bar/modules/workspaces/workspaces.tsx | 13 +++++-------- 2 files changed, 12 insertions(+), 15 deletions(-) diff --git a/src/components/bar/modules/workspaces/helpers/utils.ts b/src/components/bar/modules/workspaces/helpers/utils.ts index 955537c..5d2c033 100644 --- a/src/components/bar/modules/workspaces/helpers/utils.ts +++ b/src/components/bar/modules/workspaces/helpers/utils.ts @@ -194,25 +194,25 @@ export const renderClassnames = ( monitor: number, i: number, ): string => { + const isWorkspaceActive = hyprlandService.focusedWorkspace?.id === i || isWorkspaceActiveOnMonitor(monitor, i); + const isActive = isWorkspaceActive ? 'active' : ''; + if (showIcons) { - return 'workspace-icon txt-icon bar'; + return `workspace-icon txt-icon bar ${isActive}`; } if (showNumbered || showWsIcons) { - const numActiveInd = - hyprlandService.focusedWorkspace?.id === i || isWorkspaceActiveOnMonitor(monitor, i) - ? numberedActiveIndicator - : ''; + const numActiveInd = isWorkspaceActive ? numberedActiveIndicator : ''; const wsIconClass = showWsIcons ? 'txt-icon' : ''; const smartHighlightClass = smartHighlight ? 'smart-highlight' : ''; - const className = `workspace-number can_${numberedActiveIndicator} ${numActiveInd} ${wsIconClass} ${smartHighlightClass}`; + const className = `workspace-number can_${numberedActiveIndicator} ${numActiveInd} ${wsIconClass} ${smartHighlightClass} ${isActive}`; return className.trim(); } - return 'default'; + return `default ${isActive}`; }; /** diff --git a/src/components/bar/modules/workspaces/workspaces.tsx b/src/components/bar/modules/workspaces/workspaces.tsx index fa3f924..d630aab 100644 --- a/src/components/bar/modules/workspaces/workspaces.tsx +++ b/src/components/bar/modules/workspaces/workspaces.tsx @@ -55,8 +55,9 @@ export const WorkspaceModule = ({ monitor }: WorkspaceModuleProps): JSX.Element bind(applicationIconFallback), bind(matugen), bind(smartHighlight), - + bind(hyprlandService, 'clients'), bind(hyprlandService, 'monitors'), + bind(ignored), bind(showAllActive), bind(hyprlandService, 'focusedWorkspace'), @@ -84,10 +85,9 @@ export const WorkspaceModule = ({ monitor }: WorkspaceModuleProps): JSX.Element applicationIconFallback: string, matugenEnabled: boolean, smartHighlightEnabled: boolean, + clients: AstalHyprland.Client[], monitorList: AstalHyprland.Monitor[], ) => { - const activeWorkspace = hyprlandService.focusedWorkspace?.id || -99999; - const workspacesToRender = getWorkspacesToRender( totalWorkspaces, workspaceList, @@ -149,11 +149,8 @@ export const WorkspaceModule = ({ monitor }: WorkspaceModuleProps): JSX.Element monitor, )} setup={(self) => { - self.toggleClassName('active', activeWorkspace === wsId); - self.toggleClassName( - 'occupied', - (hyprlandService.get_workspace(wsId)?.get_clients()?.length || 0) > 0, - ); + const currentWsClients = clients.filter((client) => client.workspace.id === wsId); + self.toggleClassName('occupied', currentWsClients.length > 0); }} />