vivien / i3blocks-contrib

Official repository for community contributed blocklets
https://github.com/vivien/i3blocks
Other
1.31k stars 488 forks source link

calendar: calendar display at wrong position for different i3 bar position #485

Open shivankgarg98 opened 1 year ago

shivankgarg98 commented 1 year ago

Expected behavior

calendar(yad) dialog should display near calendar button when it is clicked on i3block.

Actual behavior

calendar dialog is displayed at right bottom if i3 bar position is set at top. It is far from i3block button and mouse pointer, making it unclickable.

i3blocks config relevant to blocklet(s)

[calendar] interval=30 LABEL= HEIGHT=180 WIDTH=220

Output of any relevant other commands that might help diagnostics

BLOCK_X, BLOCK_Y are not used properly to calculate calendar position.

Suggested Fix

Many people use calendar on upper right corner, using below suggestion can fix the issue (tested on my installation) Using multiple cases for different i3 bar position and checking screen constraint can give generic fix.

# calculate length of screen
RESOLUTION_X=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1) 
# check calendar is not crossing the screen boundary
posX=$(($BLOCK_X + $WIDTH / 2 > $RESOLUTION_X ? $RESOLUTION_X - $WIDTH : $BLOCK_X - $WIDTH / 2))
posY=0
shivankgarg98 commented 1 year ago

https://ibb.co/RDYtQhX - this is how it looks on my system using above position for yad.

phcerdan commented 1 year ago

Thanks for the solution! If you have two monitors, the RESOLUTION_X will output two lines, one for each, I added head -n 1 to select the first one (primary monitor). RESOLUTION_X=$(xrandr --current | grep '*' | uniq | awk '{print $1}' | cut -d 'x' -f1 | head -n 1) I guess there are many ways to make that more resilient, but it works for me.