5 /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
6 #define _SVID_SOURCE 1 /* putenv in glibc */
15 #include <X11/Xutil.h>
19 Client *hiddenc[MAXHIDDEN];
26 Client * currents[NUMVIRTUALS] =
28 NULL, NULL, NULL, NULL
31 char *b2items[NUMVIRTUALS+1] =
53 char *b3items[B3FIXED+MAXHIDDEN+1] =
83 button(XButtonEvent *e)
91 s = getscreen(e->root);
94 c = getclient(e->window, 0);
96 if(debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
97 e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
98 if(borderorient(c, e->x, e->y) != BorderUnknown){
102 reshape(c, e->button, pull, e);
111 e->x += c->x - BORDER;
112 e->y += c->y - BORDER;
113 } else if(e->window != e->root){
114 if(debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
116 XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
122 XMapRaised(dpy, c->parent);
129 XMapRaised(dpy, c->parent);
131 XAllowEvents (dpy, ReplayPointer, curtime);
132 } else if((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)){
134 } else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
140 /* scroll up changes to previous virtual screen */
141 if(!c && e->type == ButtonPress)
142 if(numvirtuals > 1 && virt > 0)
146 /* scroll down changes to next virtual screen */
147 if(!c && e->type == ButtonPress)
148 if(numvirtuals > 1 && virt < numvirtuals - 1)
155 if(current && current->screen == s)
157 switch (n = menuhit(e, &b3menu)){
162 reshape(selectwin(1, 0, s), Button3, sweep, 0);
165 move(selectwin(0, 0, s), Button3);
169 c = selectwin(1, &shift, s);
173 hide(selectwin(1, 0, s));
175 default: /* unhide window */
176 unhide(n - B3FIXED, 1);
178 case -1: /* nothing */
181 if(current && current->screen == s)
189 * ugly dance to cause sweeping for terminals.
190 * the very next window created will require sweeping.
191 * hope it's created by the program we're about to
196 * ugly dance to avoid leaving zombies. Could use SIGCHLD,
197 * but it's not very portable.
201 close(ConnectionNumber(dpy));
202 if(s->display[0] != '\0')
204 signal(SIGINT, SIG_DFL);
205 signal(SIGTERM, SIG_DFL);
206 signal(SIGHUP, SIG_DFL);
207 if(termprog != NULL){
208 execl(shell, shell, "-c", termprog, (char*)0);
209 fprintf(stderr, "rio: exec %s", shell);
212 execlp("9term", "9term", scrolling ? "-ws" : "-w", (char*)0);
213 execlp("xterm", "xterm", "-ut", (char*)0);
214 perror("rio: exec 9term/xterm failed");
223 reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEvent *e)
231 if(fn(c, but, e) == 0)
235 XRaiseWindow(dpy, c->parent);
236 XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER,
237 c->dx+2*BORDER, c->dy+2*BORDER);
238 if(c->dx == odx && c->dy == ody)
241 XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
245 move(Client *c, int but)
249 if(drag(c, but) == 0)
253 XRaiseWindow(dpy, c->parent);
254 XMoveWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER);
259 delete(Client *c, int shift)
263 if((c->proto & Pdelete) && !shift)
264 sendcmessage(c->window, wm_protocols, wm_delete, 0, 0);
266 XKillClient(dpy, c->window); /* let event clean up */
272 if(c == 0 || numhidden == MAXHIDDEN)
275 fprintf(stderr, "rio: already hidden: %s\n", c->label);
278 XUnmapWindow(dpy, c->parent);
279 XUnmapWindow(dpy, c->window);
280 setstate(c, IconicState);
284 memmove(hiddenc+1, hiddenc, numhidden*sizeof hiddenc[0]);
285 memmove(b3items+B3FIXED+1, b3items+B3FIXED, numhidden*sizeof b3items[0]);
287 b3items[B3FIXED] = c->label;
289 hiddenc[numhidden] = c;
290 b3items[B3FIXED+numhidden] = c->label;
293 b3items[B3FIXED+numhidden] = 0;
297 unhide(int n, int map)
303 fprintf(stderr, "rio: unhide: n %d numhidden %d\n", n, numhidden);
308 fprintf(stderr, "rio: unhide: not hidden: %s(0x%x)\n",
309 c->label, (int)c->window);
315 XMapWindow(dpy, c->window);
316 XMapRaised(dpy, c->parent);
317 setstate(c, NormalState);
323 for(i = n; i < numhidden; i++){
324 hiddenc[i] = hiddenc[i+1];
325 b3items[B3FIXED+i] = b3items[B3FIXED+i+1];
327 b3items[B3FIXED+numhidden] = 0;
331 unhidec(Client *c, int map)
335 for(i = 0; i < numhidden; i++)
340 fprintf(stderr, "rio: unhidec: not hidden: %s(0x%x)\n",
341 c->label, (int)c->window);
345 renamec(Client *c, char *name)
354 for(i = 0; i < numhidden; i++)
356 b3items[B3FIXED+i] = name;
370 switch_to_c(int n, Client *c)
376 switch_to_c(n, c->next);
378 if(c->parent == DefaultRootWindow(dpy))
381 if(c->virt != virt && c->state == NormalState){
382 XUnmapWindow(dpy, c->parent);
383 XUnmapWindow(dpy, c->window);
384 setstate(c, IconicState);
387 } else if(c->virt == virt && c->state == IconicState){
390 for(i = 0; i < numhidden; i++)
395 XMapWindow(dpy, c->window);
396 XMapWindow(dpy, c->parent);
397 setstate(c, NormalState);
398 if(currents[virt] == c)
409 currents[virt] = current;
412 /* redundant when called from a menu switch
413 * but needed for scroll-button switches
417 switch_to_c(n, clients);
418 current = currents[virt];