+unmanage_window(struct ws_win *win)
+{
+ struct ws_win *parent;
+
+ if (win == NULL)
+ return;
+
+ DNPRINTF(SWM_D_MISC, "unmanage_window: %lu\n", win->id);
+
+ if (win->transient) {
+ parent = find_window(win->transient);
+ if (parent)
+ parent->child_trans = NULL;
+ }
+
+ /* work around for mplayer going full screen */
+ if (!win->floating)
+ focus_prev(win);
+
+ TAILQ_REMOVE(&win->ws->winlist, win, entry);
+ TAILQ_INSERT_TAIL(&win->ws->unmanagedlist, win, entry);
+
+ kill_refs(win);
+}
+
+void
+focus_magic(struct ws_win *win, int do_trans)
+{
+ DNPRINTF(SWM_D_FOCUS, "focus_magic: %lu %d\n", WINID(win), do_trans);
+
+ if (win == NULL)
+ return;
+
+ if (do_trans == SWM_F_TRANSIENT && win->child_trans) {
+ /* win = parent & has a transient so focus on that */
+ if (win->java) {
+ focus_win(win->child_trans);
+ if (win->child_trans->take_focus)
+ client_msg(win, takefocus);
+ } else {
+ focus_win(win->child_trans);
+ if (win->child_trans->take_focus)
+ client_msg(win->child_trans, takefocus);
+ }
+ } else {
+ /* regular focus */
+ focus_win(win);
+ if (win->take_focus)
+ client_msg(win, takefocus);
+ }
+}
+
+void
+expose(XEvent *e)
+{
+ DNPRINTF(SWM_D_EVENT, "expose: window: %lu\n", e->xexpose.window);
+}
+
+void
+keypress(XEvent *e)
+{
+ unsigned int i;
+ KeySym keysym;
+ XKeyEvent *ev = &e->xkey;
+
+ DNPRINTF(SWM_D_EVENT, "keypress: window: %lu\n", ev->window);
+
+ keysym = XKeycodeToKeysym(display, (KeyCode)ev->keycode, 0);
+ for (i = 0; i < keys_length; i++)
+ if (keysym == keys[i].keysym
+ && CLEANMASK(keys[i].mod) == CLEANMASK(ev->state)
+ && keyfuncs[keys[i].funcid].func) {
+ if (keys[i].funcid == kf_spawn_custom)
+ spawn_custom(
+ root_to_region(ev->root),
+ &(keyfuncs[keys[i].funcid].args),
+ keys[i].spawn_name
+ );
+ else
+ keyfuncs[keys[i].funcid].func(
+ root_to_region(ev->root),
+ &(keyfuncs[keys[i].funcid].args)
+ );
+ }
+}
+
+void
+buttonpress(XEvent *e)
+{
+ struct ws_win *win;
+ int i, action;
+ XButtonPressedEvent *ev = &e->xbutton;
+
+ DNPRINTF(SWM_D_EVENT, "buttonpress: window: %lu\n", ev->window);
+
+ action = root_click;
+ if ((win = find_window(ev->window)) == NULL)
+ return;
+
+ focus_magic(win, SWM_F_TRANSIENT);
+ action = client_click;
+
+ for (i = 0; i < LENGTH(buttons); i++)
+ if (action == buttons[i].action && buttons[i].func &&
+ buttons[i].button == ev->button &&
+ CLEANMASK(buttons[i].mask) == CLEANMASK(ev->state))
+ buttons[i].func(win, &buttons[i].args);
+}
+
+void