removed unnecessary crap

This commit is contained in:
Anselm R. Garbe 2006-07-13 01:30:55 +02:00
parent da2bbd371c
commit 8b59083eb1
15 changed files with 94 additions and 784 deletions

View file

@ -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
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 gridmenu
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
${OBJ}: wm.h
gridmenu: ${MENOBJ}
gridwm: ${OBJ}
@echo LD $@
@${CC} -o $@ ${MENOBJ} ${LDFLAGS}
gridwm: ${WMOBJ}
@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}

6
README
View file

@ -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.

41
bar.c
View file

@ -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);
}

View file

@ -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);

View file

@ -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 */

5
draw.c
View file

@ -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)

36
draw.h
View file

@ -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);

View file

@ -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,9 +201,6 @@ 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);
}
}

View file

@ -1,68 +0,0 @@
.TH GRIDMENU 1 grid-0.0
.SH NAME
gridmenu \- grid window manager menu
.SH SYNOPSIS
.B gridmenu
.RB [ \-v ]
.RB [ \-t
.IR title ]
.SH DESCRIPTION
.SS Overview
.B gridmenu
is a generic, highly customizable, and efficient menu for the X Window System,
originally designed for
.BR grid (1).
It supports arbitrary, user defined menu contents.
.SS Options
.TP
.B \-v
prints version information to stdout, then exits.
.TP
.BI \-t " title"
displays
.I title
above the menu.
.SS Usage
.B gridmenu
reads a list of newline-separated items from stdin and creates a menu.
When the user selects an item or enters any text and presses Enter, his choice
is printed to stdout and
.B gridmenu
terminates.
.SS Keyboard Control
.B gridmenu
is completely controlled by the keyboard. The following keys are recognized:
.TP 2
Any printable character
appends the character to the text in the input field. This works as a filter:
only items containing this text will be displayed.
.TP 2
Left/Right (Control-p/Control-n)
select the previous/next item.
.TP 2
Tab (Control-i)
copy the selected item to the input field.
.TP 2
Enter (Control-j)
confirm selection and quit (print the selected item to stdout).
.TP 2
Shift-Enter (Shift-Control-j)
confirm selection and quit (print the text in the input field to stdout).
.TP 2
Escape (Control-[)
quit without selecting an item.
.TP 2
Backspace (Control-h)
remove enough characters from the input field to change its filtering effect.
.TP 2
Control-u
remove all characters from the input field.
.SS Exit codes
.B gridmenu
returns
.B 0
if Enter is pressed on termination,
.B 1
if Escape is pressed.
.SH SEE ALSO
.BR gridwm (1)

12
kb.c
View file

@ -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 },
};

432
menu.c
View file

@ -1,432 +0,0 @@
/*
* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com>
* (C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com>
* See LICENSE file for license details.
*/
#include "config.h"
#include "draw.h"
#include "util.h"
#include <ctype.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include <X11/cursorfont.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
typedef struct Item Item;
struct Item {
Item *next; /* traverses all items */
Item *left, *right; /* traverses items matching current search pattern */
char *text;
};
static Display *dpy;
static Window root;
static Window win;
static Bool done = False;
static Item *allitem = NULL; /* first of all items */
static Item *item = NULL; /* first of pattern matching items */
static Item *sel = NULL;
static Item *nextoff = NULL;
static Item *prevoff = NULL;
static Item *curroff = NULL;
static int screen, mx, my, mw, mh;
static char *title = NULL;
static char text[4096];
static int ret = 0;
static int nitem = 0;
static unsigned int cmdw = 0;
static unsigned int tw = 0;
static unsigned int cw = 0;
static const int seek = 30; /* 30px */
static Brush brush = {0};
static void draw_menu();
static void kpress(XKeyEvent * e);
static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
static void
usage() { error("usage: gridmenu [-v] [-t <title>]\n"); }
static void
update_offsets()
{
unsigned int tw, w = cmdw + 2 * seek;
if(!curroff)
return;
for(nextoff = curroff; nextoff; nextoff=nextoff->right) {
tw = textw(&brush.font, nextoff->text);
if(tw > mw / 3)
tw = mw / 3;
w += tw + brush.font.height;
if(w > mw)
break;
}
w = cmdw + 2 * seek;
for(prevoff = curroff; prevoff && prevoff->left; prevoff=prevoff->left) {
tw = textw(&brush.font, prevoff->left->text);
if(tw > mw / 3)
tw = mw / 3;
w += tw + brush.font.height;
if(w > mw)
break;
}
}
static void
update_items(char *pattern)
{
unsigned int plen = strlen(pattern);
Item *i, *j;
if(!pattern)
return;
if(!title || *pattern)
cmdw = cw;
else
cmdw = tw;
item = j = NULL;
nitem = 0;
for(i = allitem; i; i=i->next)
if(!plen || !strncmp(pattern, i->text, plen)) {
if(!j)
item = i;
else
j->right = i;
i->left = j;
i->right = NULL;
j = i;
nitem++;
}
for(i = allitem; i; i=i->next)
if(plen && strncmp(pattern, i->text, plen)
&& strstr(i->text, pattern)) {
if(!j)
item = i;
else
j->right = i;
i->left = j;
i->right = NULL;
j = i;
nitem++;
}
curroff = prevoff = nextoff = sel = item;
update_offsets();
}
/* creates brush structs for brush mode drawing */
static void
draw_menu()
{
Item *i;
brush.x = 0;
brush.y = 0;
brush.w = mw;
brush.h = mh;
draw(dpy, &brush, False, 0);
/* print command */
if(!title || text[0]) {
cmdw = cw;
if(cmdw && item)
brush.w = cmdw;
draw(dpy, &brush, False, text);
}
else {
cmdw = tw;
brush.w = cmdw;
draw(dpy, &brush, False, title);
}
brush.x += brush.w;
if(curroff) {
brush.w = seek;
draw(dpy, &brush, False, (curroff && curroff->left) ? "<" : 0);
brush.x += brush.w;
/* determine maximum items */
for(i = curroff; i != nextoff; i=i->right) {
brush.border = False;
brush.w = textw(&brush.font, i->text);
if(brush.w > mw / 3)
brush.w = mw / 3;
brush.w += brush.font.height;
if(sel == i) {
swap((void **)&brush.fg, (void **)&brush.bg);
draw(dpy, &brush, True, i->text);
swap((void **)&brush.fg, (void **)&brush.bg);
}
else
draw(dpy, &brush, False, i->text);
brush.x += brush.w;
}
brush.x = mw - seek;
brush.w = seek;
draw(dpy, &brush, False, nextoff ? ">" : 0);
}
XCopyArea(dpy, brush.drawable, win, brush.gc, 0, 0, mw, mh, 0, 0);
XFlush(dpy);
}
static void
kpress(XKeyEvent * e)
{
KeySym ksym;
char buf[32];
int num, prev_nitem;
unsigned int i, len = strlen(text);
buf[0] = 0;
num = XLookupString(e, buf, sizeof(buf), &ksym, 0);
if(IsFunctionKey(ksym) || IsKeypadKey(ksym)
|| IsMiscFunctionKey(ksym) || IsPFKey(ksym)
|| IsPrivateKeypadKey(ksym))
return;
/* first check if a control mask is omitted */
if(e->state & ControlMask) {
switch (ksym) {
default: /* ignore other control sequences */
return;
break;
case XK_h:
ksym = XK_BackSpace;
break;
case XK_U:
case XK_u:
text[0] = 0;
update_items(text);
draw_menu();
return;
break;
case XK_bracketleft:
ksym = XK_Escape;
break;
}
}
switch(ksym) {
case XK_Left:
if(!(sel && sel->left))
return;
sel=sel->left;
if(sel->right == curroff) {
curroff = prevoff;
update_offsets();
}
break;
case XK_Tab:
if(!sel)
return;
strncpy(text, sel->text, sizeof(text));
update_items(text);
break;
case XK_Right:
if(!(sel && sel->right))
return;
sel=sel->right;
if(sel == nextoff) {
curroff = nextoff;
update_offsets();
}
break;
case XK_Return:
if(e->state & ShiftMask) {
if(text)
fprintf(stdout, "%s", text);
}
else if(sel)
fprintf(stdout, "%s", sel->text);
else if(text)
fprintf(stdout, "%s", text);
fflush(stdout);
done = True;
break;
case XK_Escape:
ret = 1;
done = True;
break;
case XK_BackSpace:
if((i = len)) {
prev_nitem = nitem;
do {
text[--i] = 0;
update_items(text);
} while(i && nitem && prev_nitem == nitem);
update_items(text);
}
break;
default:
if(num && !iscntrl((int) buf[0])) {
buf[num] = 0;
if(len > 0)
strncat(text, buf, sizeof(text));
else
strncpy(text, buf, sizeof(text));
update_items(text);
}
}
draw_menu();
}
static char *
read_allitems()
{
static char *maxname = NULL;
char *p, buf[1024];
unsigned int len = 0, max = 0;
Item *i, *new;
i = 0;
while(fgets(buf, sizeof(buf), stdin)) {
len = strlen(buf);
if (buf[len - 1] == '\n')
buf[len - 1] = 0;
p = estrdup(buf);
if(max < len) {
maxname = p;
max = len;
}
new = emalloc(sizeof(Item));
new->next = new->left = new->right = NULL;
new->text = p;
if(!i)
allitem = new;
else
i->next = new;
i = new;
}
return maxname;
}
int
main(int argc, char *argv[])
{
int i;
XSetWindowAttributes wa;
char *maxname;
XEvent ev;
/* command line args */
for(i = 1; i < argc; i++) {
if (argv[i][0] == '-')
switch (argv[i][1]) {
case 'v':
fprintf(stdout, "%s", version);
exit(0);
break;
case 't':
if(++i < argc)
title = argv[i];
else
usage();
break;
default:
usage();
break;
}
else
usage();
}
dpy = XOpenDisplay(0);
if(!dpy)
error("gridmenu: cannot open dpy\n");
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
maxname = read_allitems();
/* grab as early as possible, but after reading all items!!! */
while(XGrabKeyboard(dpy, root, True, GrabModeAsync,
GrabModeAsync, CurrentTime) != GrabSuccess)
usleep(1000);
/* style */
loadcolors(dpy, screen, &brush, BGCOLOR, FGCOLOR, BORDERCOLOR);
loadfont(dpy, &brush.font, FONT);
wa.override_redirect = 1;
wa.background_pixmap = ParentRelative;
wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
mx = my = 0;
mw = DisplayWidth(dpy, screen);
mh = texth(&brush.font);
win = XCreateWindow(dpy, root, mx, my, mw, mh, 0,
DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm));
XFlush(dpy);
/* pixmap */
brush.gc = XCreateGC(dpy, root, 0, 0);
brush.drawable = XCreatePixmap(dpy, win, mw, mh,
DefaultDepth(dpy, screen));
XFlush(dpy);
if(maxname)
cw = textw(&brush.font, maxname) + brush.font.height;
if(cw > mw / 3)
cw = mw / 3;
if(title) {
tw = textw(&brush.font, title) + brush.font.height;
if(tw > mw / 3)
tw = mw / 3;
}
cmdw = title ? tw : cw;
text[0] = 0;
update_items(text);
XMapRaised(dpy, win);
draw_menu();
XFlush(dpy);
/* main event loop */
while(!done && !XNextEvent(dpy, &ev)) {
switch (ev.type) {
case KeyPress:
kpress(&ev.xkey);
break;
case Expose:
if(ev.xexpose.count == 0)
draw_menu();
break;
default:
break;
}
}
XUngrabKeyboard(dpy, CurrentTime);
XFreePixmap(dpy, brush.drawable);
XFreeGC(dpy, brush.gc);
XDestroyWindow(dpy, win);
XCloseDisplay(dpy);
return ret;
}

51
util.c
View file

@ -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);
}

22
util.h
View file

@ -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);

56
wm.c
View file

@ -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;
th = texth(&brush.font);
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);
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();
}
(handler[ev.type])(&ev); /* call handler */
}
cleanup();

63
wm.h
View file

@ -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);