I'm building a status bar using Eww in Hyprland, and I want to highlight the currently active workspace with a different color. I've set up a poll for the active workspaces using `defpoll` and that works fine. However, when I try to poll the active workspace with `defpoll activeworkspace`, the variable `activeworkspace` shows up empty when I check by running `eww state`, resulting in an error in my logs regarding turning an empty value into a JSON type. I've also attempted to manipulate the output of `hyprctl` using jq, but I can't seem to resolve this issue. Any insights or suggestions on how to get the active workspace variable to set properly? By the way, I'm using Arch Linux.
1 Answer
It looks like the error happens because the command is returning a null or empty string for the active workspace. You might want to check out this [discussion on GitHub](https://github.com/hyprwm/Hyprland/discussions/860). One suggestion was to use `hyprctl monitors` to get the active workspace directly from there instead of trying to get it via `activeworkspace`. Here's a snippet you could use to get the active workspace ID from the monitors output, which might work better for your situation.
```bash
#!/bin/sh
CURRENT_DESKTOP=$(echo -e "$(hyprctl -j monitors)" | jq -r '.[0] | "(.activeWorkspace.id)"')
...```
Try it out and see if that fixes the empty variable issue!
I see what you're saying about getting the ID from monitors, but I ran `hyprctl activeworkspace -j` directly in the terminal, and it seems to work fine there. Why would it be empty in Eww? This script seems to complicate things too much.