cleanup drw_text lines by setting an integer depending on whether or not

USERTL is true once globally
This commit is contained in:
speedie 2023-03-02 17:51:25 +01:00
parent fbfdfe2583
commit 327636b0ee
4 changed files with 42 additions and 31 deletions

View file

@ -58,12 +58,8 @@ drawitem(struct item *item, int x, int y, int w)
/* draw text */ /* draw text */
rw = TEXTWM(buffer) - lrpad; rw = TEXTWM(buffer) - lrpad;
#if USERTL
apply_fribidi(buffer); apply_fribidi(buffer);
drw_text(drw, x, y, rw + lp, bh, lp, fribidi_text, 0, pango_item ? True : False); drw_text(drw, x, y, rw + lp, bh, lp, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False);
#else
drw_text(drw, x, y, rw + lp, bh, lp, buffer, 0, pango_item ? True : False);
#endif
x += rw + lp; x += rw + lp;
ib = 1; ib = 1;
@ -108,12 +104,8 @@ drawitem(struct item *item, int x, int y, int w)
buffer[wr] = '\0'; buffer[wr] = '\0';
/* draw any text that doesn't use sgr sequences */ /* draw any text that doesn't use sgr sequences */
#if USERTL
apply_fribidi(buffer); apply_fribidi(buffer);
int r = drw_text(drw, x, y, w - rw, bh, lp, fribidi_text, 0, pango_item ? True : False); int r = drw_text(drw, x, y, w - rw, bh, lp, isrtl ? fribidi_text : buffer, 0, pango_item ? True : False);
#else
int r = drw_text(drw, x, y, w - rw, bh, lp, buffer, 0, pango_item ? True : False);
#endif
if (!hidehighlight && !ib) drawhighlights(item, x, y, w - rw); if (!hidehighlight && !ib) drawhighlights(item, x, y, w - rw);
return r; return r;
@ -130,8 +122,15 @@ drawmenu(void)
drw_setscheme(drw, scheme[SchemeMenu]); drw_setscheme(drw, scheme[SchemeMenu]);
drw_rect(drw, 0, 0, mw, mh, 1, 1); drw_rect(drw, 0, 0, mw, mh, 1, 1);
if (hidemode) int numberWidth = 0;
strcpy(modetext, ""); int modeWidth = 0;
int larrowWidth = 0;
int rarrowWidth = 0;
if (!hidematchcount) numberWidth = TEXTW(numbers);
if (!hidemode) modeWidth = TEXTW(modetext);
if (!hidelarrow) larrowWidth = TEXTW(leftarrow);
if (!hiderarrow) rarrowWidth = TEXTW(rightarrow);
if (prompt && *prompt) { if (prompt && *prompt) {
if (colorprompt) { if (colorprompt) {
@ -146,23 +145,18 @@ drawmenu(void)
if (passwd) { if (passwd) {
censort = ecalloc(1, sizeof(text)); censort = ecalloc(1, sizeof(text));
memset(censort, '.', strlen(text)); memset(censort, '.', strlen(text));
#if USERTL
apply_fribidi(censort); apply_fribidi(censort);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, pango_password ? True : False); drw_text(drw, x, 0, w, bh, lrpad / 2, isrtl ? fribidi_text : censort, 0, pango_password ? True : False);
#else
drw_text(drw, x, 0, w - LENGTH(censort), bh, lrpad / 2, censort, 0, pango_password ? True : False); curpos = TEXTW(censort) - TEXTW(&text[cursor]);
#endif
free(censort); free(censort);
} else { } else if (!passwd) {
#if USERTL
apply_fribidi(text); apply_fribidi(text);
drw_text(drw, x, 0, w, bh, lrpad / 2, fribidi_text, 0, pango_input ? True : False); drw_text(drw, x, 0, w, bh, lrpad / 2, isrtl ? fribidi_text : text, 0, pango_input ? True : False);
#else curpos = TEXTW(text) - TEXTW(&text[cursor]);
drw_text(drw, x, 0, w, bh, lrpad / 2, text, 0, pango_input ? True : False);
#endif
} }
curpos = TEXTW(text) - TEXTW(&text[cursor]);
if ((curpos += lrpad / 2 - 1) < w) { if ((curpos += lrpad / 2 - 1) < w) {
drw_setscheme(drw, scheme[SchemeCaret]); drw_setscheme(drw, scheme[SchemeCaret]);
drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0); drw_rect(drw, x + curpos, 2 + (bh - fh) / 2, 2, fh - 4, 1, 0);

View file

@ -1,6 +1,9 @@
void void
apply_fribidi(char *str) apply_fribidi(char *str)
{ {
#if !USERTL
return;
#endif
FriBidiStrIndex len = strlen(str); FriBidiStrIndex len = strlen(str);
FriBidiChar logical[BUFSIZ]; FriBidiChar logical[BUFSIZ];
FriBidiChar visual[BUFSIZ]; FriBidiChar visual[BUFSIZ];

View file

@ -65,6 +65,8 @@ static char *prompt = NULL; /* Default prompt, set to NULL (n
/* Hide options */ /* Hide options */
static int hidematchcount = 0; /* Hide match count (0/1) */ static int hidematchcount = 0; /* Hide match count (0/1) */
static int hidemode = 0; /* Hide mode (0/1) */ static int hidemode = 0; /* Hide mode (0/1) */
static int hidelarrow = 0; /* Hide left arrow (0/1) */
static int hiderarrow = 0; /* Hide right arrow (0/1) */
static int hidehighlight = 0; /* Hide highlight (0/1) */ static int hidehighlight = 0; /* Hide highlight (0/1) */
static int hideimage = 0; /* Hide image (0/1) */ static int hideimage = 0; /* Hide image (0/1) */

View file

@ -121,6 +121,12 @@ static struct item *prev, *curr, *next, *sel;
static int mon = -1, screen; static int mon = -1, screen;
static int managed = 0; static int managed = 0;
#if USERTL
static int isrtl = 1;
#else
static int isrtl = 0;
#endif
#include "libs/mode.h" #include "libs/mode.h"
static Atom clip, utf8, types, dock; static Atom clip, utf8, types, dock;
@ -269,12 +275,18 @@ calcoffsets(void)
if (lines > 0) if (lines > 0)
n = lines * columns * bh; n = lines * columns * bh;
else else {
/* hide match count */ int numberWidth = 0;
if (hidematchcount) { int modeWidth = 0;
n = mw - (promptw + inputw + TEXTW(leftarrow) + TEXTW(rightarrow) + TEXTW(modetext)); int larrowWidth = 0;
} else { int rarrowWidth = 0;
n = mw - (promptw + inputw + TEXTW(leftarrow) + TEXTW(rightarrow) + TEXTW(numbers) + TEXTW(modetext));
if (!hidematchcount) numberWidth = TEXTW(numbers);
if (!hidemode) modeWidth = TEXTW(modetext);
if (!hidelarrow) larrowWidth = TEXTW(leftarrow);
if (!hiderarrow) rarrowWidth = TEXTW(rightarrow);
n = mw - (promptw + inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth);
} }
/* calculate which items will begin the next page and previous page */ /* calculate which items will begin the next page and previous page */
for (i = 0, next = curr; next; next = next->right) for (i = 0, next = curr; next; next = next->right)