-/* $scrotwm$
+/* $scrotwm$ */
/*
* Copyright (c) 2009 Marco Peereboom <marco@peereboom.us>
* Copyright (c) 2009 Ryan McBride <mcbride@countersiege.com>
#define DNPRINTF(n,x...) do { if (swm_debug & n) fprintf(stderr, x); } while(0)
#define SWM_D_EVENT 0x0001
#define SWM_D_WS 0x0002
+#define SWM_D_FOCUS 0x0004
+#define SWM_D_MISC 0x0008
uint32_t swm_debug = 0
| SWM_D_EVENT
| SWM_D_WS
+ | SWM_D_FOCUS
+ | SWM_D_MISC
;
#else
#define DPRINTF(x...)
int running = 1;
int ignore_enter = 0;
unsigned int numlockmask = 0;
+unsigned long col_focus = 0xff0000; /* XXX should this be per ws? */
+unsigned long col_unfocus = 0x888888;
Display *display;
Window root;
struct ws_win {
TAILQ_ENTRY(ws_win) entry;
Window id;
+ int x;
+ int y;
+ int width;
+ int height;
};
TAILQ_HEAD(ws_win_list, ws_win);
/* define work spaces */
#define SWM_WS_MAX (10)
struct workspace {
- int visible; /* workspace visible */
+ int visible; /* workspace visible */
struct ws_win *focus; /* which win has focus */
- int winno; /* total nr of windows */
- struct ws_win_list winlist;
+ int winno; /* total nr of windows */
+ struct ws_win_list winlist;
} ws[SWM_WS_MAX];
int current_ws = 0;
/* args to functions */
union arg {
- int id;
+ int id;
#define SWM_ARG_ID_FOCUSNEXT (0)
#define SWM_ARG_ID_FOCUSPREV (1)
#define SWM_ARG_ID_FOCUSMAIN (2)
+ char **argv;
};
void
quit(union arg *args)
{
+ DNPRINTF(SWM_D_MISC, "quit\n");
running = 0;
}
void
spawn(union arg *args)
{
- char *argv[] = { "xterm", NULL }; /* XXX make this in args */
-
+ DNPRINTF(SWM_D_MISC, "spawn: %s\n", args->argv[0]);
/*
* The double-fork construct avoids zombie processes and keeps the code
* clean from stupid signal handlers.
if(display)
close(ConnectionNumber(display));
setsid();
- execvp(argv[0], argv);
+ execvp(args->argv[0], args->argv);
fprintf(stderr, "execvp failed\n");
perror(" failed");
}
void
focus_win(struct ws_win *win)
{
- XSetWindowBorder(display, win->id, 0xff0000);
+ DNPRINTF(SWM_D_FOCUS, "focus_win: id: %d\n", win->id);
+ XSetWindowBorder(display, win->id, col_focus);
XSetInputFocus(display, win->id, RevertToPointerRoot, CurrentTime);
ws[current_ws].focus = win;
}
void
unfocus_win(struct ws_win *win)
{
- XSetWindowBorder(display, win->id, 0x888888);
+ DNPRINTF(SWM_D_FOCUS, "unfocus_win: id: %d\n", win->id);
+ XSetWindowBorder(display, win->id, col_unfocus);
if (ws[current_ws].focus == win)
ws[current_ws].focus = NULL;
}
{
struct ws_win *winfocus, *winlostfocus;
+ DNPRINTF(SWM_D_FOCUS, "focus: id %d\n", args->id);
if (ws[current_ws].focus == NULL || ws[current_ws].winno == 0)
return;
}
bzero(&wc, sizeof wc);
- wc.x = x;
- wc.y = y;
- wc.width = w;
- wc.height = h;
+ win->x = wc.x = x;
+ win->y = wc.y = y;
+ win->width = wc.width = w;
+ win->height = wc.height = h;
wc.border_width = 1;
XConfigureWindow(display, win->id, CWX | CWY | CWWidth |
CWHeight | CWBorderWidth, &wc);
i++;
}
- focus_win(winfocus);
+ focus_win(winfocus); /* this has to be done outside of the loop */
XSync(display, False);
}
{
struct ws_win *tmpwin = TAILQ_FIRST(&ws[current_ws].winlist);
+ DNPRINTF(SWM_D_MISC, "swap_to_main: win: %d\n", ws[current_ws].focus->id);
TAILQ_REMOVE(&ws[current_ws].winlist, tmpwin, entry);
TAILQ_INSERT_AFTER(&ws[current_ws].winlist, ws[current_ws].focus,
tmpwin, entry);
stack();
}
+/* terminal + args */
+char *term[] = { "xterm", NULL };
+
/* key definitions */
struct key {
unsigned int mod;
} keys[] = {
/* modifier key function argument */
{ MODKEY, XK_Return, swap_to_main, {0} },
- { MODKEY | ShiftMask, XK_Return, spawn, {0} },
+ { MODKEY | ShiftMask, XK_Return, spawn, {.argv = term } },
{ MODKEY | ShiftMask, XK_q, quit, {0} },
{ MODKEY, XK_m, focus, {.id = SWM_ARG_ID_FOCUSMAIN} },
{ MODKEY, XK_1, switchws, {.id = 0} },
unsigned int i, j;
XModifierKeymap *modmap;
+ DNPRINTF(SWM_D_MISC, "updatenumlockmask\n");
numlockmask = 0;
modmap = XGetModifierMapping(display);
for (i = 0; i < 8; i++)
unsigned int modifiers[] =
{ 0, LockMask, numlockmask, numlockmask | LockMask };
+ DNPRINTF(SWM_D_MISC, "grabkeys\n");
updatenumlockmask();
XUngrabKey(display, AnyKey, AnyModifier, root);
void
destroynotify(XEvent *e)
{
- size_t sz;
+ size_t sz;
struct ws_win *win;
XDestroyWindowEvent *ev = &e->xdestroywindow;
DNPRINTF(SWM_D_EVENT, "destroynotify: window %d\n", ev->window);
TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) {
- DNPRINTF(SWM_D_EVENT, "trying: %x\n", win->id);
if (ev->window == win->id) {
/* find a window to focus */
ws[current_ws].focus =