mirror of
https://github.imc.re/void-land/hyprland-void-dots
synced 2025-06-07 21:03:43 +02:00
refactor: eww workspaces
This commit is contained in:
parent
09970d3479
commit
17f46b149a
7 changed files with 53 additions and 111 deletions
|
@ -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()
|
6
hypr-configs/hyprland/eww/scripts/workspace/get-active
Executable file
6
hypr-configs/hyprland/eww/scripts/workspace/get-active
Executable file
|
@ -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}'
|
9
hypr-configs/hyprland/eww/scripts/workspace/get-workspaces
Executable file
9
hypr-configs/hyprland/eww/scripts/workspace/get-workspaces
Executable file
|
@ -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
|
21
hypr-configs/hyprland/eww/scripts/workspace/set-active
Executable file
21
hypr-configs/hyprland/eww/scripts/workspace/set-active
Executable file
|
@ -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
|
|
@ -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 <direction> <current>}" >&2
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
main "$@"
|
|
@ -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 '{
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Add table
Reference in a new issue