cmdtree

A trie command launcher for X11
git clone git://jb55.com/cmdtree
Log | Files | Refs | README | LICENSE

commit ac19bbde72ba629b7901938bf8f3b3dd55872ace
parent 1b8fbbd843ddeb5fc81c9303db9c590a436d499b
Author: William Casarin <jb55@jb55.com>
Date:   Mon,  9 Jul 2018 14:19:40 -0700

progress

Diffstat:
Mcfg.def.h | 25+++++++++++++++++++++----
Mcmdtree.c | 74++++++++++++++++++++++++++++++++++++++++++++++++++++----------------------
Mdrw.c | 3++-
Mdrw.h | 2++
4 files changed, 77 insertions(+), 27 deletions(-)

diff --git a/cfg.def.h b/cfg.def.h @@ -2,15 +2,32 @@ /* Default settings; can be overriden by command line. */ static int topbar = 1; /* -b option; if 0, dmenu appears at bottom */ + +static const char *separator = " → "; + /* -fn option overrides fonts[0]; default X11 font or font set */ static const char *fonts[] = { - "Monospace:size=12" + "Monospace:size=14" }; /* static const char *prompt = NULL; /\* -p option; prompt to the left of input field *\/ */ static struct scheme schemes[SchemeLast] = { - [SchemeNorm] = { .bg = "#222222", .bind = "#bbbbbb", .name = "#bbbbbb" }, - [SchemeSel] = { .bg = "#005577", .bind = "#eeeeee", .name = "#eeeeee" }, - [SchemeOut] = { .bg = "#00ffff", .bind = "#000000", .name = "#000000" }, + [SchemeNorm] = { .bg = "#222222", + .bind = "#D19A66", + .arrow = "#888", + .name = "#bbbbbb" + }, + + [SchemeSel] = { .bg = "#005577", + .bind = "#eeeeee", + .arrow = "#666666", + .name = "#eeeeee" + }, + + [SchemeOut] = { .bg = "#00ffff", + .bind = "#000000", + .arrow = "#666666", + .name = "#000000" + }, }; /* -l option; if nonzero, dmenu uses vertical list with given number of lines */ diff --git a/cmdtree.c b/cmdtree.c @@ -25,7 +25,8 @@ enum { static Window root, parentwin, win; static int screen; static Display *display; -static int mw, mh; +static int sep_width; +static int bh, mw, mh; static XIC xic; #include "cfg.h" @@ -60,6 +61,7 @@ setup(Drw *drw) XIM xim; XClassHint ch = {"cmdtree", "cmdtree"}; + bh = drw->fonts->h + 2; /* init appearance */ drw_scm_create(drw, schemes, LENGTH(schemes)); @@ -69,9 +71,10 @@ setup(Drw *drw) x = 0; y = topbar ? 0 : wa.height - mh; mw = wa.width; + lines = 3; lines = MAX(lines, 0); - /* mh = (lines + 1) * bh; */ - mh = 100; + mh = (lines + 1) * bh; + sep_width = drw_fontset_getwidth(drw, separator); swa.override_redirect = True; swa.background_pixel = schemes[SchemeNorm].bg_clr.pixel; @@ -111,44 +114,71 @@ setup(Drw *drw) /* drawmenu(); */ } -static void +static int draw_command(Drw *drw, int x, int y, const char *name, const char *binding) { - int lpad = 7; + int lpad = 0; + int pad = 0; unsigned int w = 50; - unsigned int h = 20; int invert = 0; - int res = 1; - x += drw_fontset_getwidth(drw, binding) + 1; + //drw_fontset_getwidth(drw, binding) + 1; - drw_setscheme(drw, &schemes[SchemeNorm].bg_clr, + drw_setscheme(drw, &schemes[SchemeNorm].bind_clr, &schemes[SchemeNorm].bg_clr); - drw_rect(drw, 0, 0, mw, mh, 1, 1); - - drw_setscheme(drw, &schemes[SchemeSel].bind_clr, - &schemes[SchemeSel].bg_clr); + w = drw_fontset_getwidth(drw, binding); + x = drw_text(drw, x+pad, y, w, bh, lpad, binding, invert); - res = drw_text(drw, x, y, w, h, lpad, binding, invert); + w = sep_width; + drw_setscheme(drw, &schemes[SchemeNorm].arrow_clr, + &schemes[SchemeNorm].bg_clr); + x = drw_text(drw, x+pad, y, w, bh, lpad, separator, invert); - x += drw_fontset_getwidth(drw, binding) + 10; + drw_setscheme(drw, &schemes[SchemeNorm].name_clr, + &schemes[SchemeNorm].bg_clr); - res = drw_text(drw, x, y, w, h, lpad, name, invert); - assert(res != 0); + w = drw_fontset_getwidth(drw, name); + x = drw_text(drw, x+pad, y, w, bh, lpad, name, invert); + return x; } +/* static void */ +/* calc_tree_exts(struct node *nodes, int num_nodes, int *rows, int *cols) { */ +/* } */ + static void draw_tree(Drw *drw, int x, int y, int w, int h) { - draw_command(drw, x, y, "apps", "a"); - - x += 10; - if (x > w) - x = 0; + int i, dx = x, dy = y; + char buf[512]; + char smallbuf[32]; if (!drw) return; + drw_setscheme(drw, &schemes[SchemeNorm].bg_clr, + &schemes[SchemeNorm].bg_clr); + drw_rect(drw, 0, 0, w, h, 1, 1); + + int c = '0'; + for (i = 0; i < 50; ++i, ++c) { + if (i % 2 == 0) + snprintf(buf, 512, "item-long-%d", i); + else if (i % 6 == 0) + snprintf(buf, 512, "herpderp-%d", i); + else if (i % 7 == 0) + snprintf(buf, 512, "ksdfsdjhfsdf-%d", i); + else + snprintf(buf, 512, "hi-%d", i); + if (c > '~') c = '0'; + sprintf(smallbuf, "%c", c); + dx = draw_command(drw, dx, dy, buf, smallbuf) + 20; + if (dx >= mw) { + dx = 0; + dy += bh; + } + } + XCopyArea(drw->dpy, drw->drawable, win, drw->gc, x, y, w, h, x, y); XSync(drw->dpy, False); } diff --git a/drw.c b/drw.c @@ -156,6 +156,7 @@ drw_scm_create(Drw *drw, struct scheme *schemes, size_t clrcount) drw_clr_create(drw, &schemes[i].bind_clr, schemes[i].bind); drw_clr_create(drw, &schemes[i].bg_clr, schemes[i].bg); drw_clr_create(drw, &schemes[i].name_clr, schemes[i].name); + drw_clr_create(drw, &schemes[i].arrow_clr, schemes[i].arrow); } return; @@ -208,7 +209,7 @@ drw_text(Drw *drw, int x, int y, unsigned int w, unsigned int h, XftResult result; int charexists = 0; - if (!drw || (render && !drw->scheme) || !text || !drw->fonts) + if (!drw || (render && !drw->scheme[0]) || !text || !drw->fonts) return 0; if (!render) { diff --git a/drw.h b/drw.h @@ -26,10 +26,12 @@ typedef XftColor Clr; struct scheme { const char *bg; const char *bind; + const char *arrow; const char *name; Clr bg_clr; Clr name_clr; Clr bind_clr; + Clr arrow_clr; };