replace almost all /* style comments with // where it makes sense

This commit is contained in:
speedie 2023-03-16 16:54:36 +01:00
parent 81f26de355
commit 1153d416ab
17 changed files with 97 additions and 97 deletions

View file

@ -4,7 +4,7 @@ move(const Arg *arg)
struct item *tmpsel; struct item *tmpsel;
int i, offscreen = 0; int i, offscreen = 0;
if (arg->i == 3) { /* left */ if (arg->i == 3) { // left
if (columns > 1) { if (columns > 1) {
if (!sel) if (!sel)
return; return;
@ -33,7 +33,7 @@ move(const Arg *arg)
} }
if (lines > 0) if (lines > 0)
return; return;
} else if (arg->i == 4) { } else if (arg->i == 4) { // right
if (columns > 1) { if (columns > 1) {
if (!sel) if (!sel)
return; return;
@ -63,13 +63,13 @@ move(const Arg *arg)
if (lines > 0) if (lines > 0)
return; return;
} else if (arg->i == 2) { } else if (arg->i == 2) { // down
if (sel && sel->right && (sel = sel->right) == next) { if (sel && sel->right && (sel = sel->right) == next) {
curr = next; curr = next;
calcoffsets(); calcoffsets();
} }
drawmenu(); drawmenu();
} else if (arg->i == 1) { } else if (arg->i == 1) { // up
if (sel && sel->left && (sel = sel->left)->right == curr) { if (sel && sel->left && (sel = sel->left)->right == curr) {
curr = prev; curr = prev;
calcoffsets(); calcoffsets();
@ -81,8 +81,7 @@ move(const Arg *arg)
void void
complete(const Arg *arg) complete(const Arg *arg)
{ {
if (!sel) if (!sel) return;
return;
strncpy(text, sel->text, sizeof text - 1); strncpy(text, sel->text, sizeof text - 1);
text[sizeof text - 1] = '\0'; text[sizeof text - 1] = '\0';
@ -282,7 +281,7 @@ savehistory(char *input)
die("failed to write to %s", histfile); 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)) { if (0 >= fputs(input, fp)) {
die("failed to write to %s", histfile); die("failed to write to %s", histfile);
} }
@ -347,7 +346,7 @@ setimggaps(const Arg *arg)
if (imagegaps < 0) if (imagegaps < 0)
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) if (imagegaps > imagewidth / 2)
imagegaps -= arg->i; imagegaps -= arg->i;

View file

@ -5,7 +5,7 @@ typedef union {
const void *v; const void *v;
} Arg; } Arg;
/* keybind functions */ // declare keybind functions
static void move(const Arg *arg); static void move(const Arg *arg);
static void moveend(const Arg *arg); static void moveend(const Arg *arg);
static void movestart(const Arg *arg); static void movestart(const Arg *arg);

View file

@ -1,8 +1,6 @@
/* Color options */ // color scheme arrays
/* Alpha */
static const unsigned int alphas[][3] = { static const unsigned int alphas[][3] = {
/* fg bg border */ // fg bg border
[SchemeLArrow] = { fgalpha, bgalpha, borderalpha }, [SchemeLArrow] = { fgalpha, bgalpha, borderalpha },
[SchemeRArrow] = { fgalpha, bgalpha, borderalpha }, [SchemeRArrow] = { fgalpha, bgalpha, borderalpha },
[SchemeItemNorm] = { fgalpha, bgalpha, borderalpha }, [SchemeItemNorm] = { fgalpha, bgalpha, borderalpha },
@ -20,9 +18,8 @@ static const unsigned int alphas[][3] = {
[SchemeBorder] = { fgalpha, bgalpha, borderalpha }, [SchemeBorder] = { fgalpha, bgalpha, borderalpha },
}; };
/* Colors */
static const char *colors[SchemeLast][2] = { static const char *colors[SchemeLast][2] = {
/* fg bg */ // fg bg
[SchemeLArrow] = { col_larrowfg, col_larrowbg }, [SchemeLArrow] = { col_larrowfg, col_larrowbg },
[SchemeRArrow] = { col_rarrowfg, col_rarrowbg }, [SchemeRArrow] = { col_rarrowfg, col_rarrowbg },
[SchemeItemNorm] = { col_itemnormfg, col_itemnormbg }, [SchemeItemNorm] = { col_itemnormfg, col_itemnormbg },
@ -40,7 +37,8 @@ static const char *colors[SchemeLast][2] = {
[SchemeBorder] = { NULL, col_bordercolor }, [SchemeBorder] = { NULL, col_bordercolor },
}; };
/* sgr colors */ // sgr colors
// to enable 256 color support, append to this.
static char *textcolors[] = { static char *textcolors[] = {
col_sgrcolor0, col_sgrcolor0,
col_sgrcolor1, col_sgrcolor1,

View file

@ -11,7 +11,7 @@
#define NUMBERSMAXDIGITS 100 #define NUMBERSMAXDIGITS 100
#define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1 #define NUMBERSBUFSIZE (NUMBERSMAXDIGITS * 2) + 1
/* user friendly names for all the modifiers */ // user friendly names for all the modifiers
#define CONTROL ControlMask #define CONTROL ControlMask
#define SHIFT ShiftMask #define SHIFT ShiftMask
#define ALT Mod1Mask #define ALT Mod1Mask
@ -19,5 +19,5 @@
#define SUPER Mod4Mask #define SUPER Mod4Mask
#define SUPERR Mod5Mask #define SUPERR Mod5Mask
/* alpha */ // alpha
#define opaque 0xffU #define opaque 0xffU

View file

@ -20,7 +20,7 @@ drawhighlights(struct item *item, int x, int y, int w)
indent = TEXTW(itemtext) - lrpad; indent = TEXTW(itemtext) - lrpad;
*highlight = c; *highlight = c;
/* highlight character */ // highlight character
c = highlight[1]; c = highlight[1];
highlight[1] = '\0'; highlight[1] = '\0';
drw_text( drw_text(
@ -41,9 +41,9 @@ drawitem(struct item *item, int x, int y, int w)
{ {
char buffer[sizeof(item->text) + lrpad / 2]; char buffer[sizeof(item->text) + lrpad / 2];
Clr scm[3]; Clr scm[3];
int lp = lrpad / 2; /* padding */ int lp = lrpad / 2; // padding
int wr, rd; int wr, rd;
int rw = 0; /* width of text */ int rw = 0; // width of text
int orw = 0; int orw = 0;
int fg = 7; int fg = 7;
int bg = 0; int bg = 0;
@ -65,7 +65,7 @@ drawitem(struct item *item, int x, int y, int w)
drw_setscheme(drw, scm); // set scheme drw_setscheme(drw, scm); // set scheme
/* parse item text */ // parse item text
for (wr = 0, rd = 0; item->text[rd]; rd++) { for (wr = 0, rd = 0; item->text[rd]; rd++) {
if (item->text[rd] == '' && item->text[rd + 1] == '[') { if (item->text[rd] == '' && item->text[rd + 1] == '[') {
size_t alen = strspn(item->text + rd + 2, 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; char *ep = item->text + rd + 1;
/* parse hex colors in scm */ // parse hex colors in scm
while (*ep != 'm') { while (*ep != 'm') {
unsigned v = strtoul(ep + 1, &ep, 10); unsigned v = strtoul(ep + 1, &ep, 10);
if (ignore) if (ignore)

View file

@ -20,7 +20,7 @@ eventloop(void)
drw_map(drw, win, 0, 0, mw, mh); drw_map(drw, win, 0, 0, mw, mh);
break; break;
case FocusIn: case FocusIn:
/* regrab focus from parent window */ // regrab focus from parent window
if (ev.xfocus.window != win) if (ev.xfocus.window != win)
grabfocus(); grabfocus();
break; break;
@ -37,7 +37,7 @@ eventloop(void)
break; break;
} }
/* redraw image on X11 event */ // redraw image on X11 event
#if USEIMAGE #if USEIMAGE
drawimage(); drawimage();
#endif #endif

View file

@ -8,7 +8,7 @@ setimagesize(int width, int height)
int oih = 0; int oih = 0;
int oiw = 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; if ((!image && height < imageheight) || (!image && width < imagewidth) || width > mw || hideimage) return;
oih = imageheight; oih = imageheight;
@ -34,13 +34,13 @@ void
flipimage(void) flipimage(void)
{ {
switch (flip) { switch (flip) {
case 1: /* horizontal */ case 1: // horizontal
imlib_image_flip_horizontal(); imlib_image_flip_horizontal();
break; break;
case 2: /* vertical */ case 2: // vertical
imlib_image_flip_vertical(); imlib_image_flip_vertical();
break; break;
case 3: /* diagonal */ case 3: // diagonal
imlib_image_flip_diagonal(); imlib_image_flip_diagonal();
break; break;
default: default:
@ -73,7 +73,7 @@ drawimage(void)
if (!lines || hideimage) return; if (!lines || hideimage) return;
/* to prevent the image from being drawn multiple times */ // to prevent the image from being drawn multiple times
if (!needredraw) { if (!needredraw) {
needredraw = 1; needredraw = 1;
return; return;
@ -96,15 +96,15 @@ drawimage(void)
resizetoimageheight(height); resizetoimageheight(height);
} }
if (!imageposition) { /* top mode = 0 */ if (!imageposition) { // top mode = 0
if (height > width) if (height > width)
width = height; width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, bh+imagegaps); 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) if (height > width)
width = height; width = height;
imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, mh-height-imagegaps); 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); imlib_render_image_on_drawable(leftmargin+(imagewidth-width)/2, (mh-bh-height)/2+bh);
} else { } else {
int minh = MIN(height, mh-bh-imagegaps*2); 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; char *xdg_cache, *home = NULL, *dsize, *buf = NULL;
struct passwd *pw = 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) { if (longestedge > 256) {
loadimage(file, width, height); loadimage(file, width, height);
if (image) if (image)
@ -228,7 +228,7 @@ loadimagecache(const char *file, int *width, int *height)
} }
if (generatecache) { if (generatecache) {
/* try find image from cache first */ // try find image from cache first
if(!(xdg_cache = getenv("XDG_CACHE_HOME"))) { if(!(xdg_cache = getenv("XDG_CACHE_HOME"))) {
if(!(home = getenv("HOME")) && (pw = getpwuid(getuid()))) if(!(home = getenv("HOME")) && (pw = getpwuid(getuid())))
home = pw->pw_dir; 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"; dsize = "normal";
if (longestedge > 128) if (longestedge > 128)
dsize = "large"; dsize = "large";
@ -250,7 +250,7 @@ loadimagecache(const char *file, int *width, int *height)
return; return;
} }
/* calculate md5 from path */ // calculate md5 from path
sprintf(buf, "file://%s", file); sprintf(buf, "file://%s", file);
MD5((unsigned char*)buf, slen, digest); 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) for(i = 0; i < MD5_DIGEST_LENGTH; ++i)
sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]); sprintf(&md5[i*2], "%02x", (unsigned int)digest[i]);
/* path for cached thumbnail */ // path for cached thumbnail
if (xdg_cache) if (xdg_cache)
slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1; slen = snprintf(NULL, 0, "%s/thumbnails/%s/%s.png", xdg_cache, dsize, md5)+1;
else else
@ -284,14 +284,14 @@ loadimagecache(const char *file, int *width, int *height)
scaleimage(width, height); scaleimage(width, height);
} }
/* we are done */ // we are done
if (image) { if (image) {
free(buf); free(buf);
return; 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); loadimage(file, width, height);
scaleimage(width, height); scaleimage(width, height);

View file

@ -63,9 +63,10 @@ grabkeyboard(void)
struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 }; struct timespec ts = { .tv_sec = 0, .tv_nsec = 1000000 };
int i; int i;
// don't grab if embedded
if (embed || managed) if (embed || managed)
return; 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++) { for (i = 0; i < 1000; i++) {
if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync, if (XGrabKeyboard(dpy, DefaultRootWindow(dpy), True, GrabModeAsync,
GrabModeAsync, CurrentTime) == GrabSuccess) GrabModeAsync, CurrentTime) == GrabSuccess)

View file

@ -11,15 +11,15 @@ fuzzymatch(void)
matches = matchend = NULL; matches = matchend = NULL;
/* walk through all items */ // walk through all items
for (it = items; it && it->text; it++) { for (it = items; it && it->text; it++) {
if (text_len) { if (text_len) {
itext_len = strlen(it->text); itext_len = strlen(it->text);
pidx = 0; /* pointer */ pidx = 0; // pointer
sidx = eidx = -1; /* start of match, end of match */ sidx = eidx = -1; // start of match, end of match
/* walk through item text */ // walk through item text
for (i = 0; i < itext_len && (c = it->text[i]); i++) { for (i = 0; i < itext_len && (c = it->text[i]); i++) {
/* fuzzy match pattern */ // fuzzy match pattern
if (!fstrncmp(&text[pidx], &c, 1)) { if (!fstrncmp(&text[pidx], &c, 1)) {
if(sidx == -1) if(sidx == -1)
sidx = i; sidx = i;
@ -30,13 +30,13 @@ fuzzymatch(void)
} }
} }
} }
/* build list of matches */ // build list of matches
if (eidx != -1) { if (eidx != -1) {
/* compute distance */ // compute distance
/* add penalty if match starts late (log(sidx+2)) // add penalty if match starts late (log(sidx+2))
* add penalty for long a match without many matching characters */ //add penalty for long a match without many matching characters
it->distance = log(sidx + 2) + (double)(eidx - sidx - text_len); 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); appenditem(it, &matches, &matchend);
number_of_matches++; number_of_matches++;
} }
@ -46,16 +46,16 @@ fuzzymatch(void)
} }
if (number_of_matches) { if (number_of_matches) {
/* initialize array with matches */ // initialize array with matches
if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*)))) if (!(fuzzymatches = realloc(fuzzymatches, number_of_matches * sizeof(struct item*))))
die("cannot realloc %u bytes:", 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) { for (i = 0, it = matches; it && i < number_of_matches; i++, it = it->right) {
fuzzymatches[i] = it; 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); if (sortmatches) qsort(fuzzymatches, number_of_matches, sizeof(struct item*), compare_distance);
/* rebuild list of matches */ // rebuild list of matches
matches = matchend = NULL; matches = matchend = NULL;
for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \ for (i = 0, it = fuzzymatches[i]; i < number_of_matches && it && \
it->text; i++, it = fuzzymatches[i]) { it->text; i++, it = fuzzymatches[i]) {
@ -102,7 +102,7 @@ match(void)
strcpy(buf, text); 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, " ")) for (s = strtok(buf, " "); s; tokv[tokc - 1] = s, s = strtok(NULL, " "))
if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv))) if (++tokc > tokn && !(tokv = realloc(tokv, ++tokn * sizeof *tokv)))
die("cannot realloc %u bytes:", tokn * sizeof *tokv); die("cannot realloc %u bytes:", tokn * sizeof *tokv);
@ -114,12 +114,12 @@ match(void)
for (i = 0; i < tokc; i++) for (i = 0; i < tokc; i++)
if (!fstrstr(item->text, tokv[i])) if (!fstrstr(item->text, tokv[i]))
break; break;
if (i != tokc) /* not all tokens match */ if (i != tokc) // not all tokens match
continue; continue;
if (!sortmatches) if (!sortmatches)
appenditem(item, &matches, &matchend); appenditem(item, &matches, &matchend);
else { 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)) if (item->hp && !fstrncmp(tokv[0], item->text, len))
appenditem(item, &lhpprefix, &hpprefixend); appenditem(item, &lhpprefix, &hpprefixend);
else if (!tokc || !fstrncmp(text, item->text, textsize)) else if (!tokc || !fstrncmp(text, item->text, textsize))

View file

@ -1,8 +1,8 @@
static char modetext[16] = "Insert"; /* default mode text */ static char modetext[16] = "Insert"; // default mode text
/* mode settings */ // mode settings
static int curMode = 1; /* 0 is command mode */ static int curMode = 1; // 0 is command mode
static int allowkeys = 1; /* whether or not to interpret a keypress as an insertion */ static int allowkeys = 1; // whether or not to interpret a keypress as an insertion
/* mode functions */ // mode functions
static void switchmode(const Arg *arg); static void switchmode(const Arg *arg);

View file

@ -5,22 +5,21 @@ buttonpress(XEvent *e)
XButtonPressedEvent *ev = &e->xbutton; XButtonPressedEvent *ev = &e->xbutton;
int x = 0, y = 0, h = bh, w, item_num = 0; int x = 0, y = 0, h = bh, w, item_num = 0;
// if incorrect or wrong window, return
if (ev->window != win) if (ev->window != win)
return; return;
/* right-click: exit */ // right-click: exit
if (ev->button == Button3) if (ev->button == Button3)
exit(1); exit(1);
if (prompt && *prompt) if (prompt && *prompt)
x += promptw; x += promptw;
/* input field */ // input field
w = (lines > 0 || !matches) ? mw - x : inputw; w = (lines > 0 || !matches) ? mw - x : inputw;
/* left-click on input: clear input, // 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 */
if (ev->button == Button1 && if (ev->button == Button1 &&
((lines <= 0 && ev->x >= 0 && ev->x <= x + w + ((lines <= 0 && ev->x >= 0 && ev->x <= x + w +
((!prev || !curr->left) ? TEXTW(leftarrow) : 0)) || ((!prev || !curr->left) ? TEXTW(leftarrow) : 0)) ||
@ -29,21 +28,21 @@ buttonpress(XEvent *e)
drawmenu(); drawmenu();
return; return;
} }
/* middle-mouse click: paste selection */ // middle-mouse click: paste selection
if (ev->button == Button2) { if (ev->button == Button2) {
XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY, XConvertSelection(dpy, (ev->state & ShiftMask) ? clip : XA_PRIMARY,
utf8, utf8, win, CurrentTime); utf8, utf8, win, CurrentTime);
drawmenu(); drawmenu();
return; return;
} }
/* scroll up */ // scroll up
if (ev->button == Button4 && prev) { if (ev->button == Button4 && prev) {
sel = curr = prev; sel = curr = prev;
calcoffsets(); calcoffsets();
drawmenu(); drawmenu();
return; return;
} }
/* scroll down */ // scroll down
if (ev->button == Button5 && next) { if (ev->button == Button5 && next) {
sel = curr = next; sel = curr = next;
calcoffsets(); calcoffsets();
@ -55,7 +54,7 @@ buttonpress(XEvent *e)
if (ev->state & ~ControlMask) if (ev->state & ~ControlMask)
return; return;
if (lines > 0) { if (lines > 0) {
/* vertical list: (ctrl)left-click on item */ // vertical list: (ctrl)left-click on item
w = mw - x; w = mw - x;
for (item = curr; item != next; item = item->right) { for (item = curr; item != next; item = item->right) {
if (item_num++ == lines){ if (item_num++ == lines){
@ -77,7 +76,7 @@ buttonpress(XEvent *e)
} }
} }
} else if (matches) { } else if (matches) {
/* left-click on left arrow */ // left-click on left arrow
x += inputw; x += inputw;
w = TEXTW(leftarrow); w = TEXTW(leftarrow);
if (prev && curr->left) { if (prev && curr->left) {
@ -88,7 +87,7 @@ buttonpress(XEvent *e)
return; return;
} }
} }
/* horizontal list: (ctrl)left-click on item */ // horizontal list: (ctrl)left-click on item
for (item = curr; item != next; item = item->right) { for (item = curr; item != next; item = item->right) {
x += w; x += w;
w = MIN(TEXTW(item->text), mw - x - TEXTW(rightarrow)); w = MIN(TEXTW(item->text), mw - x - TEXTW(rightarrow));
@ -103,7 +102,7 @@ buttonpress(XEvent *e)
return; return;
} }
} }
/* left-click on right arrow */ // left-click on right arrow
w = TEXTW(rightarrow); w = TEXTW(rightarrow);
x = mw - w; x = mw - w;
if (next && ev->x >= x && ev->x <= x + w) { if (next && ev->x >= x && ev->x <= x + w) {

View file

@ -1,4 +1,4 @@
static char fribidi_text[BUFSIZ] = ""; static char fribidi_text[BUFSIZ] = "";
/* functions */ // declare functions
static void apply_fribidi(char *str); static void apply_fribidi(char *str);

View file

@ -11,7 +11,7 @@ init_appearance(void)
char cbuf[8]; char cbuf[8];
/* init appearance */ // create color schemes from array
for (j = 0; j < SchemeLast; j++) { for (j = 0; j < SchemeLast; j++) {
scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2); scheme[j] = drw_scm_create(drw, colors[j], alphas[j], 2);
} }

View file

@ -1,5 +1,6 @@
static void init_appearance(void); static void init_appearance(void);
/* color schemes */
// Color schemes
enum { SchemeLArrow, enum { SchemeLArrow,
SchemeRArrow, SchemeRArrow,
SchemeItemNorm, SchemeItemNorm,

View file

@ -10,6 +10,6 @@ typedef struct {
void *dst; void *dst;
} ResourcePref; } ResourcePref;
/* functions */ // declare functions
static void load_xresources(void); static void load_xresources(void);
static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst); static void resource_load(XrmDatabase db, char *name, enum resource_type rtype, void *dst);

View file

@ -1,7 +1,4 @@
/* This header is for the .Xresources options. // This .Xresources array is read and compared to the xrdb. Simply add to the array if you need to.
* These will be set on startup by xrdb.
*/
ResourcePref resources[] = { ResourcePref resources[] = {
{ "font", STRING, &font }, { "font", STRING, &font },
{ "col_caretfgcolor", STRING, &col_caretfgcolor }, { "col_caretfgcolor", STRING, &col_caretfgcolor },
@ -32,7 +29,7 @@ ResourcePref resources[] = {
{ "col_promptfg", STRING, &col_promptfg }, { "col_promptfg", STRING, &col_promptfg },
{ "col_promptbg", STRING, &col_promptbg }, { "col_promptbg", STRING, &col_promptbg },
/* Pywal support */ // Universal colors
{ "color10", STRING, &col_caretfgcolor }, { "color10", STRING, &col_caretfgcolor },
{ "color4", STRING, &col_larrowfg }, { "color4", STRING, &col_larrowfg },
{ "color4", STRING, &col_rarrowfg }, { "color4", STRING, &col_rarrowfg },
@ -61,7 +58,7 @@ ResourcePref resources[] = {
{ "color0", STRING, &col_normhlfgcolor }, { "color0", STRING, &col_normhlfgcolor },
{ "color0", STRING, &col_selhlfgcolor }, { "color0", STRING, &col_selhlfgcolor },
/* sgr colors */ // SGR sequence colors
{ "col_sgrcolor0", STRING, &col_sgrcolor0 }, { "col_sgrcolor0", STRING, &col_sgrcolor0 },
{ "col_sgrcolor1", STRING, &col_sgrcolor1 }, { "col_sgrcolor1", STRING, &col_sgrcolor1 },
{ "col_sgrcolor2", STRING, &col_sgrcolor2 }, { "col_sgrcolor2", STRING, &col_sgrcolor2 },
@ -79,7 +76,7 @@ ResourcePref resources[] = {
{ "col_sgrcolor14", STRING, &col_sgrcolor14 }, { "col_sgrcolor14", STRING, &col_sgrcolor14 },
{ "col_sgrcolor15", STRING, &col_sgrcolor15 }, { "col_sgrcolor15", STRING, &col_sgrcolor15 },
/* sgr colors */ // SGR sequence colors (universal)
{ "color0", STRING, &col_sgrcolor0 }, { "color0", STRING, &col_sgrcolor0 },
{ "color1", STRING, &col_sgrcolor1 }, { "color1", STRING, &col_sgrcolor1 },
{ "color2", STRING, &col_sgrcolor2 }, { "color2", STRING, &col_sgrcolor2 },

View file

@ -285,7 +285,8 @@ calcoffsets(void)
n = mw - (promptw + inputw + larrowWidth + rarrowWidth + modeWidth + numberWidth); 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)
if ((i += (lines > 0) ? bh : MIN(TEXTWM(next->text), n)) > n) if ((i += (lines > 0) ? bh : MIN(TEXTWM(next->text), n)) > n)
break; break;
@ -638,6 +639,7 @@ readstdin(void)
// spmenu:test // spmenu:test
if (!strncmp("test", items[i].ex, strlen("test"))) { if (!strncmp("test", items[i].ex, strlen("test"))) {
system("command -v spmenu_test > /dev/null && spmenu_test"); system("command -v spmenu_test > /dev/null && spmenu_test");
exit(0);
} }
} }
} }
@ -690,14 +692,15 @@ setup(void)
lines = MAX(lines, 0); lines = MAX(lines, 0);
reallines = lines; reallines = lines;
// resize client to image height if deemed necessary
#if USEIMAGE #if USEIMAGE
if (image) if (image) resizetoimageheight(imageheight);
resizetoimageheight(imageheight);
#endif #endif
mh = (lines + 1) * bh; mh = (lines + 1) * bh; // lines + 1 * bh is the menu height
promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; promptw = (prompt && *prompt) ? TEXTWM(prompt) - lrpad / 4 : 0; // prompt width
// get accurate width
if (accuratewidth) { if (accuratewidth) {
for (item = items; !lines && item && item->text; ++item) { for (item = items; !lines && item && item->text; ++item) {
curstrlen = strlen(item->text); curstrlen = strlen(item->text);
@ -713,6 +716,7 @@ setup(void)
} }
} }
// init xinerama screens
#if USEXINERAMA #if USEXINERAMA
i = 0; i = 0;
if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) { if (parentwin == root && (info = XineramaQueryScreens(dpy, &n))) {
@ -720,12 +724,12 @@ setup(void)
if (mon >= 0 && mon < n) if (mon >= 0 && mon < n)
i = mon; i = mon;
else if (w != root && w != PointerRoot && w != None) { 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 { do {
if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws) if (XQueryTree(dpy, (pw = w), &dw, &w, &dws, &du) && dws)
XFree(dws); XFree(dws);
} while (w != root && w != pw); } 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)) if (XGetWindowAttributes(dpy, pw, &wa))
for (j = 0; j < n; j++) for (j = 0; j < n; j++)
if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) { if ((a = INTERSECT(wa.x, wa.y, wa.width, wa.height, info[j])) > area) {
@ -733,21 +737,20 @@ setup(void)
i = j; 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)) if (mon < 0 && !area && XQueryPointer(dpy, root, &dw, &dw, &x, &y, &di, &di, &du))
for (i = 0; i < n; i++) for (i = 0; i < n; i++)
if (INTERSECT(x, y, 1, 1, info[i])) if (INTERSECT(x, y, 1, 1, info[i]))
break; break;
// calculate x/y position
if (centered) { if (centered) {
mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width);
x = info[i].x_org + ((info[i].width - mw) / 2); 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); y = info[i].y_org + ((info[i].height - mh) / 2);
mw = MIN(MAX(max_textw() + promptw, minwidth), info[i].width);
} else { } else {
x = info[i].x_org + dmx; x = info[i].x_org + dmx;
y = info[i].y_org + (menuposition ? 0 : info[i].height - mh - dmy); 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); mw = (dmw>0 ? dmw : info[i].width);
} }
@ -801,6 +804,8 @@ setup(void)
} }
grabfocus(); grabfocus();
} }
// resize and draw
drw_resize(drw, mw, mh); drw_resize(drw, mw, mh);
drawmenu(); drawmenu();
} }
@ -879,5 +884,5 @@ main(int argc, char *argv[])
setup(); setup();
eventloop(); eventloop();
return 1; /* unreachable */ return 1;
} }