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)
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 @@
4 */ 4 */
5 5
6#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*" 6#define FONT "-*-terminus-medium-*-*-*-12-*-*-*-*-*-iso10646-*"
7#define BGCOLOR "#666699" 7#define SELBGCOLOR "#666699"
8#define FGCOLOR "#eeeeee" 8#define SELFGCOLOR "#eeeeee"
9#define BORDERCOLOR "#9999CC" 9#define NORMBGCOLOR "#333366"
10#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 @@
4 */ 4 */
5 5
6#define FONT "fixed" 6#define FONT "fixed"
7#define BGCOLOR "#666699" 7#define SELBGCOLOR "#666699"
8#define FGCOLOR "#eeeeee" 8#define SELFGCOLOR "#eeeeee"
9#define BORDERCOLOR "#9999CC" 9#define NORMBGCOLOR "#333366"
10#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 @@
9 9
10#define SPACE 30 /* px */ 10#define SPACE 30 /* px */
11 11
12/* color */
13enum { ColFG, ColBG, ColLast };
14
12typedef struct DC DC; 15typedef struct DC DC;
13typedef struct Fnt Fnt; 16typedef struct Fnt Fnt;
14 17
@@ -22,9 +25,8 @@ struct Fnt {
22 25
23struct DC { /* draw context */ 26struct DC { /* draw context */
24 int x, y, w, h; 27 int x, y, w, h;
25 unsigned long bg; 28 unsigned long norm[ColLast];
26 unsigned long fg; 29 unsigned long sel[ColLast];
27 unsigned long border;
28 Drawable drawable; 30 Drawable drawable;
29 Fnt font; 31 Fnt font;
30 GC gc; 32 GC gc;
@@ -35,7 +37,7 @@ extern Display *dpy;
35extern DC dc; 37extern DC dc;
36 38
37/* draw.c */ 39/* draw.c */
38extern void drawtext(const char *text, Bool invert, Bool border); 40extern void drawtext(const char *text, unsigned long col[ColLast]);
39extern unsigned long getcolor(const char *colstr); 41extern unsigned long getcolor(const char *colstr);
40extern void setfont(const char *fontstr); 42extern void setfont(const char *fontstr);
41extern unsigned int textw(const char *text); 43extern 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)
24/* extern */ 24/* extern */
25 25
26void 26void
27drawtext(const char *text, Bool invert, Bool border) 27drawtext(const char *text, unsigned long col[ColLast])
28{ 28{
29 int x, y, w, h; 29 int x, y, w, h;
30 static char buf[256]; 30 static char buf[256];
31 unsigned int len, olen; 31 unsigned int len, olen;
32 XGCValues gcv; 32 XGCValues gcv;
33 XPoint points[5];
34 XRectangle r = { dc.x, dc.y, dc.w, dc.h }; 33 XRectangle r = { dc.x, dc.y, dc.w, dc.h };
35 34
36 XSetForeground(dpy, dc.gc, invert ? dc.fg : dc.bg); 35 XSetForeground(dpy, dc.gc, col[ColBG]);
37 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); 36 XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1);
38 37
39 w = 0;
40 if(border) {
41 points[0].x = dc.x;
42 points[0].y = dc.y;
43 points[1].x = dc.w - 1;
44 points[1].y = 0;
45 points[2].x = 0;
46 points[2].y = dc.h - 1;
47 points[3].x = -(dc.w - 1);
48 points[3].y = 0;
49 points[4].x = 0;
50 points[4].y = -(dc.h - 1);
51 XSetForeground(dpy, dc.gc, dc.border);
52 XDrawLines(dpy, dc.drawable, dc.gc, points, 5, CoordModePrevious);
53 }
54
55 if(!text) 38 if(!text)
56 return; 39 return;
57 40
41 w = 0;
58 olen = len = strlen(text); 42 olen = len = strlen(text);
59 if(len >= sizeof(buf)) 43 if(len >= sizeof(buf))
60 len = sizeof(buf) - 1; 44 len = sizeof(buf) - 1;
@@ -80,17 +64,16 @@ drawtext(const char *text, Bool invert, Bool border)
80 if(w > dc.w) 64 if(w > dc.w)
81 return; /* too long */ 65 return; /* too long */
82 66
83 gcv.foreground = invert ? dc.bg : dc.fg; 67 gcv.foreground = col[ColFG];
84 gcv.background = invert ? dc.fg : dc.bg;
85 if(dc.font.set) { 68 if(dc.font.set) {
86 XChangeGC(dpy, dc.gc, GCForeground | GCBackground, &gcv); 69 XChangeGC(dpy, dc.gc, GCForeground, &gcv);
87 XmbDrawImageString(dpy, dc.drawable, dc.font.set, dc.gc, 70 XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc,
88 x, y, buf, len); 71 x, y, buf, len);
89 } 72 }
90 else { 73 else {
91 gcv.font = dc.font.xfont->fid; 74 gcv.font = dc.font.xfont->fid;
92 XChangeGC(dpy, dc.gc, GCForeground | GCBackground | GCFont, &gcv); 75 XChangeGC(dpy, dc.gc, GCForeground | GCFont, &gcv);
93 XDrawImageString(dpy, dc.drawable, dc.gc, x, y, buf, len); 76 XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
94 } 77 }
95} 78}
96 79
diff --git a/main.c b/main.c
index 840a7bc..51fa20f 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, False); 80 drawtext(NULL, dc.norm);
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, False); 85 drawtext(text[0] ? text : NULL, dc.norm);
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, False); 90 drawtext((curr && curr->left) ? "<" : NULL, dc.norm);
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, sel == i); 98 drawtext(i->text, (sel == i) ? dc.sel : dc.norm);
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, False); 104 drawtext(next ? ">" : NULL, dc.norm);
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);
@@ -315,9 +315,10 @@ main(int argc, char *argv[])
315 usleep(1000); 315 usleep(1000);
316 316
317 /* style */ 317 /* style */
318 dc.bg = getcolor(BGCOLOR); 318 dc.sel[ColBG] = getcolor(SELBGCOLOR);
319 dc.fg = getcolor(FGCOLOR); 319 dc.sel[ColFG] = getcolor(SELFGCOLOR);
320 dc.border = getcolor(BORDERCOLOR); 320 dc.norm[ColBG] = getcolor(NORMBGCOLOR);
321 dc.norm[ColFG] = getcolor(NORMFGCOLOR);
321 setfont(FONT); 322 setfont(FONT);
322 323
323 wa.override_redirect = 1; 324 wa.override_redirect = 1;
@@ -326,7 +327,7 @@ main(int argc, char *argv[])
326 327
327 mx = my = 0; 328 mx = my = 0;
328 mw = DisplayWidth(dpy, screen); 329 mw = DisplayWidth(dpy, screen);
329 mh = dc.font.height + 4; 330 mh = dc.font.height + 2;
330 331
331 win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, 332 win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
332 DefaultDepth(dpy, screen), CopyFromParent, 333 DefaultDepth(dpy, screen), CopyFromParent,