From 87013fdfce9bc0972a75d1dc0a0ffc4044554364 Mon Sep 17 00:00:00 2001 From: Michael Bradley Date: Sun, 21 Apr 2024 23:16:23 -0400 Subject: [PATCH] Implement proper EWW first-workspace-on-monitor detection --- eww/eww.yuck | 4 ++-- eww/scripts/get-workspaces | 7 ++++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/eww/eww.yuck b/eww/eww.yuck index a7e7f3c..6852390 100644 --- a/eww/eww.yuck +++ b/eww/eww.yuck @@ -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" diff --git a/eww/scripts/get-workspaces b/eww/scripts/get-workspaces index 4854261..1741b2b 100755 --- a/eww/scripts/get-workspaces +++ b/eww/scripts/get-workspaces @@ -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