popup-calendar: fix positions

This commit is contained in:
Sad-Soul-Eater 2019-02-23 00:43:19 +02:00 committed by x70b1
parent 414e8d1640
commit 466927f976
2 changed files with 29 additions and 20 deletions

View File

@ -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: Change these values if you want:
```sh ```sh
BAR_HEIGHT=22
YAD_WIDTH=200 YAD_WIDTH=200
YAD_HEIGHT=200 YAD_HEIGHT=200
BOTTOM=false
DATE="$(date +"%a %d %H:%M")" 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 ```ini
for_window [class="Yad"] floating enable for_window [class="Yad" title="yad-calendar"] floating enable
``` ```

View File

@ -1,27 +1,36 @@
#!/bin/sh #!/bin/sh
BAR_HEIGHT=22
YAD_WIDTH=200 YAD_WIDTH=200
YAD_HEIGHT=200 YAD_HEIGHT=200
BOTTOM=false
DATE="$(date +"%a %d %H:%M")" DATE="$(date +"%a %d %H:%M")"
case "$1" in case "$1" in
--popup) --popup)
eval "$(xdotool getmouselocation --shell)" eval "$(xdotool getmouselocation --shell)"
eval "$(xdotool getdisplaygeometry --shell)"
if [ $BOTTOM = true ]; then # X
: $(( pos_y = Y - YAD_HEIGHT - 20 )) if [ "$((X + 35 + YAD_WIDTH / 2))" -gt "$WIDTH" ]; then #Right side
: $(( pos_x = X - (YAD_WIDTH / 2) )) : $((pos_x = WIDTH - 35 - YAD_WIDTH))
else elif [ "$((X - YAD_WIDTH / 2))" -lt 1 ]; then #Left side
: $(( pos_y = Y + 20 )) : $((pos_x = 10))
: $(( pos_x = X - (YAD_WIDTH / 2) )) else #Center
fi : $((pos_x = X - YAD_WIDTH / 2))
fi
yad --calendar --undecorated --fixed --close-on-unfocus --no-buttons \ # Y
--width=$YAD_WIDTH --height=$YAD_HEIGHT --posx=$pos_x --posy=$pos_y \ if [ "$((Y + YAD_HEIGHT))" -gt "$HEIGHT" ]; then #Bottom
> /dev/null : $((pos_y = HEIGHT - BAR_HEIGHT - YAD_HEIGHT))
;; else #Top
*) : $((pos_y = Y + BAR_HEIGHT))
echo "$DATE" 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 esac