diff --git a/libs/arg.c b/libs/arg.c index c4a0d35..9cc96fb 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -11,25 +11,25 @@ void moveleft(Arg *arg) { } if (columns > 1) { - if (!sel) { + if (!selecteditem) { return; } - tmpsel = sel; + tmpsel = selecteditem; for (i = 0; i < lines; i++) { if (!tmpsel->left || tmpsel->left->right != tmpsel) { if (offscreen) drawmenu(); return; } - if (tmpsel == curr) + if (tmpsel == currentitem) offscreen = 1; tmpsel = tmpsel->left; } - sel = tmpsel; + selecteditem = tmpsel; if (offscreen) { for (int j = 0; j < argu; j++) { - curr = prev; + currentitem = previousitem; } } @@ -49,9 +49,9 @@ void moveright(Arg *arg) { } if (columns > 1) { - if (!sel) + if (!selecteditem) return; - tmpsel = sel; + tmpsel = selecteditem; for (i = 0; i < lines; i++) { if (!tmpsel->right || tmpsel->right->left != tmpsel) { if (offscreen) @@ -59,13 +59,13 @@ void moveright(Arg *arg) { return; } tmpsel = tmpsel->right; - if (tmpsel == next) + if (tmpsel == nextitem) offscreen = 1; } - sel = tmpsel; + selecteditem = tmpsel; if (offscreen) { for (int j = 0; j < argu; j++) - curr = next; + currentitem = nextitem; } calcoffsets(); } @@ -77,8 +77,8 @@ void movedown(Arg *arg) { int argu = arg->i ? arg->i : 1; for (int j = 0; j < argu; j++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; // Current item is now the next item + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; // Current item is now the next item } } @@ -90,8 +90,8 @@ void moveup(Arg *arg) { int argu = arg->i ? arg->i : 1; for (int j = 0; j < argu; j++) { - if (sel && sel->left && (sel = sel->left)->right == curr) { - curr = prev; // Current item is now the previous item + if (selecteditem && selecteditem->left && (selecteditem = selecteditem->left)->right == currentitem) { + currentitem = previousitem; // Current item is now the previous item } } @@ -116,7 +116,7 @@ void complete(Arg *arg) { return; } - strncpy(tx.text, sel->nsgrtext, sizeof tx.text - 1); + strncpy(tx.text, selecteditem->nsgrtext, sizeof tx.text - 1); tx.text[sizeof tx.text - 1] = '\0'; sp.cursor = strlen(tx.text); @@ -125,26 +125,28 @@ void complete(Arg *arg) { } void movenext(Arg *arg) { - if (!next) + if (!nextitem) { return; + } - sel = curr = next; + selecteditem = currentitem = nextitem; // next page drawmenu(); } void moveprev(Arg *arg) { - if (!prev) + if (!previousitem) { return; + } - sel = curr = prev; + selecteditem = currentitem = previousitem; // previous page calcoffsets(); drawmenu(); } void moveitem(Arg *arg) { for (int i = 0; i < arg->i; i++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; calcoffsets(); } } @@ -153,13 +155,13 @@ void moveitem(Arg *arg) { } void movestart(Arg *arg) { - if (sel == matches) { + if (selecteditem == matches) { sp.cursor = 0; drawmenu(); return; } - sel = curr = matches; + selecteditem = currentitem = matches; calcoffsets(); drawmenu(); } @@ -171,17 +173,17 @@ void moveend(Arg *arg) { return; } - if (next) { - curr = matchend; + if (nextitem) { + currentitem = matchend; calcoffsets(); - curr = prev; + currentitem = previousitem; calcoffsets(); - while (next && (curr = curr->right)) + while (nextitem && (currentitem = currentitem->right)) calcoffsets(); } - sel = matchend; + selecteditem = matchend; drawmenu(); } @@ -197,8 +199,8 @@ void viewhist(Arg *arg) { int i; if (histfile) { - if (!backup_items) { - backup_items = items; + if (!history_items) { + history_items = items; items = calloc(histsz + 1, sizeof(struct item)); if (!items) { @@ -210,8 +212,8 @@ void viewhist(Arg *arg) { } } else { free(items); - items = backup_items; - backup_items = NULL; + items = history_items; + history_items = NULL; } } @@ -273,23 +275,23 @@ void backspace(Arg *arg) { void markitem(Arg *arg) { if (!mark) return; - if (sel && is_selected(sel->index)) { + if (selecteditem && is_selected(selecteditem->index)) { for (int i = 0; i < sel_size; i++) { - if (sel_index[i] == sel->index) { + if (sel_index[i] == selecteditem->index) { sel_index[i] = -1; } } } else { for (int i = 0; i < sel_size; i++) { if (sel_index[i] == -1) { - sel_index[i] = sel->index; + sel_index[i] = selecteditem->index; return; } } sel_size++; sel_index = realloc(sel_index, (sel_size + 1) * sizeof(int)); - sel_index[sel_size - 1] = sel->index; + sel_index[sel_size - 1] = selecteditem->index; } } @@ -297,21 +299,21 @@ void selectitem(Arg *arg) { char *selection; // print index - if (printindex && sel && arg->i) { - fprintf(stdout, "%d\n", sel->index); + if (printindex && selecteditem && arg->i) { + fprintf(stdout, "%d\n", selecteditem->index); cleanup(); exit(0); } // selected item or input? - if (sel && arg->i && !hideitem) { - selection = sel->text; + if (selecteditem && arg->i && !hideitem) { + selection = selecteditem->text; } else { selection = tx.text; } for (int i = 0; i < sel_size; i++) { - if (sel_index[i] != -1 && (!sel || sel->index != sel_index[i])) { + if (sel_index[i] != -1 && (!selecteditem || selecteditem->index != sel_index[i])) { puts(items[sel_index[i]].text); } } @@ -468,7 +470,7 @@ void setlines(Arg *arg) { if (!overridelines) return; insert(NULL, 0 - sp.cursor); - sel = curr = matches; + selecteditem = currentitem = matches; lines += arg->i; diff --git a/libs/draw.c b/libs/draw.c index e2a5787..6c6f5da 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -29,10 +29,10 @@ void drawhighlights(struct item *item, int x, int y, int w, int p, const char *i y, MIN(w - indent - sp.lrpad, TEXTW(highlight) - sp.lrpad), sp.bh, 0, highlight, 0, False, - item == sel ? col_hlselfg : col_hlnormfg, - item == sel ? col_hlselbg : col_hlnormbg, - item == sel ? alpha_hlselfg : alpha_hlnormfg, - item == sel ? alpha_hlselbg : alpha_hlnormbg); + item == selecteditem ? col_hlselfg : col_hlnormfg, + item == selecteditem ? col_hlselbg : col_hlnormbg, + item == selecteditem ? alpha_hlselfg : alpha_hlnormfg, + item == selecteditem ? alpha_hlselbg : alpha_hlnormbg); highlight[1] = c; i++; } @@ -66,7 +66,7 @@ int drawitemtext(struct item *item, int x, int y, int w) { int oleftpadding; // memcpy the correct scheme - if (item == sel) { + if (item == selecteditem) { selitem = 1; bgcol = col_itemselbg; fgcol = col_itemselfg; @@ -306,7 +306,7 @@ int drawitem(int x, int y, int w) { int itemoverride = 1; itemn = 0; - for (item = curr; item != next; item = item->right, i++) { + for (item = currentitem; item != nextitem; item = item->right, i++) { x = drawitemtext( item, rx + menumarginh + ((i / lines) * ((sp.mw - rx) / columns)) + (powerlineitems ? sp.plw : 0), @@ -314,7 +314,7 @@ int drawitem(int x, int y, int w) { (sp.mw - rx) / columns - (powerlineitems ? 2 * sp.plw : 0) - (2 * menumarginh) ); - if (item == sel && itemoverride) { + if (item == selecteditem && itemoverride) { sp.itemnumber = i; itemoverride = 0; } @@ -334,7 +334,7 @@ int drawitem(int x, int y, int w) { sp.itemnumber = 0; int itemoverride = 1; - for (item = curr; item != next; item = item->right) { // draw items + for (item = currentitem; item != nextitem; 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 - rarroww - @@ -350,7 +350,7 @@ int drawitem(int x, int y, int w) { sp.itemnumber++; } - if (item == sel) { + if (item == selecteditem) { itemoverride = 0; } } @@ -425,7 +425,7 @@ int drawinput(int x, int y, int w) { int drawlarrow(int x, int y, int w) { if (hidelarrow) return x; - if (curr->left) { // draw left arrow + if (currentitem->left) { // draw left arrow draw_text(draw, x, y, w, sp.bh, sp.lrpad / 2, leftarrow, 0, pango_leftarrow ? True : False, col_larrowfg, col_larrowbg, alpha_larrowfg, alpha_larrowbg); x += w; } @@ -436,7 +436,7 @@ int drawlarrow(int x, int y, int w) { int drawrarrow(int x, int y, int w) { if (hiderarrow) return x; - if (next) { // draw right arrow + if (nextitem) { // draw right arrow draw_text(draw, sp.mw - w, y, w, sp.bh, sp.lrpad / 2, rightarrow, 0, pango_rightarrow ? True : False, col_rarrowfg, col_rarrowbg, alpha_rarrowfg, alpha_rarrowbg); x += w; } @@ -545,8 +545,8 @@ void drawmenu(void) { match(); for (int i = 0; i < sp.itemnumber; i++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; } } @@ -568,8 +568,8 @@ void drawmenu(void) { match(); for (int i = 0; i < sp.itemnumber; i++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; } } } diff --git a/libs/img.c b/libs/img.c index 4a02e72..2cefa1f 100644 --- a/libs/img.c +++ b/libs/img.c @@ -41,10 +41,10 @@ void drawimage(void) { if (!lines || !columns || hideimage || !imagetype) return; // load image cache - if (sel && sel->image && strcmp(sel->image, limg ? limg : "")) { + if (selecteditem && selecteditem->image && strcmp(selecteditem->image, limg ? limg : "")) { if (img.longestedge) - loadimagecache(sel->image, &width, &height); - } else if ((!sel || !sel->image) && image) { // free image + loadimagecache(selecteditem->image, &width, &height); + } else if ((!selecteditem || !selecteditem->image) && image) { // free image cleanupimage(); } @@ -96,8 +96,8 @@ void drawimage(void) { } } - if (sel) { - limg = sel->image; + if (selecteditem) { + limg = selecteditem->image; } else { limg = NULL; } @@ -296,13 +296,13 @@ void loadimagecache(const char *file, int *width, int *height) { void jumptoindex(unsigned int index) { unsigned int i; - sel = curr = matches; + selecteditem = currentitem = matches; calcoffsets(); for (i = 1; i < index; ++i) { // move to item index - if(sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; calcoffsets(); } } @@ -360,7 +360,7 @@ void resizetoimageheight_x11(int imageheight) { unsigned int i = 1; // walk through all matches - for (item = matches; item && item != sel; item = item->right) + for (item = matches; item && item != selecteditem; item = item->right) ++i; jumptoindex(i); @@ -390,7 +390,7 @@ void resizetoimageheight_wl(int imageheight) { unsigned int i = 1; // walk through all matches - for (item = matches; item && item != sel; item = item->right) + for (item = matches; item && item != selecteditem; item = item->right) ++i; jumptoindex(i); diff --git a/libs/match.c b/libs/match.c index bdd27d2..dcae623 100644 --- a/libs/match.c +++ b/libs/match.c @@ -94,11 +94,11 @@ void fuzzymatch(void) { matches = lhpprefix; } - curr = sel = matches; + currentitem = selecteditem = matches; for (i = 0; i < preselected; i++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; } } @@ -180,11 +180,12 @@ void match(void) { matches = lsubstr; matchend = substrend; } - curr = sel = matches; + + currentitem = selecteditem = matches; for (i = 0; i < preselected; i++) { - if (sel && sel->right && (sel = sel->right) == next) { - curr = next; + if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) { + currentitem = nextitem; } } diff --git a/libs/wl/wayland.c b/libs/wl/wayland.c index 9d442a6..9c82733 100644 --- a/libs/wl/wayland.c +++ b/libs/wl/wayland.c @@ -266,7 +266,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; if ((lines <= 0 && ex >= 0 && ex <= x + w + sp.promptw + - ((!prev || !curr->left) ? larroww : 0)) || + ((!previousitem || !currentitem->left) ? larroww : 0)) || (lines > 0 && ey >= y && ey <= y + h)) { click = ClickInput; @@ -289,7 +289,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { ey += h; } - for (item = curr; item != next; item = item->right) { + for (item = currentitem; item != nextitem; item = item->right) { if (item_num++ == lines) { item_num = 1; x += w / columns; @@ -328,7 +328,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { x += sp.inputw; w = larroww; - if (prev && curr->left) { + if (previousitem && currentitem->left) { if (ex >= x && ex <= x + w) { click = ClickLArrow; } @@ -337,7 +337,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) { // right arrow w = rarroww; x = sp.mw - w; - if (next && ex >= x && ex <= x + w) { + if (nextitem && ex >= x && ex <= x + w) { click = ClickRArrow; } } diff --git a/libs/x11/mouse.c b/libs/x11/mouse.c index 4c9c5f8..346afe9 100644 --- a/libs/x11/mouse.c +++ b/libs/x11/mouse.c @@ -50,7 +50,7 @@ void buttonpress_x11(XEvent *e) { w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + sp.promptw + - ((!prev || !curr->left) ? larroww : 0)) || + ((!previousitem || !currentitem->left) ? larroww : 0)) || (lines > 0 && ev->y >= y && ev->y <= y + h)) { click = ClickInput; @@ -73,7 +73,7 @@ void buttonpress_x11(XEvent *e) { ev->y += h; } - for (item = curr; item != next; item = item->right) { + for (item = currentitem; item != nextitem; item = item->right) { if (item_num++ == lines) { item_num = 1; x += w / columns; @@ -112,7 +112,7 @@ void buttonpress_x11(XEvent *e) { x += sp.inputw; w = larroww; - if (prev && curr->left) { + if (previousitem && currentitem->left) { if (ev->x >= x && ev->x <= x + w) { click = ClickLArrow; } @@ -121,7 +121,7 @@ void buttonpress_x11(XEvent *e) { // right arrow w = rarroww; x = sp.mw - w; - if (next && ev->x >= x && ev->x <= x + w) { + if (nextitem && ev->x >= x && ev->x <= x + w) { click = ClickRArrow; } } diff --git a/spmenu.c b/spmenu.c index 269b76b..48a74b4 100644 --- a/spmenu.c +++ b/spmenu.c @@ -195,9 +195,16 @@ static struct img img = {0}; static struct x11 x11 = {0}; #endif -static struct item *items = NULL, *backup_items, *list_items; -static struct item *matches, *matchend; -static struct item *prev, *curr, *next, *sel; +static struct item *items = NULL; +static struct item *history_items; +static struct item *list_items; +static struct item *matches; +static struct item *matchend; + +static struct item *previousitem; // previous item +static struct item *currentitem; // current item +static struct item *nextitem; // next item +static struct item *selecteditem; // selected item // various headers #include "libs/draw/draw.h" @@ -376,14 +383,16 @@ void calcoffsets(void) { } // calculate which items will begin the next page - for (i = 0, next = curr; next; next = next->right) - if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(next->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) + for (i = 0, nextitem = currentitem; nextitem; nextitem = nextitem->right) { + if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(nextitem->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) break; + } // calculate which items will begin the previous page - for (i = 0, prev = curr; prev && prev->left; prev = prev->left) - if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(prev->left->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) + for (i = 0, previousitem = currentitem; previousitem && previousitem->left; previousitem = previousitem->left) { + if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(previousitem->left->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) break; + } } int max_textw(void) {