From c8e657f3f93e62e3dfa9383c729942c0bbc18a98 Mon Sep 17 00:00:00 2001 From: Jas Singh Date: Sun, 3 Nov 2024 20:23:55 -0800 Subject: [PATCH] Improve workspace module performance. (#430) * Move out rule fetching to on startup * Discard null tray values --- modules/bar/systray/index.ts | 2 +- modules/bar/workspaces/variants/occupied.ts | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/bar/systray/index.ts b/modules/bar/systray/index.ts index ea9ddfa..237c0db 100644 --- a/modules/bar/systray/index.ts +++ b/modules/bar/systray/index.ts @@ -12,7 +12,7 @@ const SysTray = (): BarBoxChild => { const items = Utils.merge( [systemtray.bind('items'), ignore.bind('value'), customIcons.bind('value')], (items, ignored, custIcons) => { - const filteredTray = items.filter(({ id }) => !ignored.includes(id)); + const filteredTray = items.filter(({ id }) => !ignored.includes(id) && id !== null); isVis.value = filteredTray.length > 0; diff --git a/modules/bar/workspaces/variants/occupied.ts b/modules/bar/workspaces/variants/occupied.ts index afffa97..49825f6 100644 --- a/modules/bar/workspaces/variants/occupied.ts +++ b/modules/bar/workspaces/variants/occupied.ts @@ -9,6 +9,7 @@ import { WorkspaceIconMap } from 'lib/types/workspace'; const { workspaces, monitorSpecific, workspaceMask, spacing, ignored, showAllActive } = options.bar.workspaces; export const occupiedWses = (monitor: number): BoxWidget => { + const workspaceRules = getWorkspaceRules(); return Widget.Box({ children: Utils.merge( [ @@ -61,9 +62,7 @@ export const occupiedWses = (monitor: number): BoxWidget => { ) => { const activeId = hyprland.active.workspace.id; let allWkspcs = range(totalWkspcs || 8); - const activeWorkspaces = wkSpaces.map((w) => w.id); - const workspaceRules = getWorkspaceRules(); // Sometimes hyprland doesn't have all the monitors in the list // so we complement it with monitors from the workspace list @@ -77,7 +76,7 @@ export const occupiedWses = (monitor: number): BoxWidget => { const workspacesWithRules = Object.keys(workspaceRules).reduce((acc: number[], k: string) => { return [...acc, ...workspaceRules[k]]; - }, [] as number[]); + }, []); const activesForMonitor = activeWorkspaces.filter((w) => { if ( @@ -99,7 +98,7 @@ export const occupiedWses = (monitor: number): BoxWidget => { allWkspcs = [...new Set([...allWkspcs, ...activeWorkspaces])]; } - return allWkspcs + const returnWs = allWkspcs .sort((a, b) => { return a - b; }) @@ -159,6 +158,7 @@ export const occupiedWses = (monitor: number): BoxWidget => { }), }); }); + return returnWs; }, ), });