aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnselm R. Garbe <arg@10kloc.org>2006-08-25 14:45:17 +0200
committerAnselm R. Garbe <arg@10kloc.org>2006-08-25 14:45:17 +0200
commit13ef97e65ea5a713a3d5ab46916d1ac6d071b825 (patch)
treeb8a9f831677cbd40cc27e1f0c8bf313b7e04addb
parent65be999a3f76ad51fb97e12f2fb481f5038f6817 (diff)
downloaddmenu-13ef97e65ea5a713a3d5ab46916d1ac6d071b825.tar.gz
dmenu-13ef97e65ea5a713a3d5ab46916d1ac6d071b825.tar.bz2
dmenu-13ef97e65ea5a713a3d5ab46916d1ac6d071b825.zip
updated dmenu to borderless drawing as well
-rw-r--r--config.arg.h7
-rw-r--r--config.default.h7
-rw-r--r--dmenu.h10
-rw-r--r--draw.c33
-rw-r--r--main.c19
5 files changed, 32 insertions, 44 deletions
diff --git a/config.arg.h b/config.arg.h
index 066c1a4..1e0ff8c 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -4,6 +4,7 @@
*/
#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
-#define BGCOLOR "#666699"
-#define FGCOLOR "#eeeeee"
-#define BORDERCOLOR "#9999CC"
+#define SELBGCOLOR "#666699"
+#define SELFGCOLOR "#eeeeee"
+#define NORMBGCOLOR "#333366"
+#define NORMFGCOLOR "#cccccc"
diff --git a/config.default.h b/config.default.h
index cf1baea..1f66553 100644
--- a/config.default.h
+++ b/config.default.h
@@ -4,6 +4,7 @@
*/
#define FONT "fixed"
-#define BGCOLOR "#666699"
-#define FGCOLOR "#eeeeee"
-#define BORDERCOLOR "#9999CC"
+#define SELBGCOLOR "#666699"
+#define SELFGCOLOR "#eeeeee"
+#define NORMBGCOLOR "#333366"
+#define NORMFGCOLOR "#cccccc"
diff --git a/dmenu.h b/dmenu.h
index 2a8796f..337e094 100644
--- a/dmenu.h
+++ b/dmenu.h
@@ -9,6 +9,9 @@
#define SPACE 30 /* px */
+/* color */
+enum { ColFG, ColBG, ColLast };
+
typedef struct DC DC;
typedef struct Fnt Fnt;
@@ -22,9 +25,8 @@ struct Fnt {
struct DC { /* draw context */
int x, y, w, h;
- unsigned long bg;
- unsigned long fg;
- unsigned long border;
+ unsigned long norm[ColLast];
+ unsigned long sel[ColLast];
Drawable drawable;
Fnt font;
GC gc;
@@ -35,7 +37,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 long col[ColLast]);
extern unsigned long getcolor(const char *colstr);
extern void setfont(const char *fontstr);
extern unsigned int textw(const char *text);
diff --git a/draw.c b/draw.c
index 38ae8c3..d0f21cd 100644
--- a/draw.c
+++ b/draw.c
@@ -24,37 +24,21 @@ textnw(const char *text, unsigned int len)
/* extern */
void
-drawtext(const char *text, Bool invert, Bool border)
+drawtext(const char *text, unsigned long col[ColLast])
{
int x, y, w, h;
static char buf[256];
unsigned int len, olen;
XGCValues gcv;
- 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, col[ColBG]);
XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
- w = 0;
- if(border) {
- points[0].x = dc.x;
- points[0].y = dc.y;
- points[1].x = dc.w - 1;
- points[1].y = 0;
- points[2].x = 0;
- points[2].y = dc.h - 1;
- points[3].x = -(dc.w - 1);
- 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);
- }
-
if(!text)
return;
+ w = 0;
olen = len = strlen(text);
if(len >= sizeof(buf))
len = sizeof(buf) - 1;
@@ -80,17 +64,16 @@ 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;
+ gcv.foreground = col[ColFG];
if(dc.font.set) {
- XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
- XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
+ XChangeGC(dpy, dc.gc, GCForeground, &gcv);
+ 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, GCForeground | GCFont, &gcv);
+ XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
}
diff --git a/main.c b/main.c
index 840a7bc..51fa20f 100644
--- a/main.c
+++ b/main.c
@@ -77,17 +77,17 @@ drawmenu()
dc.y = 0;
dc.w = mw;
dc.h = mh;
- drawtext(NULL, False, False);
+ drawtext(NULL, dc.norm);
/* print command */
if(cmdw && item)
dc.w = cmdw;
- drawtext(text[0] ? text : NULL, False, False);
+ drawtext(text[0] ? text : NULL, dc.norm);
dc.x += cmdw;
if(curr) {
dc.w = SPACE;
- drawtext((curr && curr->left) ? "<" : NULL, False, False);
+ drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
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) ? dc.sel : dc.norm);
dc.x += dc.w;
}
dc.x = mw - SPACE;
dc.w = SPACE;
- drawtext(next ? ">" : NULL, False, False);
+ drawtext(next ? ">" : NULL, dc.norm);
}
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.sel[ColBG] = getcolor(SELBGCOLOR);
+ dc.sel[ColFG] = getcolor(SELFGCOLOR);
+ dc.norm[ColBG] = getcolor(NORMBGCOLOR);
+ dc.norm[ColFG] = getcolor(NORMFGCOLOR);
setfont(FONT);
wa.override_redirect = 1;
@@ -326,7 +327,7 @@ main(int argc, char *argv[])
mx = my = 0;
mw = DisplayWidth(dpy, screen);
- mh = dc.font.height + 4;
+ mh = dc.font.height + 2;
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent,