1 /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
13 Client *hiddenc[MAXHIDDEN];
19 Client * currents[NUMVIRTUALS] =
21 NULL, NULL, NULL, NULL,
24 char *b2items[NUMVIRTUALS+1] =
46 char *b3items[B3FIXED+MAXHIDDEN+1] =
67 button(XButtonEvent *e)
75 s = getscreen(e->root);
78 c = getclient(e->window, 0);
80 if (debug) fprintf(stderr, "but: e x=%d y=%d c x=%d y=%d dx=%d dy=%d BORDR %d\n",
81 e->x, e->y, c->x, c->y, c->dx, c->dy, BORDER);
82 if(borderorient(c, e->x, e->y) != BorderUnknown){
86 reshape(c, e->button, pull, e);
95 e->x += c->x - BORDER;
96 e->y += c->y - BORDER;
97 } else if (e->window != e->root) {
98 if (debug) fprintf(stderr, "but no client: e x=%d y=%d\n",
100 XTranslateCoordinates(dpy, e->window, s->root, e->x, e->y,
106 XMapRaised(dpy, c->parent);
113 XMapRaised(dpy, c->parent);
115 XAllowEvents (dpy, ReplayPointer, curtime);
116 } else if ((e->state&(ShiftMask|ControlMask))==(ShiftMask|ControlMask)) {
118 } else if(numvirtuals > 1 && (n = menuhit(e, &b2menu)) > -1)
124 /* scroll up changes to previous virtual screen */
125 if(!c && e->type == ButtonPress)
126 if(numvirtuals > 1 && virt > 0)
130 /* scroll down changes to next virtual screen */
131 if(!c && e->type == ButtonPress)
132 if(numvirtuals > 1 && virt < numvirtuals - 1)
139 if (current && current->screen == s)
141 switch (n = menuhit(e, &b3menu)) {
145 case 1: /* Reshape */
146 reshape(selectwin(1, 0, s), Button3, sweep, 0);
149 move(selectwin(0, 0, s), Button3);
153 c = selectwin(1, &shift, s);
157 hide(selectwin(1, 0, s));
159 default: /* unhide window */
160 unhide(n - B3FIXED, 1);
162 case -1: /* nothing */
165 if (current && current->screen == s)
173 * ugly dance to cause sweeping for terminals.
174 * the very next window created will require sweeping.
175 * hope it's created by the program we're about to
180 * ugly dance to avoid leaving zombies. Could use SIGCHLD,
181 * but it's not very portable.
185 close(ConnectionNumber(dpy));
186 if (s->display[0] != '\0')
188 signal(SIGINT, SIG_DFL);
189 signal(SIGTERM, SIG_DFL);
190 signal(SIGHUP, SIG_DFL);
191 if (termprog != NULL) {
192 execl(shell, shell, "-c", termprog, 0);
193 fprintf(stderr, "rio: exec %s", shell);
196 execlp("9term", "9term", scrolling ? "-ws" : "-w", 0);
197 execlp("xterm", "xterm", "-ut", 0);
198 perror("rio: exec 9term/xterm failed");
207 reshape(Client *c, int but, int (*fn)(Client*, int, XButtonEvent *), XButtonEvent *e)
215 if (fn(c, but, e) == 0)
219 XRaiseWindow(dpy, c->parent);
220 XMoveResizeWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER,
221 c->dx+2*BORDER, c->dy+2*BORDER);
222 if (c->dx == odx && c->dy == ody)
225 XMoveResizeWindow(dpy, c->window, BORDER, BORDER, c->dx, c->dy);
229 move(Client *c, int but)
233 if (drag(c, but) == 0)
237 XRaiseWindow(dpy, c->parent);
238 XMoveWindow(dpy, c->parent, c->x-BORDER, c->y-BORDER);
243 delete(Client *c, int shift)
247 if ((c->proto & Pdelete) && !shift)
248 sendcmessage(c->window, wm_protocols, wm_delete, 0, 0);
250 XKillClient(dpy, c->window); /* let event clean up */
256 if (c == 0 || numhidden == MAXHIDDEN)
259 fprintf(stderr, "rio: already hidden: %s\n", c->label);
262 XUnmapWindow(dpy, c->parent);
263 XUnmapWindow(dpy, c->window);
264 setstate(c, IconicState);
267 hiddenc[numhidden] = c;
268 b3items[B3FIXED+numhidden] = c->label;
270 b3items[B3FIXED+numhidden] = 0;
274 unhide(int n, int map)
279 if (n >= numhidden) {
280 fprintf(stderr, "rio: unhide: n %d numhidden %d\n", n, numhidden);
285 fprintf(stderr, "rio: unhide: not hidden: %s(0x%x)\n",
286 c->label, (int)c->window);
292 XMapWindow(dpy, c->window);
293 XMapRaised(dpy, c->parent);
294 setstate(c, NormalState);
300 for (i = n; i < numhidden; i ++) {
301 hiddenc[i] = hiddenc[i+1];
302 b3items[B3FIXED+i] = b3items[B3FIXED+i+1];
304 b3items[B3FIXED+numhidden] = 0;
308 unhidec(Client *c, int map)
312 for (i = 0; i < numhidden; i++)
313 if (c == hiddenc[i]) {
317 fprintf(stderr, "rio: unhidec: not hidden: %s(0x%x)\n",
318 c->label, (int)c->window);
322 renamec(Client *c, char *name)
331 for (i = 0; i < numhidden; i++)
332 if (c == hiddenc[i]) {
333 b3items[B3FIXED+i] = name;
347 switch_to_c(int n, Client *c)
350 switch_to_c(n,c->next);
352 if (c->parent == DefaultRootWindow(dpy))
355 if (c->virt != virt && c->state == NormalState) {
356 XUnmapWindow(dpy, c->parent);
357 XUnmapWindow(dpy, c->window);
358 setstate(c, IconicState);
361 } else if (c->virt == virt && c->state == IconicState) {
364 for (i = 0; i < numhidden; i++)
368 if (i == numhidden) {
369 XMapWindow(dpy, c->window);
370 XMapWindow(dpy, c->parent);
371 setstate(c, NormalState);
372 if (currents[virt] == c)
383 currents[virt] = current;
386 /* redundant when called from a menu switch
387 * but needed for scroll-button switches
391 switch_to_c(n, clients);
392 current = currents[virt];