diff options
| author | rsc <devnull@localhost> | 2005-07-13 03:54:35 +0000 |
|---|---|---|
| committer | rsc <devnull@localhost> | 2005-07-13 03:54:35 +0000 |
| commit | ac33a34a29f96ada24895ee56364eab27533143f (patch) | |
| tree | f3677b30ed99cfcb8168ceacc9e37ace6ac941ca /src/cmd/rio/manage.c | |
| parent | 7ce3f20d73df41eaed90f26741325c4d7e1c0013 (diff) | |
| download | plan9port-ac33a34a29f96ada24895ee56364eab27533143f.tar.gz plan9port-ac33a34a29f96ada24895ee56364eab27533143f.zip | |
formatting changes; attempt at keyboard-based window switching
Diffstat (limited to 'src/cmd/rio/manage.c')
| -rw-r--r-- | src/cmd/rio/manage.c | 132 |
1 files changed, 68 insertions, 64 deletions
diff --git a/src/cmd/rio/manage.c b/src/cmd/rio/manage.c index 11892a06..86c23e8f 100644 --- a/src/cmd/rio/manage.c +++ b/src/cmd/rio/manage.c @@ -1,3 +1,7 @@ +/* + * Window management. + */ + /* Copyright (c) 1994-1996 David Hogan, see README for licence details */ #include <stdio.h> #include <stdlib.h> @@ -26,7 +30,7 @@ manage(Client *c, int mapped) /* Get loads of hints */ - if (XGetClassHint(dpy, c->window, &class) != 0) { /* ``Success'' */ + if(XGetClassHint(dpy, c->window, &class) != 0){ /* ``Success'' */ c->instance = class.res_name; c->class = class.res_class; c->is9term = 0; @@ -45,63 +49,63 @@ manage(Client *c, int mapped) setlabel(c); hints = XGetWMHints(dpy, c->window); - if (XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) + if(XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0) c->size.flags = PSize; /* not specified - punt */ getcmaps(c); getproto(c); gettrans(c); - if (c->is9term) + if(c->is9term) c->hold = getiprop(c->window, _rio_hold_mode); /* Figure out what to do with the window from hints */ - if (!getstate(c->window, &state)) + if(!getstate(c->window, &state)) state = hints ? hints->initial_state : NormalState; dohide = (state == IconicState); fixsize = 0; - if ((c->size.flags & (USSize|PSize))) + if((c->size.flags & (USSize|PSize))) fixsize = 1; - if ((c->size.flags & (PMinSize|PMaxSize)) == (PMinSize|PMaxSize) && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height) + if((c->size.flags & (PMinSize|PMaxSize)) == (PMinSize|PMaxSize) && c->size.min_width == c->size.max_width && c->size.min_height == c->size.max_height) fixsize = 1; doreshape = !mapped; - if (fixsize) { - if (c->size.flags & USPosition) + if(fixsize){ + if(c->size.flags & USPosition) doreshape = 0; - if (dohide && (c->size.flags & PPosition)) + if(dohide && (c->size.flags & PPosition)) doreshape = 0; - if (c->trans != None) + if(c->trans != None) doreshape = 0; } - if (c->is9term) + if(c->is9term) fixsize = 0; - if (c->size.flags & PBaseSize) { + if(c->size.flags & PBaseSize){ c->min_dx = c->size.base_width; c->min_dy = c->size.base_height; } - else if (c->size.flags & PMinSize) { + else if(c->size.flags & PMinSize){ c->min_dx = c->size.min_width; c->min_dy = c->size.min_height; } - else if (c->is9term) { + else if(c->is9term){ c->min_dx = 100; c->min_dy = 50; } else c->min_dx = c->min_dy = 0; - if (hints) + if(hints) XFree(hints); /* Now do it!!! */ - if (doreshape) { + if(doreshape){ if(0) fprintf(stderr, "in doreshape is9term=%d fixsize=%d, x=%d, y=%d, min_dx=%d, min_dy=%d, dx=%d, dy=%d\n", c->is9term, fixsize, c->x, c->y, c->min_dx, c->min_dy, c->dx, c->dy); - if (current && current->screen == c->screen) + if(current && current->screen == c->screen) cmapnofocus(c->screen); - if (!c->is9term && c->x==0 && c->y==0) { + if(!c->is9term && c->x==0 && c->y==0){ static int nwin; c->x = 20*nwin+BORDER; @@ -110,10 +114,10 @@ manage(Client *c, int mapped) nwin %= 10; } - if (c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))) { + if(c->is9term && !(fixsize ? drag(c, Button3) : sweep(c, Button3))){ XKillClient(dpy, c->window); rmclient(c); - if (current && current->screen == c->screen) + if(current && current->screen == c->screen) cmapfocus(current); return 0; } @@ -135,9 +139,9 @@ manage(Client *c, int mapped) &attrs); XSelectInput(dpy, c->parent, SubstructureRedirectMask | SubstructureNotifyMask|ButtonPressMask| PointerMotionMask|LeaveWindowMask); - if (mapped) + if(mapped) c->reparenting = 1; - if (doreshape && !fixsize) + if(doreshape && !fixsize) XResizeWindow(dpy, c->window, c->dx, c->dy); XSetWindowBorderWidth(dpy, c->window, 0); @@ -149,13 +153,13 @@ manage(Client *c, int mapped) * (black (or white) border around black (or white) window * is not very helpful. */ - if (c->screen->depth <= 8) { + if(c->screen->depth <= 8){ XSetWindowBorderWidth(dpy, c->parent, 1); } XReparentWindow(dpy, c->window, c->parent, BORDER, BORDER); #ifdef SHAPE - if (shape) { + if(shape){ XShapeSelectInput(dpy, c->window, ShapeNotifyMask); ignore_badwindow = 1; /* magic */ setshape(c); @@ -163,21 +167,21 @@ manage(Client *c, int mapped) } #endif XAddToSaveSet(dpy, c->window); - if (dohide) + if(dohide) hide(c); else { XMapWindow(dpy, c->window); XMapWindow(dpy, c->parent); XUnmapWindow(dpy, c->screen->sweepwin); - if (nostalgia || doreshape) + if(nostalgia || doreshape) active(c); - else if (c->trans != None && current && current->window == c->trans) + else if(c->trans != None && current && current->window == c->trans) active(c); else setactive(c, 0); setstate(c, NormalState); } - if (current && (current != c)) + if(current && (current != c)) cmapfocus(current); c->init = 1; @@ -202,12 +206,12 @@ scanwins(ScreenInfo *s) XWindowAttributes attr; XQueryTree(dpy, s->root, &dw1, &dw2, &wins, &nwins); - for (i = 0; i < nwins; i++) { + for(i = 0; i < nwins; i++){ XGetWindowAttributes(dpy, wins[i], &attr); - if (attr.override_redirect || wins[i] == s->menuwin) + if(attr.override_redirect || wins[i] == s->menuwin) continue; c = getclient(wins[i], 1); - if (c != 0 && c->window == wins[i] && !c->init) { + if(c != 0 && c->window == wins[i] && !c->init){ c->x = attr.x; c->y = attr.y; c->dx = attr.width; @@ -215,7 +219,7 @@ scanwins(ScreenInfo *s) c->border = attr.border_width; c->screen = s; c->parent = s->root; - if (attr.map_state == IsViewable) + if(attr.map_state == IsViewable) manage(c, 1); } } @@ -228,7 +232,7 @@ gettrans(Client *c) Window trans; trans = None; - if (XGetTransientForHint(dpy, c->window, &trans) != 0) + if(XGetTransientForHint(dpy, c->window, &trans) != 0) c->trans = trans; else c->trans = None; @@ -256,11 +260,11 @@ gravitate(Client *c, int invert) int gravity, dx, dy, delta; gravity = NorthWestGravity; - if (c->size.flags & PWinGravity) + if(c->size.flags & PWinGravity) gravity = c->size.win_gravity; delta = c->border-BORDER; - switch (gravity) { + switch (gravity){ case NorthWestGravity: dx = 0; dy = 0; @@ -304,7 +308,7 @@ gravitate(Client *c, int invert) } dx += BORDER; dy += BORDER; - if (invert) { + if(invert){ dx = -dx; dy = -dy; } @@ -315,7 +319,7 @@ gravitate(Client *c, int invert) static void installcmap(ScreenInfo *s, Colormap cmap) { - if (cmap == None) + if(cmap == None) XInstallColormap(dpy, s->def_cmap); else XInstallColormap(dpy, cmap); @@ -327,19 +331,19 @@ cmapfocus(Client *c) int i, found; Client *cc; - if (c == 0) + if(c == 0) return; - else if (c->ncmapwins != 0) { + else if(c->ncmapwins != 0){ found = 0; - for (i = c->ncmapwins-1; i >= 0; i--) { + for(i = c->ncmapwins-1; i >= 0; i--){ installcmap(c->screen, c->wmcmaps[i]); - if (c->cmapwins[i] == c->window) + if(c->cmapwins[i] == c->window) found++; } - if (!found) + if(!found) installcmap(c->screen, c->cmap); } - else if (c->trans != None && (cc = getclient(c->trans, 0)) != 0 && cc->ncmapwins != 0) + else if(c->trans != None && (cc = getclient(c->trans, 0)) != 0 && cc->ncmapwins != 0) cmapfocus(cc); else installcmap(c->screen, c->cmap); @@ -358,7 +362,7 @@ getcmaps(Client *c) Window *cw; XWindowAttributes attr; - if (!c->init) { + if(!c->init){ ignore_badwindow = 1; XGetWindowAttributes(dpy, c->window, &attr); c->cmap = attr.colormap; @@ -367,11 +371,11 @@ getcmaps(Client *c) } n = _getprop(c->window, wm_colormaps, XA_WINDOW, 100L, (void*)&cw); - if (c->ncmapwins != 0) { + if(c->ncmapwins != 0){ XFree((char *)c->cmapwins); free((char *)c->wmcmaps); } - if (n <= 0) { + if(n <= 0){ c->ncmapwins = 0; return; } @@ -380,8 +384,8 @@ getcmaps(Client *c) c->cmapwins = cw; c->wmcmaps = (Colormap*)malloc(n*sizeof(Colormap)); - for (i = 0; i < n; i++) { - if (cw[i] == c->window) + for(i = 0; i < n; i++){ + if(cw[i] == c->window) c->wmcmaps[i] = c->cmap; else { /* flush any errors (e.g., caused by mozilla tabs) */ @@ -400,17 +404,17 @@ setlabel(Client *c) { char *label, *p; - if (c->iconname != 0) + if(c->iconname != 0) label = c->iconname; - else if (c->name != 0) + else if(c->name != 0) label = c->name; - else if (c->instance != 0) + else if(c->instance != 0) label = c->instance; - else if (c->class != 0) + else if(c->class != 0) label = c->class; else label = "no label"; - if ((p = index(label, ':')) != 0) + if((p = index(label, ':')) != 0) *p = '\0'; c->label = label; } @@ -424,7 +428,7 @@ setshape(Client *c) /* don't try to add a border if the window is non-rectangular */ rect = XShapeGetRectangles(dpy, c->window, ShapeBounding, &n, &order); - if (n > 1) + if(n > 1) XShapeCombineShape(dpy, c->parent, ShapeBounding, BORDER, BORDER, c->window, ShapeBounding, ShapeSet); XFree((void*)rect); @@ -440,9 +444,9 @@ _getprop(Window w, Atom a, Atom type, long len, unsigned char **p) int status; status = XGetWindowProperty(dpy, w, a, 0L, len, False, type, &real_type, &format, &n, &extra, p); - if (status != Success || *p == 0) + if(status != Success || *p == 0) return -1; - if (n == 0) + if(n == 0) XFree((void*) *p); /* could check real_type, format, extra here... */ return n; @@ -453,7 +457,7 @@ getprop(Window w, Atom a) { unsigned char *p; - if (_getprop(w, a, XA_STRING, 100L, &p) <= 0) + if(_getprop(w, a, XA_STRING, 100L, &p) <= 0) return 0; return (char *)p; } @@ -463,7 +467,7 @@ get1prop(Window w, Atom a, Atom type) { char **p, *x; - if (_getprop(w, a, type, 1L, (void*)&p) <= 0) + if(_getprop(w, a, type, 1L, (void*)&p) <= 0) return 0; x = *p; XFree((void*) p); @@ -500,7 +504,7 @@ getstate(Window w, int *state) { long *p = 0; - if (_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) + if(_getprop(w, wm_state, wm_state, 2L, (void*)&p) <= 0) return 0; *state = (int) *p; @@ -518,15 +522,15 @@ getproto(Client *c) w = c->window; c->proto = 0; - if ((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) + if((n = _getprop(w, wm_protocols, XA_ATOM, 20L, (void*)&p)) <= 0) return; - for (i = 0; i < n; i++) - if (p[i] == wm_delete) + for(i = 0; i < n; i++) + if(p[i] == wm_delete) c->proto |= Pdelete; - else if (p[i] == wm_take_focus) + else if(p[i] == wm_take_focus) c->proto |= Ptakefocus; - else if (p[i] == wm_lose_focus) + else if(p[i] == wm_lose_focus) c->proto |= Plosefocus; XFree((char *) p); |
