diff --git a/modules/home/wayland/apps/eww/bar/css/_powermenu.scss b/modules/home/wayland/apps/eww/bar/css/_powermenu.scss new file mode 100644 index 0000000..efd3350 --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/css/_powermenu.scss @@ -0,0 +1,26 @@ +.powermenu-box { + padding-left: 2.5rem; + padding-right: 2.5rem; + padding-top: 3rem; + padding-bottom: 3rem; + margin:0 0 0 0; +} + +.powermenu-entry { + margin: 0 0.5rem; +} + +.powermenu-button { + background-color: $base02; + border-radius: 1rem; + transition: 0.3s; + padding: 3.25rem 4rem; +} + +.powermenu-button:hover { + background-color:$base03; +} + +.powermenu-icon { + font-size: 4rem; +} \ No newline at end of file diff --git a/modules/home/wayland/apps/eww/bar/css/_radio.scss b/modules/home/wayland/apps/eww/bar/css/_radio.scss index 5705e9f..7686c82 100644 --- a/modules/home/wayland/apps/eww/bar/css/_radio.scss +++ b/modules/home/wayland/apps/eww/bar/css/_radio.scss @@ -35,7 +35,6 @@ font-size: 20px; font-weight: bold; margin: $gaps-screen 0px; - } .btn_play { @@ -44,6 +43,11 @@ margin: 0 12px; } +.btn_play:hover { + color: $base07; +} + + .station_list { border-right-color: $base03; border-right-style: solid; @@ -60,4 +64,15 @@ margin-right: $gaps-screen; background-color: $base00; border-radius: $border-radius; + border-color: $base00; + border-style: solid; + border-width: $border-width; +} + +.station_art:hover { + border-color: $base04; +} + +.station_sel { + border-color: $base03; } \ No newline at end of file diff --git a/modules/home/wayland/apps/eww/bar/css/_sys.scss b/modules/home/wayland/apps/eww/bar/css/_sys.scss index 76dc192..30800b7 100644 --- a/modules/home/wayland/apps/eww/bar/css/_sys.scss +++ b/modules/home/wayland/apps/eww/bar/css/_sys.scss @@ -71,3 +71,8 @@ color: $base0B; margin: $gaps-screen; padding: .5em; } + + .sys-label { + font-weight: bolder; + color: $base04; + } \ No newline at end of file diff --git a/modules/home/wayland/apps/eww/bar/eww.scss b/modules/home/wayland/apps/eww/bar/eww.scss index 1750531..afe2cdb 100644 --- a/modules/home/wayland/apps/eww/bar/eww.scss +++ b/modules/home/wayland/apps/eww/bar/eww.scss @@ -14,6 +14,7 @@ @import 'css/net'; @import 'css/clock'; @import 'css/radio'; +@import 'css/powermenu'; * { all: unset; diff --git a/modules/home/wayland/apps/eww/bar/eww.yuck b/modules/home/wayland/apps/eww/bar/eww.yuck index 2d0431b..d59afa1 100644 --- a/modules/home/wayland/apps/eww/bar/eww.yuck +++ b/modules/home/wayland/apps/eww/bar/eww.yuck @@ -7,6 +7,7 @@ (include "windows/calendar.yuck") (include "windows/sys.yuck") (include "windows/radio.yuck") +(include "windows/powermenu.yuck") (defwidget left [] diff --git a/modules/home/wayland/apps/eww/bar/modules/clock.yuck b/modules/home/wayland/apps/eww/bar/modules/clock.yuck index 35f11a4..65a9c96 100644 --- a/modules/home/wayland/apps/eww/bar/modules/clock.yuck +++ b/modules/home/wayland/apps/eww/bar/modules/clock.yuck @@ -20,9 +20,11 @@ :orientation "v" (button :onclick "${EWW_CMD} open --toggle calendar" + :onrightclick "${EWW_CMD} open --toggle powermenu" :class "day" day) (button :onclick "${EWW_CMD} open --toggle calendar" + :onrightclick "${EWW_CMD} open --toggle powermenu" :class "month" month))))))) (defpoll hour :interval "15s" "date '+%H'") diff --git a/modules/home/wayland/apps/eww/bar/scripts/radio b/modules/home/wayland/apps/eww/bar/scripts/radio index 7a1e0e2..fcfd6d3 100755 --- a/modules/home/wayland/apps/eww/bar/scripts/radio +++ b/modules/home/wayland/apps/eww/bar/scripts/radio @@ -4,97 +4,91 @@ function get_time_ms { date -u +%s%3N } - URL_BASE="https://www.radiorecord.ru/api" -STATIONS=$(curl -s "$URL_BASE/stations/" | jq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})') MPV_PID_FILE="/tmp/mpv_radio_pid" RADIO_ID_FILE="/tmp/radio_id" +STATIONS="[]" + +PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 ) +RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) +RADIO_URL="" +INFO='{"id":null,"artist":null,"song":null,"image600":null}' +PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 )) +STATUS="{}" + get_radio() { - echo "$STATIONS" | jq -r --argjson sel_id "$1" 'map(select(.id == $sel_id)).[0]' + echo "$STATIONS" | jq -r --argjson sel_id "$RADIO_ID" 'map(select(.id == $sel_id)).[0]' } get_song() { - echo $(curl -s "$URL_BASE/station/history/?id=$1" | jq '.result.history[0] | ({id, artist, song, image600})') + echo $(curl -s "$URL_BASE/station/history/?id=$RADIO_ID" | jq '.result.history[0] | ({id, artist, song, image600})') } -# Function to play audio stream -start() { - radio_url=$(get_radio $1 | jq -r ".stream_hls") - if [ -f "$MPV_PID_FILE" ]; then - mpv_pid=$(cat "$MPV_PID_FILE") - if ps -p "$mpv_pid" > /dev/null; then - kill -SIGTERM "$mpv_pid" - fi - fi - mpv "$radio_url" & echo $! > "$MPV_PID_FILE" - echo $1 > "$RADIO_ID_FILE" -} - -# Function to pause/play the audio stream -pause() { - if [ -f "$MPV_PID_FILE" ]; then - mpv_pid=$(cat "$MPV_PID_FILE") - if ps -p "$mpv_pid" > /dev/null; then - kill -9 "$mpv_pid" - fi - fi - rm -f $MPV_PID_FILE -} - -play() { - pause - radio_id=$(cat "$RADIO_ID_FILE") - start "$radio_id" -} - -toggle() { +update() { PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 ) RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 )) +} + +start() { + STATIONS=$(curl -s "$URL_BASE/stations/" | jq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})') + RADIO_URL=$(get_radio | jq -r '.stream_hls') + if [ "$PAUSED" = 0 ]; then + kill -9 $PID + fi + mpv "$RADIO_URL" & echo $! > "$MPV_PID_FILE" + echo $RADIO_ID > "$RADIO_ID_FILE" +} + + +toggle() { if [ "$PAUSED" = 1 ]; then - play + echo $RADIO_ID $PID + start else - pause + kill -9 "$PID" + rm -f $MPV_PID_FILE fi } status() { - PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 ) - RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) - PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 )) - INFO=$1 - RES=$(jq -cn --argjson pid "$PID" --argjson stations "$STATIONS" --argjson radio_id "$RADIO_ID" --argjson is_paused "$PAUSED" --argjson info "$INFO" '{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations}') - echo "$RES" + echo $(jq -cnr --argjson pid "$PID" --argjson stations "$STATIONS" --argjson radio_id "$RADIO_ID" --argjson is_paused "$PAUSED" --argjson info "$INFO" '{"is_paused": $is_paused, "song": $info, "radio": $radio_id, "stations": $stations}') } status_loop() { - RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) - INFO=$(get_song "$RADIO_ID") - status "$INFO" - last_time_info=$(get_time_ms) - last_time=$(get_time_ms) + STATUS=$(status) + echo $STATUS + STATIONS=$(curl -s "$URL_BASE/stations/" | jq --argjson ids '[507,522,523,536,537,42532,42602]' '.result.stations | map(select(.id | IN($ids[]))) | map({id, title, stream_hls, icon_fill_white})') + last_time_info=0 + last_time=0 while true; do - RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) - current_time=$(get_time_ms) - delta=$((current_time - last_time_info)) - if [[ $delta -gt 15000 ]]; then - NEW_INFO=$(get_song $RADIO_ID) - INFO=$(echo "$INFO" "$NEW_INFO" | jq -s ' reduce .[] as $item ( {}; . + ( - reduce ($item | to_entries[]) as $entry ( {}; - if $entry.value != null then .[$entry.key] = $entry.value else . end - )) )') - - last_time_info=$(get_time_ms) - fi current_time=$(get_time_ms) delta=$((current_time - last_time)) + delta_i=$((current_time - last_time_info)) if [[ $delta -gt 1000 ]]; then - status "$INFO" - last_time=$(get_time_ms) + PID=$( [ -e "$MPV_PID_FILE" ] && cat "$MPV_PID_FILE" || echo 0 ) + RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) + PAUSED=$(( $PID == 0 && $RADIO_ID > 0 ? 1 : 0 )) + NEW_STATUS=$(status) + if [[ "$NEW_STATUS" != "$STATUS" ]]; then + STATUS=$NEW_STATUS + echo $STATUS + fi + last_time=$current_time + fi + if [[ $delta_i -gt 15000 ]]; then + if [ "$PAUSED" = 1 ]; then + INFO="{\"id\":null,\"artist\":null,\"song\":null,\"image600\": \"$(get_radio | jq -r '.icon_fill_white')\"}" + else + INFO=$(echo "$INFO" "$(get_song)" | jq -s ' reduce .[] as $item ( {}; . + ( + reduce ($item | to_entries[]) as $entry ( {}; if $entry.value != null then .[$entry.key] = $entry.value else . end + )) )') + fi + last_time_info=$current_time fi done } @@ -102,25 +96,13 @@ status_loop() { # Main script case "$1" in "start") - start "$2" + RADIO_ID=$2 + start ;; "toggle") toggle ;; - "pause") - pause - ;; - "play") - play - ;; - "status") - RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) - INFO=$(get_song $RADIO_ID) - status "$INFO" - ;; *) - RADIO_ID=$( [ -e "$RADIO_ID_FILE" ] && cat "$RADIO_ID_FILE" || echo 0 ) - echo $(get_song $RADIO_ID) status_loop ;; esac diff --git a/modules/home/wayland/apps/eww/bar/windows/powermenu.yuck b/modules/home/wayland/apps/eww/bar/windows/powermenu.yuck new file mode 100644 index 0000000..a6da69e --- /dev/null +++ b/modules/home/wayland/apps/eww/bar/windows/powermenu.yuck @@ -0,0 +1,45 @@ +(defwidget powermenu_entry [label icon onclick] + (box :orientation "v" :space-evenly false :class "powermenu-entry" + (button :class "powermenu-button" :onclick {onclick} + :tooltip "${label}" + (label :class "powermenu-icon" :text {icon}) + ) + ) +) + +(defwidget powermenu [] + (box :orientation "h" :space-evenly true :valign "center" :halign "center" :class "powermenu-box" + (powermenu_entry :label "Power off" + :icon "󰐥" + :onclick "systemctl poweroff") + (powermenu_entry :label "Reboot" + :icon "󰜉" + :onclick "systemctl reboot") + (powermenu_entry :label "Lock" + :icon "󰍁" + :onclick "sleep 0.1 && gtklock & eww close powermenu &") + + (powermenu_entry :label "Suspend" + :icon "󰤄" + :onclick "sleep 0.1 && gtklock & systemctl suspend & eww close powermenu &") + + (powermenu_entry :label "Sign out" + :icon "󰗼" + :onclick "hyprctl dispatch exit 0") + + (powermenu_entry :label "Cancel" + :icon "󰅖" + :onclick "eww close powermenu") + ) +) + +(defwindow powermenu + :monitor 0 + :stacking "overlay" + :geometry (geometry + :anchor "center" + :width "120%" + :height "120%") + :namespace "eww-blur" + (powermenu) +) \ No newline at end of file diff --git a/modules/home/wayland/apps/eww/bar/windows/radio.yuck b/modules/home/wayland/apps/eww/bar/windows/radio.yuck index 5513d29..a6555ea 100644 --- a/modules/home/wayland/apps/eww/bar/windows/radio.yuck +++ b/modules/home/wayland/apps/eww/bar/windows/radio.yuck @@ -12,8 +12,8 @@ :x "0%" :y "0%" :anchor "bottom right" - :width "200px" - :height "300px") + :width "0px" + :height "0px") (radio-win)) @@ -32,9 +32,7 @@ (box :class "album_art" - :vexpand "false" - :hexpand "false" - :style "background-size:cover; background-image: url('${radio.song.image600}');") + :style "background-size:cover; background-image: url('${radio.song.image600?:'https://www.radiorecord.ru/upload/stations_images/record_image600_white_fill.png'}');") (box :space-evenly false :orientation "v" @@ -42,14 +40,14 @@ :halign "center" :class "song" :wrap "true" - :limit-width 25 - :text "${radio.song.song}") + :limit-width 18 + :text "${radio.song.song?:'...'}") (label :halign "center" :class "artist" :wrap "true" :limit-width 22 - :text "${radio.song.artist}") + :text "${radio.song.artist?:'...'}") (box :space-evenly true :orientation "h" @@ -61,9 +59,9 @@ :onclick "${EWW_CMD} update radio_rev=${!radio_rev}" (box "󰷐")) - (button + (button :class "btn_play" - :timeout "1s" + :timeout "2s" :onclick "scripts/radio toggle" "${radio.is_paused==1 ? "󰐌" : "󰏥"}") @@ -91,8 +89,8 @@ (for station in {radio.stations} (button - :class "station_art" - :timeout "1s" + :class "station_art ${(radio.radio == station.id)?'station_sel':''}" + :timeout "2s" :onclick "scripts/radio start ${station.id}" :tooltip "${station.title}" :style "background-size:cover; background-image: url('${station.icon_fill_white}');" @@ -104,7 +102,7 @@ (defwidget radio-button [] (button - :onclick "${EWW_CMD} open --toggle radio" + :onclick "${EWW_CMD} open --toggle --no-daemonize radio" (box :class "module" :orientation "v" diff --git a/modules/home/wayland/apps/eww/bar/windows/sys.yuck b/modules/home/wayland/apps/eww/bar/windows/sys.yuck index 5a61094..3419971 100644 --- a/modules/home/wayland/apps/eww/bar/windows/sys.yuck +++ b/modules/home/wayland/apps/eww/bar/windows/sys.yuck @@ -3,8 +3,8 @@ (box :orientation "v" :space-evenly false + (box :class "sys-label" "CPU") (box - :orientation "v" (for core in {EWW_CPU.cores} (box @@ -27,22 +27,23 @@ (box :orientation "v" :space-evenly false + (box :class "sys-label" "GPU") (progress - :value {gpu.devices[0].GRBM2.CommandProcessor-Compute.value} + :value {gpu.devices[0].GRBM2?.CommandProcessor-Compute?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" :tooltip "Compute" ) (progress - :value {gpu.devices[0].GRBM2.CommandProcessor-Fetcher.value} + :value {gpu.devices[0].GRBM2?.CommandProcessor-Fetcher?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" :tooltip "Fetcher" ) (progress - :value {gpu.devices[0].GRBM2.CommandProcessor-Graphics.value} + :value {gpu.devices[0].GRBM2?.CommandProcessor-Graphics?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" @@ -50,21 +51,21 @@ ) (box :class "spacer") (progress - :value {gpu.devices[0].gpu_activity.GFX.value} + :value {gpu.devices[0]?.gpu_activity?.GFX?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" :tooltip "GFX" ) (progress - :value {gpu.devices[0].gpu_activity.Memory.value} + :value {gpu.devices[0]?.gpu_activity?.Memory?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" :tooltip "Memory" ) (progress - :value {gpu.devices[0].gpu_activity.MediaEngine.value} + :value {gpu.devices[0]?.gpu_activity?.MediaEngine?.value?:0.0} :orientation "h" :flipped true :class "gpu-core-usage" @@ -72,7 +73,7 @@ ) (box :class "spacer") (progress - :value {100*gpu.devices[0].VRAM.TotalVRAMUsage.value/gpu.devices[0].VRAM.TotalVRAM.value} + :value {100*(gpu.devices[0]?.VRAM?.TotalVRAMUsage?.value?:0.0)/(gpu.devices[0]?.VRAM?.TotalVRAM?.value?:1.0)} :orientation "h" :flipped true :class "gpu-core-usage" @@ -83,7 +84,9 @@ (defwidget ram-sys-win [] (box + :orientation "v" :space-evenly false + (box :class "sys-label" "RAM") (progress :value {100*memory.used/memory.total} :orientation "h" diff --git a/modules/home/wayland/apps/waybar/default.nix b/modules/home/wayland/apps/waybar/default.nix index 18450b4..ae48203 100644 --- a/modules/home/wayland/apps/waybar/default.nix +++ b/modules/home/wayland/apps/waybar/default.nix @@ -220,7 +220,7 @@ in { "custom/powermenu" = { "format" = "{icon}"; "format-icons" = [ "󰐥" ]; - "on-click" = "wlogout"; + "on-click" = "eww open powermenu"; "tooltip" = false; }; "tray" = { diff --git a/modules/home/wayland/apps/waylock/default.nix b/modules/home/wayland/apps/waylock/default.nix index 73d9caf..998dac6 100755 --- a/modules/home/wayland/apps/waylock/default.nix +++ b/modules/home/wayland/apps/waylock/default.nix @@ -1,7 +1,7 @@ { lib, pkgs, config, ... }: { config = lib.mkIf (config.homecfg.wm == "Wayland") { - home.packages = with pkgs; [ swayidle swaylock-effects wlogout ]; + home.packages = with pkgs; [ swayidle swaylock-effects ]; xdg.configFile."swaylock/config".text = '' screenshots diff --git a/modules/home/wayland/hyprland/config.nix b/modules/home/wayland/hyprland/config.nix index ec00402..397d3d7 100755 --- a/modules/home/wayland/hyprland/config.nix +++ b/modules/home/wayland/hyprland/config.nix @@ -147,6 +147,8 @@ windowrulev2 = float,class:^(org.telegram.desktop)$,title:^(Media viewer)$ windowrulev2 = center,class:^(org.telegram.desktop)$,title:^(Media viewer)$ + layerrule = blur,^(eww-blur) + #binds bind = SUPER, RETURN, exec, kitty