fix: drawing images when the top line is removed causes it to keep

resizing for all eternity, which eventually makes your computer
unusable
This commit is contained in:
speedie 2023-04-01 13:59:31 +02:00
parent ad4c468abd
commit 1495140dbd
2 changed files with 38 additions and 13 deletions

View file

@ -170,12 +170,12 @@ drawitem(int x, int y, int w)
if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow);
if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(numbers) : TEXTW(numbers);
// mode indicator is always going to be at the right
if (hidemode) {
numberWidth += 2 * sp + borderwidth;
} else {
modeWidth += 2 * sp + borderwidth;
}
// mode indicator is always going to be at the right
if (hidemode) {
numberWidth += 2 * sp + borderwidth;
} else {
modeWidth += 2 * sp + borderwidth;
}
#if USEIMAGE
int ox = 0; // original x position
@ -375,7 +375,12 @@ drawmenu(void)
}
// why have an empty line?
if (hideprompt && hideinput && hidemode && hidematchcount) {
if ((hideprompt && hideinput && hidemode && hidematchcount
#if USEIMAGE
) && !image || hideimage) {
#else
)) {
#endif
y -= bh;
mh = (lines + 1) * bh - bh;
@ -384,6 +389,11 @@ drawmenu(void)
XResizeWindow(dpy, win, mw, mh);
drw_resize(drw, mw, mh);
}
#if USEIMAGE
else if (hideprompt && hideinput && hidemode && hidematchcount) {
y -= bh;
}
#endif
if (!hideprompt) x = drawprompt(x, y, w);
if (!hideinput) x = drawinput(x, y, w);

View file

@ -55,6 +55,8 @@ flipimage(void)
void
rotateimage(void)
{
if (!image) return;
rotation %= 4;
imlib_image_orientate(rotation);
}
@ -94,8 +96,16 @@ drawimage(void)
flipimage();
int leftmargin = imagegaps;
int wtr = 0;
int wta = 0;
if (mh != bh + height + imagegaps * 2) { // menu height cannot be smaller than image height
if (hideprompt && hideinput && hidemode && hidematchcount) {
wtr = bh;
} else {
wta = bh;
}
if (mh != bh + height + imagegaps * 2 - wtr) { // menu height cannot be smaller than image height
resizetoimageheight(height);
}
@ -103,16 +113,16 @@ drawimage(void)
if (!imageposition) { // top mode = 0
if (height > width)
width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, bh+imagegaps);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, wta+imagegaps);
} else if (imageposition == 1) { // bottom mode = 1
if (height > width)
width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, mh-height-imagegaps);
} else if (imageposition == 2) { // center mode = 2
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-bh-height)/2+bh);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-wta-height)/2+wta);
} else {
int minh = MIN(height, mh-bh-imagegaps*2);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (minh-height)/2+bh+imagegaps);
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (minh-height)/2+wta+imagegaps);
}
}
@ -176,6 +186,7 @@ void
loadimage(const char *file, int *width, int *height)
{
image = imlib_load_image(file);
if (!image)
return;
@ -332,14 +343,18 @@ resizetoimageheight(int imageheight)
{
int omh = mh, olines = lines;
lines = reallines;
int wtr = 0;
if (lines * bh < imageheight + imagegaps * 2)
lines = (imageheight + imagegaps * 2) / bh;
mh = (lines + 1) * bh;
if (hideprompt && hideinput && hidemode && hidematchcount)
wtr = bh;
mh = (lines + 1) * bh - wtr;
if (mh - bh < imageheight + imagegaps * 2)
mh = imageheight + imagegaps * 2 + bh;
mh = imageheight + imagegaps * 2 + bh - wtr;
if (!win || omh == mh)
return;