some more code cleanup

This commit is contained in:
speedie 2023-05-21 23:52:28 +02:00
parent 7f2ad4b5d6
commit a701060f8b
3 changed files with 30 additions and 20 deletions

View file

@ -14,6 +14,27 @@ void prepare_window_size(void) {
return; return;
} }
void get_width(int numwidthchecks, unsigned int minstrlen, unsigned int curstrlen) {
struct item *item;
unsigned int tmp = 0;
// get accurate width
if (accuratewidth) {
for (item = items; !lines && item && item->text; ++item) {
curstrlen = strlen(item->text);
if (numwidthchecks || minstrlen < curstrlen) {
numwidthchecks = MAX(numwidthchecks - 1, 0);
minstrlen = MAX(minstrlen, curstrlen);
if ((tmp = MIN(TEXTW(item->text), mw/3) > inputw)) {
inputw = tmp;
if (tmp == mw/3)
break;
}
}
}
}
}
void create_window(int x, int y, int w, int h) { void create_window(int x, int y, int w, int h) {
XSetWindowAttributes swa; XSetWindowAttributes swa;
@ -71,14 +92,14 @@ void resizeclient(void) {
#endif #endif
XWindowAttributes wa; XWindowAttributes wa;
struct item *item; struct item *item;
int itemCount = 0; int ic = 0; // item count
// walk through all items // walk through all items
for (item = items; item && item->text; item++) for (item = items; item && item->text; item++)
itemCount++; ic++;
bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); bh = MAX(drw->font->h, drw->font->h + 2 + lineheight);
lines = MIN(itemCount, MAX(lines, 0)); lines = MIN(ic, MAX(lines, 0));
reallines = lines; reallines = lines;
// resize client to image height // resize client to image height

View file

@ -1,5 +1,6 @@
/* See LICENSE file for copyright and license details. */ /* See LICENSE file for copyright and license details. */
static void create_window(int x, int y, int w, int h); static void create_window(int x, int y, int w, int h);
static void get_width(int numwidthchecks, unsigned int minstrlen, unsigned int curstrlen);
static void prepare_window_size(void); static void prepare_window_size(void);
static void set_window(void); static void set_window(void);
static void set_prop(void); static void set_prop(void);

View file

@ -4,11 +4,13 @@ void setupdisplay(void) {
int j, di; int j, di;
#endif #endif
unsigned int du; unsigned int du;
unsigned int tmp, minstrlen = 0, curstrlen = 0;
unsigned int minstrlen = 0, curstrlen = 0;
int numwidthchecks = 100; int numwidthchecks = 100;
struct item *item;
Window w, dw, *dws; Window w, dw, *dws;
XWindowAttributes wa; XWindowAttributes wa;
#if USEXINERAMA #if USEXINERAMA
XineramaScreenInfo *info; XineramaScreenInfo *info;
Window pw; Window pw;
@ -28,21 +30,7 @@ void setupdisplay(void) {
promptw = (prompt && *prompt) promptw = (prompt && *prompt)
? pango_prompt ? TEXTWM(prompt) : TEXTW(prompt) - lrpad / 4 : 0; // prompt width ? pango_prompt ? TEXTWM(prompt) : TEXTW(prompt) - lrpad / 4 : 0; // prompt width
// get accurate width get_width(numwidthchecks, minstrlen, curstrlen);
if (accuratewidth) {
for (item = items; !lines && item && item->text; ++item) {
curstrlen = strlen(item->text);
if (numwidthchecks || minstrlen < curstrlen) {
numwidthchecks = MAX(numwidthchecks - 1, 0);
minstrlen = MAX(minstrlen, curstrlen);
if ((tmp = MIN(TEXTW(item->text), mw/3) > inputw)) {
inputw = tmp;
if (tmp == mw/3)
break;
}
}
}
}
// init xinerama screens // init xinerama screens
#if USEXINERAMA #if USEXINERAMA