summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--Makefile12
-rw-r--r--config.h9
-rw-r--r--config.mk4
-rw-r--r--draw.c163
-rw-r--r--draw.h6
-rw-r--r--font.c81
-rw-r--r--gridmenu.116
-rw-r--r--util.c18
-rw-r--r--util.h41
-rw-r--r--wm.c9
-rw-r--r--wm.h5
11 files changed, 328 insertions, 36 deletions
diff --git a/Makefile b/Makefile
index 6d853bd..1eb6c50 100644
--- a/Makefile
+++ b/Makefile
@@ -3,8 +3,8 @@
3 3
4include config.mk 4include config.mk
5 5
6SRC = wm.c 6WMSRC = wm.c draw.c util.c
7OBJ = ${SRC:.c=.o} 7WMOBJ = ${WMSRC:.c=.o}
8MAN = gridwm.1 8MAN = gridwm.1
9BIN = gridwm gridmenu 9BIN = gridwm gridmenu
10 10
@@ -22,18 +22,18 @@ config:
22 @echo CC $< 22 @echo CC $<
23 @${CC} -c ${CFLAGS} $< 23 @${CC} -c ${CFLAGS} $<
24 24
25${OBJ}: wm.h 25${WMOBJ}: wm.h draw.h config.h
26 26
27gridwm: ${OBJ} 27gridwm: ${WMOBJ}
28 @echo LD $@ 28 @echo LD $@
29 @${CC} -o $@ ${OBJ} ${X11LDFLAGS} 29 @${CC} -o $@ ${WMOBJ} ${LDFLAGS}
30 30
31clean: 31clean:
32 rm -f gridwm *.o 32 rm -f gridwm *.o
33 33
34dist: clean 34dist: clean
35 mkdir -p gridwm-${VERSION} 35 mkdir -p gridwm-${VERSION}
36 cp -R Makefile README LICENSE config.mk ${SRC} ${MAN} gridwm-${VERSION} 36 cp -R Makefile README LICENSE config.mk ${WMSRC} ${MAN} gridwm-${VERSION}
37 tar -cf gridwm-${VERSION}.tar gridwm-${VERSION} 37 tar -cf gridwm-${VERSION}.tar gridwm-${VERSION}
38 gzip gridwm-${VERSION}.tar 38 gzip gridwm-${VERSION}.tar
39 rm -rf gridwm-${VERSION} 39 rm -rf gridwm-${VERSION}
diff --git a/config.h b/config.h
new file mode 100644
index 0000000..036a41b
--- /dev/null
+++ b/config.h
@@ -0,0 +1,9 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#define FONT "fixed"
7#define FGCOLOR "#000000"
8#define BGCOLOR "#ffaa00"
9#define BOCOLOR "#000000"
diff --git a/config.mk b/config.mk
index 8fc41d7..4fa9e86 100644
--- a/config.mk
+++ b/config.mk
@@ -11,14 +11,12 @@ X11LIB = /usr/X11R6/lib
11VERSION = 0.0 11VERSION = 0.0
12 12
13# includes and libs 13# includes and libs
14LIBS = -L${PREFIX}/lib -L/usr/lib -lc 14LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11
15X11LIBS = -L${X11LIB} -lX11
16 15
17# Linux/BSD 16# Linux/BSD
18CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ 17CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \
19 -DVERSION=\"${VERSION}\" 18 -DVERSION=\"${VERSION}\"
20LDFLAGS = -g ${LIBS} 19LDFLAGS = -g ${LIBS}
21X11LDFLAGS = ${LDFLAGS} ${X11LIBS}
22 20
23# Solaris 21# Solaris
24#CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\" 22#CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\"
diff --git a/draw.c b/draw.c
new file mode 100644
index 0000000..85ff41b
--- /dev/null
+++ b/draw.c
@@ -0,0 +1,163 @@
1/*
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdio.h>
7#include <string.h>
8
9#include "draw.h"
10#include "util.h"
11
12static void
13drawborder(Display *dpy, Brush *b)
14{
15 XPoint points[5];
16 XSetLineAttributes(dpy, b->gc, 1, LineSolid, CapButt, JoinMiter);
17 XSetForeground(dpy, b->gc, b->color.border);
18 points[0].x = b->rect.x;
19 points[0].y = b->rect.y;
20 points[1].x = b->rect.width - 1;
21 points[1].y = 0;
22 points[2].x = 0;
23 points[2].y = b->rect.height - 1;
24 points[3].x = -(b->rect.width - 1);
25 points[3].y = 0;
26 points[4].x = 0;
27 points[4].y = -(b->rect.height - 1);
28 XDrawLines(dpy, b->drawable, b->gc, points, 5, CoordModePrevious);
29}
30
31void
32draw(Display *dpy, Brush *b)
33{
34 unsigned int x, y, w, h, len;
35 static char buf[256];
36 XGCValues gcv;
37
38 XSetForeground(dpy, b->gc, b->color.bg);
39 XFillRectangles(dpy, b->drawable, b->gc, &b->rect, 1);
40
41 if(b->border)
42 drawborder(dpy, b);
43
44 if(!b->text)
45 return;
46
47 len = strlen(b->text);
48 if(len >= sizeof(buf))
49 len = sizeof(buf) - 1;
50 memcpy(buf, b->text, len);
51 buf[len] = 0;
52
53 h = b->font->ascent + b->font->descent;
54 y = b->rect.y + (b->rect.height / 2) - (h / 2) + b->font->ascent;
55 x = b->rect.x + (h / 2);
56
57 /* shorten text if necessary */
58 while(len && (w = textwidth_l(b->font, buf, len)) > b->rect.width - h)
59 buf[--len] = 0;
60
61 if(w > b->rect.width)
62 return; /* too long */
63
64 gcv.foreground = b->color.fg;
65 gcv.background = b->color.bg;
66 if(b->font->set) {
67 XChangeGC(dpy, b->gc, GCForeground | GCBackground, &gcv);
68 XmbDrawImageString(dpy, b->drawable, b->font->set, b->gc,
69 x, y, buf, len);
70 }
71 else {
72 gcv.font = b->font->xfont->fid;
73 XChangeGC(dpy, b->gc, GCForeground | GCBackground | GCFont, &gcv);
74 XDrawImageString(dpy, b->drawable, b->gc, x, y, buf, len);
75 }
76}
77
78static unsigned long
79xloadcolor(Display *dpy, Colormap cmap, const char *colstr)
80{
81 XColor color;
82 XAllocNamedColor(dpy, cmap, colstr, &color, &color);
83 return color.pixel;
84}
85
86void
87loadcolor(Display *dpy, int screen, Color *c,
88 const char *bg, const char *fg, const char *border)
89{
90 Colormap cmap = DefaultColormap(dpy, screen);
91 c->bg = xloadcolor(dpy, cmap, bg);
92 c->fg = xloadcolor(dpy, cmap, fg);
93 c->border = xloadcolor(dpy, cmap, border);
94}
95
96unsigned int
97textwidth_l(Fnt *font, char *text, unsigned int len)
98{
99 if(font->set) {
100 XRectangle r;
101 XmbTextExtents(font->set, text, len, 0, &r);
102 return r.width;
103 }
104 return XTextWidth(font->xfont, text, len);
105}
106
107unsigned int
108textwidth(Fnt *font, char *text)
109{
110 return textwidth_l(font, text, strlen(text));
111}
112
113void
114loadfont(Display *dpy, Fnt *font, const char *fontstr)
115{
116 char **missing, *def;
117 int n;
118
119 missing = 0;
120 def = "?";
121 setlocale(LC_ALL, "");
122 if(font->set)
123 XFreeFontSet(dpy, font->set);
124 font->set = XCreateFontSet(dpy, fontstr, &missing, &n, &def);
125 if(missing) {
126 while(n--)
127 fprintf(stderr, "missing fontset: %s\n", missing[n]);
128 XFreeStringList(missing);
129 if(font->set) {
130 XFreeFontSet(dpy, font->set);
131 font->set = 0;
132 }
133 }
134 if(font->set) {
135 XFontSetExtents *font_extents;
136 XFontStruct **xfonts;
137 char **font_names;
138 unsigned int i;
139
140 font->ascent = font->descent = 0;
141 font_extents = XExtentsOfFontSet(font->set);
142 n = XFontsOfFontSet(font->set, &xfonts, &font_names);
143 for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
144 if(font->ascent < (*xfonts)->ascent)
145 font->ascent = (*xfonts)->ascent;
146 if(font->descent < (*xfonts)->descent)
147 font->descent = (*xfonts)->descent;
148 xfonts++;
149 }
150 }
151 else {
152 if(font->xfont)
153 XFreeFont(dpy, font->xfont);
154 font->xfont = 0;
155 font->xfont = XLoadQueryFont(dpy, fontstr);
156 if (!font->xfont)
157 font->xfont = XLoadQueryFont(dpy, "fixed");
158 if (!font->xfont)
159 error("error, cannot load 'fixed' font\n");
160 font->ascent = font->xfont->ascent;
161 font->descent = font->xfont->descent;
162 }
163}
diff --git a/draw.h b/draw.h
new file mode 100644
index 0000000..d3f9872
--- /dev/null
+++ b/draw.h
@@ -0,0 +1,6 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6extern void error(char *errstr, ...);
diff --git a/font.c b/font.c
new file mode 100644
index 0000000..99301b5
--- /dev/null
+++ b/font.c
@@ -0,0 +1,81 @@
1/*
2 * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdio.h>
7#include <stdlib.h>
8#include <string.h>
9#include <locale.h>
10
11unsigned int
12textwidth_l(BlitzFont *font, char *text, unsigned int len)
13{
14 if(font->set) {
15 XRectangle r;
16 XmbTextExtents(font->set, text, len, nil, &r);
17 return r.width;
18 }
19 return XTextWidth(font->xfont, text, len);
20}
21
22unsigned int
23textwidth(BlitzFont *font, char *text)
24{
25 return blitz_textwidth_l(font, text, strlen(text));
26}
27
28void
29loadfont(Blitz *blitz, BlitzFont *font)
30{
31 char *fontname = font->fontstr;
32 char **missing = nil, *def = "?";
33 int n;
34
35 setlocale(LC_ALL, "");
36 if(font->set)
37 XFreeFontSet(blitz->dpy, font->set);
38 font->set = XCreateFontSet(blitz->dpy, fontname, &missing, &n, &def);
39 if(missing) {
40 while(n--)
41 fprintf(stderr, "liblitz: missing fontset: %s\n", missing[n]);
42 XFreeStringList(missing);
43 if(font->set) {
44 XFreeFontSet(blitz->dpy, font->set);
45 font->set = nil;
46 }
47 }
48 if(font->set) {
49 XFontSetExtents *font_extents;
50 XFontStruct **xfonts;
51 char **font_names;
52 unsigned int i;
53
54 font->ascent = font->descent = 0;
55 font_extents = XExtentsOfFontSet(font->set);
56 n = XFontsOfFontSet(font->set, &xfonts, &font_names);
57 for(i = 0, font->ascent = 0, font->descent = 0; i < n; i++) {
58 if(font->ascent < (*xfonts)->ascent)
59 font->ascent = (*xfonts)->ascent;
60 if(font->descent < (*xfonts)->descent)
61 font->descent = (*xfonts)->descent;
62 xfonts++;
63 }
64 }
65 else {
66 if(font->xfont)
67 XFreeFont(blitz->dpy, font->xfont);
68 font->xfont = nil;
69 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
70 if (!font->xfont) {
71 fontname = "fixed";
72 font->xfont = XLoadQueryFont(blitz->dpy, fontname);
73 }
74 if (!font->xfont) {
75 fprintf(stderr, "%s", "liblitz: error, cannot load 'fixed' font\n");
76 exit(1);
77 }
78 font->ascent = font->xfont->ascent;
79 font->descent = font->xfont->descent;
80 }
81}
diff --git a/gridmenu.1 b/gridmenu.1
index 03ae454..527f186 100644
--- a/gridmenu.1
+++ b/gridmenu.1
@@ -64,21 +64,5 @@ returns
64if Enter is pressed on termination, 64if Enter is pressed on termination,
65.B 1 65.B 1
66if Escape is pressed. 66if Escape is pressed.
67.SH ENVIRONMENT
68.TP
69GRID_FONT
70The X11 font used to display each item in the menu.
71.br
72Default: fixed
73.TP
74GRID_NORMCOLORS
75The foreground, background, and border colors of a label. Syntactically, three blank-separated color values of the form #RRGGBB are expected.
76.br
77Default: #222222 #eeeeee #666666
78.TP
79GRID_SELCOLORS
80Like GRID_NORMCOLORS, but for the selected label.
81.br
82Default: #ffffff #335577 #447799
83.SH SEE ALSO 67.SH SEE ALSO
84.BR gridwm (1) 68.BR gridwm (1)
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..3553f5d
--- /dev/null
+++ b/util.c
@@ -0,0 +1,18 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <stdarg.h>
7#include <stdio.h>
8#include <stdlib.h>
9
10void
11error(char *errstr, ...) {
12 va_list ap;
13 va_start(ap, errstr);
14 vfprintf(stderr, errstr, ap);
15 va_end(ap);
16 exit(1);
17}
18
diff --git a/util.h b/util.h
new file mode 100644
index 0000000..be296e8
--- /dev/null
+++ b/util.h
@@ -0,0 +1,41 @@
1/*
2 * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
3 * See LICENSE file for license details.
4 */
5
6#include <X11/Xlib.h>
7#include <X11/Xlocale.h>
8
9typedef struct Brush Brush;
10typedef struct Color Color;
11typedef struct Fnt Fnt;
12
13struct Color {
14 unsigned long bg;
15 unsigned long fg;
16 unsigned long border;
17};
18
19struct Fnt {
20 XFontStruct *xfont;
21 XFontSet set;
22 int ascent;
23 int descent;
24};
25
26struct Brush {
27 GC gc;
28 Drawable drawable;
29 XRectangle rect;
30 Bool border;
31 Fnt *font;
32 Color color;
33 const char *text;
34};
35
36extern void draw(Display *dpy, Brush *b);
37extern void loadcolor(Display *dpy, int screen, Color *c,
38 const char *bg, const char *fg, const char *bo);
39extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len);
40extern unsigned int textwidth(Fnt *font, char *text);
41extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
diff --git a/wm.c b/wm.c
index de5324c..4c4a513 100644
--- a/wm.c
+++ b/wm.c
@@ -36,15 +36,6 @@ usage()
36 exit(1); 36 exit(1);
37} 37}
38 38
39void
40error(char *errstr, ...) {
41 va_list ap;
42 va_start(ap, errstr);
43 vfprintf(stderr, errstr, ap);
44 va_end(ap);
45 exit(1);
46}
47
48static void 39static void
49scan_wins() 40scan_wins()
50{ 41{
diff --git a/wm.h b/wm.h
index 3885cb5..70f7ec7 100644
--- a/wm.h
+++ b/wm.h
@@ -3,7 +3,9 @@
3 * See LICENSE file for license details. 3 * See LICENSE file for license details.
4 */ 4 */
5 5
6#include <X11/Xlib.h> 6#include "draw.h"
7#include "util.h"
8
7#include <X11/Xutil.h> 9#include <X11/Xutil.h>
8 10
9/* WM atoms */ 11/* WM atoms */
@@ -54,4 +56,3 @@ extern Cursor cursor[CurLast];
54extern Pixmap pmap; 56extern Pixmap pmap;
55 57
56/* wm.c */ 58/* wm.c */
57extern void error(char *errstr, ...);