From f7ae531efd21f6f9e529a94bc9fb53b04a9aacf4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Dias?= Date: Sun, 24 Nov 2024 11:14:12 -0300 Subject: [PATCH] :sparkles: feat(eww): add mediaplayer widget, fix workspaces, window and audio widgets --- eww/eww.yuck | 1 + eww/scripts/active-workspace.sh | 9 ++++++++ eww/scripts/get-volume.sh | 13 ------------ eww/scripts/get-window.sh | 37 --------------------------------- eww/scripts/volume.sh | 18 ++++++++++++---- eww/scripts/window.sh | 12 +++++++++++ eww/scripts/workspaces.sh | 12 +++++++++++ eww/styles/bar.scss | 34 +++++++++++++++++++++++++++--- eww/widgets/media.yuck | 21 +++++++++++++++++++ eww/widgets/window.yuck | 10 ++++----- eww/widgets/workspaces.yuck | 19 ++++++++++------- 11 files changed, 115 insertions(+), 71 deletions(-) create mode 100644 eww/scripts/active-workspace.sh delete mode 100644 eww/scripts/get-volume.sh delete mode 100644 eww/scripts/get-window.sh create mode 100644 eww/scripts/window.sh create mode 100644 eww/scripts/workspaces.sh diff --git a/eww/eww.yuck b/eww/eww.yuck index 59253e4..69a2f15 100644 --- a/eww/eww.yuck +++ b/eww/eww.yuck @@ -31,6 +31,7 @@ :space-evenly false (clock) (window) + (media) ) (box :class "widgets-right" :halign "end" diff --git a/eww/scripts/active-workspace.sh b/eww/scripts/active-workspace.sh new file mode 100644 index 0000000..f8c07dc --- /dev/null +++ b/eww/scripts/active-workspace.sh @@ -0,0 +1,9 @@ +#!/usr/bin/env + +handle() { + case $1 in + workspace*) hyprctl -j activeworkspace | jq -c ;; + esac +} + +socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done diff --git a/eww/scripts/get-volume.sh b/eww/scripts/get-volume.sh deleted file mode 100644 index 6639b00..0000000 --- a/eww/scripts/get-volume.sh +++ /dev/null @@ -1,13 +0,0 @@ -#!/usr/bin/env bash - -WP_VOLUME=$(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -e 's/^Volume: //') - -formatted_volume() { - if ! [ $WP_VOLUME == "1.00" ]; then - echo "${WP_VOLUME#0.}%" - else - echo "100%" - fi -} - -formatted_volume \ No newline at end of file diff --git a/eww/scripts/get-window.sh b/eww/scripts/get-window.sh deleted file mode 100644 index bec309e..0000000 --- a/eww/scripts/get-window.sh +++ /dev/null @@ -1,37 +0,0 @@ -#!/usr/bin/env bash - -ACTIVE_WINDOW=$(hyprctl -j activewindow) -WINDOW_TITLE=$(echo $ACTIVE_WINDOW | jq '.title' | sed -e 's/^\"//' -e 's/\"$//') -WINDOW_CLASS=$(echo $ACTIVE_WINDOW | jq '.class' | sed -e 's/^\"//' -e 's/\"$//') -WINDOW_NAME="$WINDOW_CLASS: $WINDOW_TITLE" -WINDOW_CHAR_LIMIT="50" - -# Rewrite window names -case $WINDOW_CLASS in - "zen-alpha") - WINDOW_NAME="Zen Browser" - ;; - "firefox" | "org.mozilla.firefox") - WINDOW_NAME="Mozilla Firefox" - ;; -esac - -#case $WINDOW_TITLE in -# "example with window title") # case -# WINDOW_NAME="you just learned!" # statement -# ;; # breaks -#esac - -#case $WINDOW_NAME in -# "example with window name") # case -# WINDOW_NAME="something cool" # statement -# ;; # breaks -#esac - -if ! [[ $WINDOW_CLASS == "null" ]]; then - echo "${WINDOW_NAME:0:WINDOW_CHAR_LIMIT}" - eww update widget_window_visible=true -else - echo "" - eww update widget_window_visible=false -fi diff --git a/eww/scripts/volume.sh b/eww/scripts/volume.sh index ec82a19..44ff958 100644 --- a/eww/scripts/volume.sh +++ b/eww/scripts/volume.sh @@ -2,17 +2,27 @@ # Note: $SCROLL is defined by eww -$DEFAULT_INCREASE='5' +DEFAULT_INCREASE='5' Guess_increase_decrease() { - local $CURRENT_VOL=$(wpctl get-volume "@DEFAULT_AUDIO_SINK@") + CURRENT_VOL=$(Translate_volume_to_int) + + if [[ $SCROLL == "up" ]]; then + if [[ $(awk "BEGIN { ($CURRENT_VOL+$DEFAULT_INCREASE) }") > 100 ]]; then + echo "1.00" + else + echo "$DEFAULT_INCREASE%+" + fi + else + echo "$DEFAULT_INCREASE%-" + fi } Update_volume() { - local $UPDATED_VOL=$(Guess_increase_decrease) + UPDATED_VOL=$(Guess_increase_decrease) wpctl set-volume "@DEFAULT_AUDIO_SINK@" "$UPDATED_VOL" } Translate_volume_to_int() { - echo $(wpctl get-volume "@DEFAULT_AUDIO_SINK@" | sed -e "s/^Volume: //" -e "s/^1.//1") + echo $(wpctl get-volume @DEFAULT_AUDIO_SINK@ | sed -e 's/Volume: //' -e 's/^1\./1/' -e 's/^0.//' -e 's/^00/0/') } diff --git a/eww/scripts/window.sh b/eww/scripts/window.sh new file mode 100644 index 0000000..4f4d09e --- /dev/null +++ b/eww/scripts/window.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# output current window before event trigger to prevent issues +hyprctl -j activewindow | jq -c + +handle() { + case $1 in + activewindow*) hyprctl -j activewindow | jq -c ;; + esac +} + +socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done diff --git a/eww/scripts/workspaces.sh b/eww/scripts/workspaces.sh new file mode 100644 index 0000000..7b933b4 --- /dev/null +++ b/eww/scripts/workspaces.sh @@ -0,0 +1,12 @@ +#!/usr/bin/env bash + +# display workspaces before checking for events +hyprctl -j workspaces | jq -c + +handle() { + case $1 in + workspace*) hyprctl -j workspaces | jq -c ;; + esac +} + +socat -U - UNIX-CONNECT:$XDG_RUNTIME_DIR/hypr/$HYPRLAND_INSTANCE_SIGNATURE/.socket2.sock | while read -r line; do handle "$line"; done diff --git a/eww/styles/bar.scss b/eww/styles/bar.scss index bbbf6e5..4a18189 100644 --- a/eww/styles/bar.scss +++ b/eww/styles/bar.scss @@ -84,12 +84,22 @@ menu { border-radius: 16px; & > button { - padding: 0 9px; - border-radius: 50%; + padding: 0 0; + border-radius: 16px; margin: 0 2px; background: darken($color1, 20); - } + font-weight: 500; + &.active { + background: $color1; + font-weight: 600; + padding: 0 24px; + } + + &:not(.active) { + padding: 0 10px; + } + } } .workspaces button:hover { color: $color1; @@ -111,6 +121,24 @@ menu { } } +.mediaplayer { + border-radius: 12px; + box-shadow: inset 0 0 0px 2px $color3; + padding: 0 4px; + + & > label { + margin: 0 4px; + padding-right: 5px; + border-right: 2px solid $color3; + } + + & > button { + padding: 0 7px; + border-radius: 4px; + margin: 2px 2px; + } +} + .notifications button { padding-left: 11px; padding-right: 11px; diff --git a/eww/widgets/media.yuck b/eww/widgets/media.yuck index e69de29..ece0fdc 100644 --- a/eww/widgets/media.yuck +++ b/eww/widgets/media.yuck @@ -0,0 +1,21 @@ + +(deflisten media :initial "{}" +`python3 ./scripts/mediaplayer.py`) + +(defwidget media [] + (box :class "mediaplayer" + :space-evenly false + :visible true + + (label :text "${media.title} - ${media.artist}") + (button :class "previous" + :onclick "playerctl previous --player=${media.player}" + "󰒮") + (button :class "toggle play-pause" + :onclick "playerctl play-pause --player=${media.player}" + { media.status == "playing" ? "󰏤" : "󰐊" }) + (button :class "next" + :onclick "playerctl next --player=${media.player}" + "󰒭") + ) +) diff --git a/eww/widgets/window.yuck b/eww/widgets/window.yuck index 7b97ae2..a417191 100644 --- a/eww/widgets/window.yuck +++ b/eww/widgets/window.yuck @@ -1,10 +1,8 @@ -(defpoll windowInfo :interval "250ms" -"sh ./scripts/get-window.sh") - -(defvar widget_window_visible true) +(deflisten active_window :initial "" +`sh -c 'source ./scripts/window.sh; get_active_window'`) (defwidget window [] - (button :visible "${widget_window_visible}" - "${windowInfo}") + (button :visible { active_window.class == "null" ? false : true } + "${active_window.class}: ${active_window.title}") ) diff --git a/eww/widgets/workspaces.yuck b/eww/widgets/workspaces.yuck index 68ccf44..6207791 100644 --- a/eww/widgets/workspaces.yuck +++ b/eww/widgets/workspaces.yuck @@ -1,15 +1,18 @@ -(deflisten json_workspaces - :initial "[{1: {}, 2:{}}]" -`hyprctl -j workspaces`) +(deflisten json_workspaces :initial '[{"id": "1"},{"id": "2"}]' +`sh ./scripts/workspaces.sh`) + +(deflisten json_active_workspace :initial '{ "id": 1 }' +`sh ./scripts/active-workspace.sh`) (defwidget workspaces [] - (eventbox :onscroll "[[ {} =~ up ]] && hyprctl dispatch workspace e+1 || hyprctl dispatch workspace e-1" + (eventbox :onscroll "[[ {} == up ]] && hyprctl dispatch workspace e+1 || hyprctl dispatch workspace e-1" (box :class "workspaces" - (for i in json_workspaces - (button :onclick "hyprctl dispatch workspace ${i}" - "${i[0].num}") + (for workspace in json_workspaces + (button :onclick "hyprctl dispatch workspace ${workspace.id}" + :class "${ json_active_workspace.id == workspace.id ? "active" : "default" }" + "${workspace.id}") ) ) ) - ) +)