Commit 8b59083
Changed files (15)
bar.c
@@ -1,41 +0,0 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-
-#include "wm.h"
-
-void
-draw_bar()
-{
- int i;
- brush.x = brush.y = 0;
- brush.w = bw;
- brush.h = bh;
- draw(dpy, &brush, False, NULL);
-
- brush.w = 0;
- for(i = 0; i < TLast; i++) {
- brush.x += brush.w;
- brush.w = textw(&brush.font, tags[i]) + bh;
- if(i == tsel) {
- swap((void **)&brush.fg, (void **)&brush.bg);
- draw(dpy, &brush, True, tags[i]);
- swap((void **)&brush.fg, (void **)&brush.bg);
- }
- else
- draw(dpy, &brush, True, tags[i]);
- }
- if(stack) {
- swap((void **)&brush.fg, (void **)&brush.bg);
- brush.x += brush.w;
- brush.w = textw(&brush.font, stack->name) + bh;
- draw(dpy, &brush, True, stack->name);
- swap((void **)&brush.fg, (void **)&brush.bg);
- }
- brush.w = textw(&brush.font, stext) + bh;
- brush.x = bx + bw - brush.w;
- draw(dpy, &brush, False, stext);
- XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0);
- XFlush(dpy);
-}
client.c
@@ -7,8 +7,8 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xatom.h>
+#include <X11/Xutil.h>
-#include "util.h"
#include "wm.h"
void (*arrange)(void *aux);
@@ -19,9 +19,9 @@ max(void *aux)
if(!stack)
return;
stack->x = sx;
- stack->y = bh;
+ stack->y = sy;
stack->w = sw - 2 * stack->border;
- stack->h = sh - bh - 2 * stack->border;
+ stack->h = sh - 2 * stack->border;
resize(stack);
discard_events(EnterWindowMask);
}
@@ -59,11 +59,11 @@ grid(void *aux)
cols = rows;
gw = (sw - 2) / cols;
- gh = (sh - bh - 2) / rows;
+ gh = (sh - 2) / rows;
for(i = j = 0, c = clients; c; c = c->next) {
c->x = i * gw;
- c->y = j * gh + bh;
+ c->y = j * gh;
c->w = gw;
c->h = gh;
resize(c);
@@ -89,12 +89,12 @@ sel(void *aux)
for(c = stack; c && c->snext; c = c->snext);
if(!c)
c = stack;
- raise(c);
+ craise(c);
focus(c);
}
void
-kill(void *aux)
+ckill(void *aux)
{
Client *c = stack;
@@ -114,8 +114,8 @@ resize_title(Client *c)
c->tw = 0;
for(i = 0; i < TLast; i++)
if(c->tags[i])
- c->tw += textw(&brush.font, c->tags[i]) + bh;
- c->tw += textw(&brush.font, c->name) + bh;
+ c->tw += textw(&brush.font, c->tags[i]) + brush.font.height;
+ c->tw += textw(&brush.font, c->name) + brush.font.height;
if(c->tw > c->w)
c->tw = c->w + 2;
c->tx = c->x + c->w - c->tw + 2;
@@ -190,7 +190,7 @@ update_size(Client *c)
}
void
-raise(Client *c)
+craise(Client *c)
{
XRaiseWindow(dpy, c->win);
XRaiseWindow(dpy, c->title);
@@ -234,11 +234,9 @@ manage(Window w, XWindowAttributes *wa)
c->win = w;
c->tx = c->x = wa->x;
c->ty = c->y = wa->y;
- if(c->y < bh)
- c->ty = c->y += bh;
c->tw = c->w = wa->width;
c->h = wa->height;
- c->th = bh;
+ c->th = th;
c->border = 1;
update_size(c);
XSetWindowBorderWidth(dpy, c->win, 1);
@@ -379,10 +377,8 @@ unmanage(Client *c)
XDestroyWindow(dpy, c->title);
for(l=&clients; *l && *l != c; l=&(*l)->next);
- eassert(*l == c);
*l = c->next;
for(l=&stack; *l && *l != c; l=&(*l)->snext);
- eassert(*l == c);
*l = c->snext;
free(c);
@@ -418,10 +414,8 @@ void
draw_client(Client *c)
{
int i;
- if(c == stack) {
- draw_bar();
+ if(c == stack)
return;
- }
brush.x = brush.y = 0;
brush.h = c->th;
@@ -430,12 +424,12 @@ draw_client(Client *c)
for(i = 0; i < TLast; i++) {
if(c->tags[i]) {
brush.x += brush.w;
- brush.w = textw(&brush.font, c->tags[i]) + bh;
+ brush.w = textw(&brush.font, c->tags[i]) + brush.font.height;
draw(dpy, &brush, True, c->tags[i]);
}
}
brush.x += brush.w;
- brush.w = textw(&brush.font, c->name) + bh;
+ brush.w = textw(&brush.font, c->name) + brush.font.height;
draw(dpy, &brush, True, c->name);
XCopyArea(dpy, brush.drawable, c->title, brush.gc,
0, 0, c->tw, c->th, 0, 0);
config.h
@@ -1,15 +0,0 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-
-#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
-#define BGCOLOR "#666699"
-#define FGCOLOR "#ffffff"
-#define BORDERCOLOR "#9999CC"
-#define STATUSDELAY 10 /* seconds */
-
-/* tags, see wm.c for further config */
-enum { Tscratch, Tdev, Tirc, Twww, Twork, /* never remove: */ TLast };
-
-/* see kb.c for shortcut customization */
draw.c
@@ -6,8 +6,9 @@
#include <stdio.h>
#include <string.h>
-#include "draw.h"
-#include "util.h"
+#include <X11/Xlocale.h>
+
+#include "wm.h"
static void
drawborder(Display *dpy, Brush *b)
draw.h
@@ -1,36 +0,0 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-
-#include <X11/Xlib.h>
-#include <X11/Xlocale.h>
-
-typedef struct Brush Brush;
-typedef struct Fnt Fnt;
-
-struct Fnt {
- XFontStruct *xfont;
- XFontSet set;
- int ascent;
- int descent;
- int height;
-};
-
-struct Brush {
- GC gc;
- Drawable drawable;
- int x, y, w, h;
- Fnt font;
- unsigned long bg;
- unsigned long fg;
- unsigned long border;
-};
-
-extern void draw(Display *dpy, Brush *b, Bool border, const char *text);
-extern void loadcolors(Display *dpy, int screen, Brush *b,
- const char *bg, const char *fg, const char *bo);
-extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
-extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
-extern unsigned int textw(Fnt *font, char *text);
-extern unsigned int texth(Fnt *font);
event.c
@@ -51,7 +51,7 @@ buttonpress(XEvent *e)
Client *c;
if((c = getclient(ev->window))) {
- raise(c);
+ craise(c);
switch(ev->button) {
default:
break;
@@ -147,8 +147,6 @@ expose(XEvent *e)
if(ev->count == 0) {
if((c = gettitle(ev->window)))
draw_client(c);
- else if(ev->window == barwin)
- draw_bar();
}
}
@@ -203,10 +201,7 @@ propertynotify(XEvent *e)
}
if(ev->atom == XA_WM_NAME || ev->atom == net_atom[NetWMName]) {
update_name(c);
- if(c == stack)
- draw_bar();
- else
- draw_client(c);
+ draw_client(c);
}
}
}
kb.c
@@ -9,25 +9,19 @@
/********** CUSTOMIZE **********/
-char *cmdterm[] = {
+char *term[] = {
"aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
};
-char *cmdproglist[] = {
- "sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null "
- "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0
-};
-
static Key key[] = {
- { Mod1Mask, XK_Return, run, cmdterm },
- { Mod1Mask, XK_p, run, cmdproglist},
+ { Mod1Mask, XK_Return, run, term },
{ Mod1Mask, XK_k, sel, "prev" },
{ Mod1Mask, XK_j, sel, "next" },
{ Mod1Mask, XK_g, grid, NULL },
{ Mod1Mask, XK_f, floating, NULL },
{ Mod1Mask, XK_m, max, NULL },
- { Mod1Mask | ShiftMask, XK_c, kill, NULL },
+ { Mod1Mask | ShiftMask, XK_c, ckill, NULL },
{ Mod1Mask | ShiftMask, XK_q, quit, NULL },
};
Makefile
@@ -3,14 +3,12 @@
include config.mk
-WMSRC = bar.c client.c draw.c event.c kb.c mouse.c util.c wm.c
-WMOBJ = ${WMSRC:.c=.o}
-MENSRC = menu.c draw.c util.c
-MENOBJ = ${MENSRC:.c=.o}
-MAN1 = gridwm.1 gridmenu.1
-BIN = gridwm gridmenu
-
-all: config gridwm gridmenu
+SRC = client.c draw.c event.c kb.c mouse.c util.c wm.c
+OBJ = ${SRC:.c=.o}
+MAN1 = gridwm.1
+BIN = gridwm
+
+all: config gridwm
@echo finished
config:
@@ -24,18 +22,14 @@ config:
@echo CC $<
@${CC} -c ${CFLAGS} $<
-${WMOBJ}: wm.h draw.h config.h util.h
-
-gridmenu: ${MENOBJ}
- @echo LD $@
- @${CC} -o $@ ${MENOBJ} ${LDFLAGS}
+${OBJ}: wm.h
-gridwm: ${WMOBJ}
+gridwm: ${OBJ}
@echo LD $@
- @${CC} -o $@ ${WMOBJ} ${LDFLAGS}
+ @${CC} -o $@ ${OBJ} ${LDFLAGS}
clean:
- rm -f gridwm gridmenu *.o core
+ rm -f gridwm *.o core
dist: clean
mkdir -p gridwm-${VERSION}
README
@@ -37,7 +37,5 @@ This will start gridwm on display :1 of the host foo.bar.
Configuration
-------------
-The configuration of gridwm is done by customizing the config.h source file. To
-customize the key bindings edit kb.c. To change the status output, edit the
-status command definition in wm.c.
-
+The configuration of gridwm is done by customizing the wm.h source file. To
+customize the key bindings edit kb.c.
util.c
@@ -11,7 +11,7 @@
#include <sys/wait.h>
#include <unistd.h>
-#include "util.h"
+#include "wm.h"
void
error(char *errstr, ...) {
@@ -60,19 +60,12 @@ erealloc(void *ptr, unsigned int size)
char *
estrdup(const char *str)
{
- void *res = strdup(str);
+ char *res = strdup(str);
if(!res)
bad_malloc(strlen(str));
return res;
}
-void
-failed_assert(char *a, char *file, int line)
-{
- fprintf(stderr, "Assertion \"%s\" failed at %s:%d\n", a, file, line);
- abort();
-}
-
void
swap(void **p1, void **p2)
{
@@ -99,43 +92,3 @@ spawn(Display *dpy, char *argv[])
}
wait(0);
}
-
-void
-pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[])
-{
- unsigned int l, n;
- int pfd[2];
-
- if(!argv || !argv[0])
- return;
-
- if(pipe(pfd) == -1) {
- perror("pipe");
- exit(1);
- }
-
- if(fork() == 0) {
- if(dpy)
- close(ConnectionNumber(dpy));
- setsid();
- dup2(pfd[1], STDOUT_FILENO);
- close(pfd[0]);
- close(pfd[1]);
- execvp(argv[0], argv);
- fprintf(stderr, "gridwm: execvp %s", argv[0]);
- perror(" failed");
- }
- else {
- l = n = 0;
- close(pfd[1]);
- while(n < len) {
- if((l = read(pfd[0], buf + n, len - n)) < 1)
- break;
- n += l;
- }
- while(l > n);
- close(pfd[0]);
- buf[n < len ? n : len - 1] = 0;
- }
- wait(0);
-}
util.h
@@ -1,22 +0,0 @@
-/*
- * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
- * See LICENSE file for license details.
- */
-#include <X11/Xlib.h>
-
-extern void error(char *errstr, ...);
-extern void *emallocz(unsigned int size);
-extern void *emalloc(unsigned int size);
-extern void *erealloc(void *ptr, unsigned int size);
-extern char *estrdup(const char *str);
-#define eassert(a) \
- do { \
- if(!(a)) \
- failed_assert(#a, __FILE__, __LINE__); \
- } while (0)
-extern void failed_assert(char *a, char *file, int line);
-extern void pipe_spawn(char *buf, unsigned int len, Display *dpy, char *argv[]);
-extern void spawn(Display *dpy, char *argv[]);
-extern void swap(void **p1, void **p2);
-extern unsigned int tokenize(char **result, unsigned int reslen,
- char *str, char delim);
wm.c
@@ -3,15 +3,10 @@
* See LICENSE file for license details.
*/
-#include <errno.h>
-
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
-#include <sys/types.h>
-#include <sys/time.h>
-
#include <X11/cursorfont.h>
#include <X11/Xatom.h>
#include <X11/Xproto.h>
@@ -28,17 +23,6 @@ char *tags[TLast] = {
[Twork] = "work",
};
-/* commands */
-static char *cmdwallpaper[] = {
- "feh", "--bg-scale", "/home/garbeam/wallpaper/bg.jpg", NULL
-};
-
-static char *cmdstatus[] = {
- "sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`"
- " `uptime | sed 's/.*://; s/,//g'`"
- " `acpi | awk '{print $4}' | sed 's/,//'`", NULL
-};
-
/********** CUSTOMIZE **********/
/* X structs */
@@ -51,7 +35,7 @@ Bool issel;
char stext[1024];
int tsel = Tdev; /* default tag */
-int screen, sx, sy, sw, sh, bx, by, bw, bh;
+int screen, sx, sy, sw, sh, th;
Brush brush = {0};
Client *clients = NULL;
@@ -209,11 +193,6 @@ main(int argc, char *argv[])
unsigned int mask;
Window w;
XEvent ev;
- fd_set fds;
- struct timeval t, timeout = {
- .tv_usec = 0,
- .tv_sec = STATUSDELAY,
- };
/* command line args */
for(i = 1; (i < argc) && (argv[i][0] == '-'); i++) {
@@ -245,7 +224,6 @@ main(int argc, char *argv[])
if(other_wm_running)
error("gridwm: another window manager is already running\n");
- spawn(dpy, cmdwallpaper);
sx = sy = 0;
sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen);
@@ -275,25 +253,11 @@ main(int argc, char *argv[])
loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
loadfont(dpy, &brush.font, FONT);
- wa.override_redirect = 1;
- wa.background_pixmap = ParentRelative;
- wa.event_mask = ExposureMask;
-
- bx = by = 0;
- bw = sw;
- bh = texth(&brush.font);
- barwin = XCreateWindow(dpy, root, bx, by, bw, bh, 0, DefaultDepth(dpy, screen),
- CopyFromParent, DefaultVisual(dpy, screen),
- CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
- XDefineCursor(dpy, barwin, cursor[CurNormal]);
- XMapRaised(dpy, barwin);
+ th = texth(&brush.font);
- brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
+ brush.drawable = XCreatePixmap(dpy, root, sw, th, DefaultDepth(dpy, screen));
brush.gc = XCreateGC(dpy, root, 0, 0);
- pipe_spawn(stext, sizeof(stext), dpy, cmdstatus);
- draw_bar();
-
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
| LeaveWindowMask;
wa.cursor = cursor[CurNormal];
@@ -303,21 +267,9 @@ main(int argc, char *argv[])
scan_wins();
while(running) {
- if(XPending(dpy) > 0) {
- XNextEvent(dpy, &ev);
- if(handler[ev.type])
- (handler[ev.type]) (&ev); /* call handler */
- continue;
- }
- FD_ZERO(&fds);
- FD_SET(ConnectionNumber(dpy), &fds);
- t = timeout;
- if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0)
- continue;
- else if(errno != EINTR) {
- pipe_spawn(stext, sizeof(stext), dpy, cmdstatus);
- draw_bar();
- }
+ XNextEvent(dpy, &ev);
+ if(handler[ev.type])
+ (handler[ev.type])(&ev); /* call handler */
}
cleanup();
wm.h
@@ -3,15 +3,25 @@
* See LICENSE file for license details.
*/
-#include "config.h"
-#include "draw.h"
-#include "util.h"
+#include <X11/Xlib.h>
-#include <X11/Xutil.h>
+/********** CUSTOMIZE **********/
+#define FONT "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*"
+#define BGCOLOR "#666699"
+#define FGCOLOR "#ffffff"
+#define BORDERCOLOR "#9999CC"
+#define STATUSDELAY 10 /* seconds */
#define WM_PROTOCOL_DELWIN 1
+/* tags */
+enum { Tscratch, Tdev, Tirc, Twww, Twork, TLast };
+
+/********** CUSTOMIZE **********/
+
+typedef struct Brush Brush;
typedef struct Client Client;
+typedef struct Fnt Fnt;
typedef struct Key Key;
/* atoms */
@@ -21,6 +31,24 @@ enum { NetSupported, NetWMName, NetLast };
/* cursor */
enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
+struct Fnt {
+ XFontStruct *xfont;
+ XFontSet set;
+ int ascent;
+ int descent;
+ int height;
+};
+
+struct Brush {
+ GC gc;
+ Drawable drawable;
+ int x, y, w, h;
+ Fnt font;
+ unsigned long bg;
+ unsigned long fg;
+ unsigned long border;
+};
+
struct Client {
char name[256];
char *tags[TLast];
@@ -46,21 +74,27 @@ struct Key {
};
extern Display *dpy;
-extern Window root, barwin;
+extern Window root;
extern Atom wm_atom[WMLast], net_atom[NetLast];
extern Cursor cursor[CurLast];
extern Bool running, issel;
extern void (*handler[LASTEvent]) (XEvent *);
extern void (*arrange)(void *aux);
-extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh;
+extern int tsel, screen, sx, sy, sw, sh, th;
extern char stext[1024], *tags[TLast];
extern Brush brush;
extern Client *clients, *stack;
-/* bar.c */
-extern void draw_bar();
+/* draw.c */
+extern void draw(Display *dpy, Brush *b, Bool border, const char *text);
+extern void loadcolors(Display *dpy, int screen, Brush *b,
+ const char *bg, const char *fg, const char *bo);
+extern void loadfont(Display *dpy, Fnt *font, const char *fontstr);
+extern unsigned int textnw(Fnt *font, char *text, unsigned int len);
+extern unsigned int textw(Fnt *font, char *text);
+extern unsigned int texth(Fnt *font);
/* client.c */
extern void manage(Window w, XWindowAttributes *wa);
@@ -72,9 +106,9 @@ extern void draw_client(Client *c);
extern void resize(Client *c);
extern void update_size(Client *c);
extern Client *gettitle(Window w);
-extern void raise(Client *c);
+extern void craise(Client *c);
extern void lower(Client *c);
-extern void kill(void *aux);
+extern void ckill(void *aux);
extern void sel(void *aux);
extern void max(void *aux);
extern void floating(void *aux);
@@ -92,6 +126,15 @@ extern void keypress(XEvent *e);
extern void mresize(Client *c);
extern void mmove(Client *c);
+/* util.c */
+extern void error(char *errstr, ...);
+extern void *emallocz(unsigned int size);
+extern void *emalloc(unsigned int size);
+extern void *erealloc(void *ptr, unsigned int size);
+extern char *estrdup(const char *str);
+extern void spawn(Display *dpy, char *argv[]);
+extern void swap(void **p1, void **p2);
+
/* wm.c */
extern int error_handler(Display *dpy, XErrorEvent *error);
extern void send_message(Window w, Atom a, long value);