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);
316 if (w->extents != None)
317 XFixesDestroyRegion (dpy, w->extents);
319 /* rebuild the shadow */
320 w->extents = win_extents (dpy, w);
323 /* fading windows need to be drawn, mark them as damaged.
324 when a window maps, if it tries to fade in but it already at the right
325 opacity (map/unmap/map fast) then it will never get drawn without this
337 now = get_time_in_milliseconds();
338 delta = fade_time - now;
341 /* printf ("timeout %d\n", delta); */
346 run_fades (Display *dpy)
348 int now = get_time_in_milliseconds();
354 printf ("run fades\n");
356 if (fade_time - now > 0)
358 steps = 1 + (now - fade_time) / fade_delta;
365 f->cur += f->step * steps;
371 printf ("opacity now %g\n", f->cur);
373 w->opacity = f->cur * OPAQUE;
374 need_dequeue = False;
377 if (f->cur >= f->finish)
379 w->opacity = f->finish*OPAQUE;
385 if (f->cur <= f->finish)
387 w->opacity = f->finish*OPAQUE;
391 determine_mode (dpy, w);
394 XRenderFreePicture (dpy, w->shadow);
397 if (w->extents != None)
398 XFixesDestroyRegion (dpy, w->extents);
400 /* rebuild the shadow */
401 w->extents = win_extents(dpy, w);
403 /* Must do this last as it might destroy f->w in callbacks */
405 dequeue_fade (dpy, f);
407 fade_time = now + fade_delta;
411 gaussian (double r, double x, double y)
413 return ((1 / (sqrt (2 * M_PI * r))) *
414 exp ((- (x * x + y * y)) / (2 * r * r)));
419 make_gaussian_map (Display *dpy, double r)
422 int size = ((int) ceil ((r * 3)) + 1) & ~1;
423 int center = size / 2;
428 c = malloc (sizeof (conv) + size * size * sizeof (double));
430 c->data = (double *) (c + 1);
432 for (y = 0; y < size; y++)
433 for (x = 0; x < size; x++)
435 g = gaussian (r, (double) (x - center), (double) (y - center));
437 c->data[y * size + x] = g;
439 /* printf ("gaussian total %f\n", t); */
440 for (y = 0; y < size; y++)
441 for (x = 0; x < size; x++)
443 c->data[y*size + x] /= t;
449 * A picture will help
451 * -center 0 width width+center
452 * -center +-----+-------------------+-----+
455 * 0 +-----+-------------------+-----+
459 * height +-----+-------------------+-----+
462 * center +-----+-------------------+-----+
466 sum_gaussian (conv *map, double opacity, int x, int y, int width, int height)
470 double *g_line = map->data;
471 int g_size = map->size;
472 int center = g_size / 2;
473 int fx_start, fx_end;
474 int fy_start, fy_end;
478 * Compute set of filter values which are "in range",
479 * that's the set with:
480 * 0 <= x + (fx-center) && x + (fx-center) < width &&
481 * 0 <= y + (fy-center) && y + (fy-center) < height
483 * 0 <= x + (fx - center) x + fx - center < width
484 * center - x <= fx fx < width + center - x
487 fx_start = center - x;
490 fx_end = width + center - x;
494 fy_start = center - y;
497 fy_end = height + center - y;
501 g_line = g_line + fy_start * g_size + fx_start;
504 for (fy = fy_start; fy < fy_end; fy++)
509 for (fx = fx_start; fx < fx_end; fx++)
515 return ((unsigned char) (v * opacity * 255.0));
518 /* precompute shadow corners and sides to save time for large windows */
520 presum_gaussian (conv *map)
522 int center = map->size/2;
528 free ((void *)shadowCorner);
530 free ((void *)shadowTop);
532 shadowCorner = (unsigned char *)(malloc ((Gsize + 1) * (Gsize + 1) * 26));
533 shadowTop = (unsigned char *)(malloc ((Gsize + 1) * 26));
535 for (x = 0; x <= Gsize; x++)
537 shadowTop[25 * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, center, Gsize * 2, Gsize * 2);
538 for(opacity = 0; opacity < 25; opacity++)
539 shadowTop[opacity * (Gsize + 1) + x] = shadowTop[25 * (Gsize + 1) + x] * opacity / 25;
540 for(y = 0; y <= x; y++)
542 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
543 = sum_gaussian (map, 1, x - center, y - center, Gsize * 2, Gsize * 2);
544 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
545 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
546 for(opacity = 0; opacity < 25; opacity++)
547 shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
548 = shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
549 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] * opacity / 25;
555 make_shadow (Display *dpy, double opacity, int width, int height)
559 int gsize = gaussianMap->size;
561 int swidth = width + gsize;
562 int sheight = height + gsize;
563 int center = gsize / 2;
567 int opacity_int = (int)(opacity * 25);
568 data = malloc (swidth * sheight * sizeof (unsigned char));
571 ximage = XCreateImage (dpy,
572 DefaultVisual(dpy, DefaultScreen(dpy)),
577 swidth, sheight, 8, swidth * sizeof (unsigned char));
584 * Build the gaussian in sections
588 * center (fill the complete data array)
591 d = shadowTop[opacity_int * (Gsize + 1) + Gsize];
593 d = sum_gaussian (gaussianMap, opacity, center, center, width, height);
594 memset(data, d, sheight * swidth);
600 if (ylimit > sheight / 2)
601 ylimit = (sheight + 1) / 2;
603 if (xlimit > swidth / 2)
604 xlimit = (swidth + 1) / 2;
606 for (y = 0; y < ylimit; y++)
607 for (x = 0; x < xlimit; x++)
609 if (xlimit == Gsize && ylimit == Gsize)
610 d = shadowCorner[opacity_int * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
612 d = sum_gaussian (gaussianMap, opacity, x - center, y - center, width, height);
613 data[y * swidth + x] = d;
614 data[(sheight - y - 1) * swidth + x] = d;
615 data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d;
616 data[y * swidth + (swidth - x - 1)] = d;
622 x_diff = swidth - (gsize * 2);
623 if (x_diff > 0 && ylimit > 0)
625 for (y = 0; y < ylimit; y++)
628 d = shadowTop[opacity_int * (Gsize + 1) + y];
630 d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height);
631 memset (&data[y * swidth + gsize], d, x_diff);
632 memset (&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
640 for (x = 0; x < xlimit; x++)
643 d = shadowTop[opacity_int * (Gsize + 1) + x];
645 d = sum_gaussian (gaussianMap, opacity, x - center, center, width, height);
646 for (y = gsize; y < sheight - gsize; y++)
648 data[y * swidth + x] = d;
649 data[y * swidth + (swidth - x - 1)] = d;
657 shadow_picture (Display *dpy, double opacity, Picture alpha_pict, int width, int height, int *wp, int *hp)
661 Picture shadowPicture;
664 shadowImage = make_shadow (dpy, opacity, width, height);
667 shadowPixmap = XCreatePixmap (dpy, root,
673 XDestroyImage (shadowImage);
677 shadowPicture = XRenderCreatePicture (dpy, shadowPixmap,
678 XRenderFindStandardFormat (dpy, PictStandardA8),
682 XDestroyImage (shadowImage);
683 XFreePixmap (dpy, shadowPixmap);
687 gc = XCreateGC (dpy, shadowPixmap, 0, 0);
690 XDestroyImage (shadowImage);
691 XFreePixmap (dpy, shadowPixmap);
692 XRenderFreePicture (dpy, shadowPicture);
696 XPutImage (dpy, shadowPixmap, gc, shadowImage, 0, 0, 0, 0,
698 shadowImage->height);
699 *wp = shadowImage->width;
700 *hp = shadowImage->height;
702 XDestroyImage (shadowImage);
703 XFreePixmap (dpy, shadowPixmap);
704 return shadowPicture;
708 solid_picture (Display *dpy, Bool argb, double a, double r, double g, double b)
712 XRenderPictureAttributes pa;
715 pixmap = XCreatePixmap (dpy, root, 1, 1, argb ? 32 : 8);
720 picture = XRenderCreatePicture (dpy, pixmap,
721 XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8),
726 XFreePixmap (dpy, pixmap);
730 c.alpha = a * 0xffff;
732 c.green = g * 0xffff;
734 XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1);
735 XFreePixmap (dpy, pixmap);
740 discard_ignore (Display *dpy, unsigned long sequence)
744 if ((long) (sequence - ignore_head->sequence) > 0)
746 ignore *next = ignore_head->next;
750 ignore_tail = &ignore_head;
758 set_ignore (Display *dpy, unsigned long sequence)
760 ignore *i = malloc (sizeof (ignore));
763 i->sequence = sequence;
766 ignore_tail = &i->next;
770 should_ignore (Display *dpy, unsigned long sequence)
772 discard_ignore (dpy, sequence);
773 return ignore_head && ignore_head->sequence == sequence;
777 find_win (Display *dpy, Window id)
781 for (w = list; w; w = w->next)
787 static const char *backgroundProps[] = {
794 root_tile (Display *dpy)
800 unsigned long nitems;
801 unsigned long bytes_after;
804 XRenderPictureAttributes pa;
808 for (p = 0; backgroundProps[p]; p++)
810 if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False),
811 0, 4, False, AnyPropertyType,
812 &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success &&
813 actual_type == XInternAtom (dpy, "PIXMAP", False) && actual_format == 32 && nitems == 1)
815 memcpy (&pixmap, prop, 4);
823 pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr));
827 picture = XRenderCreatePicture (dpy, pixmap,
828 XRenderFindVisualFormat (dpy,
829 DefaultVisual (dpy, scr)),
835 c.red = c.green = c.blue = 0x8080;
837 XRenderFillRectangle (dpy, PictOpSrc, picture, &c,
844 paint_root (Display *dpy)
847 rootTile = root_tile (dpy);
849 XRenderComposite (dpy, PictOpSrc,
850 rootTile, None, rootBuffer,
851 0, 0, 0, 0, 0, 0, root_width, root_height);
855 win_extents (Display *dpy, win *w)
861 r.width = w->a.width + w->a.border_width * 2;
862 r.height = w->a.height + w->a.border_width * 2;
863 if (winTypeShadow[w->windowType])
865 if (compMode == CompServerShadows || w->mode != WINDOW_ARGB)
869 if (compMode == CompServerShadows)
873 w->shadow_width = w->a.width;
874 w->shadow_height = w->a.height;
878 w->shadow_dx = shadowOffsetX;
879 w->shadow_dy = shadowOffsetY;
882 double opacity = shadowOpacity;
883 if (w->mode == WINDOW_TRANS)
884 opacity = opacity * ((double)w->opacity)/((double)OPAQUE);
885 w->shadow = shadow_picture (dpy, opacity, w->alphaPict,
886 w->a.width + w->a.border_width * 2,
887 w->a.height + w->a.border_width * 2,
888 &w->shadow_width, &w->shadow_height);
891 sr.x = w->a.x + w->shadow_dx;
892 sr.y = w->a.y + w->shadow_dy;
893 sr.width = w->shadow_width;
894 sr.height = w->shadow_height;
897 r.width = (r.x + r.width) - sr.x;
902 r.height = (r.y + r.height) - sr.y;
905 if (sr.x + sr.width > r.x + r.width)
906 r.width = sr.x + sr.width - r.x;
907 if (sr.y + sr.height > r.y + r.height)
908 r.height = sr.y + sr.height - r.y;
911 return XFixesCreateRegion (dpy, &r, 1);
915 border_size (Display *dpy, win *w)
917 XserverRegion border;
919 * if window doesn't exist anymore, this will generate an error
920 * as well as not generate a region. Perhaps a better XFixes
921 * architecture would be to have a request that copies instead
922 * of creates, that way you'd just end up with an empty region
923 * instead of an invalid XID.
925 set_ignore (dpy, NextRequest (dpy));
926 border = XFixesCreateRegionFromWindow (dpy, w->id, WindowRegionBounding);
928 set_ignore (dpy, NextRequest (dpy));
929 XFixesTranslateRegion (dpy, border,
930 w->a.x + w->a.border_width,
931 w->a.y + w->a.border_width);
936 paint_all (Display *dpy, XserverRegion region)
946 r.width = root_width;
947 r.height = root_height;
948 region = XFixesCreateRegion (dpy, &r, 1);
951 rootBuffer = rootPicture;
955 Pixmap rootPixmap = XCreatePixmap (dpy, root, root_width, root_height,
956 DefaultDepth (dpy, scr));
957 rootBuffer = XRenderCreatePicture (dpy, rootPixmap,
958 XRenderFindVisualFormat (dpy,
959 DefaultVisual (dpy, scr)),
961 XFreePixmap (dpy, rootPixmap);
964 XFixesSetPictureClipRegion (dpy, rootPicture, 0, 0, region);
966 XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture,
967 0, 0, 0, 0, 0, 0, root_width, root_height);
972 for (w = list; w; w = w->next)
978 /* never painted, ignore it */
981 /* if invisible, ignore it */
982 if (w->a.x + w->a.width < 1 || w->a.y + w->a.height < 1
983 || w->a.x >= root_width || w->a.y >= root_height)
987 XRenderPictureAttributes pa;
988 XRenderPictFormat *format;
989 Drawable draw = w->id;
991 #if HAS_NAME_WINDOW_PIXMAP
992 if (hasNamePixmap && !w->pixmap)
993 w->pixmap = XCompositeNameWindowPixmap (dpy, w->id);
997 format = XRenderFindVisualFormat (dpy, w->a.visual);
998 pa.subwindow_mode = IncludeInferiors;
999 w->picture = XRenderCreatePicture (dpy, draw,
1005 printf (" 0x%x", w->id);
1011 set_ignore (dpy, NextRequest (dpy));
1012 XFixesDestroyRegion (dpy, w->borderSize);
1013 w->borderSize = None;
1017 XFixesDestroyRegion (dpy, w->extents);
1022 XFixesDestroyRegion (dpy, w->borderClip);
1023 w->borderClip = None;
1027 w->borderSize = border_size (dpy, w);
1029 w->extents = win_extents (dpy, w);
1030 if (w->mode == WINDOW_SOLID)
1033 #if HAS_NAME_WINDOW_PIXMAP
1036 wid = w->a.width + w->a.border_width * 2;
1037 hei = w->a.height + w->a.border_width * 2;
1039 x = w->a.x + w->a.border_width;
1040 y = w->a.y + w->a.border_width;
1044 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1045 set_ignore (dpy, NextRequest (dpy));
1046 XFixesSubtractRegion (dpy, region, region, w->borderSize);
1047 set_ignore (dpy, NextRequest (dpy));
1048 XRenderComposite (dpy, PictOpSrc, w->picture, None, rootBuffer,
1054 w->borderClip = XFixesCreateRegion (dpy, 0, 0);
1055 XFixesCopyRegion (dpy, w->borderClip, region);
1064 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1066 for (w = t; w; w = w->prev_trans)
1068 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, w->borderClip);
1069 if (winTypeShadow[w->windowType]) {
1073 case CompServerShadows:
1074 set_ignore (dpy, NextRequest (dpy));
1075 if (w->opacity != OPAQUE && !w->shadowPict)
1076 w->shadowPict = solid_picture (dpy, True,
1077 (double) w->opacity / OPAQUE * 0.3,
1079 XRenderComposite (dpy, PictOpOver,
1080 w->shadowPict ? w->shadowPict : transBlackPicture,
1081 w->picture, rootBuffer,
1083 w->a.x + w->shadow_dx,
1084 w->a.y + w->shadow_dy,
1085 w->shadow_width, w->shadow_height);
1087 case CompClientShadows:
1088 XRenderComposite (dpy, PictOpOver, blackPicture, w->shadow, rootBuffer,
1090 w->a.x + w->shadow_dx,
1091 w->a.y + w->shadow_dy,
1092 w->shadow_width, w->shadow_height);
1096 if (w->opacity != OPAQUE && !w->alphaPict)
1097 w->alphaPict = solid_picture (dpy, False,
1098 (double) w->opacity / OPAQUE, 0, 0, 0);
1099 if (w->mode == WINDOW_TRANS)
1102 #if HAS_NAME_WINDOW_PIXMAP
1105 wid = w->a.width + w->a.border_width * 2;
1106 hei = w->a.height + w->a.border_width * 2;
1108 x = w->a.x + w->a.border_width;
1109 y = w->a.y + w->a.border_width;
1113 set_ignore (dpy, NextRequest (dpy));
1114 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1118 else if (w->mode == WINDOW_ARGB)
1121 #if HAS_NAME_WINDOW_PIXMAP
1124 wid = w->a.width + w->a.border_width * 2;
1125 hei = w->a.height + w->a.border_width * 2;
1127 x = w->a.x + w->a.border_width;
1128 y = w->a.y + w->a.border_width;
1132 set_ignore (dpy, NextRequest (dpy));
1133 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1137 XFixesDestroyRegion (dpy, w->borderClip);
1138 w->borderClip = None;
1140 XFixesDestroyRegion (dpy, region);
1141 if (rootBuffer != rootPicture)
1143 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, None);
1144 XRenderComposite (dpy, PictOpSrc, rootBuffer, None, rootPicture,
1145 0, 0, 0, 0, 0, 0, root_width, root_height);
1150 add_damage (Display *dpy, XserverRegion damage)
1154 XFixesUnionRegion (dpy, allDamage, allDamage, damage);
1155 XFixesDestroyRegion (dpy, damage);
1162 repair_win (Display *dpy, win *w)
1164 XserverRegion parts;
1168 parts = win_extents (dpy, w);
1169 set_ignore (dpy, NextRequest (dpy));
1170 XDamageSubtract (dpy, w->damage, None, None);
1175 parts = XFixesCreateRegion (dpy, 0, 0);
1176 set_ignore (dpy, NextRequest (dpy));
1177 XDamageSubtract (dpy, w->damage, None, parts);
1178 XFixesTranslateRegion (dpy, parts,
1179 w->a.x + w->a.border_width,
1180 w->a.y + w->a.border_width);
1181 if (compMode == CompServerShadows)
1183 o = XFixesCreateRegion (dpy, 0, 0);
1184 XFixesCopyRegion (dpy, o, parts);
1185 XFixesTranslateRegion (dpy, o, w->shadow_dx, w->shadow_dy);
1186 XFixesUnionRegion (dpy, parts, parts, o);
1187 XFixesDestroyRegion (dpy, o);
1190 add_damage (dpy, parts);
1195 wintype_name(wintype type)
1199 case WINTYPE_DESKTOP: t = "desktop"; break;
1200 case WINTYPE_DOCK: t = "dock"; break;
1201 case WINTYPE_TOOLBAR: t = "toolbar"; break;
1202 case WINTYPE_MENU: t = "menu"; break;
1203 case WINTYPE_UTILITY: t = "utility"; break;
1204 case WINTYPE_SPLASH: t = "slash"; break;
1205 case WINTYPE_DIALOG: t = "dialog"; break;
1206 case WINTYPE_NORMAL: t = "normal"; break;
1207 case WINTYPE_DROPDOWN_MENU: t = "dropdown"; break;
1208 case WINTYPE_POPUP_MENU: t = "popup"; break;
1209 case WINTYPE_TOOLTIP: t = "tooltip"; break;
1210 case WINTYPE_NOTIFY: t = "notification"; break;
1211 case WINTYPE_COMBO: t = "combo"; break;
1212 case WINTYPE_DND: t = "dnd"; break;
1213 default: t = "unknown"; break;
1219 get_wintype_prop(Display * dpy, Window w)
1224 unsigned long n, left, off;
1225 unsigned char *data;
1231 set_ignore (dpy, NextRequest (dpy));
1232 int result = XGetWindowProperty (dpy, w, winTypeAtom, off, 1L, False,
1233 XA_ATOM, &actual, &format,
1236 if (result != Success)
1242 for (i = 0; i < NUM_WINTYPES; ++i) {
1244 memcpy (&a, data, sizeof (Atom));
1245 if (a == winType[i]) {
1252 XFree ( (void *) data);
1256 } while (left >= 4 && ret == (wintype)-1);
1262 determine_wintype (Display *dpy, Window w, Window top)
1264 Window root_return, parent_return;
1265 Window *children = NULL;
1266 unsigned int nchildren, i;
1269 type = get_wintype_prop (dpy, w);
1270 if (type != (wintype)-1)
1273 set_ignore (dpy, NextRequest (dpy));
1274 if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
1277 /* XQueryTree failed. */
1279 XFree ((void *)children);
1283 for (i = 0;i < nchildren;i++)
1285 type = determine_wintype (dpy, children[i], top);
1286 if (type != (wintype)-1)
1291 XFree ((void *)children);
1296 return WINTYPE_NORMAL;
1300 get_opacity_prop (Display *dpy, win *w, unsigned int def);
1303 configure_win (Display *dpy, XConfigureEvent *ce);
1306 map_win (Display *dpy, Window id, unsigned long sequence, Bool fade)
1308 win *w = find_win (dpy, id);
1313 w->a.map_state = IsViewable;
1315 w->windowType = determine_wintype (dpy, w->id, w->id);
1317 printf("window 0x%x type %s\n", w->id, wintype_name(w->windowType));
1320 /* select before reading the property so that no property changes are lost */
1321 XSelectInput (dpy, id, PropertyChangeMask);
1322 w->opacity = get_opacity_prop (dpy, w, OPAQUE);
1324 determine_mode (dpy, w);
1327 w->damage_bounds.x = w->damage_bounds.y = 0;
1328 w->damage_bounds.width = w->damage_bounds.height = 0;
1332 if (fade && winTypeFade[w->windowType])
1333 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1335 /* if any configure events happened while the window was unmapped, then
1336 configure the window to its correct place */
1337 if (w->need_configure)
1338 configure_win (dpy, &w->queue_configure);
1342 finish_unmap_win (Display *dpy, win *w)
1348 if (w->extents != None)
1350 add_damage (dpy, w->extents); /* destroys region */
1354 #if HAS_NAME_WINDOW_PIXMAP
1357 XFreePixmap (dpy, w->pixmap);
1364 set_ignore (dpy, NextRequest (dpy));
1365 XRenderFreePicture (dpy, w->picture);
1371 set_ignore (dpy, NextRequest (dpy));
1372 XFixesDestroyRegion (dpy, w->borderSize);
1373 w->borderSize = None;
1377 XRenderFreePicture (dpy, w->shadow);
1382 XFixesDestroyRegion (dpy, w->borderClip);
1383 w->borderClip = None;
1389 #if HAS_NAME_WINDOW_PIXMAP
1391 unmap_callback (Display *dpy, win *w)
1393 finish_unmap_win (dpy, w);
1398 unmap_win (Display *dpy, Window id, Bool fade)
1400 win *w = find_win (dpy, id);
1403 w->a.map_state = IsUnmapped;
1405 /* don't care about properties anymore */
1406 set_ignore (dpy, NextRequest (dpy));
1407 XSelectInput(dpy, w->id, 0);
1409 #if HAS_NAME_WINDOW_PIXMAP
1410 if (w->pixmap && fade && winTypeFade[w->windowType])
1411 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step, unmap_callback, False, True);
1414 finish_unmap_win (dpy, w);
1417 /* Get the opacity prop from window
1422 get_opacity_prop(Display *dpy, win *w, unsigned int def)
1426 unsigned long n, left;
1428 unsigned char *data;
1429 int result = XGetWindowProperty(dpy, w->id, opacityAtom, 0L, 1L, False,
1430 XA_CARDINAL, &actual, &format,
1432 if (result == Success && data != NULL)
1435 memcpy (&i, data, sizeof (unsigned int));
1436 XFree( (void *) data);
1442 /* Get the opacity property from the window in a percent format
1444 otherwise: the value
1447 get_opacity_percent(Display *dpy, win *w)
1449 double def = winTypeOpacity[w->windowType];
1450 unsigned int opacity = get_opacity_prop (dpy, w, (unsigned int)(OPAQUE*def));
1452 return opacity*1.0/OPAQUE;
1456 determine_mode(Display *dpy, win *w)
1459 XRenderPictFormat *format;
1461 /* if trans prop == -1 fall back on previous tests*/
1465 XRenderFreePicture (dpy, w->alphaPict);
1466 w->alphaPict = None;
1470 XRenderFreePicture (dpy, w->shadowPict);
1471 w->shadowPict = None;
1474 if (w->a.class == InputOnly)
1480 format = XRenderFindVisualFormat (dpy, w->a.visual);
1483 if (format && format->type == PictTypeDirect && format->direct.alphaMask)
1487 else if (w->opacity != OPAQUE)
1489 mode = WINDOW_TRANS;
1493 mode = WINDOW_SOLID;
1498 XserverRegion damage;
1499 damage = XFixesCreateRegion (dpy, 0, 0);
1500 XFixesCopyRegion (dpy, damage, w->extents);
1501 add_damage (dpy, damage);
1506 add_win (Display *dpy, Window id, Window prev)
1508 win *new = malloc (sizeof (win));
1515 for (p = &list; *p; p = &(*p)->next)
1516 if ((*p)->id == prev)
1522 set_ignore (dpy, NextRequest (dpy));
1523 if (!XGetWindowAttributes (dpy, id, &new->a))
1530 new->usable = False;
1532 #if HAS_NAME_WINDOW_PIXMAP
1535 new->picture = None;
1536 if (new->a.class == InputOnly)
1538 new->damage_sequence = 0;
1543 new->damage_sequence = NextRequest (dpy);
1544 new->damage = XDamageCreate (dpy, id, XDamageReportNonEmpty);
1546 new->alphaPict = None;
1547 new->shadowPict = None;
1548 new->borderSize = None;
1549 new->extents = None;
1553 new->shadow_width = 0;
1554 new->shadow_height = 0;
1555 new->opacity = OPAQUE;
1556 new->need_configure = False;
1558 new->borderClip = None;
1559 new->prev_trans = 0;
1563 if (new->a.map_state == IsViewable)
1564 map_win (dpy, id, new->damage_sequence - 1, True);
1568 restack_win (Display *dpy, win *w, Window new_above)
1573 old_above = w->next->id;
1576 if (old_above != new_above)
1581 for (prev = &list; *prev; prev = &(*prev)->next)
1587 for (prev = &list; *prev; prev = &(*prev)->next)
1589 if ((*prev)->id == new_above)
1598 configure_win (Display *dpy, XConfigureEvent *ce)
1600 win *w = find_win (dpy, ce->window);
1601 XserverRegion damage = None;
1605 if (ce->window == root)
1609 XRenderFreePicture (dpy, rootBuffer);
1612 root_width = ce->width;
1613 root_height = ce->height;
1618 if (w->a.map_state == IsUnmapped) {
1619 /* save the configure event for when the window maps */
1620 w->need_configure = True;
1621 w->queue_configure = *ce;
1624 w->need_configure = False;
1630 damage = XFixesCreateRegion (dpy, 0, 0);
1631 if (w->extents != None)
1632 XFixesCopyRegion (dpy, damage, w->extents);
1637 if (w->a.width != ce->width || w->a.height != ce->height)
1639 #if HAS_NAME_WINDOW_PIXMAP
1642 XFreePixmap (dpy, w->pixmap);
1646 XRenderFreePicture (dpy, w->picture);
1653 XRenderFreePicture (dpy, w->shadow);
1657 w->a.width = ce->width;
1658 w->a.height = ce->height;
1659 w->a.border_width = ce->border_width;
1660 if (w->a.map_state != IsUnmapped && damage)
1662 XserverRegion extents = win_extents (dpy, w);
1663 XFixesUnionRegion (dpy, damage, damage, extents);
1664 XFixesDestroyRegion (dpy, extents);
1665 add_damage (dpy, damage);
1668 w->a.override_redirect = ce->override_redirect;
1669 restack_win (dpy, w, ce->above);
1674 circulate_win (Display *dpy, XCirculateEvent *ce)
1676 win *w = find_win (dpy, ce->window);
1682 if (ce->place == PlaceOnTop)
1683 new_above = list->id;
1686 restack_win (dpy, w, new_above);
1691 finish_destroy_win (Display *dpy, Window id)
1695 for (prev = &list; (w = *prev); prev = &w->next)
1698 finish_unmap_win (dpy, w);
1702 XRenderFreePicture (dpy, w->alphaPict);
1703 w->alphaPict = None;
1707 XRenderFreePicture (dpy, w->shadowPict);
1708 w->shadowPict = None;
1710 if (w->damage != None)
1712 set_ignore (dpy, NextRequest (dpy));
1713 XDamageDestroy (dpy, w->damage);
1717 cleanup_fade (dpy, w);
1723 #if HAS_NAME_WINDOW_PIXMAP
1725 destroy_callback (Display *dpy, win *w)
1727 finish_destroy_win (dpy, w->id);
1732 destroy_win (Display *dpy, Window id, Bool fade)
1734 win *w = find_win (dpy, id);
1736 #if HAS_NAME_WINDOW_PIXMAP
1737 if (w && w->pixmap && fade && winTypeFade[w->windowType])
1738 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step,
1739 destroy_callback, False, (w->a.map_state != IsUnmapped));
1743 finish_destroy_win (dpy, id);
1751 printf ("\t%08lx: %d x %d + %d + %d (%d)\n", w->id,
1752 w->a.width, w->a.height, w->a.x, w->a.y, w->a.border_width);
1761 printf ("windows:\n");
1762 for (w = list; w; w = w->next)
1768 damage_win (Display *dpy, XDamageNotifyEvent *de)
1770 win *w = find_win (dpy, de->drawable);
1777 if (w->damage_bounds.width == 0 || w->damage_bounds.height == 0)
1779 w->damage_bounds = de->area;
1783 if (de->area.x < w->damage_bounds.x)
1785 w->damage_bounds.width += (w->damage_bounds.x - de->area.x);
1786 w->damage_bounds.x = de->area.x;
1788 if (de->area.y < w->damage_bounds.y)
1790 w->damage_bounds.height += (w->damage_bounds.y - de->area.y);
1791 w->damage_bounds.y = de->area.y;
1793 if (de->area.x + de->area.width > w->damage_bounds.x + w->damage_bounds.width)
1794 w->damage_bounds.width = de->area.x + de->area.width - w->damage_bounds.x;
1795 if (de->area.y + de->area.height > w->damage_bounds.y + w->damage_bounds.height)
1796 w->damage_bounds.height = de->area.y + de->area.height - w->damage_bounds.y;
1799 printf ("unusable damage %d, %d: %d x %d bounds %d, %d: %d x %d\n",
1806 w->damage_bounds.width,
1807 w->damage_bounds.height);
1809 if (w->damage_bounds.x <= 0 &&
1810 w->damage_bounds.y <= 0 &&
1811 w->a.width <= w->damage_bounds.x + w->damage_bounds.width &&
1812 w->a.height <= w->damage_bounds.y + w->damage_bounds.height)
1815 if (winTypeFade[w->windowType])
1816 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1822 repair_win (dpy, w);
1826 error (Display *dpy, XErrorEvent *ev)
1829 const char *name = 0;
1831 if (should_ignore (dpy, ev->serial))
1834 if (ev->request_code == composite_opcode &&
1835 ev->minor_code == X_CompositeRedirectSubwindows)
1837 fprintf (stderr, "Another composite manager is already running\n");
1841 o = ev->error_code - xfixes_error;
1843 case BadRegion: name = "BadRegion"; break;
1846 o = ev->error_code - damage_error;
1848 case BadDamage: name = "BadDamage"; break;
1851 o = ev->error_code - render_error;
1853 case BadPictFormat: name ="BadPictFormat"; break;
1854 case BadPicture: name ="BadPicture"; break;
1855 case BadPictOp: name ="BadPictOp"; break;
1856 case BadGlyphSet: name ="BadGlyphSet"; break;
1857 case BadGlyph: name ="BadGlyph"; break;
1861 printf ("error %d request %d minor %d serial %lu\n",
1862 ev->error_code, ev->request_code, ev->minor_code, ev->serial);
1864 /* abort (); this is just annoying to most people */
1869 expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
1871 XserverRegion region = XFixesCreateRegion (dpy, rects, nrects);
1873 add_damage (dpy, region);
1878 ev_serial (XEvent *ev)
1880 if (ev->type & 0x7f != KeymapNotify)
1881 return ev->xany.serial;
1882 return NextRequest (ev->xany.display);
1886 ev_name (XEvent *ev)
1888 static char buf[128];
1889 switch (ev->type & 0x7f) {
1896 case ReparentNotify:
1898 case CirculateNotify:
1901 if (ev->type == damage_event + XDamageNotify)
1903 sprintf (buf, "Event %d", ev->type);
1909 ev_window (XEvent *ev)
1913 return ev->xexpose.window;
1915 return ev->xmap.window;
1917 return ev->xunmap.window;
1918 case ReparentNotify:
1919 return ev->xreparent.window;
1920 case CirculateNotify:
1921 return ev->xcirculate.window;
1923 if (ev->type == damage_event + XDamageNotify)
1924 return ((XDamageNotifyEvent *) ev)->drawable;
1931 usage (char *program)
1933 fprintf (stderr, "%s v1.1.3\n", program);
1934 fprintf (stderr, "usage: %s [options]\n", program);
1935 fprintf (stderr, "Options\n");
1936 fprintf (stderr, " -d display\n Specifies which display should be managed.\n");
1937 fprintf (stderr, " -r radius\n Specifies the blur radius for client-side shadows. (default 12)\n");
1938 fprintf (stderr, " -o opacity\n Specifies the translucency for client-side shadows. (default .75)\n");
1939 fprintf (stderr, " -l left-offset\n Specifies the left offset for client-side shadows. (default -15)\n");
1940 fprintf (stderr, " -t top-offset\n Specifies the top offset for clinet-side shadows. (default -15)\n");
1941 fprintf (stderr, " -I fade-in-step\n Specifies the opacity change between steps while fading in. (default 0.028)\n");
1942 fprintf (stderr, " -O fade-out-step\n Specifies the opacity change between steps while fading out. (default 0.03)\n");
1943 fprintf (stderr, " -D fade-delta-time\n Specifies the time between steps in a fade in milliseconds. (default 10)\n");
1944 fprintf (stderr, " -m opacity\n Specifies the opacity for menus. (default 1.0)\n");
1945 fprintf (stderr, " -a\n Use automatic server-side compositing. Faster, but no special effects.\n");
1946 fprintf (stderr, " -c\n Draw client-side shadows with fuzzy edges.\n");
1947 fprintf (stderr, " -C\n Avoid drawing shadows on dock/panel windows.\n");
1948 fprintf (stderr, " -f\n Fade windows in/out when opening/closing.\n");
1949 fprintf (stderr, " -F\n Fade windows during opacity changes.\n");
1950 fprintf (stderr, " -n\n Normal client-side compositing with transparency support\n");
1951 fprintf (stderr, " -s\n Draw server-side shadows with sharp edges.\n");
1952 fprintf (stderr, " -S\n Enable synchronous operation (for debugging).\n");
1957 register_cm (int scr)
1964 if (scr < 0) return;
1966 w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
1969 Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
1972 len = strlen(REGISTER_PROP) + 2;
1979 snprintf(buf, len, REGISTER_PROP"%d", scr);
1981 a = XInternAtom (dpy, buf, False);
1984 XSetSelectionOwner (dpy, a, w, 0);
1988 main (int argc, char **argv)
1991 Window root_return, parent_return;
1993 unsigned int nchildren;
1995 XRenderPictureAttributes pa;
1996 XRectangle *expose_rects = 0;
1997 int size_expose = 0;
2001 int composite_major, composite_minor;
2004 Bool noDockShadow = False;
2006 for (i = 0; i < NUM_WINTYPES; ++i) {
2007 winTypeFade[i] = False;
2008 winTypeShadow[i] = False;
2009 winTypeOpacity[i] = 1.0;
2012 /* don't bother to draw a shadow for the desktop */
2013 winTypeShadow[WINTYPE_DESKTOP] = False;
2015 while ((o = getopt (argc, argv, "D:I:O:d:r:o:m:l:t:scnfFCaS")) != -1)
2022 fade_delta = atoi (optarg);
2027 fade_in_step = atof (optarg);
2028 if (fade_in_step <= 0)
2029 fade_in_step = 0.01;
2032 fade_out_step = atof (optarg);
2033 if (fade_out_step <= 0)
2034 fade_out_step = 0.01;
2037 compMode = CompServerShadows;
2038 for (i = 0; i < NUM_WINTYPES; ++i)
2039 winTypeShadow[i] = True;
2042 compMode = CompClientShadows;
2043 for (i = 0; i < NUM_WINTYPES; ++i)
2044 winTypeShadow[i] = True;
2047 noDockShadow = True;
2050 compMode = CompSimple;
2051 for (i = 0; i < NUM_WINTYPES; ++i)
2052 winTypeShadow[i] = False;
2055 winTypeOpacity[WINTYPE_DROPDOWN_MENU] = atof (optarg);
2056 winTypeOpacity[WINTYPE_POPUP_MENU] = atof (optarg);
2059 for (i = 0; i < NUM_WINTYPES; ++i)
2060 winTypeFade[i] = True;
2066 autoRedirect = True;
2072 shadowRadius = atoi (optarg);
2075 shadowOpacity = atof (optarg);
2078 shadowOffsetX = atoi (optarg);
2081 shadowOffsetY = atoi (optarg);
2090 winTypeShadow[WINTYPE_DOCK] = False;
2092 dpy = XOpenDisplay (display);
2095 fprintf (stderr, "Can't open display\n");
2098 XSetErrorHandler (error);
2100 XSynchronize (dpy, 1);
2101 scr = DefaultScreen (dpy);
2102 root = RootWindow (dpy, scr);
2104 if (!XRenderQueryExtension (dpy, &render_event, &render_error))
2106 fprintf (stderr, "No render extension\n");
2109 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode,
2110 &composite_event, &composite_error))
2112 fprintf (stderr, "No composite extension\n");
2115 XCompositeQueryVersion (dpy, &composite_major, &composite_minor);
2116 #if HAS_NAME_WINDOW_PIXMAP
2117 if (composite_major > 0 || composite_minor >= 2)
2118 hasNamePixmap = True;
2121 if (!XDamageQueryExtension (dpy, &damage_event, &damage_error))
2123 fprintf (stderr, "No damage extension\n");
2126 if (!XFixesQueryExtension (dpy, &xfixes_event, &xfixes_error))
2128 fprintf (stderr, "No XFixes extension\n");
2135 opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
2136 winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
2137 winType[WINTYPE_DESKTOP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
2138 winType[WINTYPE_DOCK] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
2139 winType[WINTYPE_TOOLBAR] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
2140 winType[WINTYPE_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
2141 winType[WINTYPE_UTILITY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
2142 winType[WINTYPE_SPLASH] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
2143 winType[WINTYPE_DIALOG] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
2144 winType[WINTYPE_NORMAL] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
2145 winType[WINTYPE_DROPDOWN_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
2146 winType[WINTYPE_POPUP_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", False);
2147 winType[WINTYPE_TOOLTIP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
2148 winType[WINTYPE_NOTIFY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
2149 winType[WINTYPE_COMBO] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_COMBO", False);
2150 winType[WINTYPE_DND] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DND", False);
2152 pa.subwindow_mode = IncludeInferiors;
2154 if (compMode == CompClientShadows)
2156 gaussianMap = make_gaussian_map(dpy, shadowRadius);
2157 presum_gaussian (gaussianMap);
2160 root_width = DisplayWidth (dpy, scr);
2161 root_height = DisplayHeight (dpy, scr);
2163 rootPicture = XRenderCreatePicture (dpy, root,
2164 XRenderFindVisualFormat (dpy,
2165 DefaultVisual (dpy, scr)),
2168 blackPicture = solid_picture (dpy, True, 1, 0, 0, 0);
2169 if (compMode == CompServerShadows)
2170 transBlackPicture = solid_picture (dpy, True, 0.3, 0, 0, 0);
2175 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectAutomatic);
2178 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual);
2179 XSelectInput (dpy, root,
2180 SubstructureNotifyMask|
2182 StructureNotifyMask|
2183 PropertyChangeMask);
2184 XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren);
2185 for (i = 0; i < nchildren; i++)
2186 add_win (dpy, children[i], i ? children[i-1] : None);
2189 XUngrabServer (dpy);
2190 ufd.fd = ConnectionNumber (dpy);
2191 ufd.events = POLLIN;
2193 paint_all (dpy, None);
2202 if (poll (&ufd, 1, fade_timeout()) == 0)
2209 XNextEvent (dpy, &ev);
2210 if ((ev.type & 0x7f) != KeymapNotify)
2211 discard_ignore (dpy, ev.xany.serial);
2213 printf ("event %10.10s serial 0x%08x window 0x%08x\n",
2214 ev_name(&ev), ev_serial (&ev), ev_window (&ev));
2216 if (!autoRedirect) switch (ev.type) {
2218 add_win (dpy, ev.xcreatewindow.window, 0);
2220 case ConfigureNotify:
2221 configure_win (dpy, &ev.xconfigure);
2224 destroy_win (dpy, ev.xdestroywindow.window, True);
2227 map_win (dpy, ev.xmap.window, ev.xmap.serial, True);
2230 unmap_win (dpy, ev.xunmap.window, True);
2232 case ReparentNotify:
2233 if (ev.xreparent.parent == root)
2234 add_win (dpy, ev.xreparent.window, 0);
2236 destroy_win (dpy, ev.xreparent.window, True);
2238 case CirculateNotify:
2239 circulate_win (dpy, &ev.xcirculate);
2242 if (ev.xexpose.window == root)
2244 int more = ev.xexpose.count + 1;
2245 if (n_expose == size_expose)
2249 expose_rects = realloc (expose_rects,
2250 (size_expose + more) *
2251 sizeof (XRectangle));
2252 size_expose += more;
2256 expose_rects = malloc (more * sizeof (XRectangle));
2260 expose_rects[n_expose].x = ev.xexpose.x;
2261 expose_rects[n_expose].y = ev.xexpose.y;
2262 expose_rects[n_expose].width = ev.xexpose.width;
2263 expose_rects[n_expose].height = ev.xexpose.height;
2265 if (ev.xexpose.count == 0)
2267 expose_root (dpy, root, expose_rects, n_expose);
2272 case PropertyNotify:
2273 for (p = 0; backgroundProps[p]; p++)
2275 if (ev.xproperty.atom == XInternAtom (dpy, backgroundProps[p], False))
2279 XClearArea (dpy, root, 0, 0, 0, 0, True);
2280 XRenderFreePicture (dpy, rootTile);
2286 /* check if Trans property was changed */
2287 if (ev.xproperty.atom == opacityAtom)
2289 /* reset mode and redraw window */
2290 win * w = find_win(dpy, ev.xproperty.window);
2294 set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w),
2295 fade_out_step, 0, True, False);
2298 w->opacity = get_opacity_prop(dpy, w, OPAQUE);
2299 determine_mode(dpy, w);
2302 XRenderFreePicture (dpy, w->shadow);
2305 if (w->extents != None)
2306 XFixesDestroyRegion (dpy, w->extents);
2308 /* rebuild the shadow */
2309 w->extents = win_extents (dpy, w);
2316 if (ev.type == damage_event + XDamageNotify)
2317 damage_win (dpy, (XDamageNotifyEvent *) &ev);
2320 } while (QLength (dpy));
2321 if (allDamage && !autoRedirect)
2324 paint_all (dpy, allDamage);
2328 clipChanged = False;