significant image drawing codebase cleanup

This commit is contained in:
speedie 2023-06-11 19:32:02 +02:00
parent 00966f7547
commit c0d8adec85
6 changed files with 52 additions and 68 deletions

View file

@ -573,24 +573,9 @@ void drawmenu_layer(void) {
calcoffsets(); calcoffsets();
get_mh(); get_mh();
// why have an empty line? // bh must be removed from menu height resizing later
if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps)) { if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) {
y -= bh; y -= bh;
mh -= bh;
if (!protocol && (hideimage || !image)) {
#if USEX
XResizeWindow(dpy, win, mw - 2 * sp - 2 * borderwidth, mh);
drw_resize(drw, mw - 2 * sp - 2 * borderwidth, mh);
#endif
} else if (protocol && (hideimage || !image)) {
#if USEWAYLAND
state.width = mw;
state.height = mh;
set_layer_size(&state, state.width, state.height);
#endif
}
} }
if (!hideprompt && !fullscreen) { if (!hideprompt && !fullscreen) {

View file

@ -107,16 +107,17 @@ void drawimage(void) {
if (height > width) if (height > width)
width = height; width = height;
drw_img(drw, leftmargin+(imagewidth-width)/2+xta, wta+leftmargin); drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, wta + leftmargin);
} else if (imageposition == 1 && image) { // bottom mode = 1 } else if (imageposition == 1 && image) { // bottom mode = 1
if (height > width) if (height > width)
width = height; width = height;
drw_img(drw, leftmargin+(imagewidth-width)/2+xta, mh-height-leftmargin);
drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, mh - height - leftmargin);
} else if (imageposition == 2 && image) { // center mode = 2 } else if (imageposition == 2 && image) { // center mode = 2
drw_img(drw, leftmargin+(imagewidth-width)/2+xta, (mh-wta-height)/2+wta); drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, (mh - wta - height) / 2 + wta);
} else if (image) { // top center } else if (image) { // top center
int minh = MIN(height, mh-bh-leftmargin*2); int minh = MIN(height, mh - bh - leftmargin * 2);
drw_img(drw, leftmargin+(imagewidth-width)/2+xta, (minh-height)/2+wta+leftmargin); drw_img(drw, leftmargin + (imagewidth - width) / 2 + xta, (minh - height) / 2 + wta + leftmargin);
} }
} }
@ -354,7 +355,6 @@ void resizetoimageheight(int imagewidth, int imageheight) {
void resizetoimageheight_x11(int imageheight) { void resizetoimageheight_x11(int imageheight) {
int omh = mh, olines = lines; int omh = mh, olines = lines;
lines = reallines; lines = reallines;
int wtr = 0;
int x, y; int x, y;
#if USEXINERAMA #if USEXINERAMA
@ -370,16 +370,8 @@ void resizetoimageheight_x11(int imageheight) {
lines = (imageheight + imagegaps * 2) / bh; lines = (imageheight + imagegaps * 2) / bh;
} }
if (hideprompt && hideinput && hidemode && hidematchcount) {
wtr = bh;
}
get_mh(); get_mh();
if (mh - bh < imageheight + imagegaps * 2) {
mh = (imageheight + imagegaps * 2 + bh) - wtr;
}
// init xinerama screens // init xinerama screens
#if USEXINERAMA #if USEXINERAMA
int i = 0; int i = 0;

View file

@ -243,7 +243,8 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
if (!strcmp(capstext, "")) capsWidth = 0; // No caps lock width for no chars if (!strcmp(capstext, ""))
capsWidth = 0;
click = ClickWindow; // Used as a default, will be overriden. click = ClickWindow; // Used as a default, will be overriden.
@ -543,14 +544,14 @@ void resizeclient_wl(struct state *state) {
reallines = lines; reallines = lines;
get_mh(); get_mh();
if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) {
mh -= bh;
}
if (mh == omh) { if (mh == omh) {
return; return;
} }
// why have an empty line? when there's nothing to draw there anyway?
if (hideprompt && hideinput && hidemode && hidematchcount)
mh += bh;
state->width = mw; state->width = mw;
state->height = mh; state->height = mh;

View file

@ -98,6 +98,10 @@ void resizeclient_x11(void) {
get_mh(); get_mh();
if (hideprompt && hideinput && hidemode && hidematchcount && hidecaps) {
mh -= bh;
}
// init xinerama screens // init xinerama screens
#if USEXINERAMA #if USEXINERAMA
int i = 0; int i = 0;
@ -157,10 +161,6 @@ void resizeclient_x11(void) {
} }
} }
// why have an empty line? when there's nothing to draw there anyway?
if (hideprompt && hideinput && hidemode && hidematchcount)
mh += bh;
// no window/invalid window or menu height we had before is the same as the current window height // no window/invalid window or menu height we had before is the same as the current window height
if (!win || omh == mh) return; if (!win || omh == mh) return;

View file

@ -26,7 +26,9 @@ void buttonpress_x11(XEvent *e) {
if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext); if (!hidemode) modeWidth = pango_mode ? TEXTWM(modetext) : TEXTW(modetext);
if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext); if (!hidecaps) capsWidth = pango_caps ? TEXTWM(capstext) : TEXTW(capstext);
if (!strcmp(capstext, "")) capsWidth = 0; // no caps lock width for no chars if (!strcmp(capstext, ""))
capsWidth = 0;
if (ev->window != win) return; // if incorrect or wrong window, return if (ev->window != win) return; // if incorrect or wrong window, return
click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific click = ClickWindow; // clicking anywhere, we use this and override it if we clicked on something specific

View file

@ -469,6 +469,10 @@ void get_width(void) {
void get_mh(void) { void get_mh(void) {
mh = (lines + 1) * bh; mh = (lines + 1) * bh;
mh += 2 * menumarginv; mh += 2 * menumarginv;
if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) {
mh -= bh;
}
} }
void set_mode(void) { void set_mode(void) {