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:
```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
```

View File

@ -1,25 +1,34 @@
#!/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)"
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) ))
# 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
# 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 \
> /dev/null
--title="yad-calendar" >/dev/null
;;
*)
echo "$DATE"