From 89f4fe33042356d9a3e5ec96d06d64b29e533091 Mon Sep 17 00:00:00 2001
From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>
Date: Sat, 18 Jan 2025 17:53:33 +1100
Subject: bar: fix null pointer errors

---
 src/modules/bar.tsx | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

(limited to 'src/modules/bar.tsx')

diff --git a/src/modules/bar.tsx b/src/modules/bar.tsx
index 05d7e9f..97787fc 100644
--- a/src/modules/bar.tsx
+++ b/src/modules/bar.tsx
@@ -125,7 +125,9 @@ const MediaPlaying = () => {
 };
 
 const Workspace = ({ idx }: { idx: number }) => {
-    let wsId = Math.floor((hyprland.focusedWorkspace.id - 1) / config.wsPerGroup) * config.wsPerGroup + idx;
+    let wsId = hyprland.focusedWorkspace
+        ? Math.floor((hyprland.focusedWorkspace.id - 1) / config.wsPerGroup) * config.wsPerGroup + idx
+        : idx;
     return (
         <button
             halign={Gtk.Align.CENTER}
@@ -139,6 +141,7 @@ const Workspace = ({ idx }: { idx: number }) => {
                     );
 
                 self.hook(hyprland, "notify::focused-workspace", () => {
+                    if (!hyprland.focusedWorkspace) return;
                     wsId = Math.floor((hyprland.focusedWorkspace.id - 1) / config.wsPerGroup) * config.wsPerGroup + idx;
                     self.toggleClassName("focused", hyprland.focusedWorkspace.id === wsId);
                     update();
@@ -147,7 +150,7 @@ const Workspace = ({ idx }: { idx: number }) => {
                 self.hook(hyprland, "client-moved", update);
                 self.hook(hyprland, "client-removed", update);
 
-                self.toggleClassName("focused", hyprland.focusedWorkspace.id === wsId);
+                self.toggleClassName("focused", hyprland.focusedWorkspace?.id === wsId);
                 update();
             }}
         />
@@ -159,7 +162,7 @@ const Workspaces = () => (
         onScroll={(_, event) => {
             const activeWs = hyprland.focusedClient?.workspace.name;
             if (activeWs?.startsWith("special:")) hyprland.dispatch("togglespecialworkspace", activeWs.slice(8));
-            else if (event.delta_y > 0 || hyprland.focusedWorkspace.id > 1)
+            else if (event.delta_y > 0 || hyprland.focusedWorkspace?.id > 1)
                 hyprland.dispatch("workspace", (event.delta_y < 0 ? "-" : "+") + 1);
         }}
     >
-- 
cgit v1.2.3-freya

