[hackers] [wmii] Restack view after mapping a client (&c)

From: Kris Maglione <jg_AT_suckless.org>
Date: Fri Feb 09 07:10:43 2007

changeset: 1803:1bd3b0886857
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Feb 09 01:06:15 2007 -0500
summary: Restack view after mapping a client (&c)

diff -r babeee0ac1eb -r 1bd3b0886857 client.c
--- a/client.c Fri Feb 09 01:01:54 2007 -0500
+++ b/client.c Fri Feb 09 01:06:15 2007 -0500
@@ -12,62 +12,6 @@ static char *Ebadcmd = "bad command",
 
 #define CLIENT_MASK (StructureNotifyMask | PropertyChangeMask | EnterWindowMask)
 #define ButtonMask (ButtonPressMask | ButtonReleaseMask)
-
-Client *
-sel_client() {
- return screen->sel && screen->sel->sel->sel ? screen->sel->sel->sel->client : nil;
-}
-
-Client *
-client_of_win(Window w) {
- Client *c;
- for(c=client; c && c->win != w; c=c->next);
- return c;
-}
-
-Frame *
-frame_of_win(Window w) {
- Client *c;
- for(c=client; c && c->framewin != w; c=c->next);
- return c ? c->frame : nil;
-}
-
-static void
-update_client_name(Client *c) {
- XTextProperty name;
- XClassHint ch;
- int n;
- char **list = nil;
-
- name.nitems = 0;
- c->name[0] = 0;
- XGetTextProperty(blz.dpy, c->win, &name, net_atom[NetWMName]);
- if(!name.nitems)
- XGetWMName(blz.dpy, c->win, &name);
- if(!name.nitems)
- return;
- if(name.encoding == XA_STRING)
- strncpy(c->name, (char *)name.value, sizeof(c->name));
- else {
- if(XmbTextPropertyToTextList(blz.dpy, &name, &list, &n) >= Success
- && n > 0 && *list)
- {
- strncpy(c->name, *list, sizeof(c->name));
- XFreeStringList(list);
- }
- }
- XFree(name.value);
- if(XGetClassHint(blz.dpy, c->win, &ch)) {
- snprintf(c->props, sizeof(c->props), "%s:%s:%s",
- ch.res_class ? ch.res_class : "",
- ch.res_name ? ch.res_name : "",
- c->name);
- if(ch.res_class)
- XFree(ch.res_class);
- if(ch.res_name)
- XFree(ch.res_name);
- }
-}
 
 Client *
 create_client(Window w, XWindowAttributes *wa) {
@@ -117,235 +61,6 @@ create_client(Window w, XWindowAttribute
 }
 
 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;
- Frame *f;
- View *v;
- unsigned int a_i;
- Area *a, *old_a;
-
- if(!sel_screen)
- return;
- f = c->sel;
- v = f->view;
- old = sel_client();
- old_in_area = sel_client_of_area(f->area);
- old_a = v->sel;
-
- if(old_a->floating != f->area->floating)
- v->revert = old_a;
- v->sel = f->area;
- f->area->sel = f;
- c->floating = f->area->floating;
- if(restack)
- restack_view(v);
- if(!c->floating && f->area->mode == Colstack)
- arrange_column(f->area, False);
- XSetInputFocus(blz.dpy, c->win, RevertToPointerRoot, CurrentTime);
- if(old && old != old_in_area && old != c) {
- update_frame_widget_colors(old->sel);
- draw_frame(old->sel);
- }
- if(old_in_area && old_in_area != c) {
- update_frame_widget_colors(old_in_area->sel);
- draw_frame(old_in_area->sel);
- }
- update_frame_widget_colors(c->sel);
- draw_frame(c->sel);
- XSync(blz.dpy, False);
- if(old_a != v->sel) {
- for(a = v->area, a_i = 0; a; a = a->next, a_i++)
- if(a == v->sel) break;
- if(a_i)
- write_event("ColumnFocus %d\n", a_i);
- else
- write_event("FocusFloating\n");
- }
- if(c != old)
- write_event("ClientFocus 0x%x\n", c->win);
-}
-
-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) {
- 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);
-}
-
-void
-reparent_client(Client *c, Window w, int x, int y) {
- XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
- XReparentWindow(blz.dpy, c->win, w, x, y);
- XSelectInput(blz.dpy, c->win, CLIENT_MASK);
-}
-
-void
-configure_client(Client *c) {
- XConfigureEvent e;
- Frame *f = c->sel;
-
- e.type = ConfigureNotify;
- e.event = c->win;
- e.window = c->win;
- e.x = c->rect.x;
- e.y = c->rect.y;
- if(f) {
- e.x += f->rect.x;
- e.y += f->rect.y;
- }
- e.width = c->rect.width;
- e.height = c->rect.height;
- e.border_width = c->border;
- e.above = None;
- e.override_redirect = False;
- XSendEvent(blz.dpy, c->win, False,
- StructureNotifyMask, (XEvent *) & e);
- XSync(blz.dpy, False);
-}
-
-static void
-send_client_message(Window w, Atom a, long value) {
- XEvent e;
-
- e.type = ClientMessage;
- e.xclient.window = w;
- e.xclient.message_type = a;
- e.xclient.format = 32;
- e.xclient.data.l[0] = value;
- e.xclient.data.l[1] = CurrentTime;
- XSendEvent(blz.dpy, w, False, NoEventMask, &e);
- XSync(blz.dpy, False);
-}
-
-void
-kill_client(Client * c) {
- if(c->proto & WM_PROTOCOL_DELWIN)
- send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
- else
- XKillClient(blz.dpy, c->win);
-}
-
-void
-prop_client(Client *c, XPropertyEvent *e) {
- XWMHints *wmh;
- long msize;
-
- if(e->atom == wm_atom[WMProtocols]) {
- c->proto = win_proto(c->win);
- return;
- }
- switch (e->atom) {
- case XA_WM_TRANSIENT_FOR:
- XGetTransientForHint(blz.dpy, c->win, &c->trans);
- break;
- case XA_WM_NORMAL_HINTS:
- if(!XGetWMNormalHints(blz.dpy, c->win, &c->size, &msize) || !c->size.flags) {
- c->size.flags = PSize;
- }
- if(c->size.flags & PMinSize && c->size.flags & PMaxSize
- && c->size.min_width == c->size.max_width
- && c->size.min_height == c->size.max_height)
- c->fixedsize = True;
- else
- c->fixedsize = False;
- break;
- case XA_WM_HINTS:
- wmh = XGetWMHints(blz.dpy, c->win);
- if(wmh->flags&XUrgencyHint && !client->urgent) {
- write_event("Urgent 0x%x\n", client->win);;
- client->urgent = True;
- }
- else if(!(wmh->flags&XUrgencyHint) && client->urgent) {
- write_event("NotUrgent 0x%x\n", client->win);;
- client->urgent = False;
- }
- break;
- }
- if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) {
- update_client_name(c);
- if(c->frame)
- draw_frame(c->sel);
- }
-}
-
-void
-gravitate_client(Client *c, Bool invert) {
- int dx = 0, dy = 0;
- int gravity = NorthWestGravity;
-
- if(c->size.flags & PWinGravity) {
- gravity = c->size.win_gravity;
- }
- /* y */
- switch (gravity) {
- case StaticGravity:
- case NorthWestGravity:
- case NorthGravity:
- case NorthEastGravity:
- dy = labelh(&def.font);
- break;
- case EastGravity:
- case CenterGravity:
- case WestGravity:
- dy = -(c->rect.height / 2) + labelh(&def.font);
- break;
- case SouthEastGravity:
- case SouthGravity:
- case SouthWestGravity:
- dy = -c->rect.height;
- break;
- default:
- break;
- }
- /* x */
- switch (gravity) {
- case StaticGravity:
- case NorthWestGravity:
- case WestGravity:
- case SouthWestGravity:
- dx = def.border;
- break;
- case NorthGravity:
- case CenterGravity:
- case SouthGravity:
- dx = -(c->rect.width / 2) + def.border;
- break;
- case NorthEastGravity:
- case EastGravity:
- case SouthEastGravity:
- dx = -(c->rect.width + def.border);
- break;
- default:
- break;
- }
-
- if(invert) {
- dx = -dx;
- dy = -dy;
- }
- c->rect.x += dx;
- c->rect.y += dy;
-}
-
-void
 manage_client(Client *c) {
         XTextProperty tags;
         Client *trans;
@@ -369,6 +84,291 @@ manage_client(Client *c) {
         if(c->sel->area->view == screen->sel)
                 focus_client(c, False);
         flush_masked_events(EnterWindowMask);
+}
+
+Client *
+sel_client() {
+ return screen->sel && screen->sel->sel->sel ? screen->sel->sel->sel->client : nil;
+}
+
+Client *
+client_of_win(Window w) {
+ Client *c;
+ for(c=client; c && c->win != w; c=c->next);
+ return c;
+}
+
+Frame *
+frame_of_win(Window w) {
+ Client *c;
+ for(c=client; c && c->framewin != w; c=c->next);
+ return c ? c->frame : nil;
+}
+
+static void
+update_client_name(Client *c) {
+ XTextProperty name;
+ XClassHint ch;
+ int n;
+ char **list = nil;
+
+ name.nitems = 0;
+ c->name[0] = 0;
+ XGetTextProperty(blz.dpy, c->win, &name, net_atom[NetWMName]);
+ if(!name.nitems)
+ XGetWMName(blz.dpy, c->win, &name);
+ if(!name.nitems)
+ return;
+ if(name.encoding == XA_STRING)
+ strncpy(c->name, (char *)name.value, sizeof(c->name));
+ else {
+ if(XmbTextPropertyToTextList(blz.dpy, &name, &list, &n) >= Success
+ && n > 0 && *list)
+ {
+ strncpy(c->name, *list, sizeof(c->name));
+ XFreeStringList(list);
+ }
+ }
+ XFree(name.value);
+ if(XGetClassHint(blz.dpy, c->win, &ch)) {
+ snprintf(c->props, sizeof(c->props), "%s:%s:%s",
+ ch.res_class ? ch.res_class : "",
+ ch.res_name ? ch.res_name : "",
+ c->name);
+ if(ch.res_class)
+ XFree(ch.res_class);
+ if(ch.res_name)
+ XFree(ch.res_name);
+ }
+}
+
+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;
+ Frame *f;
+ View *v;
+ unsigned int a_i;
+ Area *a, *old_a;
+
+ if(!sel_screen)
+ return;
+ f = c->sel;
+ v = f->view;
+ old = sel_client();
+ old_in_area = sel_client_of_area(f->area);
+ old_a = v->sel;
+
+ if(old_a->floating != f->area->floating)
+ v->revert = old_a;
+ v->sel = f->area;
+ f->area->sel = f;
+ c->floating = f->area->floating;
+ if(restack)
+ restack_view(v);
+ if(!c->floating && f->area->mode == Colstack)
+ arrange_column(f->area, False);
+ XSetInputFocus(blz.dpy, c->win, RevertToPointerRoot, CurrentTime);
+ if(old && old != old_in_area && old != c) {
+ update_frame_widget_colors(old->sel);
+ draw_frame(old->sel);
+ }
+ if(old_in_area && old_in_area != c) {
+ update_frame_widget_colors(old_in_area->sel);
+ draw_frame(old_in_area->sel);
+ }
+ update_frame_widget_colors(c->sel);
+ draw_frame(c->sel);
+ XSync(blz.dpy, False);
+ if(old_a != v->sel) {
+ for(a = v->area, a_i = 0; a; a = a->next, a_i++)
+ if(a == v->sel) break;
+ if(a_i)
+ write_event("ColumnFocus %d\n", a_i);
+ else
+ write_event("FocusFloating\n");
+ }
+ if(c != old)
+ write_event("ClientFocus 0x%x\n", c->win);
+}
+
+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) {
+ 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);
+}
+
+void
+reparent_client(Client *c, Window w, int x, int y) {
+ XSelectInput(blz.dpy, c->win, CLIENT_MASK & ~StructureNotifyMask);
+ XReparentWindow(blz.dpy, c->win, w, x, y);
+ XSelectInput(blz.dpy, c->win, CLIENT_MASK);
+}
+
+void
+configure_client(Client *c) {
+ XConfigureEvent e;
+ Frame *f = c->sel;
+
+ e.type = ConfigureNotify;
+ e.event = c->win;
+ e.window = c->win;
+ e.x = c->rect.x;
+ e.y = c->rect.y;
+ if(f) {
+ e.x += f->rect.x;
+ e.y += f->rect.y;
+ }
+ e.width = c->rect.width;
+ e.height = c->rect.height;
+ e.border_width = c->border;
+ e.above = None;
+ e.override_redirect = False;
+ XSendEvent(blz.dpy, c->win, False,
+ StructureNotifyMask, (XEvent *) & e);
+ XSync(blz.dpy, False);
+}
+
+static void
+send_client_message(Window w, Atom a, long value) {
+ XEvent e;
+
+ e.type = ClientMessage;
+ e.xclient.window = w;
+ e.xclient.message_type = a;
+ e.xclient.format = 32;
+ e.xclient.data.l[0] = value;
+ e.xclient.data.l[1] = CurrentTime;
+ XSendEvent(blz.dpy, w, False, NoEventMask, &e);
+ XSync(blz.dpy, False);
+}
+
+void
+kill_client(Client * c) {
+ if(c->proto & WM_PROTOCOL_DELWIN)
+ send_client_message(c->win, wm_atom[WMProtocols], wm_atom[WMDelete]);
+ else
+ XKillClient(blz.dpy, c->win);
+}
+
+void
+prop_client(Client *c, XPropertyEvent *e) {
+ XWMHints *wmh;
+ long msize;
+
+ if(e->atom == wm_atom[WMProtocols]) {
+ c->proto = win_proto(c->win);
+ return;
+ }
+ switch (e->atom) {
+ case XA_WM_TRANSIENT_FOR:
+ XGetTransientForHint(blz.dpy, c->win, &c->trans);
+ break;
+ case XA_WM_NORMAL_HINTS:
+ if(!XGetWMNormalHints(blz.dpy, c->win, &c->size, &msize) || !c->size.flags) {
+ c->size.flags = PSize;
+ }
+ if(c->size.flags & PMinSize && c->size.flags & PMaxSize
+ && c->size.min_width == c->size.max_width
+ && c->size.min_height == c->size.max_height)
+ c->fixedsize = True;
+ else
+ c->fixedsize = False;
+ break;
+ case XA_WM_HINTS:
+ wmh = XGetWMHints(blz.dpy, c->win);
+ if(wmh->flags&XUrgencyHint && !client->urgent) {
+ write_event("Urgent 0x%x\n", client->win);;
+ client->urgent = True;
+ }
+ else if(!(wmh->flags&XUrgencyHint) && client->urgent) {
+ write_event("NotUrgent 0x%x\n", client->win);;
+ client->urgent = False;
+ }
+ break;
+ }
+ if(e->atom == XA_WM_NAME || e->atom == net_atom[NetWMName]) {
+ update_client_name(c);
+ if(c->frame)
+ draw_frame(c->sel);
+ }
+}
+
+void
+gravitate_client(Client *c, Bool invert) {
+ int dx = 0, dy = 0;
+ int gravity = NorthWestGravity;
+
+ if(c->size.flags & PWinGravity) {
+ gravity = c->size.win_gravity;
+ }
+ /* y */
+ switch (gravity) {
+ case StaticGravity:
+ case NorthWestGravity:
+ case NorthGravity:
+ case NorthEastGravity:
+ dy = labelh(&def.font);
+ break;
+ case EastGravity:
+ case CenterGravity:
+ case WestGravity:
+ dy = -(c->rect.height / 2) + labelh(&def.font);
+ break;
+ case SouthEastGravity:
+ case SouthGravity:
+ case SouthWestGravity:
+ dy = -c->rect.height;
+ break;
+ default:
+ break;
+ }
+ /* x */
+ switch (gravity) {
+ case StaticGravity:
+ case NorthWestGravity:
+ case WestGravity:
+ case SouthWestGravity:
+ dx = def.border;
+ break;
+ case NorthGravity:
+ case CenterGravity:
+ case SouthGravity:
+ dx = -(c->rect.width / 2) + def.border;
+ break;
+ case NorthEastGravity:
+ case EastGravity:
+ case SouthEastGravity:
+ dx = -(c->rect.width + def.border);
+ break;
+ default:
+ break;
+ }
+
+ if(invert) {
+ dx = -dx;
+ dy = -dy;
+ }
+ c->rect.x += dx;
+ c->rect.y += dy;
 }
 
 static int
diff -r babeee0ac1eb -r 1bd3b0886857 view.c
--- a/view.c Fri Feb 09 01:01:54 2007 -0500
+++ b/view.c Fri Feb 09 01:06:15 2007 -0500
@@ -122,7 +122,7 @@ focus_view(WMScreen *s, View *v) {
                                                 f->rect.y);
                 }
         if((c = sel_client()))
- focus_client(c, False);
+ focus_client(c, True);
         draw_frames();
         XSync(blz.dpy, False);
         XUngrabServer(blz.dpy);
Received on Fri Feb 09 2007 - 07:10:43 UTC

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