Implement proper EWW first-workspace-on-monitor detection

This commit is contained in:
Michael Bradley 2024-04-21 23:16:23 -04:00
parent 2a718ec410
commit 87013fdfce
2 changed files with 6 additions and 5 deletions

View file

@ -20,7 +20,7 @@
(defwidget workspaces [monitor]
(box :space-evenly false :class "workspaces"
(for workspace in workspaces
(eventbox :onclick "hyprctl dispatch workspace ${workspace.id}" :visible {workspace.monitor == monitor} :class "${workspace.active ? "current" : ""} ${workspace.id < 4 ? "first" : ""}" :cursor "pointer"
(eventbox :onclick "hyprctl dispatch workspace ${workspace.id}" :visible {workspace.monitor == monitor} :class "${workspace.active ? "current" : ""} ${workspace.first ? "first" : ""}" :cursor "pointer"
(label :text {workspace.name})))))
@ -236,7 +236,7 @@
(above_bar))
(defwindow laptop
:monitor 0
:monitor "0x1502"
:geometry (geometry :x "0px"
:y "4px"
:width "1912px"

View file

@ -2,10 +2,11 @@
# From: https://wiki.hyprland.org/Useful-Utilities/Status-Bars/#eww
# TODO: add `first` attribute indicating if workspace is the first on its screen
spaces (){
ACTIVE_ID=$(hyprctl activeworkspace -j | jq -Mc ".id")
hyprctl workspaces -j | jq -Mc "map({id, name, monitor, active: [.id == $ACTIVE_ID][0]}) | sort_by(.id)"
ACTIVE_ID="$(hyprctl activeworkspace -j | jq -Mc '.id')"
WORKSPACES="$(hyprctl workspaces -j | jq -Mc 'sort_by(.name)')"
FIRSTS="$(echo "$WORKSPACES" | jq -Mc 'group_by(.monitor) | map(.[0].id)')"
echo "$WORKSPACES" | jq -Mc 'map(. as $ws | {id, name, monitor, active: (.id == '"$ACTIVE_ID"'), first: any('"$FIRSTS"' | .[] == $ws.id)})'
}
spaces