5 /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
6 #define _SVID_SOURCE 1 /* putenv in glibc */
7 #define _DEFAULT_SOURCE 1
16 #include <X11/Xutil.h>
20 Client *hiddenc[MAXHIDDEN];
27 Client * currents[NUMVIRTUALS] =
29 NULL, NULL, NULL, NULL
32 char *b2items[NUMVIRTUALS+1] =
54 char *b3items[B3FIXED+MAXHIDDEN+1] =
84 button(XButtonEvent *e)
92 s = getscreen(e->root);
95 c = getclient(e->window, 0);
97 if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
98 e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
99 if(borderorient(c, e->x, e->y) != BorderUnknown){
103 reshape(c, e->button, pull, e);
112 e->x += c->x - BORDER;
113 e->y += c->y - BORDER;
114 } else if(e->window != e->root){
115 if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
117 XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
123 XMapRaised(dpy, c->parent);
130 XMapRaised(dpy, c->parent);
132 XAllowEvents (dpy, ReplayPointer, curtime);
133 } else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)){
135 } else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
141 /* scroll up changes to previous virtual screen */
142 if(!c && e->type == ButtonPress)
143 if(numvirtuals > 1 && virt > 0)
147 /* scroll down changes to next virtual screen */
148 if(!c && e->type == ButtonPress)
149 if(numvirtuals > 1 && virt < numvirtuals - 1)
156 if(current && current->screen == s)
158 switch (n = menuhit(e, &b3menu)){
163 reshape(selectwin(1, 0, s), Button3, sweep, 0);
166 move(selectwin(0, 0, s), Button3);
170 c = selectwin(1, &shift, s);
174 hide(selectwin(1, 0, s));
176 default: /* unhide window */
177 unhide(n - B3FIXED, 1);
179 case -1: /* nothing */
182 if(current && current->screen == s)
190 * ugly dance to cause sweeping for terminals.
191 * the very next window created will require sweeping.
192 * hope it's created by the program we're about to
197 * ugly dance to avoid leaving zombies. Could use SIGCHLD,
198 * but it's not very portable.
202 close(ConnectionNumber(dpy));
203 if(s->display[0] != '\0')
205 signal(SIGINT, SIG_DFL);
206 signal(SIGTERM, SIG_DFL);
207 signal(SIGHUP, SIG_DFL);
208 if(termprog != NULL){
209 execl(shell, shell, "-c", termprog, (char*)0);
210 fprintf(stderr, "rio: exec %s", shell);
213 execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
214 execlp("xterm", "xterm", "-ut", (char*)0);
215 perror("rio: exec 9term/xterm failed");
224 reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEvent *e)
232 if(fn(c, but, e) == 0)
236 XRaiseWindow(dpy, c->parent);
237 XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER,
238 c->dx+2*BORDER, c->dy+2*BORDER);
239 if(c->dx == odx && c->dy == ody)
242 XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
246 move(Client *c, int but)
250 if(drag(c, but) == 0)
254 XRaiseWindow(dpy, c->parent);
255 XMoveWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER);
260 delete(Client *c, int shift)
264 if((c->proto & Pdelete) && !shift)
265 sendcmessage(c->window, wm_protocols, wm_delete, 0, 0);
267 XKillClient(dpy, c->window); /* let event clean up */
273 if(c == 0 || numhidden == MAXHIDDEN)
276 fprintf(stderr, "rio: already hidden: %s\n", c->label);
279 XUnmapWindow(dpy, c->parent);
280 XUnmapWindow(dpy, c->window);
281 setstate(c, IconicState);
285 memmove(hiddenc+1, hiddenc, numhidden*sizeof hiddenc[0]);
286 memmove(b3items+B3FIXED+1, b3items+B3FIXED, numhidden*sizeof b3items[0]);
288 b3items[B3FIXED] = c->label;
290 hiddenc[numhidden] = c;
291 b3items[B3FIXED+numhidden] = c->label;
294 b3items[B3FIXED+numhidden] = 0;
298 unhide(int n, int map)
304 fprintf(stderr, "rio: unhide: n %d numhidden %d\n", n, numhidden);
309 fprintf(stderr, "rio: unhide: not hidden: %s(0x%x)\n",
310 c->label, (int)c->window);
316 XMapWindow(dpy, c->window);
317 XMapRaised(dpy, c->parent);
318 setstate(c, NormalState);
324 for(i = n; i < numhidden; i++){
325 hiddenc[i] = hiddenc[i+1];
326 b3items[B3FIXED+i] = b3items[B3FIXED+i+1];
328 b3items[B3FIXED+numhidden] = 0;
332 unhidec(Client *c, int map)
336 for(i = 0; i < numhidden; i++)
341 fprintf(stderr, "rio: unhidec: not hidden: %s(0x%x)\n",
342 c->label, (int)c->window);
346 renamec(Client *c, char *name)
355 for(i = 0; i < numhidden; i++)
357 b3items[B3FIXED+i] = name;
371 switch_to_c(int n, Client *c)
377 switch_to_c(n, c->next);
379 if(c->parent == DefaultRootWindow(dpy))
382 if(c->virt != virt && c->state == NormalState){
383 XUnmapWindow(dpy, c->parent);
384 XUnmapWindow(dpy, c->window);
385 setstate(c, IconicState);
388 } else if(c->virt == virt && c->state == IconicState){
391 for(i = 0; i < numhidden; i++)
396 XMapWindow(dpy, c->window);
397 XMapWindow(dpy, c->parent);
398 setstate(c, NormalState);
399 if(currents[virt] == c)
410 currents[virt] = current;
413 /* redundant when called from a menu switch
414 * but needed for scroll-button switches
418 switch_to_c(n, clients);
419 current = currents[virt];