From a701060f8b2bd33214b3aea5361035d035f51688 Mon Sep 17 00:00:00 2001 From: speedie Date: Sun, 21 May 2023 23:52:28 +0200 Subject: [PATCH] some more code cleanup --- libs/x11/client.c | 27 ++++++++++++++++++++++++--- libs/x11/client.h | 1 + libs/x11/init.c | 22 +++++----------------- 3 files changed, 30 insertions(+), 20 deletions(-) diff --git a/libs/x11/client.c b/libs/x11/client.c index 55455a9..a84fd4e 100644 --- a/libs/x11/client.c +++ b/libs/x11/client.c @@ -14,6 +14,27 @@ void prepare_window_size(void) { 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) { XSetWindowAttributes swa; @@ -71,14 +92,14 @@ void resizeclient(void) { #endif XWindowAttributes wa; struct item *item; - int itemCount = 0; + int ic = 0; // item count // walk through all items for (item = items; item && item->text; item++) - itemCount++; + ic++; bh = MAX(drw->font->h, drw->font->h + 2 + lineheight); - lines = MIN(itemCount, MAX(lines, 0)); + lines = MIN(ic, MAX(lines, 0)); reallines = lines; // resize client to image height diff --git a/libs/x11/client.h b/libs/x11/client.h index 5d3367b..61c29f8 100644 --- a/libs/x11/client.h +++ b/libs/x11/client.h @@ -1,5 +1,6 @@ /* See LICENSE file for copyright and license details. */ 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 set_window(void); static void set_prop(void); diff --git a/libs/x11/init.c b/libs/x11/init.c index 9a6c29c..885ffe4 100644 --- a/libs/x11/init.c +++ b/libs/x11/init.c @@ -4,11 +4,13 @@ void setupdisplay(void) { int j, di; #endif unsigned int du; - unsigned int tmp, minstrlen = 0, curstrlen = 0; + + unsigned int minstrlen = 0, curstrlen = 0; int numwidthchecks = 100; - struct item *item; + Window w, dw, *dws; XWindowAttributes wa; + #if USEXINERAMA XineramaScreenInfo *info; Window pw; @@ -28,21 +30,7 @@ void setupdisplay(void) { promptw = (prompt && *prompt) ? pango_prompt ? TEXTWM(prompt) : TEXTW(prompt) - lrpad / 4 : 0; // prompt width - // 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; - } - } - } - } + get_width(numwidthchecks, minstrlen, curstrlen); // init xinerama screens #if USEXINERAMA