static const char *cvstag = "$scrotwm$";
-#define SWM_VERSION "1.0"
+#define SWM_VERSION "0.9.13"
#include <stdio.h>
#include <stdlib.h>
/* define work spaces */
struct workspace {
int idx; /* workspace index */
- int restack; /* restack on switch */
struct layout *cur_layout; /* current layout handlers */
struct ws_win *focus; /* may be NULL */
struct ws_win *focus_prev; /* may be NULL */
bar_toggle(struct swm_region *r, union arg *args)
{
struct swm_region *tmpr;
- int i, j, sc = ScreenCount(display);
+ int i, sc = ScreenCount(display);
DNPRINTF(SWM_D_MISC, "bar_toggle\n");
XMapRaised(display, tmpr->bar_window);
bar_enabled = !bar_enabled;
- for (i = 0; i < sc; i++)
- for (j = 0; j < SWM_WS_MAX; j++)
- screens[i].ws[j].restack = 1;
stack();
/* must be after stack */
bar_refresh();
}
-Bool
-set_win_notify_cb(Display *d, XEvent *e, char *arg)
-{
- struct ws_win *win = (struct ws_win *)arg;
-
- if (win && win->id == e->xany.window && e->xany.type == PropertyNotify)
- return (True);
- return (False);
-}
-
void
set_win_state(struct ws_win *win, long state)
{
long data[] = {state, None};
- XEvent ev;
XWindowAttributes wa;
DNPRINTF(SWM_D_EVENT, "set_win_state: window: %lu\n", win->id);
XChangeProperty(display, win->id, astate, astate, 32, PropModeReplace,
(unsigned char *)data, 2);
-
- /* wait for completion of XChangeProperty */
- while (XCheckIfEvent(display, &ev, set_win_notify_cb, (char *)win))
- ;
}
long
{
XClientMessageEvent cm;
+ if (win == NULL)
+ return;
+
bzero(&cm, sizeof cm);
cm.type = ClientMessage;
cm.window = win->id;
}
void
+configreq_win(struct ws_win *win)
+{
+ XConfigureRequestEvent cr;
+
+ if (win == NULL)
+ return;
+
+ bzero(&cr, sizeof cr);
+ cr.type = ConfigureRequest;
+ cr.display = display;
+ cr.parent = win->id;
+ cr.window = win->id;
+ cr.x = win->g.x;
+ cr.y = win->g.y;
+ cr.width = win->g.w;
+ cr.height = win->g.h;
+ cr.border_width = 1;
+
+ XSendEvent(display, win->id, False, StructureNotifyMask, (XEvent *)&cr);
+}
+
+void
config_win(struct ws_win *win)
{
XConfigureEvent ce;
DNPRINTF(SWM_D_MISC, "config_win: win %lu x %d y %d w %d h %d\n",
win->id, win->g.x, win->g.y, win->g.w, win->g.h);
+
+ if (win == NULL)
+ return;
+
ce.type = ConfigureNotify;
ce.display = display;
ce.event = win->id;
{
struct ws_win *win;
int count = 0;
- int state;
-
- /*
- * Under stress conditions windows sometimes do not get removed from
- * the managed list quickly enough. Use a very large hammer to get rid
- * of them. A smaller hammer would be nice.
- */
- TAILQ_FOREACH(win, &ws->winlist, entry) {
- state = getstate(win->id);
- if (state == -1) {
- DNPRINTF(SWM_D_MISC, "count_win:removing: %lu\n",
- win->id);
- unmanage_window(win);
- }
- }
TAILQ_FOREACH(win, &ws->winlist, entry) {
if (count_transient == 0 && win->floating)
running = 0;
}
-Bool
-unmap_window_cb(Display *d, XEvent *e, char *arg)
-{
- struct ws_win *win = (struct ws_win *)arg;
-
- if (win && win->id == e->xany.window && e->xany.type == UnmapNotify)
- return (True);
- return (False);
-}
-
void
unmap_window(struct ws_win *win)
{
- XEvent ev;
XWindowAttributes wa;
if (win == NULL)
set_win_state(win, IconicState);
XUnmapWindow(display, win->id);
-
- /* make sure we wait for XUnmapWindow completion */
- while (XCheckIfEvent(display, &ev, unmap_window_cb, (char *)win))
- ;
}
void
{
XKeyEvent event;
+ if (win == NULL)
+ return;
+
event.display = display; /* Ignored, but what the hell */
event.window = win->id;
event.root = win->s->root;
{
if (win == NULL)
return;
-
+ if (win->ws == NULL)
+ return;
if (win->ws->r == NULL)
return;
if (win == NULL)
return;
+ if (win->ws == NULL)
+ return;
/* use big hammer to make sure it works under all use cases */
unfocus_all();
struct ws_win *win, *winfocus = NULL, *parent = NULL;
struct workspace *new_ws, *old_ws;
+ if (!(r && r->s)) {
+ fprintf(stderr, "r && r->s failed\n");
+ abort();
+ }
+ if (wsid < 0 || wsid > SWM_WS_MAX) {
+ fprintf(stderr, "illegal wsid\n");
+ abort();
+ }
+
this_r = r;
old_ws = this_r->ws;
new_ws = &this_r->s->ws[wsid];
"%d -> %d\n", r->s->idx, WIDTH(r), HEIGHT(r), X(r), Y(r),
old_ws->idx, wsid);
+ if (new_ws == NULL || old_ws == NULL) {
+ fprintf(stderr, "new_ws = %p old_ws = %p\n", new_ws, old_ws);
+ abort();
+ }
+
if (new_ws == old_ws)
return;
if (old_ws->r != NULL)
old_ws->old_r = old_ws->r;
old_ws->r = NULL;
- old_ws->restack = 1;
/*
* Map new windows first if they were here before
else
return;
}
+ if (target == NULL || source == NULL)
+ return;
source->ws->focus_prev = target;
TAILQ_REMOVE(wl, target, entry);
TAILQ_INSERT_BEFORE(source, target, entry);
"(screen %d, region %d)\n", r->ws->idx, i, j++);
/* start with screen geometry, adjust for bar */
+ if (r == NULL) {
+ fprintf(stderr, "illegal r\n");
+ abort();
+ }
g = r->g;
g.w -= 2;
g.h -= 2;
g.y += bar_height;
g.h -= bar_height;
}
-
- r->ws->restack = 0;
+ if (r->ws == NULL) {
+ fprintf(stderr, "illegal ws\n");
+ abort();
+ }
+ if (r->ws->cur_layout == NULL) {
+ fprintf(stderr, "illegal cur_layout\n");
+ abort();
+ }
+ if (r->ws->cur_layout->l_stack == NULL) {
+ fprintf(stderr, "illegal l_stack\n");
+ abort();
+ }
r->ws->cur_layout->l_stack(r->ws, &g);
}
}
int w_inc = 1, h_inc, w_base = 1, h_base;
int hrh, extra = 0, h_slice, last_h = 0;
int split, colno, winno, mwin, msize, mscale;
- int remain, missing, v_slice;
+ int remain, missing, v_slice, reconfigure;
unsigned int mask;
DNPRINTF(SWM_D_STACK, "stack_master: workspace: %d\n rot=%s flip=%s",
bzero(&wc, sizeof wc);
wc.border_width = 1;
+ reconfigure = 0;
if (rot) {
- win->g.x = wc.x = win_g.y;
- win->g.y = wc.y = win_g.x;
- win->g.w = wc.width = win_g.h;
- win->g.h = wc.height = win_g.w;
+ if (win->g.x != win_g.y || win->g.y != win_g.x ||
+ win->g.w != win_g.h || win->g.h != win_g.w) {
+ reconfigure = 1;
+ win->g.x = wc.x = win_g.y;
+ win->g.y = wc.y = win_g.x;
+ win->g.w = wc.width = win_g.h;
+ win->g.h = wc.height = win_g.w;
+ }
} else {
- win->g.x = wc.x = win_g.x;
- win->g.y = wc.y = win_g.y;
- win->g.w = wc.width = win_g.w;
- win->g.h = wc.height = win_g.h;
+ if (win->g.x != win_g.x || win->g.y != win_g.y ||
+ win->g.w != win_g.w || win->g.h != win_g.h) {
+ reconfigure = 1;
+ win->g.x = wc.x = win_g.x;
+ win->g.y = wc.y = win_g.y;
+ win->g.w = wc.width = win_g.w;
+ win->g.h = wc.height = win_g.h;
+ }
+ }
+ if (reconfigure) {
+ adjust_font(win);
+ mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
+ XConfigureWindow(display, win->id, mask, &wc);
+ configreq_win(win);
}
- adjust_font(win);
- mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
- XConfigureWindow(display, win->id, mask, &wc);
XMapRaised(display, win->id);
last_h = win_g.h;
return;
TAILQ_FOREACH(win, &ws->winlist, entry) {
- if (win->transient != 0) {
+ if (win->transient) {
wintrans = win;
- } else {
+ continue;
+ }
+
+ /* only reconfigure if necessary */
+ if (win->g.x != gg.x || win->g.y != gg.y || win->g.w != gg.w ||
+ win->g.h != gg.h) {
bzero(&wc, sizeof wc);
wc.border_width = 1;
win->g.x = wc.x = gg.x;
win->g.h = wc.height = gg.h;
mask = CWX | CWY | CWWidth | CWHeight | CWBorderWidth;
XConfigureWindow(display, win->id, mask, &wc);
-
- /* unmap only if we don't have multi screen */
- if (win != ws->focus)
- if (!(ScreenCount(display) > 1 || outputs > 1))
- unmap_window(win);
+ configreq_win(win);
}
+ /* unmap only if we don't have multi screen */
+ if (win != ws->focus)
+ if (!(ScreenCount(display) > 1 || outputs > 1))
+ unmap_window(win);
}
/* put the last transient on top */
if (count_win(nws, 1) == 1)
nws->focus = win;
- ws->restack = 1;
- nws->restack = 1;
stack();
if (winfocus)
}
}
- if (win->java && win->transient) {
- }
/* alter window position if quirky */
if (win->quirks & SWM_Q_ANYWHERE) {
win->manual = 1; /* don't center the quirky windows */
wc.border_width = 1;
mask = CWBorderWidth;
XConfigureWindow(display, win->id, mask, &wc);
+ configreq_win(win);
}
XSelectInput(display, id, EnterWindowMask | FocusChangeMask |
DNPRINTF(SWM_D_MISC, "unmanage_window: %lu\n", win->id);
+ /* needed for restart wm */
+ set_win_state(win, WithdrawnState);
+
if (win->transient) {
parent = find_window(win->transient);
if (parent)
}
}
+Bool
+destroy_notify_cb(Display *d, XEvent *e, char *arg)
+{
+ struct ws_win *win = (struct ws_win *)arg;
+ if (win && win->id == e->xany.window && e->xany.type == DestroyNotify)
+ return (True);
+ return (False);
+}
+
void
expose(XEvent *e)
{
ev->value_mask |= CWY | CWHeight;
}
}
+ XMoveResizeWindow(display, win->id,
+ win->g.x, win->g.y, win->g.w, win->g.h);
if ((ev->value_mask & (CWX | CWY)) &&
!(ev->value_mask & (CWWidth | CWHeight)))
config_win(win);
- XMoveResizeWindow(display, win->id,
- win->g.x, win->g.y, win->g.w, win->g.h);
} else
config_win(win);
}
void
destroynotify(XEvent *e)
{
- struct ws_win *win, *winfocus = NULL;
+ struct ws_win *win, *w, *winfocus = NULL;
struct workspace *ws;
struct ws_win_list *wl;
XDestroyWindowEvent *ev = &e->xdestroywindow;
+ XEvent de;
DNPRINTF(SWM_D_EVENT, "destroynotify: window %lu\n", ev->window);
}
unmanage_window(win);
+ /*
+ * Under stress conditions windows sometimes do not get removed
+ * from the managed list. Use a very large hammer to get rid
+ * of them. A smaller hammer would be nice.
+ */
+ TAILQ_FOREACH(w, &ws->winlist, entry) {
+ if (win == w)
+ continue; /* can't happen but oh well */
+
+ if (getstate(w->id) != -1)
+ continue;
+
+ /* see if we have a destroy event */
+ if (XCheckIfEvent(display, &de, destroy_notify_cb,
+ (char *)w) == False)
+ unmanage_window(w); /* no event, help it */
+ else
+ XPutBackEvent(display, &de); /* oops */
+ }
+
ignore_enter = 1;
stack();
if (winfocus)
if (win == NULL)
return;
+ /* igonore transients and floaters, like mplayer */
+ if (win->transient || win->floating)
+ return;
+
/* java can not deal with this heuristic */
if (win->java)
return;
for (j = 0; j < SWM_WS_MAX; j++) {
ws = &screens[i].ws[j];
ws->idx = j;
- ws->restack = 1;
ws->focus = NULL;
ws->r = NULL;
ws->old_r = NULL;
/* attach windows to a region */
/* normal windows */
for (j = 0; j < no; j++) {
- XGetWindowAttributes(display, wins[j], &wa);
if (!XGetWindowAttributes(display, wins[j], &wa) ||
wa.override_redirect ||
XGetTransientForHint(display, wins[j], &d1))
}
/* transient windows */
for (j = 0; j < no; j++) {
- if (!XGetWindowAttributes(display, wins[j], &wa))
+ if (!XGetWindowAttributes(display, wins[j], &wa) ||
+ wa.override_redirect)
continue;
state = getstate(wins[j]);
struct passwd *pwd;
struct swm_region *r, *rr;
struct ws_win *winfocus = NULL;
+ struct timeval tv;
char conf[PATH_MAX], *cfile = NULL;
struct stat sb;
XEvent e;
FD_ZERO(&rd);
FD_SET(xfd, &rd);
- if (select(xfd + 1, &rd, NULL, NULL, NULL) == -1)
+ tv.tv_sec = 1;
+ tv.tv_usec = 0;
+ if (select(xfd + 1, &rd, NULL, NULL, &tv) == -1)
if (errno != EINTR)
DNPRINTF(SWM_D_MISC, "select failed");
if (running == 0)