aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--config.arg.h1
-rw-r--r--config.default.h1
-rw-r--r--dmenu.h3
-rw-r--r--draw.c48
-rw-r--r--main.c11
5 files changed, 38 insertions, 26 deletions
diff --git a/config.arg.h b/config.arg.h
index 30c422d..c5e1874 100644
--- a/config.arg.h
+++ b/config.arg.h
@@ -6,3 +6,4 @@
6#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" 6#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
7#define BGCOLOR "#eeeeee" 7#define BGCOLOR "#eeeeee"
8#define FGCOLOR "#666699" 8#define FGCOLOR "#666699"
9#define BORDERCOLOR "#9999CC"
diff --git a/config.default.h b/config.default.h
index 0b1abb4..cf1baea 100644
--- a/config.default.h
+++ b/config.default.h
@@ -6,3 +6,4 @@
6#define FONT "fixed" 6#define FONT "fixed"
7#define BGCOLOR "#666699" 7#define BGCOLOR "#666699"
8#define FGCOLOR "#eeeeee" 8#define FGCOLOR "#eeeeee"
9#define BORDERCOLOR "#9999CC"
diff --git a/dmenu.h b/dmenu.h
index ddea3dd..2a8796f 100644
--- a/dmenu.h
+++ b/dmenu.h
@@ -24,6 +24,7 @@ struct DC { /* draw context */
24 int x, y, w, h; 24 int x, y, w, h;
25 unsigned long bg; 25 unsigned long bg;
26 unsigned long fg; 26 unsigned long fg;
27 unsigned long border;
27 Drawable drawable; 28 Drawable drawable;
28 Fnt font; 29 Fnt font;
29 GC gc; 30 GC gc;
@@ -34,7 +35,7 @@ extern Display *dpy;
34extern DC dc; 35extern DC dc;
35 36
36/* draw.c */ 37/* draw.c */
37extern void drawtext(const char *text, Bool sel); 38extern void drawtext(const char *text, Bool invert, Bool border);
38extern unsigned long getcolor(const char *colstr); 39extern unsigned long getcolor(const char *colstr);
39extern void setfont(const char *fontstr); 40extern void setfont(const char *fontstr);
40extern unsigned int textw(const char *text); 41extern unsigned int textw(const char *text);
diff --git a/draw.c b/draw.c
index 1d6bf21..7507595 100644
--- a/draw.c
+++ b/draw.c
@@ -9,6 +9,26 @@
9 9
10/* static */ 10/* static */
11 11
12static void
13drawborder(void)
14{
15 XPoint points[5];
16
17 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
18 XSetForeground(dpy, dc.gc, dc.border);
19 points[0].x = dc.x;
20 points[0].y = dc.y;
21 points[1].x = dc.w - 1;
22 points[1].y = 0;
23 points[2].x = 0;
24 points[2].y = dc.h - 1;
25 points[3].x = -(dc.w - 1);
26 points[3].y = 0;
27 points[4].x = 0;
28 points[4].y = -(dc.h - 1);
29 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
30}
31
12static unsigned int 32static unsigned int
13textnw(const char *text, unsigned int len) 33textnw(const char *text, unsigned int len)
14{ 34{
@@ -24,18 +44,21 @@ textnw(const char *text, unsigned int len)
24/* extern */ 44/* extern */
25 45
26void 46void
27drawtext(const char *text, Bool sel) 47drawtext(const char *text, Bool invert, Bool border)
28{ 48{
29 int x, y, w, h; 49 int x, y, w, h;
30 static char buf[256]; 50 static char buf[256];
31 unsigned int len; 51 unsigned int len;
32 XGCValues gcv; 52 XGCValues gcv;
33 XPoint points[5];
34 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 53 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
35 54
36 XSetForeground(dpy, dc.gc, sel ? dc.fg : dc.bg); 55 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg);
37 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); 56 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
57
38 w = 0; 58 w = 0;
59 if(border)
60 drawborder();
61
39 if(!text) 62 if(!text)
40 return; 63 return;
41 64
@@ -56,8 +79,8 @@ drawtext(const char *text, Bool sel)
56 if(w > dc.w) 79 if(w > dc.w)
57 return; /* too long */ 80 return; /* too long */
58 81
59 gcv.foreground = sel ? dc.bg : dc.fg; 82 gcv.foreground = invert ? dc.bg : dc.fg;
60 gcv.background = sel ? dc.fg : dc.bg; 83 gcv.background = invert ? dc.fg : dc.bg;
61 if(dc.font.set) { 84 if(dc.font.set) {
62 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); 85 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv);
63 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, 86 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc,
@@ -68,21 +91,6 @@ drawtext(const char *text, Bool sel)
68 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); 91 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv);
69 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); 92 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len);
70 } 93 }
71 if(sel) {
72 XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
73 points[0].x = dc.x;
74 points[0].y = dc.y;
75 points[1].x = dc.w - 1;
76 points[1].y = 0;
77 points[2].x = 0;
78 points[2].y = dc.h - 1;
79 points[3].x = -(dc.w - 1);
80 points[3].y = 0;
81 points[4].x = 0;
82 points[4].y = -(dc.h - 1);
83 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
84 }
85
86} 94}
87 95
88unsigned long 96unsigned long
diff --git a/main.c b/main.c
index 14581c4..3b9a24b 100644
--- a/main.c
+++ b/main.c
@@ -77,17 +77,17 @@ drawmenu()
77 dc.y = 0; 77 dc.y = 0;
78 dc.w = mw; 78 dc.w = mw;
79 dc.h = mh; 79 dc.h = mh;
80 drawtext(NULL, False); 80 drawtext(NULL, False, False);
81 81
82 /* print command */ 82 /* print command */
83 if(cmdw && item) 83 if(cmdw && item)
84 dc.w = cmdw; 84 dc.w = cmdw;
85 drawtext(text[0] ? text : NULL, False); 85 drawtext(text[0] ? text : NULL, False, False);
86 dc.x += cmdw; 86 dc.x += cmdw;
87 87
88 if(curr) { 88 if(curr) {
89 dc.w = SPACE; 89 dc.w = SPACE;
90 drawtext((curr && curr->left) ? "<" : NULL, False); 90 drawtext((curr && curr->left) ? "<" : NULL, False, False);
91 dc.x += dc.w; 91 dc.x += dc.w;
92 92
93 /* determine maximum items */ 93 /* determine maximum items */
@@ -95,13 +95,13 @@ drawmenu()
95 dc.w = textw(i->text); 95 dc.w = textw(i->text);
96 if(dc.w > mw / 3) 96 if(dc.w > mw / 3)
97 dc.w = mw / 3; 97 dc.w = mw / 3;
98 drawtext(i->text, sel == i); 98 drawtext(i->text, sel == i, sel == i);
99 dc.x += dc.w; 99 dc.x += dc.w;
100 } 100 }
101 101
102 dc.x = mw - SPACE; 102 dc.x = mw - SPACE;
103 dc.w = SPACE; 103 dc.w = SPACE;
104 drawtext(next ? ">" : NULL, False); 104 drawtext(next ? ">" : NULL, False, False);
105 } 105 }
106 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0); 106 XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
107 XFlush(dpy); 107 XFlush(dpy);
@@ -316,6 +316,7 @@ main(int argc, char *argv[])
316 /* style */ 316 /* style */
317 dc.bg = getcolor(BGCOLOR); 317 dc.bg = getcolor(BGCOLOR);
318 dc.fg = getcolor(FGCOLOR); 318 dc.fg = getcolor(FGCOLOR);
319 dc.border = getcolor(BORDERCOLOR);
319 setfont(FONT); 320 setfont(FONT);
320 321
321 wa.override_redirect = 1; 322 wa.override_redirect = 1;