#define MODKEY Mod1Mask
#define CLEANMASK(mask) (mask & ~(numlockmask | LockMask))
+char **start_argv;
+Atom astate;
int (*xerrorxlib)(Display *, XErrorEvent *);
int other_wm;
int screen;
/* terminal + args */
char *spawn_term[] = { "xterm", NULL };
char *spawn_menu[] = { "dmenu_run", NULL };
-char *spawn_scrotwm[] = { "scrotwm", NULL };
/* layout manager data */
struct swm_geometry {
running = 0;
}
-
void
restart(union arg *args)
{
+ DNPRINTF(SWM_D_MISC, "restart: %s\n", start_argv[0]);
+
XCloseDisplay(display);
- execvp(args->argv[0], args->argv);
+ execvp(start_argv[0], start_argv);
fprintf(stderr, "execvp failed\n");
perror(" failed");
quit(NULL);
* The double-fork construct avoids zombie processes and keeps the code
* clean from stupid signal handlers.
*/
- if(fork() == 0) {
- if(fork() == 0) {
- if(display)
+ if (fork() == 0) {
+ if (fork() == 0) {
+ if (display)
close(ConnectionNumber(display));
setsid();
execvp(args->argv[0], args->argv);
ws[current_ws].cur_layout++;
if (ws[current_ws].cur_layout->l_stack == NULL)
ws[current_ws].cur_layout = &layouts[0];
+ ignore_enter = 1;
stack();
}
DNPRINTF(SWM_D_EVENT, "vertical_stack: workspace: %d\n", current_ws);
- winfocus->id = root;
-
winno = count_win(current_ws, 0);
if (winno == 0)
return;
+ winfocus->id = root;
if (winno > 1)
gg.w = vertical_msize[current_ws];
DNPRINTF(SWM_D_EVENT, "horizontal_stack: workspace: %d\n", current_ws);
- winfocus->id = root;
-
winno = count_win(current_ws, 0);
if (winno == 0)
return;
+ winfocus->id = root;
if (winno > 1)
gg.h = horizontal_msize[current_ws];
XWindowChanges wc;
struct swm_geometry gg = *g;
struct ws_win *win, *winfocus;
- int i, found = 0, winno;
- unsigned int mask;
+ unsigned int mask;
DNPRINTF(SWM_D_EVENT, "max_stack: workspace: %d\n", current_ws);
- winno = count_win(current_ws, 0);
- if (winno == 0)
+ if (count_win(current_ws, 0) == 0)
return;
- winfocus = TAILQ_FIRST(&ws[current_ws].winlist);
+ winfocus = ws[current_ws].focus;
+ if (!winfocus)
+ winfocus = TAILQ_FIRST(&ws[current_ws].winlist);
TAILQ_FOREACH (win, &ws[current_ws].winlist, entry) {
if (win->transient != 0 || win->floating != 0) {
- stack_floater(win);
+ if (win == winfocus)
+ stack_floater(win); /* XXX maximize? */
+ else
+ XUnmapWindow(display, win->id);
} else {
bzero(&wc, sizeof wc);
wc.border_width = 1;
mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
XConfigureWindow(display, win->id, mask, &wc);
- if (!found) {
- found = 1;
+ if (winfocus == win)
XMapRaised(display, win->id);
- } else {
- /* hide all but the master window */
+ else
XUnmapWindow(display, win->id);
- }
}
- if (win == ws[current_ws].focus)
- winfocus = win;
- else
- unfocus_win(win);
- i++;
}
focus_win(winfocus); /* this has to be done outside of the loop */
{ MODKEY | ShiftMask, XK_Return, spawn, {.argv = spawn_term} },
{ MODKEY, XK_p, spawn, {.argv = spawn_menu} },
{ MODKEY | ShiftMask, XK_q, quit, {0} },
- { MODKEY, XK_q, restart, {.argv = spawn_scrotwm } },
+ { MODKEY, XK_q, restart, {0} },
{ MODKEY, XK_m, focus, {.id = SWM_ARG_ID_FOCUSMAIN} },
{ MODKEY, XK_1, switchws, {.id = 0} },
{ MODKEY, XK_2, switchws, {.id = 1} },
updatenumlockmask();
XUngrabKey(display, AnyKey, AnyModifier, root);
- for(i = 0; i < LENGTH(keys); i++) {
- if((code = XKeysymToKeycode(display, keys[i].keysym)))
- for(j = 0; j < LENGTH(modifiers); j++)
+ for (i = 0; i < LENGTH(keys); i++) {
+ if ((code = XKeysymToKeycode(display, keys[i].keysym)))
+ for (j = 0; j < LENGTH(modifiers); j++)
XGrabKey(display, code,
keys[i].mod | modifiers[j], root,
True, GrabModeAsync, GrabModeAsync);
DNPRINTF(SWM_D_EVENT, "keypress: window: %lu\n", ev->window);
keysym = XKeycodeToKeysym(display, (KeyCode)ev->keycode, 0);
- for(i = 0; i < LENGTH(keys); i++)
- if(keysym == keys[i].keysym
+ for (i = 0; i < LENGTH(keys); i++)
+ if (keysym == keys[i].keysym
&& CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
&& keys[i].func)
keys[i].func(&(keys[i].args));
#endif
}
+void
+set_win_state(struct ws_win *win, long state)
+{
+ long data[] = {state, None};
+
+ DNPRINTF(SWM_D_EVENT, "set_win_state: window: %lu\n", win->id);
+
+ XChangeProperty(display, win->id, astate, astate, 32, PropModeReplace,
+ (unsigned char *)data, 2);
+}
+
struct ws_win *
manage_window(Window id)
{
/* XXX */
bzero(&ch, sizeof ch);
- if(XGetClassHint(display, win->id, &ch)) {
+ if (XGetClassHint(display, win->id, &ch)) {
/*fprintf(stderr, "class: %s name: %s\n", ch.res_class, ch.res_name); */
if (!strcmp(ch.res_class, "MPlayer") && !strcmp(ch.res_name, "xv")) {
win->floating = 1;
}
- if(ch.res_class)
+ if (ch.res_class)
XFree(ch.res_class);
- if(ch.res_name)
+ if (ch.res_name)
XFree(ch.res_name);
}
XSelectInput(display, id, ButtonPressMask | EnterWindowMask |
FocusChangeMask | ExposureMask);
+ set_win_state(win, NormalState);
+
return (win);
}
ws[current_ws].focus = NULL;
TAILQ_REMOVE(&ws[current_ws].winlist, win, entry);
+ set_win_state(win, WithdrawnState);
free(win);
break;
}
DNPRINTF(SWM_D_EVENT, "enternotify: window: %lu\n", ev->window);
- if((ev->mode != NotifyNormal || ev->detail == NotifyInferior) &&
+ if ((ev->mode != NotifyNormal || ev->detail == NotifyInferior) &&
ev->window != root)
return;
if (ignore_enter) {
DNPRINTF(SWM_D_EVENT, "mappingnotify: window: %lu\n", ev->window);
XRefreshKeyboardMapping(ev);
- if(ev->request == MappingKeyboard)
+ if (ev->request == MappingKeyboard)
grabkeys();
}
void
maprequest(XEvent *e)
{
+ XMapRequestEvent *ev = &e->xmaprequest;
+ XWindowAttributes wa;
+
DNPRINTF(SWM_D_EVENT, "maprequest: window: %lu\n",
e->xmaprequest.window);
+ if (!XGetWindowAttributes(display, ev->window, &wa))
+ return;
+ if (wa.override_redirect)
+ return;
manage_window(e->xmaprequest.window);
stack();
}
int
xerror(Display *d, XErrorEvent *ee)
{
- fprintf(stderr, "error: %p %p\n", display, ee);
-
+ /* fprintf(stderr, "error: %p %p\n", display, ee); */
return (-1);
}
XSelectInput(display, DefaultRootWindow(display),
SubstructureRedirectMask);
XSync(display, False);
- if(other_wm)
+ if (other_wm)
return (1);
XSetErrorHandler(xerror);
return (0);
}
+long
+getstate(Window w)
+{
+ int format, status;
+ long result = -1;
+ unsigned char *p = NULL;
+ unsigned long n, extra;
+ Atom real;
+
+ astate = XInternAtom(display, "WM_STATE", False);
+ status = XGetWindowProperty(display, w, astate, 0L, 2L, False, astate,
+ &real, &format, &n, &extra, (unsigned char **)&p);
+ if (status != Success)
+ return (-1);
+ if (n != 0)
+ result = *p;
+ XFree(p);
+ return (result);
+}
+
int
main(int argc, char *argv[])
{
Window d1, d2, *wins = NULL;
XWindowAttributes wa;
+ start_argv = argv;
fprintf(stderr, "Welcome to scrotwm V%s\n", SWM_VERSION);
- if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ if (!setlocale(LC_CTYPE, "") || !XSupportsLocale())
warnx("no locale support");
- if(!(display = XOpenDisplay(0)))
+ if (!(display = XOpenDisplay(0)))
errx(1, "can not open display");
if (active_wm())
screen = DefaultScreen(display);
root = RootWindow(display, screen);
+ astate = XInternAtom(display, "WM_STATE", False);
/* look for local and global conf file */
pwd = getpwuid(getuid());
/* grab existing windows */
if (XQueryTree(display, root, &d1, &d2, &wins, &num)) {
+ /* normal windows */
+ for (i = 0; i < num; i++) {
+ XGetWindowAttributes(display, wins[i], &wa);
+ if (!XGetWindowAttributes(display, wins[i], &wa) ||
+ wa.override_redirect || XGetTransientForHint(display, wins[i], &d1))
+ continue;
+ if (wa.map_state == IsViewable || getstate(wins[i]) == NormalState)
+ manage_window(wins[i]);
+ }
+ /* transient windows */
for (i = 0; i < num; i++) {
- if (!XGetWindowAttributes(display, wins[i], &wa)
- || wa.override_redirect ||
- XGetTransientForHint(display, wins[i], &d1))
+ if (!XGetWindowAttributes(display, wins[i], &wa))
continue;
- manage_window(wins[i]);
+ if (XGetTransientForHint(display, wins[i], &d1) &&
+ (wa.map_state == IsViewable || getstate(wins[i]) ==
+ NormalState))
+ manage_window(wins[i]);
}
- if(wins)
+ if (wins)
XFree(wins);
}
ws[0].focus = TAILQ_FIRST(&ws[0].winlist);