From d440358ce6d4ec26dc8faf11c0e97e070d0fd596 Mon Sep 17 00:00:00 2001 From: Mora Unie Youer Date: Thu, 6 Mar 2025 12:33:48 +0300 Subject: feat: dynamic workspace updating --- widget/bar/Bar.tsx | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'widget') diff --git a/widget/bar/Bar.tsx b/widget/bar/Bar.tsx index d89dc5f..3caca92 100644 --- a/widget/bar/Bar.tsx +++ b/widget/bar/Bar.tsx @@ -13,6 +13,13 @@ type NiriWorkspace = { active_window_id: number | null, }; +// Niri Event Stream +// This is used to dynamically update variables that should not be polling and +// reacting as fast as it can be possible +// NOTE: this works only in non-systemd environment on NixOS +// TODO: I should better write a module for Astal that communicate with socket +const niri = Variable("").watch("niri msg event-stream", (out, _prev) => out); + function getWorkspaces(): NiriWorkspace[] { // NOTE: this works only in non-systemd environment on NixOS // TODO: try to use Niri socket if it is documented @@ -57,10 +64,9 @@ type WorkspacesArguments = { }; function Workspaces(args: WorkspacesArguments) { - // NOTE: it is pretty inefficient and not so much responsive - // TODO: it would be better to use Niri socket in the future - const workspaces: Variable = Variable(getWorkspacesByOutput(args.connector)) - .poll(1000, () => getWorkspacesByOutput(args.connector)); + const workspaces: Variable = Variable.derive([niri], (_event) => { + return getWorkspacesByOutput(args.connector); + }); const workspaceIndices = [...Array(10).keys()]; return -- cgit v1.2.3-70-g09d2