diff --git a/polybar-scripts/popup-calendar/README.md b/polybar-scripts/popup-calendar/README.md index 33d6792..f8d4bfb 100644 --- a/polybar-scripts/popup-calendar/README.md +++ b/polybar-scripts/popup-calendar/README.md @@ -16,16 +16,16 @@ A small script that displays the date and opens a small popup calendar with YAD Change these values if you want: ```sh +BAR_HEIGHT=22 YAD_WIDTH=200 YAD_HEIGHT=200 -BOTTOM=false DATE="$(date +"%a %d %H:%M")" ``` -If you use a tiling window manager you should enable floating for `yad`. This example is for `i3wm`: +If you use a tiling window manager you should enable floating for `yad-calendar`. This example is for `i3wm`: ```ini -for_window [class="Yad"] floating enable +for_window [class="Yad" title="yad-calendar"] floating enable ``` diff --git a/polybar-scripts/popup-calendar/popup-calendar.sh b/polybar-scripts/popup-calendar/popup-calendar.sh index 0834d7b..65e142f 100644 --- a/polybar-scripts/popup-calendar/popup-calendar.sh +++ b/polybar-scripts/popup-calendar/popup-calendar.sh @@ -1,27 +1,36 @@ #!/bin/sh +BAR_HEIGHT=22 YAD_WIDTH=200 YAD_HEIGHT=200 -BOTTOM=false DATE="$(date +"%a %d %H:%M")" case "$1" in - --popup) - eval "$(xdotool getmouselocation --shell)" +--popup) + eval "$(xdotool getmouselocation --shell)" + eval "$(xdotool getdisplaygeometry --shell)" - if [ $BOTTOM = true ]; then - : $(( pos_y = Y - YAD_HEIGHT - 20 )) - : $(( pos_x = X - (YAD_WIDTH / 2) )) - else - : $(( pos_y = Y + 20 )) - : $(( pos_x = X - (YAD_WIDTH / 2) )) - fi + # X + if [ "$((X + 35 + YAD_WIDTH / 2))" -gt "$WIDTH" ]; then #Right side + : $((pos_x = WIDTH - 35 - YAD_WIDTH)) + elif [ "$((X - YAD_WIDTH / 2))" -lt 1 ]; then #Left side + : $((pos_x = 10)) + else #Center + : $((pos_x = X - YAD_WIDTH / 2)) + fi - yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \ - --width=$YAD_WIDTH --height=$YAD_HEIGHT --posx=$pos_x --posy=$pos_y \ - > /dev/null - ;; - *) - echo "$DATE" - ;; + # Y + if [ "$((Y + YAD_HEIGHT))" -gt "$HEIGHT" ]; then #Bottom + : $((pos_y = HEIGHT - BAR_HEIGHT - YAD_HEIGHT)) + else #Top + : $((pos_y = Y + BAR_HEIGHT)) + fi + + yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \ + --width=$YAD_WIDTH --height=$YAD_HEIGHT --posx=$pos_x --posy=$pos_y \ + --title="yad-calendar" >/dev/null + ;; +*) + echo "$DATE" + ;; esac