From 17f46b149a52edb610a18b63bb123f18cbe9a948 Mon Sep 17 00:00:00 2001 From: hesam-init Date: Sat, 29 Jun 2024 09:10:43 +0330 Subject: [PATCH] refactor: eww workspaces --- .../hyprland/eww/scripts/workspace.py | 42 --------------- .../hyprland/eww/scripts/workspace/get-active | 6 +++ .../eww/scripts/workspace/get-workspaces | 9 ++++ .../hyprland/eww/scripts/workspace/set-active | 21 ++++++++ hypr-configs/hyprland/eww/scripts/workspaces | 54 ------------------- .../hyprland/eww/src/_definitions.yuck | 7 +-- .../hyprland/eww/src/sidebar/main.yuck | 25 ++++----- 7 files changed, 53 insertions(+), 111 deletions(-) delete mode 100755 hypr-configs/hyprland/eww/scripts/workspace.py create mode 100755 hypr-configs/hyprland/eww/scripts/workspace/get-active create mode 100755 hypr-configs/hyprland/eww/scripts/workspace/get-workspaces create mode 100755 hypr-configs/hyprland/eww/scripts/workspace/set-active delete mode 100755 hypr-configs/hyprland/eww/scripts/workspaces diff --git a/hypr-configs/hyprland/eww/scripts/workspace.py b/hypr-configs/hyprland/eww/scripts/workspace.py deleted file mode 100755 index c56729c..0000000 --- a/hypr-configs/hyprland/eww/scripts/workspace.py +++ /dev/null @@ -1,42 +0,0 @@ -#!/usr/bin/env python3 - -import subprocess -import json -import os -import i3ipc - -eww_bin= [subprocess.getoutput("which eww"), "-c", f"{os.getcwd()}"] - -def get_workspaces(i3): - result = i3.get_workspaces() - - active = [] - - for i in range(1, 6): - active.append(dict( - focused = False, - empty = True, - name = i - )) - - for res in result: - if not res.output == "eDP-1": continue - if res.num%10-1 > 4 or res.num%10-1 < 0: - continue - active[res.num%10-1]["empty"] = False - if res.focused: - active[res.num%10-1]["focused"] = True - - return active - -def update(i3, e): - print(json.dumps(get_workspaces(i3)), flush=True) - -def main(): - i3 = i3ipc.Connection(auto_reconnect=True) - update(i3, None) - i3.on(i3ipc.Event.WORKSPACE, update) - i3.main() - -if __name__ == "__main__": - main() diff --git a/hypr-configs/hyprland/eww/scripts/workspace/get-active b/hypr-configs/hyprland/eww/scripts/workspace/get-active new file mode 100755 index 0000000..bfefc83 --- /dev/null +++ b/hypr-configs/hyprland/eww/scripts/workspace/get-active @@ -0,0 +1,6 @@ +#!/usr/bin/env bash + +hyprctl monitors -j | jq '.[] | select(.focused) | .activeWorkspace.id' + +socat -u UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock - | + stdbuf -o0 awk -F '>>|,' -e '/^workspace>>/ {print $2}' -e '/^focusedmon>>/ {print $3}' diff --git a/hypr-configs/hyprland/eww/scripts/workspace/get-workspaces b/hypr-configs/hyprland/eww/scripts/workspace/get-workspaces new file mode 100755 index 0000000..5b3d105 --- /dev/null +++ b/hypr-configs/hyprland/eww/scripts/workspace/get-workspaces @@ -0,0 +1,9 @@ +#!/usr/bin/env bash + +spaces() { + WORKSPACE_WINDOWS=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries') + + seq 1 6 | jq --argjson windows "${WORKSPACE_WINDOWS}" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})' +} + +spaces diff --git a/hypr-configs/hyprland/eww/scripts/workspace/set-active b/hypr-configs/hyprland/eww/scripts/workspace/set-active new file mode 100755 index 0000000..512ae96 --- /dev/null +++ b/hypr-configs/hyprland/eww/scripts/workspace/set-active @@ -0,0 +1,21 @@ +#!/usr/bin/env bash + +clamp() { + min=$1 + max=$2 + val=$3 + python -c "print(max($min, min($val, $max)))" +} + +direction=$1 +current=$2 + +if test "$direction" = "down"; then + target=$(clamp 1 10 $(($current + 1))) + echo "jumping to $target" + hyprctl dispatch workspace $target +elif test "$direction" = "up"; then + target=$(clamp 1 10 $(($current - 1))) + echo "jumping to $target" + hyprctl dispatch workspace $target +fi diff --git a/hypr-configs/hyprland/eww/scripts/workspaces b/hypr-configs/hyprland/eww/scripts/workspaces deleted file mode 100755 index 33838b1..0000000 --- a/hypr-configs/hyprland/eww/scripts/workspaces +++ /dev/null @@ -1,54 +0,0 @@ -#!/bin/bash - -SOCKET="/tmp/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock" - -spaces() { - local workspace_windows=$(hyprctl workspaces -j | jq 'map({key: .id | tostring, value: .windows}) | from_entries') - seq 1 5 | jq --argjson windows "$workspace_windows" --slurp -Mc 'map(tostring) | map({id: ., windows: ($windows[.]//0)})' -} - -clamp() { - python -c "print(max($1, min($3, $2)))" -} - -get_workspaces() { - spaces - socat -u UNIX-CONNECT:"$SOCKET" - | while read -r; do - spaces - done -} - -get_active_workspace() { - hyprctl monitors -j | jq '.[] | select(.focused) | .activeWorkspace.id' - socat -u UNIX-CONNECT:"$SOCKET" - | stdbuf -o0 awk -F '>>|,' '/^workspace>>/ {print $2} /^focusedmon>>/ {print $3}' -} - -change_workspace() { - local direction=$1 current=$2 target - - if [[ "$direction" == "down" ]]; then - target=$(clamp 1 9 $((current + 1))) - elif [[ "$direction" == "up" ]]; then - target=$(clamp 1 9 $((current - 1))) - else - echo "Invalid direction" >&2 - return 1 - fi - - echo "Jumping to $target" - hyprctl dispatch workspace "$target" -} - -main() { - case $1 in - get-all-workspaces) get_workspaces ;; - get-active-workspace) get_active_workspace ;; - change) change_workspace "$2" "$3" ;; - *) - echo "Usage: $0 {gw|ga|c }" >&2 - exit 1 - ;; - esac -} - -main "$@" diff --git a/hypr-configs/hyprland/eww/src/_definitions.yuck b/hypr-configs/hyprland/eww/src/_definitions.yuck index f8627bd..a42b455 100644 --- a/hypr-configs/hyprland/eww/src/_definitions.yuck +++ b/hypr-configs/hyprland/eww/src/_definitions.yuck @@ -42,7 +42,7 @@ (defvar revealMicrophone false) (defvar revealBrightness false) (defvar revealControlpanel false) -(defvar revealSystray false) +(defvar revealSystray true) ; Dock (deflisten tasksjson :initial "[]" "./scripts/tasklist.py") @@ -50,8 +50,9 @@ ; Workspaces (defvar show_no_of_windows false) -(defpoll workspacesjson :initial "[]" :interval "60s" "./scripts/workspaces get-all-workspaces") -(defpoll current_workspace :initial "0" :interval "50ms" "./scripts/workspaces get-active-workspace") +(defpoll workspacesjson :initial "[]" :interval "60s" "./scripts/workspace/get-workspaces") +(deflisten current_workspace :initial "1" "./scripts/workspace/get-active") + ; Notifications (deflisten notifications :initial '{ diff --git a/hypr-configs/hyprland/eww/src/sidebar/main.yuck b/hypr-configs/hyprland/eww/src/sidebar/main.yuck index f9960d6..e8da810 100644 --- a/hypr-configs/hyprland/eww/src/sidebar/main.yuck +++ b/hypr-configs/hyprland/eww/src/sidebar/main.yuck @@ -62,7 +62,7 @@ :class "bottom_modules" :vexpand false :hexpand false - ; (stray) + ; (systemtray) (sliders) (clock) ; (battery) @@ -71,7 +71,7 @@ (defwidget workspaces [] (eventbox :cursor "pointer" - :onscroll "./scripts/workspaces change {} ${current_workspace}" + :onscroll "./scripts/workspace/set-active {} ${current_workspace}" :onhover "${EWW_CMD} update show_no_of_windows=true" :onhoverlost "${EWW_CMD} update show_no_of_windows=false" (box @@ -88,10 +88,11 @@ (revealer :reveal { workspace.id == current_workspace } - :transition "slidedown" + :transition "slideup" + :duration 500 (box - :height 55 + :height 50 ) ) ) @@ -116,7 +117,7 @@ :cursor "pointer" (label :text "" :halign "center" :class "launchicon" :style "padding: 2px 0px;")))) -(defwidget stray [] +(defwidget systemtray [] (box :class "widget" :space-evenly false @@ -125,14 +126,14 @@ (eventbox :onclick "${EWW_CMD} update revealSystray=${!revealSystray}" (label :angle {!revealSystray ? 90 : 270} :class "revealtouch" :tooltip "reveal systray" :text "")) + (revealer - :reveal revealSystray + :reveal revealSystray :transition "slideup" - (systray - :icon_size 20 - :pack-direction "down" - :hexpand true - :vexpand true)) + (systray + :icon_size 6 + :prepend-new true + )) )) (defwidget clock [] @@ -141,7 +142,7 @@ :onclick "${EWW_CMD} open calendar --toggle" (box :orientation "v" - :space-evenly false + :space-evenly false :class "widget clock" (label :text thour)