diff --git a/libs/arg.c b/libs/arg.c index a68f16c..27a6920 100644 --- a/libs/arg.c +++ b/libs/arg.c @@ -4,7 +4,7 @@ move(const Arg *arg) struct item *tmpsel; int i, offscreen = 0; - if (arg->i == 3) { /* left */ + if (arg->i == 3) { // left if (columns > 1) { if (!sel) return; @@ -33,7 +33,7 @@ move(const Arg *arg) } if (lines > 0) return; - } else if (arg->i == 4) { + } else if (arg->i == 4) { // right if (columns > 1) { if (!sel) return; @@ -63,13 +63,13 @@ move(const Arg *arg) if (lines > 0) return; - } else if (arg->i == 2) { + } else if (arg->i == 2) { // down if (sel && sel->right && (sel = sel->right) == next) { curr = next; calcoffsets(); } drawmenu(); - } else if (arg->i == 1) { + } else if (arg->i == 1) { // up if (sel && sel->left && (sel = sel->left)->right == curr) { curr = prev; calcoffsets(); @@ -81,8 +81,7 @@ move(const Arg *arg) void complete(const Arg *arg) { - if (!sel) - return; + if (!sel) return; strncpy(text, sel->text, sizeof text - 1); text[sizeof text - 1] = '\0'; @@ -282,7 +281,7 @@ savehistory(char *input) die("failed to write to %s", histfile); } } - if (histsz == 0 || !histnodup || (histsz > 0 && strcmp(input, history[histsz-1]) != 0)) { /* TODO */ + if (histsz == 0 || !histnodup || (histsz > 0 && strcmp(input, history[histsz-1]) != 0)) { if (0 >= fputs(input, fp)) { die("failed to write to %s", histfile); } @@ -347,7 +346,7 @@ setimggaps(const Arg *arg) if (imagegaps < 0) imagegaps = 0; - /* limitation to make sure we have a reasonable gap size */ + // limitation to make sure we have a reasonable gap size if (imagegaps > imagewidth / 2) imagegaps -= arg->i; diff --git a/libs/arg.h b/libs/arg.h index 803c7d2..888ac3e 100644 --- a/libs/arg.h +++ b/libs/arg.h @@ -5,7 +5,7 @@ typedef union { const void *v; } Arg; -/* keybind functions */ +// declare keybind functions static void move(const Arg *arg); static void moveend(const Arg *arg); static void movestart(const Arg *arg); diff --git a/libs/colors.h b/libs/colors.h index c8b5853..f202939 100644 --- a/libs/colors.h +++ b/libs/colors.h @@ -1,8 +1,6 @@ -/* Color options */ - -/* Alpha */ +// color scheme arrays static const unsigned int alphas[][3] = { - /* fg bg border */ + // fg bg border [SchemeLArrow] = { fgalpha, bgalpha, borderalpha }, [SchemeRArrow] = { fgalpha, bgalpha, borderalpha }, [SchemeItemNorm] = { fgalpha, bgalpha, borderalpha }, @@ -20,9 +18,8 @@ static const unsigned int alphas[][3] = { [SchemeBorder] = { fgalpha, bgalpha, borderalpha }, }; -/* Colors */ static const char *colors[SchemeLast][2] = { - /* fg bg */ + // fg bg [SchemeLArrow] = { col_larrowfg, col_larrowbg }, [SchemeRArrow] = { col_rarrowfg, col_rarrowbg }, [SchemeItemNorm] = { col_itemnormfg, col_itemnormbg }, @@ -40,7 +37,8 @@ static const char *colors[SchemeLast][2] = { [SchemeBorder] = { NULL, col_bordercolor }, }; -/* sgr colors */ +// sgr colors +// to enable 256 color support, append to this. static char *textcolors[] = { col_sgrcolor0, col_sgrcolor1, diff --git a/libs/define.c b/libs/define.c index 879ab4c..03bc275 100644 --- a/libs/define.c +++ b/libs/define.c @@ -11,7 +11,7 @@ #define NUMBERSMAXDIGITS 100 #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 -/* user friendly names for all the modifiers */ +// user friendly names for all the modifiers #define CONTROL ControlMask #define SHIFT ShiftMask #define ALT Mod1Mask @@ -19,5 +19,5 @@ #define SUPER Mod4Mask #define SUPERR Mod5Mask -/* alpha */ +// alpha #define opaque 0xffU diff --git a/libs/draw.c b/libs/draw.c index b6da491..a8640ee 100644 --- a/libs/draw.c +++ b/libs/draw.c @@ -20,7 +20,7 @@ drawhighlights(struct item *item, int x, int y, int w) indent = TEXTW(itemtext) - lrpad; *highlight = c; - /* highlight character */ + // highlight character c = highlight[1]; highlight[1] = '\0'; drw_text( @@ -41,9 +41,9 @@ drawitem(struct item *item, int x, int y, int w) { char buffer[sizeof(item->text) + lrpad / 2]; Clr scm[3]; - int lp = lrpad / 2; /* padding */ + int lp = lrpad / 2; // padding int wr, rd; - int rw = 0; /* width of text */ + int rw = 0; // width of text int orw = 0; int fg = 7; int bg = 0; @@ -65,7 +65,7 @@ drawitem(struct item *item, int x, int y, int w) drw_setscheme(drw, scm); // set scheme - /* parse item text */ + // parse item text for (wr = 0, rd = 0; item->text[rd]; rd++) { if (item->text[rd] == '' && item->text[rd + 1] == '[') { size_t alen = strspn(item->text + rd + 2, @@ -84,7 +84,7 @@ drawitem(struct item *item, int x, int y, int w) char *ep = item->text + rd + 1; - /* parse hex colors in scm */ + // parse hex colors in scm while (*ep != 'm') { unsigned v = strtoul(ep + 1, &ep, 10); if (ignore) diff --git a/libs/event.c b/libs/event.c index ab2d510..34d4890 100644 --- a/libs/event.c +++ b/libs/event.c @@ -20,7 +20,7 @@ eventloop(void) drw_map(drw, win, 0, 0, mw, mh); break; case FocusIn: - /* regrab focus from parent window */ + // regrab focus from parent window if (ev.xfocus.window != win) grabfocus(); break; @@ -37,7 +37,7 @@ eventloop(void) break; } - /* redraw image on X11 event */ + // redraw image on X11 event #if USEIMAGE drawimage(); #endif diff --git a/libs/img-c.c b/libs/img-c.c index d3465c6..28060c1 100644 --- a/libs/img-c.c +++ b/libs/img-c.c @@ -8,7 +8,7 @@ setimagesize(int width, int height) int oih = 0; int oiw = 0; - /* this makes sure we cannot scale the image up or down too much */ + // this makes sure we cannot scale the image up or down too much if ((!image && height < imageheight) || (!image && width < imagewidth) || width > mw || hideimage) return; oih = imageheight; @@ -34,13 +34,13 @@ void flipimage(void) { switch (flip) { - case 1: /* horizontal */ + case 1: // horizontal imlib_image_flip_horizontal(); break; - case 2: /* vertical */ + case 2: // vertical imlib_image_flip_vertical(); break; - case 3: /* diagonal */ + case 3: // diagonal imlib_image_flip_diagonal(); break; default: @@ -73,7 +73,7 @@ drawimage(void) if (!lines || hideimage) return; - /* to prevent the image from being drawn multiple times */ + // to prevent the image from being drawn multiple times if (!needredraw) { needredraw = 1; return; @@ -96,15 +96,15 @@ drawimage(void) resizetoimageheight(height); } - if (!imageposition) { /* top mode = 0 */ + if (!imageposition) { // top mode = 0 if (height > width) width = height; imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, bh+imagegaps); - } else if (imageposition == 1) { /* bottom mode = 1 */ + } else if (imageposition == 1) { // bottom mode = 1 if (height > width) width = height; imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, mh-height-imagegaps); - } else if (imageposition == 2) { /* center mode = 2 */ + } else if (imageposition == 2) { // center mode = 2 imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-bh-height)/2+bh); } else { int minh = MIN(height, mh-bh-imagegaps*2); @@ -219,7 +219,7 @@ loadimagecache(const char *file, int *width, int *height) char *xdg_cache, *home = NULL, *dsize, *buf = NULL; struct passwd *pw = NULL; - /* just load and don't store or try cache */ + // just load and don't store or try cache if (longestedge > 256) { loadimage(file, width, height); if (image) @@ -228,7 +228,7 @@ loadimagecache(const char *file, int *width, int *height) } if (generatecache) { - /* try find image from cache first */ + // try find image from cache first if(!(xdg_cache = getenv("XDG_CACHE_HOME"))) { if(!(home = getenv("HOME")) && (pw = getpwuid(getuid()))) home = pw->pw_dir; @@ -238,7 +238,7 @@ loadimagecache(const char *file, int *width, int *height) } } - /* which cache do we try? */ + // which cache do we try? dsize = "normal"; if (longestedge > 128) dsize = "large"; @@ -250,7 +250,7 @@ loadimagecache(const char *file, int *width, int *height) return; } - /* calculate md5 from path */ + // calculate md5 from path sprintf(buf, "file://%s", file); MD5((unsigned char*)buf, slen, digest); @@ -259,7 +259,7 @@ loadimagecache(const char *file, int *width, int *height) for(i = 0; i < MD5_DIGEST_LENGTH; ++i) sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]); - /* path for cached thumbnail */ + // path for cached thumbnail if (xdg_cache) slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1; else @@ -284,14 +284,14 @@ loadimagecache(const char *file, int *width, int *height) scaleimage(width, height); } - /* we are done */ + // we are done if (image) { free(buf); return; } } - /* we din't find anything from cache, or it was just wrong */ + // we din't find anything from cache, or it was just wrong loadimage(file, width, height); scaleimage(width, height); diff --git a/libs/key.c b/libs/key.c index 3110b6c..eee500c 100644 --- a/libs/key.c +++ b/libs/key.c @@ -63,9 +63,10 @@ grabkeyboard(void) struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; int i; + // don't grab if embedded if (embed || managed) return; - /* try to grab keyboard, we may have to wait for another process to ungrab */ + // try to grab keyboard, we may have to wait for another process to ungrab for (i = 0; i < 1000; i++) { if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, GrabModeAsync, CurrentTime) == GrabSuccess) diff --git a/libs/match.c b/libs/match.c index 4913685..93c28cc 100644 --- a/libs/match.c +++ b/libs/match.c @@ -11,15 +11,15 @@ fuzzymatch(void) matches = matchend = NULL; - /* walk through all items */ + // walk through all items for (it = items; it && it->text; it++) { if (text_len) { itext_len = strlen(it->text); - pidx = 0; /* pointer */ - sidx = eidx = -1; /* start of match, end of match */ - /* walk through item text */ + pidx = 0; // pointer + sidx = eidx = -1; // start of match, end of match + // walk through item text for (i = 0; i < itext_len && (c = it->text[i]); i++) { - /* fuzzy match pattern */ + // fuzzy match pattern if (!fstrncmp(&text[pidx], &c, 1)) { if(sidx == -1) sidx = i; @@ -30,13 +30,13 @@ fuzzymatch(void) } } } - /* build list of matches */ + // build list of matches if (eidx != -1) { - /* compute distance */ - /* add penalty if match starts late (log(sidx+2)) - * add penalty for long a match without many matching characters */ + // compute distance + // add penalty if match starts late (log(sidx+2)) + //add penalty for long a match without many matching characters it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len); - /* fprintf(stderr, "distance %s %f\n", it->text, it->distance); */ + // fprintf(stderr, "distance %s %f\n", it->text, it->distance); appenditem(it, &matches, &matchend); number_of_matches++; } @@ -46,16 +46,16 @@ fuzzymatch(void) } if (number_of_matches) { - /* initialize array with matches */ + // initialize array with matches if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) die("cannot realloc %u bytes:", number_of_matches * sizeof(struct item*)); for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) { fuzzymatches[i] = it; } - /* sort matches according to distance */ + // sort matches according to distance if (sortmatches) qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance); - /* rebuild list of matches */ + // rebuild list of matches matches = matchend = NULL; for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \ it->text; i++, it = fuzzymatches[i]) { @@ -102,7 +102,7 @@ match(void) strcpy(buf, text); - /* separate input text into tokens to be matched individually */ + // separate input text into tokens to be matched individually for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " ")) if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) die("cannot realloc %u bytes:", tokn * sizeof *tokv); @@ -114,12 +114,12 @@ match(void) for (i = 0; i < tokc; i++) if (!fstrstr(item->text, tokv[i])) break; - if (i != tokc) /* not all tokens match */ + if (i != tokc) // not all tokens match continue; if (!sortmatches) appenditem(item, &matches, &matchend); else { - /* exact matches go first, then prefixes with high priority, then prefixes, then substrings */ + // exact matches go first, then prefixes with high priority, then prefixes, then substrings if (item->hp && !fstrncmp(tokv[0], item->text, len)) appenditem(item, &lhpprefix, &hpprefixend); else if (!tokc || !fstrncmp(text, item->text, textsize)) diff --git a/libs/mode.h b/libs/mode.h index 52a53b4..4251bab 100644 --- a/libs/mode.h +++ b/libs/mode.h @@ -1,8 +1,8 @@ -static char modetext[16] = "Insert"; /* default mode text */ +static char modetext[16] = "Insert"; // default mode text -/* mode settings */ -static int curMode = 1; /* 0 is command mode */ -static int allowkeys = 1; /* whether or not to interpret a keypress as an insertion */ +// mode settings +static int curMode = 1; // 0 is command mode +static int allowkeys = 1; // whether or not to interpret a keypress as an insertion -/* mode functions */ +// mode functions static void switchmode(const Arg *arg); diff --git a/libs/mouse.c b/libs/mouse.c index a10e668..02d665d 100644 --- a/libs/mouse.c +++ b/libs/mouse.c @@ -5,22 +5,21 @@ buttonpress(XEvent *e) XButtonPressedEvent *ev = &e->xbutton; int x = 0, y = 0, h = bh, w, item_num = 0; + // if incorrect or wrong window, return if (ev->window != win) return; - /* right-click: exit */ + // right-click: exit if (ev->button == Button3) exit(1); if (prompt && *prompt) x += promptw; - /* input field */ + // input field w = (lines > 0 || !matches) ? mw - x : inputw; - /* left-click on input: clear input, - * NOTE: if there is no left-arrow the space for < is reserved so - * add that to the input width */ + // left-click on input: clear input if (ev->button == Button1 && ((lines <= 0 && ev->x >= 0 && ev->x <= x + w + ((!prev || !curr->left) ? TEXTW(leftarrow) : 0)) || @@ -29,21 +28,21 @@ buttonpress(XEvent *e) drawmenu(); return; } - /* middle-mouse click: paste selection */ + // middle-mouse click: paste selection if (ev->button == Button2) { XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, utf8, utf8, win, CurrentTime); drawmenu(); return; } - /* scroll up */ + // scroll up if (ev->button == Button4 && prev) { sel = curr = prev; calcoffsets(); drawmenu(); return; } - /* scroll down */ + // scroll down if (ev->button == Button5 && next) { sel = curr = next; calcoffsets(); @@ -55,7 +54,7 @@ buttonpress(XEvent *e) if (ev->state & ~ControlMask) return; if (lines > 0) { - /* vertical list: (ctrl)left-click on item */ + // vertical list: (ctrl)left-click on item w = mw - x; for (item = curr; item != next; item = item->right) { if (item_num++ == lines){ @@ -77,7 +76,7 @@ buttonpress(XEvent *e) } } } else if (matches) { - /* left-click on left arrow */ + // left-click on left arrow x += inputw; w = TEXTW(leftarrow); if (prev && curr->left) { @@ -88,7 +87,7 @@ buttonpress(XEvent *e) return; } } - /* horizontal list: (ctrl)left-click on item */ + // horizontal list: (ctrl)left-click on item for (item = curr; item != next; item = item->right) { x += w; w = MIN(TEXTW(item->text), mw - x - TEXTW(rightarrow)); @@ -103,7 +102,7 @@ buttonpress(XEvent *e) return; } } - /* left-click on right arrow */ + // left-click on right arrow w = TEXTW(rightarrow); x = mw - w; if (next && ev->x >= x && ev->x <= x + w) { diff --git a/libs/rtl-c.h b/libs/rtl-c.h index cc8008f..79a92aa 100644 --- a/libs/rtl-c.h +++ b/libs/rtl-c.h @@ -1,4 +1,4 @@ static char fribidi_text[BUFSIZ] = ""; -/* functions */ +// declare functions static void apply_fribidi(char *str); diff --git a/libs/schemes.c b/libs/schemes.c index 6cc6cc6..27685ad 100644 --- a/libs/schemes.c +++ b/libs/schemes.c @@ -11,7 +11,7 @@ init_appearance(void) char cbuf[8]; - /* init appearance */ + // create color schemes from array for (j = 0; j < SchemeLast; j++) { scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2); } diff --git a/libs/schemes.h b/libs/schemes.h index e7d915d..c3625bd 100644 --- a/libs/schemes.h +++ b/libs/schemes.h @@ -1,5 +1,6 @@ static void init_appearance(void); -/* color schemes */ + +// Color schemes enum { SchemeLArrow, SchemeRArrow, SchemeItemNorm, diff --git a/libs/xrdb.h b/libs/xrdb.h index 8e0fa00..9007c7a 100644 --- a/libs/xrdb.h +++ b/libs/xrdb.h @@ -10,6 +10,6 @@ typedef struct { void *dst; } ResourcePref; -/* functions */ +// declare functions static void load_xresources(void); static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst); diff --git a/libs/xresources.h b/libs/xresources.h index 82d4f71..776c3fd 100644 --- a/libs/xresources.h +++ b/libs/xresources.h @@ -1,7 +1,4 @@ -/* This header is for the .Xresources options. - * These will be set on startup by xrdb. - */ - +// This .Xresources array is read and compared to the xrdb. Simply add to the array if you need to. ResourcePref resources[] = { { "font", STRING, &font }, { "col_caretfgcolor", STRING, &col_caretfgcolor }, @@ -32,7 +29,7 @@ ResourcePref resources[] = { { "col_promptfg", STRING, &col_promptfg }, { "col_promptbg", STRING, &col_promptbg }, - /* Pywal support */ + // Universal colors { "color10", STRING, &col_caretfgcolor }, { "color4", STRING, &col_larrowfg }, { "color4", STRING, &col_rarrowfg }, @@ -61,7 +58,7 @@ ResourcePref resources[] = { { "color0", STRING, &col_normhlfgcolor }, { "color0", STRING, &col_selhlfgcolor }, - /* sgr colors */ + // SGR sequence colors { "col_sgrcolor0", STRING, &col_sgrcolor0 }, { "col_sgrcolor1", STRING, &col_sgrcolor1 }, { "col_sgrcolor2", STRING, &col_sgrcolor2 }, @@ -79,7 +76,7 @@ ResourcePref resources[] = { { "col_sgrcolor14", STRING, &col_sgrcolor14 }, { "col_sgrcolor15", STRING, &col_sgrcolor15 }, - /* sgr colors */ + // SGR sequence colors (universal) { "color0", STRING, &col_sgrcolor0 }, { "color1", STRING, &col_sgrcolor1 }, { "color2", STRING, &col_sgrcolor2 }, diff --git a/spmenu.c b/spmenu.c index 74073fa..d84f786 100644 --- a/spmenu.c +++ b/spmenu.c @@ -285,7 +285,8 @@ calcoffsets(void) 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) if ((i += (lines > 0) ? bh : MIN(TEXTWM(next->text), n)) > n) break; @@ -638,6 +639,7 @@ readstdin(void) // spmenu:test if (!strncmp("test", items[i].ex, strlen("test"))) { system("command -v spmenu_test > /dev/null && spmenu_test"); + exit(0); } } } @@ -690,14 +692,15 @@ setup(void) lines = MAX(lines, 0); reallines = lines; + // resize client to image height if deemed necessary #if USEIMAGE - if (image) - resizetoimageheight(imageheight); + if (image) resizetoimageheight(imageheight); #endif - mh = (lines + 1) * bh; - promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; + mh = (lines + 1) * bh; // lines + 1 * bh is the menu height + promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; // prompt width + // get accurate width if (accuratewidth) { for (item = items; !lines && item && item->text; ++item) { curstrlen = strlen(item->text); @@ -713,6 +716,7 @@ setup(void) } } + // init xinerama screens #if USEXINERAMA i = 0; if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { @@ -720,12 +724,12 @@ setup(void) if (mon >= 0 && mon < n) i = mon; else if (w != root && w != PointerRoot && w != None) { - /* find top-level window containing current input focus */ + // find top-level window containing current input focus do { if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) XFree(dws); } while (w != root && w != pw); - /* find xinerama screen with which the window intersects most */ + // find xinerama screen with which the window intersects most if (XGetWindowAttributes(dpy, pw, &wa)) for (j = 0; j < n; j++) if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { @@ -733,21 +737,20 @@ setup(void) i = j; } } - /* no focused window is on screen, so use pointer location instead */ + // no focused window is on screen, so use pointer location instead if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du)) for (i = 0; i < n; i++) if (INTERSECT(x, y, 1, 1, info[i])) break; + // calculate x/y position if (centered) { - mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width); x = info[i].x_org + ((info[i].width - mw) / 2); - //y = info[i].y_org + 0; y = info[i].y_org + ((info[i].height - mh) / 2); + mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width); } else { x = info[i].x_org + dmx; y = info[i].y_org + (menuposition ? 0 : info[i].height - mh - dmy); - //y = info[i].y_org + 0; mw = (dmw>0 ? dmw : info[i].width); } @@ -801,6 +804,8 @@ setup(void) } grabfocus(); } + + // resize and draw drw_resize(drw, mw, mh); drawmenu(); } @@ -879,5 +884,5 @@ main(int argc, char *argv[]) setup(); eventloop(); - return 1; /* unreachable */ + return 1; }