Browse Source

migrated dmenu to use 4 instead of 3 colors

master
Anselm R. Garbe 19 years ago
parent
commit
e980c7ff18
  1. 7
      config.arg.h
  2. 7
      config.default.h
  3. 2
      config.mk
  4. 7
      dmenu.h
  5. 19
      draw.c
  6. 17
      main.c

7
config.arg.h

@ -4,6 +4,7 @@
*/
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
#define BGCOLOR "#666699"
#define FGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC"
#define NORMBGCOLOR "#666699"
#define NORMFGCOLOR "#eeeeee"
#define SELBGCOLOR "#eeeeee"
#define SELFGCOLOR "#666699"

7
config.default.h

@ -4,6 +4,7 @@
*/
#define FONT "fixed"
#define BGCOLOR "#666699"
#define FGCOLOR "#eeeeee"
#define BORDERCOLOR "#9999CC"
#define NORMBGCOLOR "#666699"
#define NORMFGCOLOR "#eeeeee"
#define SELBGCOLOR "#eeeeee"
#define SELBFCOLOR "#666699"

2
config.mk

@ -1,5 +1,5 @@
# dmenu version
VERSION = 0.5
VERSION = 0.6
# Customize below to fit your system

7
dmenu.h

@ -22,9 +22,8 @@ struct Fnt {
struct DC { /* draw context */
int x, y, w, h;
unsigned long bg;
unsigned long fg;
unsigned long border;
unsigned long bg[2];
unsigned long fg[2];
Drawable drawable;
Fnt font;
GC gc;
@ -35,7 +34,7 @@ extern Display *dpy;
extern DC dc;
/* draw.c */
extern void drawtext(const char *text, Bool invert, Bool border);
extern void drawtext(const char *text, unsigned int colidx, Bool border);
extern unsigned long getcolor(const char *colstr);
extern void setfont(const char *fontstr);
extern unsigned int textw(const char *text);

19
draw.c

@ -24,7 +24,7 @@ textnw(const char *text, unsigned int len)
/* extern */
void
drawtext(const char *text, Bool invert, Bool border)
drawtext(const char *text, unsigned int colidx, Bool border)
{
int x, y, w, h;
static char buf[256];
@ -33,10 +33,11 @@ drawtext(const char *text, Bool invert, Bool border)
XPoint points[5];
XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
XSetForeground(dpy, dc.gc, dc.bg[colidx]);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
w = 0;
XSetForeground(dpy, dc.gc, dc.fg[colidx]);
if(border) {
points[0].x = dc.x;
points[0].y = dc.y;
@ -48,7 +49,6 @@ drawtext(const char *text, Bool invert, Bool border)
points[3].y = 0;
points[4].x = 0;
points[4].y = -(dc.h - 1);
XSetForeground(dpy, dc.gc, dc.border);
XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
}
@ -80,17 +80,12 @@ drawtext(const char *text, Bool invert, Bool border)
if(w > dc.w)
return; /* too long */
gcv.foreground = invert ? dc.bg : dc.fg;
gcv.background = invert ? dc.fg : dc.bg;
if(dc.font.set) {
XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
x, y, buf, len);
}
if(dc.font.set)
XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
else {
gcv.font = dc.font.xfont->fid;
XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
XChangeGC(dpy, dc.gc, GCFont, &gcv);
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
}

17
main.c

@ -77,17 +77,17 @@ drawmenu()
dc.y = 0;
dc.w = mw;
dc.h = mh;
drawtext(NULL, False, False);
drawtext(NULL, 0, False);
/* print command */
if(cmdw && item)
dc.w = cmdw;
drawtext(text[0] ? text : NULL, False, False);
drawtext(text[0] ? text : NULL, 0, False);
dc.x += cmdw;
if(curr) {
dc.w = SPACE;
drawtext((curr && curr->left) ? "<" : NULL, False, False);
drawtext((curr && curr->left) ? "<" : NULL, 0, False);
dc.x += dc.w;
/* determine maximum items */
@ -95,13 +95,13 @@ drawmenu()
dc.w = textw(i->text);
if(dc.w > mw / 3)
dc.w = mw / 3;
drawtext(i->text, sel == i, sel == i);
drawtext(i->text, sel == i ? 1 : 0, sel == i);
dc.x += dc.w;
}
dc.x = mw - SPACE;
dc.w = SPACE;
drawtext(next ? ">" : NULL, False, False);
drawtext(next ? ">" : NULL, 0, False);
}
XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy);
@ -315,9 +315,10 @@ main(int argc, char *argv[])
usleep(1000);
/* style */
dc.bg = getcolor(BGCOLOR);
dc.fg = getcolor(FGCOLOR);
dc.border = getcolor(BORDERCOLOR);
dc.bg[0] = getcolor(NORMBGCOLOR);
dc.fg[0] = getcolor(NORMFGCOLOR);
dc.bg[1] = getcolor(SELBGCOLOR);
dc.fg[1] = getcolor(SELFGCOLOR);
setfont(FONT);
wa.override_redirect = 1;

Loading…
Cancel
Save