summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--widget/bar/Bar.tsx14
1 files changed, 10 insertions, 4 deletions
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<NiriWorkspace[]> = Variable(getWorkspacesByOutput(args.connector))
- .poll(1000, () => getWorkspacesByOutput(args.connector));
+ const workspaces: Variable<NiriWorkspace[]> = Variable.derive([niri], (_event) => {
+ return getWorkspacesByOutput(args.connector);
+ });
const workspaceIndices = [...Array(10).keys()];
return <box cssClasses={["Workspaces"]}>