From 1495140dbd2a2c42fb42ae72244d47f5bdfaee00 Mon Sep 17 00:00:00 2001 From: speedie Date: Sat, 1 Apr 2023 13:59:31 +0200 Subject: [PATCH] fix: drawing images when the top line is removed causes it to keep resizing for all eternity, which eventually makes your computer unusable --- libs/draw.c | 24 +++++++++++++++++------- libs/img-c.c | 27 +++++++++++++++++++++------ 2 files changed, 38 insertions(+), 13 deletions(-) diff --git a/libs/draw.c b/libs/draw.c index e9911b0..d414489 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -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); diff --git a/libs/img-c.c b/libs/img-c.c index 9a21035..878dcf0 100644 --- a/libs/img-c.c +++ b/libs/img-c.c @@ -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;