feat(eww): add mediaplayer widget, fix workspaces, window and audio widgets

This commit is contained in:
João Dias
2024-11-24 11:14:12 -03:00
parent 88af8f4a37
commit f7ae531efd
11 changed files with 115 additions and 71 deletions
+1
View File
@@ -31,6 +31,7 @@
:space-evenly false
(clock)
(window)
(media)
)
(box :class "widgets-right"
:halign "end"
+9
View File
@@ -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
-13
View File
@@ -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
-37
View File
@@ -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
+14 -4
View File
@@ -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/')
}
+12
View File
@@ -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
+12
View File
@@ -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
+30 -2
View File
@@ -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;
+21
View File
@@ -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}"
"󰒭")
)
)
+4 -6
View File
@@ -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}")
)
+11 -8
View File
@@ -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}")
)
)
)
)