before leaning things up

This commit is contained in:
Anselm R. Garbe 2006-07-13 01:04:38 +02:00
parent b1701adf75
commit da2bbd371c
9 changed files with 151 additions and 113 deletions

24
bar.c
View file

@ -8,22 +8,34 @@
void void
draw_bar() draw_bar()
{ {
int i;
brush.x = brush.y = 0; brush.x = brush.y = 0;
brush.w = bw; brush.w = bw;
brush.h = bh; brush.h = bh;
draw(dpy, &brush, False, NULL); 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) { if(stack) {
brush.w = textw(&brush.font, stack->name) + bh;
swap((void **)&brush.fg, (void **)&brush.bg);
draw(dpy, &brush, True, stack->name);
swap((void **)&brush.fg, (void **)&brush.bg); swap((void **)&brush.fg, (void **)&brush.bg);
brush.x += brush.w; 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.w = textw(&brush.font, statustext) + bh;
brush.x = bx + bw - brush.w; brush.x = bx + bw - brush.w;
draw(dpy, &brush, False, statustext); draw(dpy, &brush, False, stext);
XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0); XCopyArea(dpy, brush.drawable, barwin, brush.gc, 0, 0, bw, bh, 0, 0);
XFlush(dpy); XFlush(dpy);
} }

View file

@ -11,6 +11,8 @@
#include "util.h" #include "util.h"
#include "wm.h" #include "wm.h"
void (*arrange)(void *aux);
void void
max(void *aux) max(void *aux)
{ {
@ -25,12 +27,24 @@ max(void *aux)
} }
void void
arrange(void *aux) floating(void *aux)
{
Client *c;
arrange = floating;
for(c = stack; c; c = c->snext)
resize(c);
discard_events(EnterWindowMask);
}
void
grid(void *aux)
{ {
Client *c; Client *c;
int n, cols, rows, gw, gh, i, j; int n, cols, rows, gw, gh, i, j;
float rt, fd; float rt, fd;
arrange = grid;
if(!clients) if(!clients)
return; return;
for(n = 0, c = clients; c; c = c->next, n++); for(n = 0, c = clients; c; c = c->next, n++);
@ -95,7 +109,13 @@ kill(void *aux)
static void static void
resize_title(Client *c) resize_title(Client *c)
{ {
c->tw = textw(&brush.font, c->name) + bh; int i;
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;
if(c->tw > c->w) if(c->tw > c->w)
c->tw = c->w + 2; c->tw = c->w + 2;
c->tx = c->x + c->w - c->tw + 2; c->tx = c->x + c->w - c->tw + 2;
@ -190,8 +210,8 @@ focus(Client *c)
old = stack; old = stack;
for(l = &stack; *l && *l != c; l = &(*l)->snext); for(l = &stack; *l && *l != c; l = &(*l)->snext);
eassert(*l == c); if(*l)
*l = c->snext; *l = c->snext;
c->snext = stack; c->snext = stack;
stack = c; stack = c;
if(old && old != c) { if(old && old != c) {
@ -230,17 +250,16 @@ manage(Window w, XWindowAttributes *wa)
twa.background_pixmap = ParentRelative; twa.background_pixmap = ParentRelative;
twa.event_mask = ExposureMask; twa.event_mask = ExposureMask;
c->tags[tsel] = tags[tsel];
c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th, c->title = XCreateWindow(dpy, root, c->tx, c->ty, c->tw, c->th,
0, DefaultDepth(dpy, screen), CopyFromParent, 0, DefaultDepth(dpy, screen), CopyFromParent,
DefaultVisual(dpy, screen), DefaultVisual(dpy, screen),
CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa); CWOverrideRedirect | CWBackPixmap | CWEventMask, &twa);
update_name(c);
update_name(c);
for(l=&clients; *l; l=&(*l)->next); for(l=&clients; *l; l=&(*l)->next);
c->next = *l; /* *l == nil */ c->next = *l; /* *l == nil */
*l = c; *l = c;
c->snext = stack;
stack = c;
XMapRaised(dpy, c->win); XMapRaised(dpy, c->win);
XMapRaised(dpy, c->title); XMapRaised(dpy, c->title);
XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask, XGrabButton(dpy, Button1, Mod1Mask, c->win, False, ButtonPressMask,
@ -249,7 +268,7 @@ manage(Window w, XWindowAttributes *wa)
GrabModeAsync, GrabModeSync, None, None); GrabModeAsync, GrabModeSync, None, None);
XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask, XGrabButton(dpy, Button3, Mod1Mask, c->win, False, ButtonPressMask,
GrabModeAsync, GrabModeSync, None, None); GrabModeAsync, GrabModeSync, None, None);
resize(c); arrange(NULL);
focus(c); focus(c);
} }
@ -308,11 +327,24 @@ gravitate(Client *c, Bool invert)
c->y += dy; c->y += dy;
} }
void void
resize(Client *c) resize(Client *c)
{ {
XConfigureEvent e; XConfigureEvent e;
if(c->incw)
c->w -= (c->w - c->basew) % c->incw;
if(c->inch)
c->h -= (c->h - c->baseh) % c->inch;
if(c->minw && c->w < c->minw)
c->w = c->minw;
if(c->minh && c->h < c->minh)
c->h = c->minh;
if(c->maxw && c->w > c->maxw)
c->w = c->maxw;
if(c->maxh && c->h > c->maxh)
c->h = c->maxh;
resize_title(c); resize_title(c);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h);
e.type = ConfigureNotify; e.type = ConfigureNotify;
@ -357,6 +389,7 @@ unmanage(Client *c)
XFlush(dpy); XFlush(dpy);
XSetErrorHandler(error_handler); XSetErrorHandler(error_handler);
XUngrabServer(dpy); XUngrabServer(dpy);
arrange(NULL);
if(stack) if(stack)
focus(stack); focus(stack);
} }
@ -384,15 +417,25 @@ getclient(Window w)
void void
draw_client(Client *c) draw_client(Client *c)
{ {
int i;
if(c == stack) { if(c == stack) {
draw_bar(); draw_bar();
return; return;
} }
brush.x = brush.y = 0; brush.x = brush.y = 0;
brush.w = c->tw;
brush.h = c->th; brush.h = c->th;
brush.w = 0;
for(i = 0; i < TLast; i++) {
if(c->tags[i]) {
brush.x += brush.w;
brush.w = textw(&brush.font, c->tags[i]) + bh;
draw(dpy, &brush, True, c->tags[i]);
}
}
brush.x += brush.w;
brush.w = textw(&brush.font, c->name) + bh;
draw(dpy, &brush, True, c->name); draw(dpy, &brush, True, c->name);
XCopyArea(dpy, brush.drawable, c->title, brush.gc, XCopyArea(dpy, brush.drawable, c->title, brush.gc,
0, 0, c->tw, c->th, 0, 0); 0, 0, c->tw, c->th, 0, 0);

View file

@ -8,3 +8,8 @@
#define FGCOLOR "#ffffff" #define FGCOLOR "#ffffff"
#define BORDERCOLOR "#9999CC" #define BORDERCOLOR "#9999CC"
#define STATUSDELAY 10 /* seconds */ #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 */

View file

@ -126,7 +126,7 @@ enternotify(XEvent *e)
if((c = getclient(ev->window))) if((c = getclient(ev->window)))
focus(c); focus(c);
else if(ev->window == root) else if(ev->window == root)
sel_screen = True; issel = True;
} }
static void static void
@ -135,7 +135,7 @@ leavenotify(XEvent *e)
XCrossingEvent *ev = &e->xcrossing; XCrossingEvent *ev = &e->xcrossing;
if((ev->window == root) && !ev->same_screen) if((ev->window == root) && !ev->same_screen)
sel_screen = True; issel = True;
} }
static void static void

17
kb.c
View file

@ -7,27 +7,32 @@
#include <X11/keysym.h> #include <X11/keysym.h>
static const char *term[] = { /********** CUSTOMIZE **********/
char *cmdterm[] = {
"aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn", "aterm", "-tr", "+sb", "-bg", "black", "-fg", "white", "-fn",
"-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*", 0 "-*-terminus-medium-*-*-*-13-*-*-*-*-*-iso10646-*",NULL
}; };
static const char *proglist[] = { char *cmdproglist[] = {
"sh", "-c", "exec `ls -lL /bin /sbin /usr/bin /usr/local/bin 2>/dev/null " "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 "| awk 'NF>2 && $1 ~ /^[^d].*x/ {print $NF}' | sort | uniq | gridmenu`", 0
}; };
static Key key[] = { static Key key[] = {
{ Mod1Mask, XK_Return, run, term }, { Mod1Mask, XK_Return, run, cmdterm },
{ Mod1Mask, XK_p, run, proglist }, { Mod1Mask, XK_p, run, cmdproglist},
{ Mod1Mask, XK_k, sel, "prev" }, { Mod1Mask, XK_k, sel, "prev" },
{ Mod1Mask, XK_j, sel, "next" }, { Mod1Mask, XK_j, sel, "next" },
{ Mod1Mask, XK_g, arrange, NULL }, { Mod1Mask, XK_g, grid, NULL },
{ Mod1Mask, XK_f, floating, NULL },
{ Mod1Mask, XK_m, max, NULL }, { Mod1Mask, XK_m, max, NULL },
{ Mod1Mask | ShiftMask, XK_c, kill, NULL }, { Mod1Mask | ShiftMask, XK_c, kill, NULL },
{ Mod1Mask | ShiftMask, XK_q, quit, NULL }, { Mod1Mask | ShiftMask, XK_q, quit, NULL },
}; };
/********** CUSTOMIZE **********/
void void
update_keys() update_keys()
{ {

57
menu.c
View file

@ -12,9 +12,6 @@
#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <time.h>
#include <unistd.h> #include <unistd.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
@ -58,11 +55,7 @@ static void kpress(XKeyEvent * e);
static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; static char version[] = "gridmenu - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
static void static void
usage() usage() { error("usage: gridmenu [-v] [-t <title>]\n"); }
{
fprintf(stderr, "%s", "usage: gridmenu [-v] [-t <title>]\n");
exit(1);
}
static void static void
update_offsets() update_offsets()
@ -213,26 +206,12 @@ kpress(XKeyEvent * e)
/* first check if a control mask is omitted */ /* first check if a control mask is omitted */
if(e->state & ControlMask) { if(e->state & ControlMask) {
switch (ksym) { switch (ksym) {
case XK_H: default: /* ignore other control sequences */
return;
break;
case XK_h: case XK_h:
ksym = XK_BackSpace; ksym = XK_BackSpace;
break; break;
case XK_I:
case XK_i:
ksym = XK_Tab;
break;
case XK_J:
case XK_j:
ksym = XK_Return;
break;
case XK_N:
case XK_n:
ksym = XK_Right;
break;
case XK_P:
case XK_p:
ksym = XK_Left;
break;
case XK_U: case XK_U:
case XK_u: case XK_u:
text[0] = 0; text[0] = 0;
@ -243,12 +222,9 @@ kpress(XKeyEvent * e)
case XK_bracketleft: case XK_bracketleft:
ksym = XK_Escape; ksym = XK_Escape;
break; break;
default: /* ignore other control sequences */
return;
break;
} }
} }
switch (ksym) { switch(ksym) {
case XK_Left: case XK_Left:
if(!(sel && sel->left)) if(!(sel && sel->left))
return; return;
@ -432,21 +408,18 @@ main(int argc, char *argv[])
XFlush(dpy); XFlush(dpy);
/* main event loop */ /* main event loop */
while(!XNextEvent(dpy, &ev)) { while(!done && !XNextEvent(dpy, &ev)) {
switch (ev.type) { switch (ev.type) {
case KeyPress: case KeyPress:
kpress(&ev.xkey); kpress(&ev.xkey);
break;
case Expose:
if(ev.xexpose.count == 0) {
draw_menu();
}
break;
default:
break;
}
if(done)
break; break;
case Expose:
if(ev.xexpose.count == 0)
draw_menu();
break;
default:
break;
}
} }
XUngrabKeyboard(dpy, CurrentTime); XUngrabKeyboard(dpy, CurrentTime);

32
mouse.c
View file

@ -13,27 +13,6 @@
#define ButtonMask (ButtonPressMask | ButtonReleaseMask) #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
#define MouseMask (ButtonMask | PointerMotionMask) #define MouseMask (ButtonMask | PointerMotionMask)
static void
mmatch(Client *c, int x1, int y1, int x2, int y2)
{
c->w = abs(x1 - x2);
c->h = abs(y1 - y2);
if(c->incw)
c->w -= (c->w - c->basew) % c->incw;
if(c->inch)
c->h -= (c->h - c->baseh) % c->inch;
if(c->minw && c->w < c->minw)
c->w = c->minw;
if(c->minh && c->h < c->minh)
c->h = c->minh;
if(c->maxw && c->w > c->maxw)
c->w = c->maxw;
if(c->maxh && c->h > c->maxh)
c->h = c->maxh;
c->x = (x1 <= x2) ? x1 : x1 - c->w;
c->y = (y1 <= y2) ? y1 : y1 - c->h;
}
void void
mresize(Client *c) mresize(Client *c)
{ {
@ -55,11 +34,13 @@ mresize(Client *c)
break; break;
case MotionNotify: case MotionNotify:
XFlush(dpy); XFlush(dpy);
mmatch(c, old_cx, old_cy, ev.xmotion.x, ev.xmotion.y); c->w = abs(old_cx - ev.xmotion.x);
XResizeWindow(dpy, c->win, c->w, c->h); c->h = abs(old_cy - ev.xmotion.y);
c->x = (old_cx <= ev.xmotion.x) ? old_cx : old_cx - c->w;
c->y = (old_cy <= ev.xmotion.y) ? old_cy : old_cy - c->h;
resize(c);
break; break;
case ButtonRelease: case ButtonRelease:
resize(c);
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
return; return;
} }
@ -91,10 +72,9 @@ mmove(Client *c)
XFlush(dpy); XFlush(dpy);
c->x = old_cx + (ev.xmotion.x - x1); c->x = old_cx + (ev.xmotion.x - x1);
c->y = old_cy + (ev.xmotion.y - y1); c->y = old_cy + (ev.xmotion.y - y1);
XMoveResizeWindow(dpy, c->win, c->x, c->y, c->w, c->h); resize(c);
break; break;
case ButtonRelease: case ButtonRelease:
resize(c);
XUngrabPointer(dpy, CurrentTime); XUngrabPointer(dpy, CurrentTime);
return; return;
} }

51
wm.c
View file

@ -18,15 +18,39 @@
#include "wm.h" #include "wm.h"
/********** CUSTOMIZE **********/
char *tags[TLast] = {
[Tscratch] = "scratch",
[Tdev] = "dev",
[Tirc] = "irc",
[Twww] = "www",
[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 */ /* X structs */
Display *dpy; Display *dpy;
Window root, barwin; Window root, barwin;
Atom wm_atom[WMLast], net_atom[NetLast]; Atom wm_atom[WMLast], net_atom[NetLast];
Cursor cursor[CurLast]; Cursor cursor[CurLast];
Bool running = True; Bool running = True;
Bool sel_screen; Bool issel;
char statustext[1024], tag[256]; char stext[1024];
int tsel = Tdev; /* default tag */
int screen, sx, sy, sw, sh, bx, by, bw, bh; int screen, sx, sy, sw, sh, bx, by, bw, bh;
Brush brush = {0}; Brush brush = {0};
@ -34,21 +58,12 @@ Client *clients = NULL;
Client *stack = NULL; Client *stack = NULL;
static Bool other_wm_running; static Bool other_wm_running;
static const char version[] = "gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n"; static const char version[] =
"gridwm - " VERSION ", (C)opyright MMVI Anselm R. Garbe\n";
static int (*x_error_handler) (Display *, XErrorEvent *); static int (*x_error_handler) (Display *, XErrorEvent *);
static const char *status[] = {
"sh", "-c", "echo -n `date '+%Y-%m-%d %H:%M'`"
" `uptime | sed 's/.*://; s/,//g'`"
" `acpi | awk '{print $4}' | sed 's/,//'`", 0
};
static void static void
usage() usage() { error("usage: gridwm [-v]\n"); }
{
fputs("usage: gridwm [-v]\n", stderr);
exit(1);
}
static void static void
scan_wins() scan_wins()
@ -230,10 +245,11 @@ main(int argc, char *argv[])
if(other_wm_running) if(other_wm_running)
error("gridwm: another window manager is already running\n"); error("gridwm: another window manager is already running\n");
spawn(dpy, cmdwallpaper);
sx = sy = 0; sx = sy = 0;
sw = DisplayWidth(dpy, screen); sw = DisplayWidth(dpy, screen);
sh = DisplayHeight(dpy, screen); sh = DisplayHeight(dpy, screen);
sel_screen = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask); issel = XQueryPointer(dpy, root, &w, &w, &i, &i, &i, &i, &mask);
XSetErrorHandler(0); XSetErrorHandler(0);
x_error_handler = XSetErrorHandler(error_handler); x_error_handler = XSetErrorHandler(error_handler);
@ -275,7 +291,7 @@ main(int argc, char *argv[])
brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen)); brush.drawable = XCreatePixmap(dpy, root, sw, bh, DefaultDepth(dpy, screen));
brush.gc = XCreateGC(dpy, root, 0, 0); brush.gc = XCreateGC(dpy, root, 0, 0);
pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); pipe_spawn(stext, sizeof(stext), dpy, cmdstatus);
draw_bar(); draw_bar();
wa.event_mask = SubstructureRedirectMask | EnterWindowMask \ wa.event_mask = SubstructureRedirectMask | EnterWindowMask \
@ -283,6 +299,7 @@ main(int argc, char *argv[])
wa.cursor = cursor[CurNormal]; wa.cursor = cursor[CurNormal];
XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa); XChangeWindowAttributes(dpy, root, CWEventMask | CWCursor, &wa);
arrange = grid;
scan_wins(); scan_wins();
while(running) { while(running) {
@ -298,7 +315,7 @@ main(int argc, char *argv[])
if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0) if(select(ConnectionNumber(dpy) + 1, &fds, NULL, NULL, &t) > 0)
continue; continue;
else if(errno != EINTR) { else if(errno != EINTR) {
pipe_spawn(statustext, sizeof(statustext), dpy, (char **)status); pipe_spawn(stext, sizeof(stext), dpy, cmdstatus);
draw_bar(); draw_bar();
} }
} }

13
wm.h
View file

@ -22,7 +22,8 @@ enum { NetSupported, NetWMName, NetLast };
enum { CurNormal, CurResize, CurMove, CurInput, CurLast }; enum { CurNormal, CurResize, CurMove, CurInput, CurLast };
struct Client { struct Client {
char name[256], tag[256]; char name[256];
char *tags[TLast];
int proto; int proto;
int x, y, w, h; int x, y, w, h;
int tx, ty, tw, th; int tx, ty, tw, th;
@ -48,11 +49,12 @@ extern Display *dpy;
extern Window root, barwin; extern Window root, barwin;
extern Atom wm_atom[WMLast], net_atom[NetLast]; extern Atom wm_atom[WMLast], net_atom[NetLast];
extern Cursor cursor[CurLast]; extern Cursor cursor[CurLast];
extern Bool running, sel_screen, grid; extern Bool running, issel;
extern void (*handler[LASTEvent]) (XEvent *); extern void (*handler[LASTEvent]) (XEvent *);
extern void (*arrange)(void *aux);
extern int screen, sx, sy, sw, sh, bx, by, bw, bh; extern int tsel, screen, sx, sy, sw, sh, bx, by, bw, bh;
extern char statustext[1024], tag[256]; extern char stext[1024], *tags[TLast];
extern Brush brush; extern Brush brush;
extern Client *clients, *stack; extern Client *clients, *stack;
@ -75,7 +77,8 @@ extern void lower(Client *c);
extern void kill(void *aux); extern void kill(void *aux);
extern void sel(void *aux); extern void sel(void *aux);
extern void max(void *aux); extern void max(void *aux);
extern void arrange(void *aux); extern void floating(void *aux);
extern void grid(void *aux);
extern void gravitate(Client *c, Bool invert); extern void gravitate(Client *c, Bool invert);
/* event.c */ /* event.c */