1 /* Copyright (c) 1994-1996 David Hogan, see README for licence details */
9 #include <X11/extensions/shape.h>
12 #include "patchlevel.h"
15 mainloop(int shape_event)
31 if (shape && ev.type == shape_event)
32 shapenotify((XShapeEvent *)&ev);
35 fprintf(stderr, "rio: unknown ev.type %d\n", ev.type);
43 mapreq(&ev.xmaprequest);
45 case ConfigureRequest:
46 configurereq(&ev.xconfigurerequest);
48 case CirculateRequest:
49 circulatereq(&ev.xcirculaterequest);
55 newwindow(&ev.xcreatewindow);
58 destroy(ev.xdestroywindow.window);
61 clientmesg(&ev.xclient);
67 property(&ev.xproperty);
70 fprintf(stderr, "rio: SelectionClear (this should not happen)\n");
73 fprintf(stderr, "rio: SelectionNotify (this should not happen)\n");
75 case SelectionRequest:
76 fprintf(stderr, "rio: SelectionRequest (this should not happen)\n");
85 reparent(&ev.xreparent);
91 motionnotify(&ev.xmotion);
101 trace("ignore", 0, &ev);
109 configurereq(XConfigureRequestEvent *e)
114 /* we don't set curtime as nothing here uses it */
115 c = getclient(e->window, 0);
116 trace("configurereq", c, e);
118 e->value_mask &= ~CWSibling;
122 if (e->value_mask & CWX)
124 if (e->value_mask & CWY)
126 if (e->value_mask & CWWidth)
128 if (e->value_mask & CWHeight)
130 if (e->value_mask & CWBorderWidth)
131 c->border = e->border_width;
133 if (e->value_mask & CWStackMode) {
134 if (e->detail == Above)
137 e->value_mask &= ~CWStackMode;
139 if (c->parent != c->screen->root && c->window == e->window) {
142 wc.width = c->dx+2*BORDER;
143 wc.height = c->dy+2*BORDER;
146 wc.stack_mode = e->detail;
147 XConfigureWindow(dpy, c->parent, e->value_mask, &wc);
149 if (e->value_mask & CWStackMode) {
165 wc.height = e->height;
168 wc.stack_mode = Above;
169 e->value_mask &= ~CWStackMode;
170 e->value_mask |= CWBorderWidth;
172 XConfigureWindow(dpy, e->window, e->value_mask, &wc);
176 mapreq(XMapRequestEvent *e)
181 curtime = CurrentTime;
182 c = getclient(e->window, 0);
183 trace("mapreq", c, e);
185 if (c == 0 || c->window != e->window) {
186 /* workaround for stupid NCDware */
187 fprintf(stderr, "rio: bad mapreq c %p w %x, rescanning\n",
189 for (i = 0; i < num_screens; i++)
190 scanwins(&screens[i]);
191 c = getclient(e->window, 0);
192 if (c == 0 || c->window != e->window) {
193 fprintf(stderr, "rio: window not found after rescan\n");
200 if (c->parent == c->screen->root) {
205 XReparentWindow(dpy, c->window, c->parent, BORDER-1, BORDER-1);
206 XAddToSaveSet(dpy, c->window);
207 /* fall through... */
209 XMapWindow(dpy, c->window);
210 XMapRaised(dpy, c->parent);
212 setstate(c, NormalState);
213 if (c->trans != None && current && c->trans == current->window)
223 unmap(XUnmapEvent *e)
227 curtime = CurrentTime;
228 c = getclient(e->window, 0);
249 circulatereq(XCirculateRequestEvent *e)
251 fprintf(stderr, "It must be the warlock Krill!\n"); /* ☺ */
255 newwindow(XCreateWindowEvent *e)
260 /* we don't set curtime as nothing here uses it */
261 if (e->override_redirect)
263 c = getclient(e->window, 1);
264 if (c && c->window == e->window && (s = getscreen(e->parent))) {
269 c->border = e->border_width;
271 if (c->parent == None)
272 c->parent = c->screen->root;
281 curtime = CurrentTime;
288 /* flush any errors generated by the window's sudden demise */
289 ignore_badwindow = 1;
291 ignore_badwindow = 0;
295 clientmesg(XClientMessageEvent *e)
299 curtime = CurrentTime;
300 if (e->message_type == exit_rio) {
304 if (e->message_type == restart_rio) {
305 fprintf(stderr, "*** rio restarting ***\n");
307 execvp(myargv[0], myargv);
308 perror("rio: exec failed");
311 if (e->message_type == wm_change_state) {
312 c = getclient(e->window, 0);
313 if (e->format == 32 && e->data.l[0] == IconicState && c != 0) {
318 fprintf(stderr, "rio: WM_CHANGE_STATE: format %d data %d w 0x%x\n",
319 (int)e->format, (int)e->data.l[0], (int)e->window);
322 fprintf(stderr, "rio: strange ClientMessage, type 0x%x window 0x%x\n",
323 (int)e->message_type, (int)e->window);
327 cmap(XColormapEvent *e)
332 /* we don't set curtime as nothing here uses it */
334 c = getclient(e->window, 0);
336 c->cmap = e->colormap;
341 for (c = clients; c; c = c->next) {
342 for (i = 0; i < c->ncmapwins; i++)
343 if (c->cmapwins[i] == e->window) {
344 c->wmcmaps[i] = e->colormap;
354 property(XPropertyEvent *e)
361 /* we don't set curtime as nothing here uses it */
363 delete = (e->state == PropertyDelete);
364 c = getclient(e->window, 0);
369 case XA_WM_ICON_NAME:
370 if (c->iconname != 0)
371 XFree((char*) c->iconname);
372 c->iconname = delete ? 0 : getprop(c->window, a);
374 renamec(c, c->label);
378 XFree((char*) c->name);
379 c->name = delete ? 0 : getprop(c->window, a);
381 renamec(c, c->label);
383 case XA_WM_TRANSIENT_FOR:
387 case XA_WM_SIZE_HINTS:
388 case XA_WM_ZOOM_HINTS:
389 /* placeholders to not forget. ignore for now. -Axel */
391 case XA_WM_NORMAL_HINTS:
392 if (XGetWMNormalHints(dpy, c->window, &c->size, &msize) == 0 || c->size.flags == 0)
393 c->size.flags = PSize; /* not specified - punt */
396 if (a == _rio_hold_mode) {
397 c->hold = getiprop(c->window, _rio_hold_mode);
401 else if (a == wm_colormaps) {
409 reparent(XReparentEvent *e)
412 XWindowAttributes attr;
415 /* we don't set curtime as nothing here uses it */
416 if (!getscreen(e->event) || e->override_redirect)
418 if ((s = getscreen(e->parent)) != 0) {
419 c = getclient(e->window, 1);
420 if (c != 0 && (c->dx == 0 || c->dy == 0)) {
421 /* flush any errors */
422 ignore_badwindow = 1;
423 XGetWindowAttributes(dpy, c->window, &attr);
425 ignore_badwindow = 0;
431 c->border = attr.border_width;
433 if (c->parent == None)
434 c->parent = c->screen->root;
438 c = getclient(e->window, 0);
439 if (c != 0 && (c->parent == c->screen->root || withdrawn(c)))
446 shapenotify(XShapeEvent *e)
450 /* we don't set curtime as nothing here uses it */
451 c = getclient(e->window, 0);
460 enter(XCrossingEvent *e)
465 if (e->mode != NotifyGrab || e->detail != NotifyNonlinearVirtual)
467 c = getclient(e->window, 0);
468 if (c != 0 && c != current) {
469 /* someone grabbed the pointer; make them current */
470 XMapRaised(dpy, c->parent);
477 leave(XCrossingEvent *e)
481 c = getclient(e->window, 0);
483 XUndefineCursor(dpy, c->parent);
484 /* XDefineCursor(dpy, c->parent, c->screen->arrow); */
488 focusin(XFocusChangeEvent *e)
492 curtime = CurrentTime;
493 if (e->detail != NotifyNonlinearVirtual)
495 c = getclient(e->window, 0);
496 if (c != 0 && c->window == e->window && c != current) {
497 /* someone grabbed keyboard or seized focus; make them current */
498 XMapRaised(dpy, c->parent);
505 borderorient(Client *c, int x, int y)
509 if (debug) fprintf(stderr, "topleft\n");
512 if (y >= (c->dy + 2*BORDER) - CORNER) {
513 if (debug) fprintf(stderr, "botleft\n");
517 y < (c->dy + 2*BORDER) - CORNER) {
518 if (debug) fprintf(stderr, "left\n");
521 } else if (x <= CORNER) {
523 if (debug) fprintf(stderr, "topleft\n");
526 if (y >= (c->dy + BORDER)) {
527 if (debug) fprintf(stderr, "botleft\n");
530 } else if (x >= (c->dx + BORDER)) {
532 if (debug) fprintf(stderr, "topright\n");
535 if (y >= (c->dy + 2*BORDER) - CORNER) {
536 if (debug) fprintf(stderr, "botright\n");
540 y < (c->dy + 2*BORDER) - CORNER) {
541 if (debug) fprintf(stderr, "right\n");
544 } else if (x >= (c->dx + 2*BORDER) - CORNER) {
546 if (debug) fprintf(stderr, "topright\n");
549 if (y >= (c->dy + BORDER)) {
550 if (debug) fprintf(stderr, "botright\n");
553 } else if (x > CORNER &&
554 x < (c->dx + 2*BORDER) - CORNER) {
556 if (debug) fprintf(stderr, "top\n");
559 if (y >= (c->dy + BORDER)) {
560 if (debug) fprintf(stderr, "bot\n");
564 return BorderUnknown;
568 motionnotify(XMotionEvent *e)
573 c = getclient(e->window, 0);
575 bl = borderorient(c, e->x, e->y);
576 if (bl == BorderUnknown)
577 XUndefineCursor(dpy, c->parent);
579 XDefineCursor(dpy, c->parent, c->screen->bordcurs[bl]);