From 8e0de8f556f9979a11f8bc63cbf644ad9e5cdc49 Mon Sep 17 00:00:00 2001 From: speedie Date: Fri, 23 Jun 2023 17:27:57 +0200 Subject: [PATCH] Simplify some variables --- libs/draw.c | 64 +++++++++++++++++++++++------------------------ libs/options.h | 6 +---- libs/wl/wayland.c | 34 ++++++++++++------------- libs/x11/mouse.c | 34 ++++++++++++------------- spmenu.c | 16 ++++++------ 5 files changed, 75 insertions(+), 79 deletions(-) diff --git a/libs/draw.c b/libs/draw.c index f62c4c4..a8c8dd1 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -276,22 +276,22 @@ int drawitemtext(struct item *item, int x, int y, int w) { int drawitem(int x, int y, int w) { struct item *item; - int numberWidth = 0; - int modeWidth = 0; - int larrowWidth = 0; - int rarrowWidth = 0; - int capsWidth = 0; + int numberw = 0; + int modew = 0; + int larroww = 0; + int rarroww = 0; + int capsw = 0; // add width - if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); - if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); - if (!hidemode) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); - if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); - if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); - if (!hidecaps) capsWidth = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); + if (!hidelarrow) larroww = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); + if (!hiderarrow) rarroww = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); + if (!hidemode) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); + if (!hiderarrow) rarroww = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); + if (!hidematchcount) numberw = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); + if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); if (!strcmp(tx.capstext, "")) - capsWidth = 0; + capsw = 0; #if USEIMAGE int ox = 0; // original x position @@ -339,7 +339,7 @@ int drawitem(int x, int y, int w) { x += sp.inputw; if (!hidelarrow) { - w = larrowWidth; + w = larroww; x = drawlarrow(x, y, w); } @@ -349,10 +349,10 @@ int drawitem(int x, int y, int w) { for (item = curr; item != next; item = item->right) { // draw items x = drawitemtext(item, x + (powerlineitems ? sp.plw : 0), y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text), sp.mw - x - - rarrowWidth - - numberWidth - - modeWidth - - capsWidth - + rarroww - + numberw - + modew - + capsw - menumarginh - 2 * sp.sp - 2 * borderwidth @@ -368,7 +368,7 @@ int drawitem(int x, int y, int w) { } if (!hiderarrow) { - w = rarrowWidth + numberWidth + modeWidth + capsWidth + menumarginh + 2 * sp.sp + 2 * borderwidth; + w = rarroww + numberw + modew + capsw + menumarginh + 2 * sp.sp + 2 * borderwidth; x = drawrarrow(sp.mw - w, y, w); } } @@ -585,21 +585,21 @@ void drawmenu_layer(void) { // draw menu first using menu scheme draw_rect(draw, 0, 0, sp.mw, sp.mh, 1, 1, col_menu, col_menu, alpha_menu, alpha_menu); - int numberWidth = 0; - int modeWidth = 0; - int capsWidth = 0; + int numberw = 0; + int modew = 0; + int capsw = 0; // add width - if (!hidemode) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); - if (!hidecaps) capsWidth = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); + if (!hidemode) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); + if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); if (!strcmp(tx.capstext, "")) - capsWidth = 0; + capsw = 0; // calculate match count if (!hidematchcount) { recalculatenumbers(); - numberWidth = TEXTW(tx.numbers); + numberw = TEXTW(tx.numbers); } x += menumarginh; @@ -623,24 +623,24 @@ void drawmenu_layer(void) { x = drawinput(x, y, w); } - if (!hidemode && !fullscreen) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); + if (!hidemode && !fullscreen) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); // draw the items, this function also calls drawrarrow() and drawlarrow() if (!hideitem) drawitem(x, y, w); if (!hidematchcount && !fullscreen) { - w = numberWidth; - drawnumber(sp.mw - numberWidth - modeWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); + w = numberw; + drawnumber(sp.mw - numberw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); } if (!hidemode && !fullscreen) { - w = modeWidth; - drawmode(sp.mw - modeWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); + w = modew; + drawmode(sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); } if (!hidecaps && !fullscreen) { - w = capsWidth; - drawcaps(sp.mw - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); + w = capsw; + drawcaps(sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh, y, w); } #if USEX diff --git a/libs/options.h b/libs/options.h index 57b77bd..4a8967c 100644 --- a/libs/options.h +++ b/libs/options.h @@ -1,8 +1,4 @@ -/* spmenu - fancy dynamic menu - * - * Below is a configuration file which is technically C source code. - * See LICENSE file for copyright and license details. - */ +/* See LICENSE file for copyright and license details. */ /* spmenu options */ static char *class = "spmenu"; /* Class for spmenu */ diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 539e211..21c62aa 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -232,20 +232,20 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { x += menumarginh; - int larrowWidth = 0; - int rarrowWidth = 0; - int numberWidth = 0; - int modeWidth = 0; - int capsWidth = 0; + int larroww = 0; + int rarroww = 0; + int numberw = 0; + int modew = 0; + int capsw = 0; - if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); - if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); - if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); - if (!hidemode) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); - if (!hidecaps) capsWidth = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); + if (!hidelarrow) larroww = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); + if (!hiderarrow) rarroww = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); + if (!hidematchcount) numberw = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); + if (!hidemode) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); + if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); if (!strcmp(tx.capstext, "")) - capsWidth = 0; + capsw = 0; if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) { yp = 1; @@ -260,17 +260,17 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { // check click position and override the value of click if (yp && ex < x + sp.promptw + powerlineprompt ? sp.plw : 0) { // prompt click = ClickPrompt; - } else if (yp && (ex > sp.mw - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator + } else if (yp && (ex > sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsw) { // caps lock indicator click = ClickCaps; - } else if (yp && ex > sp.mw - modeWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator + } else if (yp && ex > sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator click = ClickMode; - } else if (yp && ex > sp.mw - modeWidth - numberWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count + } else if (yp && ex > sp.mw - modew - numberw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count click = ClickNumber; } else if (yp && !hideinput) { // input w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; if ((lines <= 0 && ex >= 0 && ex <= x + w + sp.promptw + - ((!prev || !curr->left) ? larrowWidth : 0)) || + ((!prev || !curr->left) ? larroww : 0)) || (lines > 0 && ey >= y && ey <= y + h)) { click = ClickInput; @@ -326,7 +326,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } } else if (matches) { // a single line, meaning it could be arrows too, so we check that here x += sp.inputw; - w = larrowWidth; + w = larroww; if (prev && curr->left) { if (ex >= x && ex <= x + w) { @@ -335,7 +335,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { } // right arrow - w = rarrowWidth; + w = rarroww; x = sp.mw - w; if (next && ex >= x && ex <= x + w) { click = ClickRArrow; diff --git a/libs/x11/mouse.c b/libs/x11/mouse.c index 1f4c2ca..f3d1dbf 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -10,20 +10,20 @@ void buttonpress_x11(XEvent *e) { // margin x += menumarginh; - int larrowWidth = 0; - int rarrowWidth = 0; - int numberWidth = 0; - int modeWidth = 0; - int capsWidth = 0; + int larroww = 0; + int rarroww = 0; + int numberw = 0; + int modew = 0; + int capsw = 0; - if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); - if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); - if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); - if (!hidemode) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); - if (!hidecaps) capsWidth = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); + if (!hidelarrow) larroww = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); + if (!hiderarrow) rarroww = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); + if (!hidematchcount) numberw = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); + if (!hidemode) modew = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); + if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); if (!strcmp(tx.capstext, "")) - capsWidth = 0; + capsw = 0; if ((hideprompt && hideinput && hidemode && hidematchcount && hidecaps) && lines) { yp = 1; @@ -40,17 +40,17 @@ void buttonpress_x11(XEvent *e) { // check click position and override the value of click if (yp && ev->x < x + sp.promptw + powerlineprompt ? sp.plw : 0) { // prompt click = ClickPrompt; - } else if (yp && (ev->x > sp.mw - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsWidth) { // caps lock indicator + } else if (yp && (ev->x > sp.mw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) && !hidecaps && capsw) { // caps lock indicator click = ClickCaps; - } else if (yp && ev->x > sp.mw - modeWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator + } else if (yp && ev->x > sp.mw - modew - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // mode indicator click = ClickMode; - } else if (yp && ev->x > sp.mw - modeWidth - numberWidth - capsWidth - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count + } else if (yp && ev->x > sp.mw - modew - numberw - capsw - 2 * sp.sp - 2 * borderwidth - menumarginh) { // match count click = ClickNumber; } else if (yp && !hideinput) { // input w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + sp.promptw + - ((!prev || !curr->left) ? larrowWidth : 0)) || + ((!prev || !curr->left) ? larroww : 0)) || (lines > 0 && ev->y >= y && ev->y <= y + h)) { click = ClickInput; @@ -106,7 +106,7 @@ void buttonpress_x11(XEvent *e) { } } else if (matches) { // a single line, meaning it could be arrows too, so we check that here x += sp.inputw; - w = larrowWidth; + w = larroww; if (prev && curr->left) { if (ev->x >= x && ev->x <= x + w) { @@ -115,7 +115,7 @@ void buttonpress_x11(XEvent *e) { } // right arrow - w = rarrowWidth; + w = rarroww; x = sp.mw - w; if (next && ev->x >= x && ev->x <= x + w) { click = ClickRArrow; diff --git a/spmenu.c b/spmenu.c index 1a6074b..94ace3f 100644 --- a/spmenu.c +++ b/spmenu.c @@ -337,22 +337,22 @@ void calcoffsets(void) { if (lines > 0) n = lines * columns * sp.bh; else { // no lines, therefore the size of items must be decreased to fit the menu elements - int numberWidth = 0; + int numberw = 0; int modeWidth = 0; - int larrowWidth = 0; + int larroww = 0; int rarrowWidth = 0; - int capsWidth = 0; + int capsw = 0; - if (!hidematchcount) numberWidth = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); + if (!hidematchcount) numberw = pango_numbers ? TEXTWM(tx.numbers) : TEXTW(tx.numbers); if (!hidemode) modeWidth = pango_mode ? TEXTWM(tx.modetext) : TEXTW(tx.modetext); - if (!hidelarrow) larrowWidth = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); + if (!hidelarrow) larroww = pango_leftarrow ? TEXTWM(leftarrow) : TEXTW(leftarrow); if (!hiderarrow) rarrowWidth = pango_rightarrow ? TEXTWM(rightarrow) : TEXTW(rightarrow); - if (!hidecaps) capsWidth = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); + if (!hidecaps) capsw = pango_caps ? TEXTWM(tx.capstext) : TEXTW(tx.capstext); if (!strcmp(tx.capstext, "")) - capsWidth = 0; + capsw = 0; - n = sp.mw - (sp.promptw + sp.inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth + capsWidth + menumarginh); + n = sp.mw - (sp.promptw + sp.inputw + larroww + rarrowWidth + modeWidth + numberw + capsw + menumarginh); } // calculate which items will begin the next page