From 9de6be78f9a6528741c22ce4f3f3514f7b837188 Mon Sep 17 00:00:00 2001 From: retrozinndev Date: Mon, 13 Jan 2025 10:38:11 -0300 Subject: [PATCH] :recycle: eww(scripts/eww-window): separate actions into functions --- eww/scripts/eww-window.sh | 70 +++++++++++++++++++++++++++------------ eww/styles/general.scss | 12 +++---- 2 files changed, 54 insertions(+), 28 deletions(-) diff --git a/eww/scripts/eww-window.sh b/eww/scripts/eww-window.sh index eb7ebeb..96e982e 100644 --- a/eww/scripts/eww-window.sh +++ b/eww/scripts/eww-window.sh @@ -1,18 +1,10 @@ #!/usr/bin/env bash -# arg1,$1 should be one of the options listed in help command; -# arg2,$2 should be the literal window name as defined in eww configuration. +# arg1($1) should be one of the options listed in help command; +# arg2($2) should be the literal window name as defined in eww configuration. -check_if_empty() { - if [[ -z $1 ]]; then - echo "[error] argument $2 is empty!" - exit 1 - fi -} - -case "$1" in - --help | -h | help | h) - printf \ +function help_message() { + printf \ "This is a helper script that helps opening/closing eww windows on retrozinndev's Hyprland Dots, by checking if the window is already open/closed before doing anything, also changes eww state variables. @@ -40,6 +32,45 @@ Options: Developer: retrozinndev (João Dias), https://github.com/retrozinndev Issue tracker: https://github.com/retrozinndev/Hyprland-Dots/issues Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo." +} + +function send_log() { + case "$1" in + err*) + tag_color="\e[31m" + ;; + warn*) + tag_color="\e[33m" + ;; + *) + tag_color="\e[34m" + ;; + esac + + echo -e "[$tag_color$1\e[0m] $2" +} + +function check_if_empty() { + if [[ $1 == "" ]]; then + send_log "error" "argument \$1 is empty!" + help_message + exit 1 + fi +} + +function toggle_eww_window() { + if ! [[ $(eww active-windows) =~ "$1" ]]; then + eww open "$1" + eww update "window_state_$1=open" + else + eww close "$1" + eww update "window_state_$1=closed" + fi +} + +case "$1" in + --help | -h | help | h) + help_message ;; --open | open) @@ -48,7 +79,7 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo." eww open "$2" eww update "window_state_$2=open" else - echo "[info] Window '$2' is already open, ignored." + send_log "info" "Window '$2' is already open, ignored." fi ;; @@ -58,21 +89,16 @@ Licensed under the MIT License, as in retrozinndev's Hyprland-Dots repo." eww close "$2" eww update "window_state_$2=closed" else - echo "[info] Window '$2' is already closed, ignored." + send_log "info" "Window '$2' is already closed, ignored." fi ;; --toggle | toggle) check_if_empty $2 "WINDOW_NAME" - if ! [[ $(eww active-windows) =~ "$2" ]]; then - eww open "$2" - eww update "window_state_$2=open" - else - eww close "$2" - eww update "window_state_$2=closed" - fi + toggle_eww_window $2 ;; *) - echo "[error] Action not specified or incorrect command order. Good example: \`./eww-window.sh open bar\`" + send_log "error" "Action not specified or incorrect command order. Good example: \`./eww-window.sh open bar\`" + help_message ;; esac diff --git a/eww/styles/general.scss b/eww/styles/general.scss index 7ffa4db..11fbfae 100644 --- a/eww/styles/general.scss +++ b/eww/styles/general.scss @@ -84,24 +84,24 @@ button label { menu { background: $background; border-radius: 14px; - padding: 3px; + padding: 2px; & > menuitem { padding: 8px 24px; - border-radius: 5px; + border-radius: 4px; &:hover { background: $color1; } &:first-child { - border-top-left-radius: inherit; - border-top-right-radius: inherit; + border-top-left-radius: 12px; + border-top-right-radius: 12px; } &:last-child { - border-bottom-left-radius: inherit; - border-bottom-right-radius: inherit; + border-bottom-left-radius: 12px; + border-bottom-right-radius: 12px; } label {