added new stuff
8a34fa50
11 file(s) · +328 −36
| 3 | 3 | ||
| 4 | 4 | include config.mk |
|
| 5 | 5 | ||
| 6 | - | SRC = wm.c |
|
| 7 | - | OBJ = ${SRC:.c=.o} |
|
| 6 | + | WMSRC = wm.c draw.c util.c |
|
| 7 | + | WMOBJ = ${WMSRC:.c=.o} |
|
| 8 | 8 | MAN = gridwm.1 |
|
| 9 | 9 | BIN = gridwm gridmenu |
|
| 10 | 10 | ||
| 22 | 22 | @echo CC $< |
|
| 23 | 23 | @${CC} -c ${CFLAGS} $< |
|
| 24 | 24 | ||
| 25 | - | ${OBJ}: wm.h |
|
| 25 | + | ${WMOBJ}: wm.h draw.h config.h |
|
| 26 | 26 | ||
| 27 | - | gridwm: ${OBJ} |
|
| 27 | + | gridwm: ${WMOBJ} |
|
| 28 | 28 | @echo LD $@ |
|
| 29 | - | @${CC} -o $@ ${OBJ} ${X11LDFLAGS} |
|
| 29 | + | @${CC} -o $@ ${WMOBJ} ${LDFLAGS} |
|
| 30 | 30 | ||
| 31 | 31 | clean: |
|
| 32 | 32 | rm -f gridwm *.o |
|
| 33 | 33 | ||
| 34 | 34 | dist: clean |
|
| 35 | 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 | 37 | tar -cf gridwm-${VERSION}.tar gridwm-${VERSION} |
|
| 38 | 38 | gzip gridwm-${VERSION}.tar |
|
| 39 | 39 | rm -rf gridwm-${VERSION} |
|
| 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" |
| 11 | 11 | VERSION = 0.0 |
|
| 12 | 12 | ||
| 13 | 13 | # includes and libs |
|
| 14 | - | LIBS = -L${PREFIX}/lib -L/usr/lib -lc |
|
| 15 | - | X11LIBS = -L${X11LIB} -lX11 |
|
| 14 | + | LIBS = -L${PREFIX}/lib -L/usr/lib -lc -L${X11LIB} -lX11 |
|
| 16 | 15 | ||
| 17 | 16 | # Linux/BSD |
|
| 18 | 17 | CFLAGS = -g -Wall -I. -I${PREFIX}/include -I/usr/include -I${X11INC} \ |
|
| 19 | 18 | -DVERSION=\"${VERSION}\" |
|
| 20 | 19 | LDFLAGS = -g ${LIBS} |
|
| 21 | - | X11LDFLAGS = ${LDFLAGS} ${X11LIBS} |
|
| 22 | 20 | ||
| 23 | 21 | # Solaris |
|
| 24 | 22 | #CFLAGS = -fast -xtarget=ultra ${INCLUDES} -DVERSION=\"${VERSION}\" |
| 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 | + | ||
| 12 | + | static void |
|
| 13 | + | drawborder(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 | + | ||
| 31 | + | void |
|
| 32 | + | draw(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 | + | ||
| 78 | + | static unsigned long |
|
| 79 | + | xloadcolor(Display *dpy, Colormap cmap, const char *colstr) |
|
| 80 | + | { |
|
| 81 | + | XColor color; |
|
| 82 | + | XAllocNamedColor(dpy, cmap, colstr, &color, &color); |
|
| 83 | + | return color.pixel; |
|
| 84 | + | } |
|
| 85 | + | ||
| 86 | + | void |
|
| 87 | + | loadcolor(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 | + | ||
| 96 | + | unsigned int |
|
| 97 | + | textwidth_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 | + | ||
| 107 | + | unsigned int |
|
| 108 | + | textwidth(Fnt *font, char *text) |
|
| 109 | + | { |
|
| 110 | + | return textwidth_l(font, text, strlen(text)); |
|
| 111 | + | } |
|
| 112 | + | ||
| 113 | + | void |
|
| 114 | + | loadfont(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 | + | } |
| 1 | + | /* |
|
| 2 | + | * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> |
|
| 3 | + | * See LICENSE file for license details. |
|
| 4 | + | */ |
|
| 5 | + | ||
| 6 | + | extern void error(char *errstr, ...); |
| 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 | + | ||
| 11 | + | unsigned int |
|
| 12 | + | textwidth_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 | + | ||
| 22 | + | unsigned int |
|
| 23 | + | textwidth(BlitzFont *font, char *text) |
|
| 24 | + | { |
|
| 25 | + | return blitz_textwidth_l(font, text, strlen(text)); |
|
| 26 | + | } |
|
| 27 | + | ||
| 28 | + | void |
|
| 29 | + | loadfont(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 | + | } |
| 64 | 64 | if Enter is pressed on termination, |
|
| 65 | 65 | .B 1 |
|
| 66 | 66 | if Escape is pressed. |
|
| 67 | - | .SH ENVIRONMENT |
|
| 68 | - | .TP |
|
| 69 | - | GRID_FONT |
|
| 70 | - | The X11 font used to display each item in the menu. |
|
| 71 | - | .br |
|
| 72 | - | Default: fixed |
|
| 73 | - | .TP |
|
| 74 | - | GRID_NORMCOLORS |
|
| 75 | - | The foreground, background, and border colors of a label. Syntactically, three blank-separated color values of the form #RRGGBB are expected. |
|
| 76 | - | .br |
|
| 77 | - | Default: #222222 #eeeeee #666666 |
|
| 78 | - | .TP |
|
| 79 | - | GRID_SELCOLORS |
|
| 80 | - | Like GRID_NORMCOLORS, but for the selected label. |
|
| 81 | - | .br |
|
| 82 | - | Default: #ffffff #335577 #447799 |
|
| 83 | 67 | .SH SEE ALSO |
|
| 84 | 68 | .BR gridwm (1) |
| 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 | + | ||
| 10 | + | void |
|
| 11 | + | error(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 | + |
| 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 | + | ||
| 9 | + | typedef struct Brush Brush; |
|
| 10 | + | typedef struct Color Color; |
|
| 11 | + | typedef struct Fnt Fnt; |
|
| 12 | + | ||
| 13 | + | struct Color { |
|
| 14 | + | unsigned long bg; |
|
| 15 | + | unsigned long fg; |
|
| 16 | + | unsigned long border; |
|
| 17 | + | }; |
|
| 18 | + | ||
| 19 | + | struct Fnt { |
|
| 20 | + | XFontStruct *xfont; |
|
| 21 | + | XFontSet set; |
|
| 22 | + | int ascent; |
|
| 23 | + | int descent; |
|
| 24 | + | }; |
|
| 25 | + | ||
| 26 | + | struct 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 | + | ||
| 36 | + | extern void draw(Display *dpy, Brush *b); |
|
| 37 | + | extern void loadcolor(Display *dpy, int screen, Color *c, |
|
| 38 | + | const char *bg, const char *fg, const char *bo); |
|
| 39 | + | extern unsigned int textwidth_l(Fnt *font, char *text, unsigned int len); |
|
| 40 | + | extern unsigned int textwidth(Fnt *font, char *text); |
|
| 41 | + | extern void loadfont(Display *dpy, Fnt *font, const char *fontstr); |
| 36 | 36 | exit(1); |
|
| 37 | 37 | } |
|
| 38 | 38 | ||
| 39 | - | void |
|
| 40 | - | error(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 | - | ||
| 48 | 39 | static void |
|
| 49 | 40 | scan_wins() |
|
| 50 | 41 | { |
| 3 | 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 | 9 | #include <X11/Xutil.h> |
|
| 8 | 10 | ||
| 9 | 11 | /* WM atoms */ |
|
| 54 | 56 | extern Pixmap pmap; |
|
| 55 | 57 | ||
| 56 | 58 | /* wm.c */ |
|
| 57 | - | extern void error(char *errstr, ...); |
|