Replace more variable names to more descriptive ones

This commit is contained in:
speedie 2023-07-16 03:16:45 +02:00
parent 7b7c1a56f4
commit 0627c2fc1c
7 changed files with 100 additions and 88 deletions

View file

@ -11,25 +11,25 @@ void moveleft(Arg *arg) {
} }
if (columns > 1) { if (columns > 1) {
if (!sel) { if (!selecteditem) {
return; return;
} }
tmpsel = sel; tmpsel = selecteditem;
for (i = 0; i < lines; i++) { for (i = 0; i < lines; i++) {
if (!tmpsel->left || tmpsel->left->right != tmpsel) { if (!tmpsel->left || tmpsel->left->right != tmpsel) {
if (offscreen) if (offscreen)
drawmenu(); drawmenu();
return; return;
} }
if (tmpsel == curr) if (tmpsel == currentitem)
offscreen = 1; offscreen = 1;
tmpsel = tmpsel->left; tmpsel = tmpsel->left;
} }
sel = tmpsel; selecteditem = tmpsel;
if (offscreen) { if (offscreen) {
for (int j = 0; j < argu; j++) { for (int j = 0; j < argu; j++) {
curr = prev; currentitem = previousitem;
} }
} }
@ -49,9 +49,9 @@ void moveright(Arg *arg) {
} }
if (columns > 1) { if (columns > 1) {
if (!sel) if (!selecteditem)
return; return;
tmpsel = sel; tmpsel = selecteditem;
for (i = 0; i < lines; i++) { for (i = 0; i < lines; i++) {
if (!tmpsel->right || tmpsel->right->left != tmpsel) { if (!tmpsel->right || tmpsel->right->left != tmpsel) {
if (offscreen) if (offscreen)
@ -59,13 +59,13 @@ void moveright(Arg *arg) {
return; return;
} }
tmpsel = tmpsel->right; tmpsel = tmpsel->right;
if (tmpsel == next) if (tmpsel == nextitem)
offscreen = 1; offscreen = 1;
} }
sel = tmpsel; selecteditem = tmpsel;
if (offscreen) { if (offscreen) {
for (int j = 0; j < argu; j++) for (int j = 0; j < argu; j++)
curr = next; currentitem = nextitem;
} }
calcoffsets(); calcoffsets();
} }
@ -77,8 +77,8 @@ void movedown(Arg *arg) {
int argu = arg->i ? arg->i : 1; int argu = arg->i ? arg->i : 1;
for (int j = 0; j < argu; j++) { for (int j = 0; j < argu; j++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; // Current item is now the next item currentitem = nextitem; // Current item is now the next item
} }
} }
@ -90,8 +90,8 @@ void moveup(Arg *arg) {
int argu = arg->i ? arg->i : 1; int argu = arg->i ? arg->i : 1;
for (int j = 0; j < argu; j++) { for (int j = 0; j < argu; j++) {
if (sel && sel->left && (sel = sel->left)->right == curr) { if (selecteditem && selecteditem->left && (selecteditem = selecteditem->left)->right == currentitem) {
curr = prev; // Current item is now the previous item currentitem = previousitem; // Current item is now the previous item
} }
} }
@ -116,7 +116,7 @@ void complete(Arg *arg) {
return; 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'; tx.text[sizeof tx.text - 1] = '\0';
sp.cursor = strlen(tx.text); sp.cursor = strlen(tx.text);
@ -125,26 +125,28 @@ void complete(Arg *arg) {
} }
void movenext(Arg *arg) { void movenext(Arg *arg) {
if (!next) if (!nextitem) {
return; return;
}
sel = curr = next; selecteditem = currentitem = nextitem; // next page
drawmenu(); drawmenu();
} }
void moveprev(Arg *arg) { void moveprev(Arg *arg) {
if (!prev) if (!previousitem) {
return; return;
}
sel = curr = prev; selecteditem = currentitem = previousitem; // previous page
calcoffsets(); calcoffsets();
drawmenu(); drawmenu();
} }
void moveitem(Arg *arg) { void moveitem(Arg *arg) {
for (int i = 0; i < arg->i; i++) { for (int i = 0; i < arg->i; i++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
calcoffsets(); calcoffsets();
} }
} }
@ -153,13 +155,13 @@ void moveitem(Arg *arg) {
} }
void movestart(Arg *arg) { void movestart(Arg *arg) {
if (sel == matches) { if (selecteditem == matches) {
sp.cursor = 0; sp.cursor = 0;
drawmenu(); drawmenu();
return; return;
} }
sel = curr = matches; selecteditem = currentitem = matches;
calcoffsets(); calcoffsets();
drawmenu(); drawmenu();
} }
@ -171,17 +173,17 @@ void moveend(Arg *arg) {
return; return;
} }
if (next) { if (nextitem) {
curr = matchend; currentitem = matchend;
calcoffsets(); calcoffsets();
curr = prev; currentitem = previousitem;
calcoffsets(); calcoffsets();
while (next && (curr = curr->right)) while (nextitem && (currentitem = currentitem->right))
calcoffsets(); calcoffsets();
} }
sel = matchend; selecteditem = matchend;
drawmenu(); drawmenu();
} }
@ -197,8 +199,8 @@ void viewhist(Arg *arg) {
int i; int i;
if (histfile) { if (histfile) {
if (!backup_items) { if (!history_items) {
backup_items = items; history_items = items;
items = calloc(histsz + 1, sizeof(struct item)); items = calloc(histsz + 1, sizeof(struct item));
if (!items) { if (!items) {
@ -210,8 +212,8 @@ void viewhist(Arg *arg) {
} }
} else { } else {
free(items); free(items);
items = backup_items; items = history_items;
backup_items = NULL; history_items = NULL;
} }
} }
@ -273,23 +275,23 @@ void backspace(Arg *arg) {
void markitem(Arg *arg) { void markitem(Arg *arg) {
if (!mark) return; if (!mark) return;
if (sel && is_selected(sel->index)) { if (selecteditem && is_selected(selecteditem->index)) {
for (int i = 0; i < sel_size; i++) { for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == sel->index) { if (sel_index[i] == selecteditem->index) {
sel_index[i] = -1; sel_index[i] = -1;
} }
} }
} else { } else {
for (int i = 0; i < sel_size; i++) { for (int i = 0; i < sel_size; i++) {
if (sel_index[i] == -1) { if (sel_index[i] == -1) {
sel_index[i] = sel->index; sel_index[i] = selecteditem->index;
return; return;
} }
} }
sel_size++; sel_size++;
sel_index = realloc(sel_index, (sel_size + 1) * sizeof(int)); 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; char *selection;
// print index // print index
if (printindex && sel && arg->i) { if (printindex && selecteditem && arg->i) {
fprintf(stdout, "%d\n", sel->index); fprintf(stdout, "%d\n", selecteditem->index);
cleanup(); cleanup();
exit(0); exit(0);
} }
// selected item or input? // selected item or input?
if (sel && arg->i && !hideitem) { if (selecteditem && arg->i && !hideitem) {
selection = sel->text; selection = selecteditem->text;
} else { } else {
selection = tx.text; selection = tx.text;
} }
for (int i = 0; i < sel_size; i++) { 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); puts(items[sel_index[i]].text);
} }
} }
@ -468,7 +470,7 @@ void setlines(Arg *arg) {
if (!overridelines) return; if (!overridelines) return;
insert(NULL, 0 - sp.cursor); insert(NULL, 0 - sp.cursor);
sel = curr = matches; selecteditem = currentitem = matches;
lines += arg->i; lines += arg->i;

View file

@ -29,10 +29,10 @@ void drawhighlights(struct item *item, int x, int y, int w, int p, const char *i
y, y,
MIN(w - indent - sp.lrpad, TEXTW(highlight) - sp.lrpad), MIN(w - indent - sp.lrpad, TEXTW(highlight) - sp.lrpad),
sp.bh, 0, highlight, 0, False, sp.bh, 0, highlight, 0, False,
item == sel ? col_hlselfg : col_hlnormfg, item == selecteditem ? col_hlselfg : col_hlnormfg,
item == sel ? col_hlselbg : col_hlnormbg, item == selecteditem ? col_hlselbg : col_hlnormbg,
item == sel ? alpha_hlselfg : alpha_hlnormfg, item == selecteditem ? alpha_hlselfg : alpha_hlnormfg,
item == sel ? alpha_hlselbg : alpha_hlnormbg); item == selecteditem ? alpha_hlselbg : alpha_hlnormbg);
highlight[1] = c; highlight[1] = c;
i++; i++;
} }
@ -66,7 +66,7 @@ int drawitemtext(struct item *item, int x, int y, int w) {
int oleftpadding; int oleftpadding;
// memcpy the correct scheme // memcpy the correct scheme
if (item == sel) { if (item == selecteditem) {
selitem = 1; selitem = 1;
bgcol = col_itemselbg; bgcol = col_itemselbg;
fgcol = col_itemselfg; fgcol = col_itemselfg;
@ -306,7 +306,7 @@ int drawitem(int x, int y, int w) {
int itemoverride = 1; int itemoverride = 1;
itemn = 0; itemn = 0;
for (item = curr; item != next; item = item->right, i++) { for (item = currentitem; item != nextitem; item = item->right, i++) {
x = drawitemtext( x = drawitemtext(
item, item,
rx + menumarginh + ((i / lines) * ((sp.mw - rx) / columns)) + (powerlineitems ? sp.plw : 0), 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) (sp.mw - rx) / columns - (powerlineitems ? 2 * sp.plw : 0) - (2 * menumarginh)
); );
if (item == sel && itemoverride) { if (item == selecteditem && itemoverride) {
sp.itemnumber = i; sp.itemnumber = i;
itemoverride = 0; itemoverride = 0;
} }
@ -334,7 +334,7 @@ int drawitem(int x, int y, int w) {
sp.itemnumber = 0; sp.itemnumber = 0;
int itemoverride = 1; 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), x = drawitemtext(item, x + (powerlineitems ? sp.plw : 0), y, MIN(pango_item ? TEXTWM(item->text) : TEXTW(item->text),
sp.mw - x - sp.mw - x -
rarroww - rarroww -
@ -350,7 +350,7 @@ int drawitem(int x, int y, int w) {
sp.itemnumber++; sp.itemnumber++;
} }
if (item == sel) { if (item == selecteditem) {
itemoverride = 0; itemoverride = 0;
} }
} }
@ -425,7 +425,7 @@ int drawinput(int x, int y, int w) {
int drawlarrow(int x, int y, int w) { int drawlarrow(int x, int y, int w) {
if (hidelarrow) return x; 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); 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; x += w;
} }
@ -436,7 +436,7 @@ int drawlarrow(int x, int y, int w) {
int drawrarrow(int x, int y, int w) { int drawrarrow(int x, int y, int w) {
if (hiderarrow) return x; 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); 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; x += w;
} }
@ -545,8 +545,8 @@ void drawmenu(void) {
match(); match();
for (int i = 0; i < sp.itemnumber; i++) { for (int i = 0; i < sp.itemnumber; i++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
} }
} }
@ -568,8 +568,8 @@ void drawmenu(void) {
match(); match();
for (int i = 0; i < sp.itemnumber; i++) { for (int i = 0; i < sp.itemnumber; i++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
} }
} }
} }

View file

@ -41,10 +41,10 @@ void drawimage(void) {
if (!lines || !columns || hideimage || !imagetype) return; if (!lines || !columns || hideimage || !imagetype) return;
// load image cache // load image cache
if (sel && sel->image && strcmp(sel->image, limg ? limg : "")) { if (selecteditem && selecteditem->image && strcmp(selecteditem->image, limg ? limg : "")) {
if (img.longestedge) if (img.longestedge)
loadimagecache(sel->image, &width, &height); loadimagecache(selecteditem->image, &width, &height);
} else if ((!sel || !sel->image) && image) { // free image } else if ((!selecteditem || !selecteditem->image) && image) { // free image
cleanupimage(); cleanupimage();
} }
@ -96,8 +96,8 @@ void drawimage(void) {
} }
} }
if (sel) { if (selecteditem) {
limg = sel->image; limg = selecteditem->image;
} else { } else {
limg = NULL; limg = NULL;
} }
@ -296,13 +296,13 @@ void loadimagecache(const char *file, int *width, int *height) {
void jumptoindex(unsigned int index) { void jumptoindex(unsigned int index) {
unsigned int i; unsigned int i;
sel = curr = matches; selecteditem = currentitem = matches;
calcoffsets(); calcoffsets();
for (i = 1; i < index; ++i) { // move to item index for (i = 1; i < index; ++i) { // move to item index
if(sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
calcoffsets(); calcoffsets();
} }
} }
@ -360,7 +360,7 @@ void resizetoimageheight_x11(int imageheight) {
unsigned int i = 1; unsigned int i = 1;
// walk through all matches // walk through all matches
for (item = matches; item && item != sel; item = item->right) for (item = matches; item && item != selecteditem; item = item->right)
++i; ++i;
jumptoindex(i); jumptoindex(i);
@ -390,7 +390,7 @@ void resizetoimageheight_wl(int imageheight) {
unsigned int i = 1; unsigned int i = 1;
// walk through all matches // walk through all matches
for (item = matches; item && item != sel; item = item->right) for (item = matches; item && item != selecteditem; item = item->right)
++i; ++i;
jumptoindex(i); jumptoindex(i);

View file

@ -94,11 +94,11 @@ void fuzzymatch(void) {
matches = lhpprefix; matches = lhpprefix;
} }
curr = sel = matches; currentitem = selecteditem = matches;
for (i = 0; i < preselected; i++) { for (i = 0; i < preselected; i++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
} }
} }
@ -180,11 +180,12 @@ void match(void) {
matches = lsubstr; matches = lsubstr;
matchend = substrend; matchend = substrend;
} }
curr = sel = matches;
currentitem = selecteditem = matches;
for (i = 0; i < preselected; i++) { for (i = 0; i < preselected; i++) {
if (sel && sel->right && (sel = sel->right) == next) { if (selecteditem && selecteditem->right && (selecteditem = selecteditem->right) == nextitem) {
curr = next; currentitem = nextitem;
} }
} }

View file

@ -266,7 +266,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw;
if ((lines <= 0 && ex >= 0 && ex <= x + w + sp.promptw + 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)) { (lines > 0 && ey >= y && ey <= y + h)) {
click = ClickInput; click = ClickInput;
@ -289,7 +289,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
ey += h; ey += h;
} }
for (item = curr; item != next; item = item->right) { for (item = currentitem; item != nextitem; item = item->right) {
if (item_num++ == lines) { if (item_num++ == lines) {
item_num = 1; item_num = 1;
x += w / columns; x += w / columns;
@ -328,7 +328,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
x += sp.inputw; x += sp.inputw;
w = larroww; w = larroww;
if (prev && curr->left) { if (previousitem && currentitem->left) {
if (ex >= x && ex <= x + w) { if (ex >= x && ex <= x + w) {
click = ClickLArrow; click = ClickLArrow;
} }
@ -337,7 +337,7 @@ void buttonpress_wl(uint32_t button, double ex, double ey) {
// right arrow // right arrow
w = rarroww; w = rarroww;
x = sp.mw - w; x = sp.mw - w;
if (next && ex >= x && ex <= x + w) { if (nextitem && ex >= x && ex <= x + w) {
click = ClickRArrow; click = ClickRArrow;
} }
} }

View file

@ -50,7 +50,7 @@ void buttonpress_x11(XEvent *e) {
w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw; w = (lines > 0 || !matches) ? sp.mw - x : sp.inputw;
if ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + sp.promptw + 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)) { (lines > 0 && ev->y >= y && ev->y <= y + h)) {
click = ClickInput; click = ClickInput;
@ -73,7 +73,7 @@ void buttonpress_x11(XEvent *e) {
ev->y += h; ev->y += h;
} }
for (item = curr; item != next; item = item->right) { for (item = currentitem; item != nextitem; item = item->right) {
if (item_num++ == lines) { if (item_num++ == lines) {
item_num = 1; item_num = 1;
x += w / columns; x += w / columns;
@ -112,7 +112,7 @@ void buttonpress_x11(XEvent *e) {
x += sp.inputw; x += sp.inputw;
w = larroww; w = larroww;
if (prev && curr->left) { if (previousitem && currentitem->left) {
if (ev->x >= x && ev->x <= x + w) { if (ev->x >= x && ev->x <= x + w) {
click = ClickLArrow; click = ClickLArrow;
} }
@ -121,7 +121,7 @@ void buttonpress_x11(XEvent *e) {
// right arrow // right arrow
w = rarroww; w = rarroww;
x = sp.mw - w; x = sp.mw - w;
if (next && ev->x >= x && ev->x <= x + w) { if (nextitem && ev->x >= x && ev->x <= x + w) {
click = ClickRArrow; click = ClickRArrow;
} }
} }

View file

@ -195,9 +195,16 @@ static struct img img = {0};
static struct x11 x11 = {0}; static struct x11 x11 = {0};
#endif #endif
static struct item *items = NULL, *backup_items, *list_items; static struct item *items = NULL;
static struct item *matches, *matchend; static struct item *history_items;
static struct item *prev, *curr, *next, *sel; 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 // various headers
#include "libs/draw/draw.h" #include "libs/draw/draw.h"
@ -376,14 +383,16 @@ void calcoffsets(void) {
} }
// calculate which items will begin the next page // calculate which items will begin the next page
for (i = 0, next = curr; next; next = next->right) for (i = 0, nextitem = currentitem; nextitem; nextitem = nextitem->right) {
if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(next->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(nextitem->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset)
break; break;
}
// calculate which items will begin the previous page // calculate which items will begin the previous page
for (i = 0, prev = curr; prev && prev->left; prev = prev->left) for (i = 0, previousitem = currentitem; previousitem && previousitem->left; previousitem = previousitem->left) {
if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(prev->left->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset) if ((i += (lines > 0) ? sp.bh : MIN(TEXTWM(previousitem->left->text) + (powerlineitems ? !lines ? 2 * sp.plw : 0 : 0), offset)) > offset)
break; break;
}
} }
int max_textw(void) { int max_textw(void) {