[hackers] [wmii] Unmap and set Iconic state of iconic or out-of-view windows

From: Kris Maglione <jg_AT_suckless.org>
Date: Sat Feb 10 04:08:46 2007

changeset: 1822:6171d971355e
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Feb 09 22:06:07 2007 -0500
summary: Unmap and set Iconic state of iconic or out-of-view windows

diff -r 12b661434242 -r 6171d971355e client.c
--- a/client.c Fri Feb 09 21:29:21 2007 -0500
+++ b/client.c Fri Feb 09 22:06:07 2007 -0500
@@ -155,14 +155,6 @@ update_client_grab(Client *c) {
 }
 
 void
-set_client_state(Client * c, int state)
-{
- long data[] = { state, None };
- XChangeProperty(blz.dpy, c->win, wm_atom[WMState], wm_atom[WMState], 32,
- PropModeReplace, (unsigned char *) data, 2);
-}
-
-void
 focus_client(Client *c, Bool restack) {
         Client *old_in_area;
         Client *old;
@@ -213,19 +205,31 @@ focus_client(Client *c, Bool restack) {
 }
 
 void
+set_client_state(Client * c, int state)
+{
+ long data[] = { state, None };
+ XChangeProperty(blz.dpy, c->win, wm_atom[WMState], wm_atom[WMState], 32,
+ PropModeReplace, (unsigned char *) data, 2);
+}
+
+void
 map_client(Client *c) {
         XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
         XMapWindow(blz.dpy, c->win);
         XSelectInput(blz.dpy, c->win, CLIENT_MASK);
         set_client_state(c, NormalState);
-}
-
-void
-unmap_client(Client *c) {
+ c->mapped = 1;
+}
+
+void
+unmap_client(Client *c, int state) {
         XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
         XUnmapWindow(blz.dpy, c->win);
         XSelectInput(blz.dpy, c->win, CLIENT_MASK);
- set_client_state(c, WithdrawnState);
+ set_client_state(c, state);
+ c->mapped = 0;
+ /* Always set this, since we don't care anymore once it's been destroyed */
+ c->unmapped++;
 }
 
 void
@@ -399,14 +403,15 @@ destroy_client(Client *c) {
                 c->rect.x = c->sel->rect.x;
                 c->rect.y = c->sel->rect.y;
         }
+ for(tc=&client; *tc && *tc != c; tc=&(*tc)->next)
+ if(*tc == c) break;
+ assert(*tc == c);
+ *tc = c->next;
         update_client_views(c, &dummy);
- unmap_client(c);
+ unmap_client(c, WithdrawnState);
         reparent_client(c, blz.root, c->rect.x, c->rect.y);
         XFreeGC(blz.dpy, c->gc);
         XDestroyWindow(blz.dpy, c->framewin);
- for(tc=&client; *tc && *tc != c; tc=&(*tc)->next);
- assert(*tc == c);
- *tc = c->next;
         update_views();
         free(c);
         XSync(blz.dpy, False);
@@ -502,19 +507,22 @@ resize_client(Client *c, XRectangle *r)
         if(f->area->view == screen->sel)
                 XMoveResizeWindow(blz.dpy, c->framewin, f->rect.x,
                                 f->rect.y, f->rect.width, f->rect.height);
- else
- XMoveResizeWindow(blz.dpy, c->framewin, 2 * screen->rect.width + f->rect.x,
- f->rect.y, f->rect.width, f->rect.height);
+ else {
+ unmap_client(c, IconicState);
+ XUnmapWindow(blz.dpy, c->framewin);
+ }
 
         c->rect.x = def.border;
         c->rect.y = labelh(&def.font);
         if((f->area->sel == f) || (f->area->mode != Colstack)) {
+ if(!c->mapped)
+ map_client(c);
                 c->rect.width = f->rect.width - 2 * def.border;
                 c->rect.height = f->rect.height - def.border - labelh(&def.font);
- }
-
- XMoveResizeWindow(blz.dpy, c->win, c->rect.x, c->rect.y,
+ XMoveResizeWindow(blz.dpy, c->win, c->rect.x, c->rect.y,
                                         c->rect.width, c->rect.height);
+ }else
+ unmap_client(c, IconicState);
         configure_client(c);
 }
 
diff -r 12b661434242 -r 6171d971355e event.c
--- a/event.c Fri Feb 09 21:29:21 2007 -0500
+++ b/event.c Fri Feb 09 22:06:07 2007 -0500
@@ -262,7 +262,8 @@ unmapnotify(XEvent *e) {
         XUnmapEvent *ev = &e->xunmap;
 
         if((c = client_of_win(ev->window)))
- destroy_client(c);
+ if(!c->unmapped--)
+ destroy_client(c);
 }
 
 void (*handler[LASTEvent]) (XEvent *) = {
diff -r 12b661434242 -r 6171d971355e view.c
--- a/view.c Fri Feb 09 21:29:21 2007 -0500
+++ b/view.c Fri Feb 09 22:06:07 2007 -0500
@@ -116,11 +116,14 @@ focus_view(WMScreen *s, View *v) {
         for(c=client; c; c=c->next)
                 if((f = c->sel)) {
                         if(f->view == v) {
+ map_client(c);
+ XMapWindow(blz.dpy, c->framewin);
                                 resize_client(c, &f->rect);
                                 update_client_grab(c);
- }else
- XMoveWindow(blz.dpy, c->framewin, 2 * s->rect.width + f->rect.x,
- f->rect.y);
+ } else {
+ XUnmapWindow(blz.dpy, c->framewin);
+ unmap_client(c, IconicState);
+ }
                 }
         if((c = sel_client()))
                 focus_client(c, True);
diff -r 12b661434242 -r 6171d971355e wmii.h
--- a/wmii.h Fri Feb 09 21:29:21 2007 -0500
+++ b/wmii.h Fri Feb 09 22:06:07 2007 -0500
@@ -144,6 +144,8 @@ struct Client {
         Bool floating;
         Bool fixedsize;
         Bool urgent;
+ Bool mapped;
+ int unmapped;
         Window win;
         Window trans;
         Window framewin;
@@ -270,7 +272,7 @@ extern void prop_client(Client *c, XProp
 extern void prop_client(Client *c, XPropertyEvent *e);
 extern void kill_client(Client *c);
 extern void gravitate_client(Client *c, Bool invert);
-extern void unmap_client(Client *c);
+extern void unmap_client(Client *c, int state);
 extern void map_client(Client *c);
 extern void reparent_client(Client *c, Window w, int x, int y);
 extern void manage_client(Client *c);
Received on Sat Feb 10 2007 - 04:08:46 UTC

This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:55:07 UTC