4 * Copyright © 2003 Keith Packard
6 * Permission to use, copy, modify, distribute, and sell this software and its
7 * documentation for any purpose is hereby granted without fee, provided that
8 * the above copyright notice appear in all copies and that both that
9 * copyright notice and this permission notice appear in supporting
10 * documentation, and that the name of Keith Packard not be used in
11 * advertising or publicity pertaining to distribution of the software without
12 * specific, written prior permission. Keith Packard makes no
13 * representations about the suitability of this software for any purpose. It
14 * is provided "as is" without express or implied warranty.
16 * KEITH PACKARD DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
17 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
18 * EVENT SHALL KEITH PACKARD BE LIABLE FOR ANY SPECIAL, INDIRECT OR
19 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
20 * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
21 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
22 * PERFORMANCE OF THIS SOFTWARE.
26 /* Modified by Matthew Hawn. I don't know what to say here so follow what it
27 says above. Not that I can really do anything about it
41 #include <X11/Xutil.h>
42 #include <X11/Xatom.h>
43 #include <X11/extensions/Xcomposite.h>
44 #include <X11/extensions/Xdamage.h>
45 #include <X11/extensions/Xrender.h>
47 #if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR >= 2
48 #define HAS_NAME_WINDOW_PIXMAP 1
51 #define CAN_DO_USABLE 0
62 WINTYPE_DROPDOWN_MENU,
71 typedef struct _ignore {
73 unsigned long sequence;
79 #if HAS_NAME_WINDOW_PIXMAP
84 Bool usable; /* mapped and all damaged at one point */
85 XRectangle damage_bounds; /* bounds of damage */
93 XserverRegion borderSize;
94 XserverRegion extents;
100 unsigned int opacity;
102 unsigned long damage_sequence; /* sequence when damage was created */
105 XConfigureEvent queue_configure;
107 /* for drawing translucent windows */
108 XserverRegion borderClip;
109 struct _win *prev_trans;
112 typedef struct _conv {
117 typedef struct _fade {
123 void (*callback) (Display *dpy, win *w);
134 Picture blackPicture;
135 Picture transBlackPicture;
137 XserverRegion allDamage;
139 #if HAS_NAME_WINDOW_PIXMAP
142 int root_height, root_width;
143 ignore *ignore_head, **ignore_tail = &ignore_head;
144 int xfixes_event, xfixes_error;
145 int damage_event, damage_error;
146 int composite_event, composite_error;
147 int render_event, render_error;
149 int composite_opcode;
151 /* find these once and be done with it */
154 Atom winType[NUM_WINTYPES];
155 double winTypeOpacity[NUM_WINTYPES];
156 Bool winTypeShadow[NUM_WINTYPES];
157 Bool winTypeFade[NUM_WINTYPES];
159 /* opacity property name; sometime soon I'll write up an EWMH spec for it */
160 #define OPACITY_PROP "_NET_WM_WINDOW_OPACITY"
161 #define REGISTER_PROP "_NET_WM_CM_S"
163 #define TRANSLUCENT 0xe0000000
164 #define OPAQUE 0xffffffff
168 #define WINDOW_SOLID 0
169 #define WINDOW_TRANS 1
170 #define WINDOW_ARGB 2
172 #define TRANS_OPACITY 0.75
174 #define DEBUG_REPAINT 0
175 #define DEBUG_EVENTS 0
176 #define MONITOR_REPAINT 0
179 #define SHARP_SHADOW 0
181 typedef enum _compMode {
182 CompSimple, /* looks like a regular X server */
183 CompServerShadows, /* use window alpha for shadow; sharp, but precise */
184 CompClientShadows, /* use window extents for shadow, blurred */
188 determine_mode(Display *dpy, win *w);
191 get_opacity_percent(Display *dpy, win *w);
194 win_extents (Display *dpy, win *w);
196 CompMode compMode = CompSimple;
198 int shadowRadius = 12;
199 int shadowOffsetX = -15;
200 int shadowOffsetY = -15;
201 double shadowOpacity = .75;
203 double fade_in_step = 0.028;
204 double fade_out_step = 0.03;
207 Bool fadeTrans = False;
209 Bool autoRedirect = False;
211 /* For shadow precomputation */
213 unsigned char *shadowCorner = NULL;
214 unsigned char *shadowTop = NULL;
217 get_time_in_milliseconds ()
221 gettimeofday (&tv, NULL);
222 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
230 for (f = fades; f; f = f->next)
239 dequeue_fade (Display *dpy, fade *f)
243 for (prev = &fades; *prev; prev = &(*prev)->next)
248 (*f->callback) (dpy, f->w);
255 cleanup_fade (Display *dpy, win *w)
257 fade *f = find_fade (w);
259 dequeue_fade (dpy, f);
263 enqueue_fade (Display *dpy, fade *f)
266 fade_time = get_time_in_milliseconds () + fade_delta;
272 set_fade (Display *dpy, win *w, double start, double finish, double step,
273 void (*callback) (Display *dpy, win *w),
274 Bool exec_callback, Bool override)
281 f = malloc (sizeof (fade));
285 enqueue_fade (dpy, f);
293 (*f->callback)(dpy, f->w);
303 else if (f->cur > finish)
305 f->callback = callback;
306 w->opacity = f->cur * OPAQUE;
308 printf ("set_fade start %g step %g\n", f->cur, f->step);
310 determine_mode (dpy, w);
313 XRenderFreePicture (dpy, w->shadow);
315 w->extents = win_extents (dpy, w);
326 now = get_time_in_milliseconds();
327 delta = fade_time - now;
330 /* printf ("timeout %d\n", delta); */
335 run_fades (Display *dpy)
337 int now = get_time_in_milliseconds();
343 printf ("run fades\n");
345 if (fade_time - now > 0)
347 steps = 1 + (now - fade_time) / fade_delta;
354 f->cur += f->step * steps;
360 printf ("opacity now %g\n", f->cur);
362 w->opacity = f->cur * OPAQUE;
363 need_dequeue = False;
366 if (f->cur >= f->finish)
368 w->opacity = f->finish*OPAQUE;
374 if (f->cur <= f->finish)
376 w->opacity = f->finish*OPAQUE;
380 determine_mode (dpy, w);
383 XRenderFreePicture (dpy, w->shadow);
385 w->extents = win_extents(dpy, w);
387 /* Must do this last as it might destroy f->w in callbacks */
389 dequeue_fade (dpy, f);
391 fade_time = now + fade_delta;
395 gaussian (double r, double x, double y)
397 return ((1 / (sqrt (2 * M_PI * r))) *
398 exp ((- (x * x + y * y)) / (2 * r * r)));
403 make_gaussian_map (Display *dpy, double r)
406 int size = ((int) ceil ((r * 3)) + 1) & ~1;
407 int center = size / 2;
412 c = malloc (sizeof (conv) + size * size * sizeof (double));
414 c->data = (double *) (c + 1);
416 for (y = 0; y < size; y++)
417 for (x = 0; x < size; x++)
419 g = gaussian (r, (double) (x - center), (double) (y - center));
421 c->data[y * size + x] = g;
423 /* printf ("gaussian total %f\n", t); */
424 for (y = 0; y < size; y++)
425 for (x = 0; x < size; x++)
427 c->data[y*size + x] /= t;
433 * A picture will help
435 * -center 0 width width+center
436 * -center +-----+-------------------+-----+
439 * 0 +-----+-------------------+-----+
443 * height +-----+-------------------+-----+
446 * center +-----+-------------------+-----+
450 sum_gaussian (conv *map, double opacity, int x, int y, int width, int height)
454 double *g_line = map->data;
455 int g_size = map->size;
456 int center = g_size / 2;
457 int fx_start, fx_end;
458 int fy_start, fy_end;
462 * Compute set of filter values which are "in range",
463 * that's the set with:
464 * 0 <= x + (fx-center) && x + (fx-center) < width &&
465 * 0 <= y + (fy-center) && y + (fy-center) < height
467 * 0 <= x + (fx - center) x + fx - center < width
468 * center - x <= fx fx < width + center - x
471 fx_start = center - x;
474 fx_end = width + center - x;
478 fy_start = center - y;
481 fy_end = height + center - y;
485 g_line = g_line + fy_start * g_size + fx_start;
488 for (fy = fy_start; fy < fy_end; fy++)
493 for (fx = fx_start; fx < fx_end; fx++)
499 return ((unsigned char) (v * opacity * 255.0));
502 /* precompute shadow corners and sides to save time for large windows */
504 presum_gaussian (conv *map)
506 int center = map->size/2;
512 free ((void *)shadowCorner);
514 free ((void *)shadowTop);
516 shadowCorner = (unsigned char *)(malloc ((Gsize + 1) * (Gsize + 1) * 26));
517 shadowTop = (unsigned char *)(malloc ((Gsize + 1) * 26));
519 for (x = 0; x <= Gsize; x++)
521 shadowTop[25 * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, center, Gsize * 2, Gsize * 2);
522 for(opacity = 0; opacity < 25; opacity++)
523 shadowTop[opacity * (Gsize + 1) + x] = shadowTop[25 * (Gsize + 1) + x] * opacity / 25;
524 for(y = 0; y <= x; y++)
526 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
527 = sum_gaussian (map, 1, x - center, y - center, Gsize * 2, Gsize * 2);
528 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
529 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
530 for(opacity = 0; opacity < 25; opacity++)
531 shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
532 = shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
533 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] * opacity / 25;
539 make_shadow (Display *dpy, double opacity, int width, int height)
543 int gsize = gaussianMap->size;
545 int swidth = width + gsize;
546 int sheight = height + gsize;
547 int center = gsize / 2;
551 int opacity_int = (int)(opacity * 25);
552 data = malloc (swidth * sheight * sizeof (unsigned char));
555 ximage = XCreateImage (dpy,
556 DefaultVisual(dpy, DefaultScreen(dpy)),
561 swidth, sheight, 8, swidth * sizeof (unsigned char));
568 * Build the gaussian in sections
572 * center (fill the complete data array)
575 d = shadowTop[opacity_int * (Gsize + 1) + Gsize];
577 d = sum_gaussian (gaussianMap, opacity, center, center, width, height);
578 memset(data, d, sheight * swidth);
584 if (ylimit > sheight / 2)
585 ylimit = (sheight + 1) / 2;
587 if (xlimit > swidth / 2)
588 xlimit = (swidth + 1) / 2;
590 for (y = 0; y < ylimit; y++)
591 for (x = 0; x < xlimit; x++)
593 if (xlimit == Gsize && ylimit == Gsize)
594 d = shadowCorner[opacity_int * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
596 d = sum_gaussian (gaussianMap, opacity, x - center, y - center, width, height);
597 data[y * swidth + x] = d;
598 data[(sheight - y - 1) * swidth + x] = d;
599 data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d;
600 data[y * swidth + (swidth - x - 1)] = d;
606 x_diff = swidth - (gsize * 2);
607 if (x_diff > 0 && ylimit > 0)
609 for (y = 0; y < ylimit; y++)
612 d = shadowTop[opacity_int * (Gsize + 1) + y];
614 d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height);
615 memset (&data[y * swidth + gsize], d, x_diff);
616 memset (&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
624 for (x = 0; x < xlimit; x++)
627 d = shadowTop[opacity_int * (Gsize + 1) + x];
629 d = sum_gaussian (gaussianMap, opacity, x - center, center, width, height);
630 for (y = gsize; y < sheight - gsize; y++)
632 data[y * swidth + x] = d;
633 data[y * swidth + (swidth - x - 1)] = d;
641 shadow_picture (Display *dpy, double opacity, Picture alpha_pict, int width, int height, int *wp, int *hp)
645 Picture shadowPicture;
648 shadowImage = make_shadow (dpy, opacity, width, height);
651 shadowPixmap = XCreatePixmap (dpy, root,
657 XDestroyImage (shadowImage);
661 shadowPicture = XRenderCreatePicture (dpy, shadowPixmap,
662 XRenderFindStandardFormat (dpy, PictStandardA8),
666 XDestroyImage (shadowImage);
667 XFreePixmap (dpy, shadowPixmap);
671 gc = XCreateGC (dpy, shadowPixmap, 0, 0);
674 XDestroyImage (shadowImage);
675 XFreePixmap (dpy, shadowPixmap);
676 XRenderFreePicture (dpy, shadowPicture);
680 XPutImage (dpy, shadowPixmap, gc, shadowImage, 0, 0, 0, 0,
682 shadowImage->height);
683 *wp = shadowImage->width;
684 *hp = shadowImage->height;
686 XDestroyImage (shadowImage);
687 XFreePixmap (dpy, shadowPixmap);
688 return shadowPicture;
692 solid_picture (Display *dpy, Bool argb, double a, double r, double g, double b)
696 XRenderPictureAttributes pa;
699 pixmap = XCreatePixmap (dpy, root, 1, 1, argb ? 32 : 8);
704 picture = XRenderCreatePicture (dpy, pixmap,
705 XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8),
710 XFreePixmap (dpy, pixmap);
714 c.alpha = a * 0xffff;
716 c.green = g * 0xffff;
718 XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1);
719 XFreePixmap (dpy, pixmap);
724 discard_ignore (Display *dpy, unsigned long sequence)
728 if ((long) (sequence - ignore_head->sequence) > 0)
730 ignore *next = ignore_head->next;
734 ignore_tail = &ignore_head;
742 set_ignore (Display *dpy, unsigned long sequence)
744 ignore *i = malloc (sizeof (ignore));
747 i->sequence = sequence;
750 ignore_tail = &i->next;
754 should_ignore (Display *dpy, unsigned long sequence)
756 discard_ignore (dpy, sequence);
757 return ignore_head && ignore_head->sequence == sequence;
761 find_win (Display *dpy, Window id)
765 for (w = list; w; w = w->next)
771 static const char *backgroundProps[] = {
778 root_tile (Display *dpy)
784 unsigned long nitems;
785 unsigned long bytes_after;
788 XRenderPictureAttributes pa;
792 for (p = 0; backgroundProps[p]; p++)
794 if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False),
795 0, 4, False, AnyPropertyType,
796 &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success &&
797 actual_type == XInternAtom (dpy, "PIXMAP", False) && actual_format == 32 && nitems == 1)
799 memcpy (&pixmap, prop, 4);
807 pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr));
811 picture = XRenderCreatePicture (dpy, pixmap,
812 XRenderFindVisualFormat (dpy,
813 DefaultVisual (dpy, scr)),
819 c.red = c.green = c.blue = 0x8080;
821 XRenderFillRectangle (dpy, PictOpSrc, picture, &c,
828 paint_root (Display *dpy)
831 rootTile = root_tile (dpy);
833 XRenderComposite (dpy, PictOpSrc,
834 rootTile, None, rootBuffer,
835 0, 0, 0, 0, 0, 0, root_width, root_height);
839 win_extents (Display *dpy, win *w)
845 r.width = w->a.width + w->a.border_width * 2;
846 r.height = w->a.height + w->a.border_width * 2;
847 if (winTypeShadow[w->windowType])
849 if (compMode == CompServerShadows || w->mode != WINDOW_ARGB)
853 if (compMode == CompServerShadows)
857 w->shadow_width = w->a.width;
858 w->shadow_height = w->a.height;
862 w->shadow_dx = shadowOffsetX;
863 w->shadow_dy = shadowOffsetY;
866 double opacity = shadowOpacity;
867 if (w->mode == WINDOW_TRANS)
868 opacity = opacity * ((double)w->opacity)/((double)OPAQUE);
869 w->shadow = shadow_picture (dpy, opacity, w->alphaPict,
870 w->a.width + w->a.border_width * 2,
871 w->a.height + w->a.border_width * 2,
872 &w->shadow_width, &w->shadow_height);
875 sr.x = w->a.x + w->shadow_dx;
876 sr.y = w->a.y + w->shadow_dy;
877 sr.width = w->shadow_width;
878 sr.height = w->shadow_height;
881 r.width = (r.x + r.width) - sr.x;
886 r.height = (r.y + r.height) - sr.y;
889 if (sr.x + sr.width > r.x + r.width)
890 r.width = sr.x + sr.width - r.x;
891 if (sr.y + sr.height > r.y + r.height)
892 r.height = sr.y + sr.height - r.y;
895 return XFixesCreateRegion (dpy, &r, 1);
899 border_size (Display *dpy, win *w)
901 XserverRegion border;
903 * if window doesn't exist anymore, this will generate an error
904 * as well as not generate a region. Perhaps a better XFixes
905 * architecture would be to have a request that copies instead
906 * of creates, that way you'd just end up with an empty region
907 * instead of an invalid XID.
909 set_ignore (dpy, NextRequest (dpy));
910 border = XFixesCreateRegionFromWindow (dpy, w->id, WindowRegionBounding);
912 set_ignore (dpy, NextRequest (dpy));
913 XFixesTranslateRegion (dpy, border,
914 w->a.x + w->a.border_width,
915 w->a.y + w->a.border_width);
920 paint_all (Display *dpy, XserverRegion region)
930 r.width = root_width;
931 r.height = root_height;
932 region = XFixesCreateRegion (dpy, &r, 1);
935 rootBuffer = rootPicture;
939 Pixmap rootPixmap = XCreatePixmap (dpy, root, root_width, root_height,
940 DefaultDepth (dpy, scr));
941 rootBuffer = XRenderCreatePicture (dpy, rootPixmap,
942 XRenderFindVisualFormat (dpy,
943 DefaultVisual (dpy, scr)),
945 XFreePixmap (dpy, rootPixmap);
948 XFixesSetPictureClipRegion (dpy, rootPicture, 0, 0, region);
950 XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture,
951 0, 0, 0, 0, 0, 0, root_width, root_height);
956 for (w = list; w; w = w->next)
962 /* never painted, ignore it */
965 /* if invisible, ignore it */
966 if (w->a.x + w->a.width < 1 || w->a.y + w->a.height < 1
967 || w->a.x >= root_width || w->a.y >= root_height)
971 XRenderPictureAttributes pa;
972 XRenderPictFormat *format;
973 Drawable draw = w->id;
975 #if HAS_NAME_WINDOW_PIXMAP
976 if (hasNamePixmap && !w->pixmap)
977 w->pixmap = XCompositeNameWindowPixmap (dpy, w->id);
981 format = XRenderFindVisualFormat (dpy, w->a.visual);
982 pa.subwindow_mode = IncludeInferiors;
983 w->picture = XRenderCreatePicture (dpy, draw,
989 printf (" 0x%x", w->id);
995 set_ignore (dpy, NextRequest (dpy));
996 XFixesDestroyRegion (dpy, w->borderSize);
997 w->borderSize = None;
1001 XFixesDestroyRegion (dpy, w->extents);
1006 XFixesDestroyRegion (dpy, w->borderClip);
1007 w->borderClip = None;
1011 w->borderSize = border_size (dpy, w);
1013 w->extents = win_extents (dpy, w);
1014 if (w->mode == WINDOW_SOLID)
1017 #if HAS_NAME_WINDOW_PIXMAP
1020 wid = w->a.width + w->a.border_width * 2;
1021 hei = w->a.height + w->a.border_width * 2;
1023 x = w->a.x + w->a.border_width;
1024 y = w->a.y + w->a.border_width;
1028 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1029 set_ignore (dpy, NextRequest (dpy));
1030 XFixesSubtractRegion (dpy, region, region, w->borderSize);
1031 set_ignore (dpy, NextRequest (dpy));
1032 XRenderComposite (dpy, PictOpSrc, w->picture, None, rootBuffer,
1038 w->borderClip = XFixesCreateRegion (dpy, 0, 0);
1039 XFixesCopyRegion (dpy, w->borderClip, region);
1048 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1050 for (w = t; w; w = w->prev_trans)
1052 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, w->borderClip);
1053 if (winTypeShadow[w->windowType]) {
1057 case CompServerShadows:
1058 set_ignore (dpy, NextRequest (dpy));
1059 if (w->opacity != OPAQUE && !w->shadowPict)
1060 w->shadowPict = solid_picture (dpy, True,
1061 (double) w->opacity / OPAQUE * 0.3,
1063 XRenderComposite (dpy, PictOpOver,
1064 w->shadowPict ? w->shadowPict : transBlackPicture,
1065 w->picture, rootBuffer,
1067 w->a.x + w->shadow_dx,
1068 w->a.y + w->shadow_dy,
1069 w->shadow_width, w->shadow_height);
1071 case CompClientShadows:
1072 XRenderComposite (dpy, PictOpOver, blackPicture, w->shadow, rootBuffer,
1074 w->a.x + w->shadow_dx,
1075 w->a.y + w->shadow_dy,
1076 w->shadow_width, w->shadow_height);
1080 if (w->opacity != OPAQUE && !w->alphaPict)
1081 w->alphaPict = solid_picture (dpy, False,
1082 (double) w->opacity / OPAQUE, 0, 0, 0);
1083 if (w->mode == WINDOW_TRANS)
1086 #if HAS_NAME_WINDOW_PIXMAP
1089 wid = w->a.width + w->a.border_width * 2;
1090 hei = w->a.height + w->a.border_width * 2;
1092 x = w->a.x + w->a.border_width;
1093 y = w->a.y + w->a.border_width;
1097 set_ignore (dpy, NextRequest (dpy));
1098 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1102 else if (w->mode == WINDOW_ARGB)
1105 #if HAS_NAME_WINDOW_PIXMAP
1108 wid = w->a.width + w->a.border_width * 2;
1109 hei = w->a.height + w->a.border_width * 2;
1111 x = w->a.x + w->a.border_width;
1112 y = w->a.y + w->a.border_width;
1116 set_ignore (dpy, NextRequest (dpy));
1117 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1121 XFixesDestroyRegion (dpy, w->borderClip);
1122 w->borderClip = None;
1124 XFixesDestroyRegion (dpy, region);
1125 if (rootBuffer != rootPicture)
1127 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, None);
1128 XRenderComposite (dpy, PictOpSrc, rootBuffer, None, rootPicture,
1129 0, 0, 0, 0, 0, 0, root_width, root_height);
1134 add_damage (Display *dpy, XserverRegion damage)
1138 XFixesUnionRegion (dpy, allDamage, allDamage, damage);
1139 XFixesDestroyRegion (dpy, damage);
1146 repair_win (Display *dpy, win *w)
1148 XserverRegion parts;
1152 parts = win_extents (dpy, w);
1153 set_ignore (dpy, NextRequest (dpy));
1154 XDamageSubtract (dpy, w->damage, None, None);
1159 parts = XFixesCreateRegion (dpy, 0, 0);
1160 set_ignore (dpy, NextRequest (dpy));
1161 XDamageSubtract (dpy, w->damage, None, parts);
1162 XFixesTranslateRegion (dpy, parts,
1163 w->a.x + w->a.border_width,
1164 w->a.y + w->a.border_width);
1165 if (compMode == CompServerShadows)
1167 o = XFixesCreateRegion (dpy, 0, 0);
1168 XFixesCopyRegion (dpy, o, parts);
1169 XFixesTranslateRegion (dpy, o, w->shadow_dx, w->shadow_dy);
1170 XFixesUnionRegion (dpy, parts, parts, o);
1171 XFixesDestroyRegion (dpy, o);
1174 add_damage (dpy, parts);
1179 wintype_name(wintype type)
1183 case WINTYPE_DESKTOP: t = "desktop"; break;
1184 case WINTYPE_DOCK: t = "dock"; break;
1185 case WINTYPE_TOOLBAR: t = "toolbar"; break;
1186 case WINTYPE_MENU: t = "menu"; break;
1187 case WINTYPE_UTILITY: t = "utility"; break;
1188 case WINTYPE_SPLASH: t = "slash"; break;
1189 case WINTYPE_DIALOG: t = "dialog"; break;
1190 case WINTYPE_NORMAL: t = "normal"; break;
1191 case WINTYPE_DROPDOWN_MENU: t = "dropdown"; break;
1192 case WINTYPE_POPUP_MENU: t = "popup"; break;
1193 case WINTYPE_TOOLTIP: t = "tooltip"; break;
1194 case WINTYPE_NOTIFY: t = "notification"; break;
1195 case WINTYPE_COMBO: t = "combo"; break;
1196 case WINTYPE_DND: t = "dnd"; break;
1197 default: t = "unknown"; break;
1203 get_wintype_prop(Display * dpy, Window w)
1208 unsigned long n, left, off;
1209 unsigned char *data;
1215 set_ignore (dpy, NextRequest (dpy));
1216 int result = XGetWindowProperty (dpy, w, winTypeAtom, off, 1L, False,
1217 XA_ATOM, &actual, &format,
1220 if (result != Success)
1226 for (i = 0; i < NUM_WINTYPES; ++i) {
1228 memcpy (&a, data, sizeof (Atom));
1229 if (a == winType[i]) {
1236 XFree ( (void *) data);
1240 } while (left >= 4 && ret == (wintype)-1);
1246 determine_wintype (Display *dpy, Window w, Window top)
1248 Window root_return, parent_return;
1249 Window *children = NULL;
1250 unsigned int nchildren, i;
1253 type = get_wintype_prop (dpy, w);
1254 if (type != (wintype)-1)
1257 set_ignore (dpy, NextRequest (dpy));
1258 if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
1261 /* XQueryTree failed. */
1263 XFree ((void *)children);
1267 for (i = 0;i < nchildren;i++)
1269 type = determine_wintype (dpy, children[i], top);
1270 if (type != (wintype)-1)
1275 XFree ((void *)children);
1280 return WINTYPE_NORMAL;
1284 get_opacity_prop (Display *dpy, win *w, unsigned int def);
1287 configure_win (Display *dpy, XConfigureEvent *ce);
1290 map_win (Display *dpy, Window id, unsigned long sequence, Bool fade)
1292 win *w = find_win (dpy, id);
1297 w->a.map_state = IsViewable;
1299 w->windowType = determine_wintype (dpy, w->id, w->id);
1301 printf("window 0x%x type %s\n", w->id, wintype_name(w->windowType));
1304 /* select before reading the property so that no property changes are lost */
1305 XSelectInput (dpy, id, PropertyChangeMask);
1306 w->opacity = get_opacity_prop (dpy, w, OPAQUE);
1308 determine_mode (dpy, w);
1311 w->damage_bounds.x = w->damage_bounds.y = 0;
1312 w->damage_bounds.width = w->damage_bounds.height = 0;
1316 if (fade && winTypeFade[w->windowType])
1317 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1319 /* if any configure events happened while the window was unmapped, then
1320 configure the window to its correct place */
1321 if (w->need_configure)
1322 configure_win (dpy, &w->queue_configure);
1326 finish_unmap_win (Display *dpy, win *w)
1332 if (w->extents != None)
1334 add_damage (dpy, w->extents); /* destroys region */
1338 #if HAS_NAME_WINDOW_PIXMAP
1341 XFreePixmap (dpy, w->pixmap);
1348 set_ignore (dpy, NextRequest (dpy));
1349 XRenderFreePicture (dpy, w->picture);
1355 set_ignore (dpy, NextRequest (dpy));
1356 XFixesDestroyRegion (dpy, w->borderSize);
1357 w->borderSize = None;
1361 XRenderFreePicture (dpy, w->shadow);
1366 XFixesDestroyRegion (dpy, w->borderClip);
1367 w->borderClip = None;
1373 #if HAS_NAME_WINDOW_PIXMAP
1375 unmap_callback (Display *dpy, win *w)
1377 finish_unmap_win (dpy, w);
1382 unmap_win (Display *dpy, Window id, Bool fade)
1384 win *w = find_win (dpy, id);
1387 w->a.map_state = IsUnmapped;
1389 /* don't care about properties anymore */
1390 set_ignore (dpy, NextRequest (dpy));
1391 XSelectInput(dpy, w->id, 0);
1393 #if HAS_NAME_WINDOW_PIXMAP
1394 if (w->pixmap && fade && winTypeFade[w->windowType])
1395 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step, unmap_callback, False, True);
1398 finish_unmap_win (dpy, w);
1401 /* Get the opacity prop from window
1406 get_opacity_prop(Display *dpy, win *w, unsigned int def)
1410 unsigned long n, left;
1412 unsigned char *data;
1413 int result = XGetWindowProperty(dpy, w->id, opacityAtom, 0L, 1L, False,
1414 XA_CARDINAL, &actual, &format,
1416 if (result == Success && data != NULL)
1419 memcpy (&i, data, sizeof (unsigned int));
1420 XFree( (void *) data);
1426 /* Get the opacity property from the window in a percent format
1428 otherwise: the value
1431 get_opacity_percent(Display *dpy, win *w)
1433 double def = winTypeOpacity[w->windowType];
1434 unsigned int opacity = get_opacity_prop (dpy, w, (unsigned int)(OPAQUE*def));
1436 return opacity*1.0/OPAQUE;
1440 determine_mode(Display *dpy, win *w)
1443 XRenderPictFormat *format;
1445 /* if trans prop == -1 fall back on previous tests*/
1449 XRenderFreePicture (dpy, w->alphaPict);
1450 w->alphaPict = None;
1454 XRenderFreePicture (dpy, w->shadowPict);
1455 w->shadowPict = None;
1458 if (w->a.class == InputOnly)
1464 format = XRenderFindVisualFormat (dpy, w->a.visual);
1467 if (format && format->type == PictTypeDirect && format->direct.alphaMask)
1471 else if (w->opacity != OPAQUE)
1473 mode = WINDOW_TRANS;
1477 mode = WINDOW_SOLID;
1482 XserverRegion damage;
1483 damage = XFixesCreateRegion (dpy, 0, 0);
1484 XFixesCopyRegion (dpy, damage, w->extents);
1485 add_damage (dpy, damage);
1490 add_win (Display *dpy, Window id, Window prev)
1492 win *new = malloc (sizeof (win));
1499 for (p = &list; *p; p = &(*p)->next)
1500 if ((*p)->id == prev)
1506 set_ignore (dpy, NextRequest (dpy));
1507 if (!XGetWindowAttributes (dpy, id, &new->a))
1514 new->usable = False;
1516 #if HAS_NAME_WINDOW_PIXMAP
1519 new->picture = None;
1520 if (new->a.class == InputOnly)
1522 new->damage_sequence = 0;
1527 new->damage_sequence = NextRequest (dpy);
1528 new->damage = XDamageCreate (dpy, id, XDamageReportNonEmpty);
1530 new->alphaPict = None;
1531 new->shadowPict = None;
1532 new->borderSize = None;
1533 new->extents = None;
1537 new->shadow_width = 0;
1538 new->shadow_height = 0;
1539 new->opacity = OPAQUE;
1540 new->need_configure = False;
1542 new->borderClip = None;
1543 new->prev_trans = 0;
1547 if (new->a.map_state == IsViewable)
1548 map_win (dpy, id, new->damage_sequence - 1, True);
1552 restack_win (Display *dpy, win *w, Window new_above)
1557 old_above = w->next->id;
1560 if (old_above != new_above)
1565 for (prev = &list; *prev; prev = &(*prev)->next)
1571 for (prev = &list; *prev; prev = &(*prev)->next)
1573 if ((*prev)->id == new_above)
1582 configure_win (Display *dpy, XConfigureEvent *ce)
1584 win *w = find_win (dpy, ce->window);
1585 XserverRegion damage = None;
1589 if (ce->window == root)
1593 XRenderFreePicture (dpy, rootBuffer);
1596 root_width = ce->width;
1597 root_height = ce->height;
1602 if (w->a.map_state == IsUnmapped) {
1603 /* save the configure event for when the window maps */
1604 w->need_configure = True;
1605 w->queue_configure = *ce;
1608 w->need_configure = False;
1614 damage = XFixesCreateRegion (dpy, 0, 0);
1615 if (w->extents != None)
1616 XFixesCopyRegion (dpy, damage, w->extents);
1621 if (w->a.width != ce->width || w->a.height != ce->height)
1623 #if HAS_NAME_WINDOW_PIXMAP
1626 XFreePixmap (dpy, w->pixmap);
1630 XRenderFreePicture (dpy, w->picture);
1637 XRenderFreePicture (dpy, w->shadow);
1641 w->a.width = ce->width;
1642 w->a.height = ce->height;
1643 w->a.border_width = ce->border_width;
1644 if (w->a.map_state != IsUnmapped && damage)
1646 XserverRegion extents = win_extents (dpy, w);
1647 XFixesUnionRegion (dpy, damage, damage, extents);
1648 XFixesDestroyRegion (dpy, extents);
1649 add_damage (dpy, damage);
1652 w->a.override_redirect = ce->override_redirect;
1653 restack_win (dpy, w, ce->above);
1658 circulate_win (Display *dpy, XCirculateEvent *ce)
1660 win *w = find_win (dpy, ce->window);
1666 if (ce->place == PlaceOnTop)
1667 new_above = list->id;
1670 restack_win (dpy, w, new_above);
1675 finish_destroy_win (Display *dpy, Window id)
1679 for (prev = &list; (w = *prev); prev = &w->next)
1682 finish_unmap_win (dpy, w);
1686 XRenderFreePicture (dpy, w->alphaPict);
1687 w->alphaPict = None;
1691 XRenderFreePicture (dpy, w->shadowPict);
1692 w->shadowPict = None;
1694 if (w->damage != None)
1696 set_ignore (dpy, NextRequest (dpy));
1697 XDamageDestroy (dpy, w->damage);
1701 cleanup_fade (dpy, w);
1707 #if HAS_NAME_WINDOW_PIXMAP
1709 destroy_callback (Display *dpy, win *w)
1711 finish_destroy_win (dpy, w->id);
1716 destroy_win (Display *dpy, Window id, Bool fade)
1718 win *w = find_win (dpy, id);
1720 #if HAS_NAME_WINDOW_PIXMAP
1721 if (w && w->pixmap && fade && winTypeFade[w->windowType])
1722 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step,
1723 destroy_callback, False, (w->a.map_state != IsUnmapped));
1727 finish_destroy_win (dpy, id);
1735 printf ("\t%08lx: %d x %d + %d + %d (%d)\n", w->id,
1736 w->a.width, w->a.height, w->a.x, w->a.y, w->a.border_width);
1745 printf ("windows:\n");
1746 for (w = list; w; w = w->next)
1752 damage_win (Display *dpy, XDamageNotifyEvent *de)
1754 win *w = find_win (dpy, de->drawable);
1761 if (w->damage_bounds.width == 0 || w->damage_bounds.height == 0)
1763 w->damage_bounds = de->area;
1767 if (de->area.x < w->damage_bounds.x)
1769 w->damage_bounds.width += (w->damage_bounds.x - de->area.x);
1770 w->damage_bounds.x = de->area.x;
1772 if (de->area.y < w->damage_bounds.y)
1774 w->damage_bounds.height += (w->damage_bounds.y - de->area.y);
1775 w->damage_bounds.y = de->area.y;
1777 if (de->area.x + de->area.width > w->damage_bounds.x + w->damage_bounds.width)
1778 w->damage_bounds.width = de->area.x + de->area.width - w->damage_bounds.x;
1779 if (de->area.y + de->area.height > w->damage_bounds.y + w->damage_bounds.height)
1780 w->damage_bounds.height = de->area.y + de->area.height - w->damage_bounds.y;
1783 printf ("unusable damage %d, %d: %d x %d bounds %d, %d: %d x %d\n",
1790 w->damage_bounds.width,
1791 w->damage_bounds.height);
1793 if (w->damage_bounds.x <= 0 &&
1794 w->damage_bounds.y <= 0 &&
1795 w->a.width <= w->damage_bounds.x + w->damage_bounds.width &&
1796 w->a.height <= w->damage_bounds.y + w->damage_bounds.height)
1799 if (winTypeFade[w->windowType])
1800 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1806 repair_win (dpy, w);
1810 error (Display *dpy, XErrorEvent *ev)
1813 const char *name = 0;
1815 if (should_ignore (dpy, ev->serial))
1818 if (ev->request_code == composite_opcode &&
1819 ev->minor_code == X_CompositeRedirectSubwindows)
1821 fprintf (stderr, "Another composite manager is already running\n");
1825 o = ev->error_code - xfixes_error;
1827 case BadRegion: name = "BadRegion"; break;
1830 o = ev->error_code - damage_error;
1832 case BadDamage: name = "BadDamage"; break;
1835 o = ev->error_code - render_error;
1837 case BadPictFormat: name ="BadPictFormat"; break;
1838 case BadPicture: name ="BadPicture"; break;
1839 case BadPictOp: name ="BadPictOp"; break;
1840 case BadGlyphSet: name ="BadGlyphSet"; break;
1841 case BadGlyph: name ="BadGlyph"; break;
1845 printf ("error %d request %d minor %d serial %lu\n",
1846 ev->error_code, ev->request_code, ev->minor_code, ev->serial);
1848 /* abort (); this is just annoying to most people */
1853 expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
1855 XserverRegion region = XFixesCreateRegion (dpy, rects, nrects);
1857 add_damage (dpy, region);
1862 ev_serial (XEvent *ev)
1864 if (ev->type & 0x7f != KeymapNotify)
1865 return ev->xany.serial;
1866 return NextRequest (ev->xany.display);
1870 ev_name (XEvent *ev)
1872 static char buf[128];
1873 switch (ev->type & 0x7f) {
1880 case ReparentNotify:
1882 case CirculateNotify:
1885 if (ev->type == damage_event + XDamageNotify)
1887 sprintf (buf, "Event %d", ev->type);
1893 ev_window (XEvent *ev)
1897 return ev->xexpose.window;
1899 return ev->xmap.window;
1901 return ev->xunmap.window;
1902 case ReparentNotify:
1903 return ev->xreparent.window;
1904 case CirculateNotify:
1905 return ev->xcirculate.window;
1907 if (ev->type == damage_event + XDamageNotify)
1908 return ((XDamageNotifyEvent *) ev)->drawable;
1915 usage (char *program)
1917 fprintf (stderr, "%s v1.1.3\n", program);
1918 fprintf (stderr, "usage: %s [options]\n", program);
1919 fprintf (stderr, "Options\n");
1920 fprintf (stderr, " -d display\n Specifies which display should be managed.\n");
1921 fprintf (stderr, " -r radius\n Specifies the blur radius for client-side shadows. (default 12)\n");
1922 fprintf (stderr, " -o opacity\n Specifies the translucency for client-side shadows. (default .75)\n");
1923 fprintf (stderr, " -l left-offset\n Specifies the left offset for client-side shadows. (default -15)\n");
1924 fprintf (stderr, " -t top-offset\n Specifies the top offset for clinet-side shadows. (default -15)\n");
1925 fprintf (stderr, " -I fade-in-step\n Specifies the opacity change between steps while fading in. (default 0.028)\n");
1926 fprintf (stderr, " -O fade-out-step\n Specifies the opacity change between steps while fading out. (default 0.03)\n");
1927 fprintf (stderr, " -D fade-delta-time\n Specifies the time between steps in a fade in milliseconds. (default 10)\n");
1928 fprintf (stderr, " -m opacity\n Specifies the opacity for menus. (default 1.0)\n");
1929 fprintf (stderr, " -a\n Use automatic server-side compositing. Faster, but no special effects.\n");
1930 fprintf (stderr, " -c\n Draw client-side shadows with fuzzy edges.\n");
1931 fprintf (stderr, " -C\n Avoid drawing shadows on dock/panel windows.\n");
1932 fprintf (stderr, " -f\n Fade windows in/out when opening/closing.\n");
1933 fprintf (stderr, " -F\n Fade windows during opacity changes.\n");
1934 fprintf (stderr, " -n\n Normal client-side compositing with transparency support\n");
1935 fprintf (stderr, " -s\n Draw server-side shadows with sharp edges.\n");
1936 fprintf (stderr, " -S\n Enable synchronous operation (for debugging).\n");
1941 register_cm (int scr)
1948 if (scr < 0) return;
1950 w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
1953 Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
1956 len = strlen(REGISTER_PROP) + 2;
1963 snprintf(buf, len, REGISTER_PROP"%d", scr);
1965 a = XInternAtom (dpy, buf, False);
1968 XSetSelectionOwner (dpy, a, w, 0);
1972 main (int argc, char **argv)
1975 Window root_return, parent_return;
1977 unsigned int nchildren;
1979 XRenderPictureAttributes pa;
1980 XRectangle *expose_rects = 0;
1981 int size_expose = 0;
1985 int composite_major, composite_minor;
1988 Bool noDockShadow = False;
1990 for (i = 0; i < NUM_WINTYPES; ++i) {
1991 winTypeFade[i] = False;
1992 winTypeShadow[i] = False;
1993 winTypeOpacity[i] = 1.0;
1996 /* don't bother to draw a shadow for the desktop */
1997 winTypeShadow[WINTYPE_DESKTOP] = False;
1999 while ((o = getopt (argc, argv, "D:I:O:d:r:o:m:l:t:scnfFCaS")) != -1)
2006 fade_delta = atoi (optarg);
2011 fade_in_step = atof (optarg);
2012 if (fade_in_step <= 0)
2013 fade_in_step = 0.01;
2016 fade_out_step = atof (optarg);
2017 if (fade_out_step <= 0)
2018 fade_out_step = 0.01;
2021 compMode = CompServerShadows;
2022 for (i = 0; i < NUM_WINTYPES; ++i)
2023 winTypeShadow[i] = True;
2026 compMode = CompClientShadows;
2027 for (i = 0; i < NUM_WINTYPES; ++i)
2028 winTypeShadow[i] = True;
2031 noDockShadow = True;
2034 compMode = CompSimple;
2035 for (i = 0; i < NUM_WINTYPES; ++i)
2036 winTypeShadow[i] = False;
2039 winTypeOpacity[WINTYPE_DROPDOWN_MENU] = atof (optarg);
2040 winTypeOpacity[WINTYPE_POPUP_MENU] = atof (optarg);
2043 for (i = 0; i < NUM_WINTYPES; ++i)
2044 winTypeFade[i] = True;
2050 autoRedirect = True;
2056 shadowRadius = atoi (optarg);
2059 shadowOpacity = atof (optarg);
2062 shadowOffsetX = atoi (optarg);
2065 shadowOffsetY = atoi (optarg);
2074 winTypeShadow[WINTYPE_DOCK] = False;
2076 dpy = XOpenDisplay (display);
2079 fprintf (stderr, "Can't open display\n");
2082 XSetErrorHandler (error);
2084 XSynchronize (dpy, 1);
2085 scr = DefaultScreen (dpy);
2086 root = RootWindow (dpy, scr);
2088 if (!XRenderQueryExtension (dpy, &render_event, &render_error))
2090 fprintf (stderr, "No render extension\n");
2093 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode,
2094 &composite_event, &composite_error))
2096 fprintf (stderr, "No composite extension\n");
2099 XCompositeQueryVersion (dpy, &composite_major, &composite_minor);
2100 #if HAS_NAME_WINDOW_PIXMAP
2101 if (composite_major > 0 || composite_minor >= 2)
2102 hasNamePixmap = True;
2105 if (!XDamageQueryExtension (dpy, &damage_event, &damage_error))
2107 fprintf (stderr, "No damage extension\n");
2110 if (!XFixesQueryExtension (dpy, &xfixes_event, &xfixes_error))
2112 fprintf (stderr, "No XFixes extension\n");
2119 opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
2120 winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
2121 winType[WINTYPE_DESKTOP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
2122 winType[WINTYPE_DOCK] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
2123 winType[WINTYPE_TOOLBAR] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
2124 winType[WINTYPE_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
2125 winType[WINTYPE_UTILITY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
2126 winType[WINTYPE_SPLASH] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
2127 winType[WINTYPE_DIALOG] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
2128 winType[WINTYPE_NORMAL] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
2129 winType[WINTYPE_DROPDOWN_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
2130 winType[WINTYPE_POPUP_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", False);
2131 winType[WINTYPE_TOOLTIP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
2132 winType[WINTYPE_NOTIFY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
2133 winType[WINTYPE_COMBO] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_COMBO", False);
2134 winType[WINTYPE_DND] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DND", False);
2136 pa.subwindow_mode = IncludeInferiors;
2138 if (compMode == CompClientShadows)
2140 gaussianMap = make_gaussian_map(dpy, shadowRadius);
2141 presum_gaussian (gaussianMap);
2144 root_width = DisplayWidth (dpy, scr);
2145 root_height = DisplayHeight (dpy, scr);
2147 rootPicture = XRenderCreatePicture (dpy, root,
2148 XRenderFindVisualFormat (dpy,
2149 DefaultVisual (dpy, scr)),
2152 blackPicture = solid_picture (dpy, True, 1, 0, 0, 0);
2153 if (compMode == CompServerShadows)
2154 transBlackPicture = solid_picture (dpy, True, 0.3, 0, 0, 0);
2159 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectAutomatic);
2162 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual);
2163 XSelectInput (dpy, root,
2164 SubstructureNotifyMask|
2166 StructureNotifyMask|
2167 PropertyChangeMask);
2168 XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren);
2169 for (i = 0; i < nchildren; i++)
2170 add_win (dpy, children[i], i ? children[i-1] : None);
2173 XUngrabServer (dpy);
2174 ufd.fd = ConnectionNumber (dpy);
2175 ufd.events = POLLIN;
2177 paint_all (dpy, None);
2186 if (poll (&ufd, 1, fade_timeout()) == 0)
2193 XNextEvent (dpy, &ev);
2194 if ((ev.type & 0x7f) != KeymapNotify)
2195 discard_ignore (dpy, ev.xany.serial);
2197 printf ("event %10.10s serial 0x%08x window 0x%08x\n",
2198 ev_name(&ev), ev_serial (&ev), ev_window (&ev));
2200 if (!autoRedirect) switch (ev.type) {
2202 add_win (dpy, ev.xcreatewindow.window, 0);
2204 case ConfigureNotify:
2205 configure_win (dpy, &ev.xconfigure);
2208 destroy_win (dpy, ev.xdestroywindow.window, True);
2211 map_win (dpy, ev.xmap.window, ev.xmap.serial, True);
2214 unmap_win (dpy, ev.xunmap.window, True);
2216 case ReparentNotify:
2217 if (ev.xreparent.parent == root)
2218 add_win (dpy, ev.xreparent.window, 0);
2220 destroy_win (dpy, ev.xreparent.window, True);
2222 case CirculateNotify:
2223 circulate_win (dpy, &ev.xcirculate);
2226 if (ev.xexpose.window == root)
2228 int more = ev.xexpose.count + 1;
2229 if (n_expose == size_expose)
2233 expose_rects = realloc (expose_rects,
2234 (size_expose + more) *
2235 sizeof (XRectangle));
2236 size_expose += more;
2240 expose_rects = malloc (more * sizeof (XRectangle));
2244 expose_rects[n_expose].x = ev.xexpose.x;
2245 expose_rects[n_expose].y = ev.xexpose.y;
2246 expose_rects[n_expose].width = ev.xexpose.width;
2247 expose_rects[n_expose].height = ev.xexpose.height;
2249 if (ev.xexpose.count == 0)
2251 expose_root (dpy, root, expose_rects, n_expose);
2256 case PropertyNotify:
2257 for (p = 0; backgroundProps[p]; p++)
2259 if (ev.xproperty.atom == XInternAtom (dpy, backgroundProps[p], False))
2263 XClearArea (dpy, root, 0, 0, 0, 0, True);
2264 XRenderFreePicture (dpy, rootTile);
2270 /* check if Trans property was changed */
2271 if (ev.xproperty.atom == opacityAtom)
2273 /* reset mode and redraw window */
2274 win * w = find_win(dpy, ev.xproperty.window);
2278 set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w),
2279 fade_out_step, 0, True, False);
2282 w->opacity = get_opacity_prop(dpy, w, OPAQUE);
2283 determine_mode(dpy, w);
2286 XRenderFreePicture (dpy, w->shadow);
2288 w->extents = win_extents (dpy, w);
2295 if (ev.type == damage_event + XDamageNotify)
2296 damage_win (dpy, (XDamageNotifyEvent *) &ev);
2299 } while (QLength (dpy));
2300 if (allDamage && !autoRedirect)
2303 paint_all (dpy, allDamage);
2307 clipChanged = False;