diff --git a/.config/eww/eww.yuck b/.config/eww/eww.yuck index 638e77f..c945caa 100644 --- a/.config/eww/eww.yuck +++ b/.config/eww/eww.yuck @@ -36,7 +36,7 @@ :class 'center' :space-evenly false :spacing 5 - (music) + (media) ) ) diff --git a/.config/eww/widgets.scss b/.config/eww/widgets.scss index 4fcb09d..78a61b5 100644 --- a/.config/eww/widgets.scss +++ b/.config/eww/widgets.scss @@ -32,4 +32,9 @@ background: #420042; color: white; } + + &--chromium { + background: #1a73e8; + color: white; + } } diff --git a/.config/eww/widgets.yuck b/.config/eww/widgets.yuck index 5c5a7a3..df0406c 100644 --- a/.config/eww/widgets.yuck +++ b/.config/eww/widgets.yuck @@ -4,31 +4,27 @@ ) ) -(defwidget music [] - (box :class "music" +(defvar playerIcons `{ + "spotify": "", + "mpv": "", + "firefox": "", + "chromium": "" +}`) +(defwidget media [] + (box :class "media" :halign "center" :valign "center" - :class {music == '' + :class { playerctl == '' || objectlength(playerctl) == 0 ? 'music--off' - : arraylength(search(music, 'spotify')) >= 1 - ? 'music--spotify' - : arraylength(search(music, 'firefox')) >= 1 - ? 'music--firefox' - : arraylength(search(music, 'mpv')) >= 1 - ? 'music--mpv' - : 'music--on' - } - {arraylength(search(music, 'spotify')) >= 1 - ? replace(music, 'spotify', ' ') - : arraylength(search(music, 'firefox')) >= 1 - ? replace(music, 'firefox', ' ') - : arraylength(search(music, 'mpv')) >= 1 - ? replace(music, 'mpv', ' ') - : music - } + : matches(playerctl.player, 'spotify|firefox|mpv|chromium') + ? 'music--' + playerctl.player + : 'music--on' } + { matches(playerctl.player, 'spotify|firefox|mpv|chromium') + ? "${playerIcons[playerctl.player]} ${substring(playerctl.artist, 0, 20)}${strlength(playerctl.artist) >= 20 ? '…' : ''} | ${substring(playerctl.title, 0, 25)}${strlength(playerctl.title) >= 25 ? '…' : ''}" + : "${playerctl.player} - ${substring(playerctl.artist, 0, 20)}${strlength(playerctl.artist) >= 20 ? '…' : ''} | ${s ubstring(playerctl.title, 0, 25)}${strlength(playerctl.title) >= 25 ? '…' : ''}" } ) ) -(deflisten music :initial "" - "playerctl --follow metadata --format '{{ playerName }} {{ trunc(artist,20) }} | {{ trunc(title,25) }}' || true" +(deflisten playerctl :initial "" + `playerctl --follow metadata --format '{"player": "{{ playerName }}", "trackid": "{{ mpris:trackid }}", "length": "{{ duration(mpris:length) }}", "artUrl": "{{ mrpis:artUrl }}", "album": "{{ album }}", "albumArtist": "{{ xesam:albumArtist }}", "artist": "{{ artist }}", "autoRating": "{{ xesam:autoRating }}", "discNumber": "{{ xesam:discNumber }}", "title": "{{ title }}", "trackNumber": "{{ xesam:trackNumber }}", "url": "{{ xesam:url }}", "position": "{{ position }}"}'` )