I'm working on building a status bar using Eww on Hyprland, and I want to color the currently active workspace differently. I've successfully set up polling for displaying the workspaces using `defpoll`, but I'm running into a problem with the active workspace variable. When I use `defpoll` for the active workspace, the variable remains empty when I check `eww state`. This results in an error in the logs indicating a failure to handle an empty value. I've tried using `jq` to format the output with no luck. What might be going wrong? Also, I'm on Arch Linux if that helps!
2 Answers
It's good to mention your distro! The error arises from the active workspace being empty, which can happen if there are no active windows in that workspace. You could look at the output from `hyprctl -j monitors` instead. That way, it'll provide the active workspace info even if it's a bit trickier to fetch. This approach might save you some headaches—just make sure to carefully format the JSON output using `jq`. Hope that helps!
The error you're seeing is probably because the active workspace ID is being pulled from an empty string or null value. I recommend checking out this thread on GitHub where someone had a similar issue. Instead of using `hyprctl activeworkspace -j`, you can try using `hyprctl -j monitors`, which contains a field for the active workspace. You'd need to parse that output with `jq` to get the right ID. Here's a quick script that might help:
```bash
#! /bin /sh
CURRENT_DESKTOP=$(echo -e "$(hyprctl -j monitors)" | jq -r '.[0] | "(.activeWorkspace.id)"')
... // further parsing for workspaces
```
This should simplify what you're trying to achieve!
That sounds a bit more complex than I was hoping for. I understand now why the id would be empty, but it's frustrating when the terminal command works fine. I might just use that script for now, even if it feels like overkill.