taylor85345 / hyprland-dotfiles

My dotfiles for Hyprland
248 stars 13 forks source link

Use json output for more robust parsing #5

Open kerneis-anssi opened 1 year ago

kerneis-anssi commented 1 year ago

Hi,

I just looked at your script here: https://github.com/taylor85345/hyprland-dotfiles/blob/816a0539e0ae6afdc7439a2726e94a12d3fe4b17/hypr/scripts/workspace#L4 (referenced from https://github.com/hyprwm/Hyprland/issues/747#issuecomment-1375142344)

I'm trying to get xmonad-like workspace behavior so this is exactly what I was looking for, thanks for making it public.

For your information, you could make your parsing more robust by using the json output of hyprctl, combined with jq: https://stedolan.github.io/jq/manual/

For instance, the following will display the id of the currently focused monitor:

hyprctl monitors -j|jq '.[]|select(.focused)|.id'
taylor85345 commented 1 year ago

I actually rewrote this script using jq a few months back, but jq is seriously slow, especially when running multiple queries back-to-back, which made workspace switching noticeably sluggish. Unless I can find a faster alternative to jq for parsing json, or figure out how to streamline the script to require fewer jq queries (I have some ideas), I will be sticking with the current grep+awk method for the time being and just dealing with the occasional breakage.

Honestly this would probably be better implemented as a plugin, but I don't have the C++ knowledge to make that happen.