From b6c847691f6119d3da33562382dcbfaebe4b5567 Mon Sep 17 00:00:00 2001 From: TolaMironcenko Date: Mon, 2 Sep 2024 10:24:25 +0700 Subject: [PATCH] added eww music widget --- eww/eww.scss | 75 +++++++++++++++++++++++++++++++++++++++++++++++ eww/eww.yuck | 57 +++++++++++++++++++++++++++++++++++ eww/scripts/music | 43 +++++++++++++++++++++++++++ eww/toggle_music | 9 ++++++ waybar/config | 1 + 5 files changed, 185 insertions(+) create mode 100644 eww/eww.scss create mode 100644 eww/eww.yuck create mode 100755 eww/scripts/music create mode 100755 eww/toggle_music diff --git a/eww/eww.scss b/eww/eww.scss new file mode 100644 index 0000000..51e434b --- /dev/null +++ b/eww/eww.scss @@ -0,0 +1,75 @@ +/** Global *******************************************/ +*{ + all: unset; + font-family: feather; + font-family: Iosevka; +} + +/** Background ***************************************/ +.bg { + // background-image: url("images/bg.png"); + background-color: #474D59; + opacity: 1; +} + +/** Generic window ***********************************/ +.genwin { + background-color: #2E3440; + border-radius: 16px; +} + +/** Music ***************************************/ +.album_art { + background-size: 240px; + min-height: 240px; + min-width: 240px; + margin: 20px; + border-radius: 14px; +} + +.song { + color: #8FBCBB; + font-size : 24px; + font-weight : bold; + margin : 40px 0px 0px 0px; +} + +.artist { + color: #EBCB8B; + font-size : 16px; + font-weight : normal; + margin : 0px 0px 15px 0px; +} + +.btn_prev, .btn_play, .btn_next { + font-family: Iosevka Nerd Font; +} +.btn_prev { + color: #EBCB8B; + font-size : 32px; + font-weight : normal; +} +.btn_play { + color: #A3BE8C; + font-size : 48px; + font-weight : bold; +} +.btn_next { + color: #EBCB8B; + font-size : 32px; + font-weight : normal; +} + +.music_bar scale trough highlight { + all: unset; + background-color: #B48EAD; + border-radius: 8px; +} +.music_bar scale trough { + all: unset; + background-color: #3A404C; + border-radius: 8px; + min-height: 20px; + min-width: 310px; + margin : 10px 0px 0px 0px; +} \ No newline at end of file diff --git a/eww/eww.yuck b/eww/eww.yuck new file mode 100644 index 0000000..7fd6918 --- /dev/null +++ b/eww/eww.yuck @@ -0,0 +1,57 @@ +; Music vars +(deflisten music_metadata "scripts/music listen-metadata") +(deflisten music_position "scripts/music listen-position") +(deflisten music_status "scripts/music listen-status") + +(defwidget music_progress_widget [] + (box + :class "music_progress_box" + :halign "center" + :space-evenly false + (box + :state "progress" + (scale + :onscroll "playerctl position {}" + :min 0 + :max "${music_metadata.length}" + :active true + :hexpand true + :vexpand true + :value "${music_position.position}" + ) + ) + ) +) + +; Music +(defwidget music [] + (box :class "genwin" :orientation "h" :space-evenly "false" :vexpand "false" :hexpand "false" + (box :class "album_art" :vexpand "false" :hexpand "false" :style "background-image: url('${music_metadata.arturl}');") + (box :orientation "v" :spacing 20 :space-evenly "false" :vexpand "false" :hexpand "false" + (label :halign "center" :class "song" :wrap "true" :limit-width 20 :text "${music_metadata.title}") + (label :halign "center" :class "artist" :wrap "true" :limit-width 15 :text "${music_metadata.artist}") + (box :orientation "h" :spacing 20 :halign "center" :space-evenly "true" :vexpand "false" :hexpand "false" + (button :class "btn_prev" :onclick "playerctl previous" "") + (button :class "btn_play" :onclick "playerctl play-pause" {"${music_status.status}" == "Playing" ? "" : ""}) + (button :class "btn_next" :onclick "playerctl next" "") + ) + (box :class "music_bar" :halign "center" :state "progress" + (scale + :onscroll "playerctl position {}" + :onclick "playerctl position {}" + :min 0 + :max "${music_metadata.length}" + :active true + :hexpand true + :vexpand true + :value "${music_position.position}" + ) + ) + ) + ) +) + +; music +(defwindow music :stacking "fg" :focusable "false" :screen 1 :monitor 0 + :geometry (geometry :x 100 :y 100 :width 610 :height 280) + (music)) diff --git a/eww/scripts/music b/eww/scripts/music new file mode 100755 index 0000000..d4488f4 --- /dev/null +++ b/eww/scripts/music @@ -0,0 +1,43 @@ +#!/bin/sh + +listen_metadata() { + fmt="\"artist\":\"{{artist}}\",\"title\":\"{{title}}\",\"album\":\"{{album}}\"" + fmt="$fmt,\"arturl\":\"{{mpris:artUrl}}\",\"length\":\"{{mpris:length}}\"" + fmt="$fmt,\"duration\":\"{{duration(mpris:length)}}\"" + playerctl --follow metadata --format "{$fmt}" | while read -r info; do + artist=$(echo -e $info | jq -r ".artist") + title=$(echo -e $info | jq -r ".title") + url=$(echo -e $info | jq -r ".arturl") + # cover=$(cover_art "$url") + # lyrics=$(lyrics_lines "$artist" "$title") + echo $info | jq -cr ". + {\"cover\":\"$cover\",\"lyrics\":\"$lyrics\"}" + done +} + +listen_position() { + fmt="{\"position\":\"{{position}}\",\"time\":\"{{duration(position)}}\"}" + playerctl --follow position --format "$fmt" +} + +listen_status() { + playerctl --follow status | while read -r playstatus; do + if [[ $playstatus != "Playing" ]]; then + icon="" + else + icon="" + fi + echo "{\"status\":\"$playstatus\",\"icon\":\"$icon\"}" + done +} + +case "$1" in + "listen-metadata") + listen_metadata + ;; + "listen-position") + listen_position + ;; + "listen-status") + listen_status + ;; +esac diff --git a/eww/toggle_music b/eww/toggle_music new file mode 100755 index 0000000..bf3a477 --- /dev/null +++ b/eww/toggle_music @@ -0,0 +1,9 @@ +#!/bin/sh + +if [ ! -f ~/.eww_music ]; then + eww --config ~/dotfiles/eww open music + echo $! > ~/.eww_music +else + eww --config ~/dotfiles/eww close music + rm ~/.eww_music +fi diff --git a/waybar/config b/waybar/config index 5dfd2e0..81a6319 100644 --- a/waybar/config +++ b/waybar/config @@ -229,6 +229,7 @@ "playing": "", "paused": "" }, + "on-click-right": "~/dotfiles/eww/toggle_music", // "ignored-players": ["firefox"] } }