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 */
106 XConfigureEvent queue_configure;
108 /* for drawing translucent windows */
109 XserverRegion borderClip;
110 struct _win *prev_trans;
113 typedef struct _conv {
118 typedef struct _fade {
124 void (*callback) (Display *dpy, win *w);
135 Picture blackPicture;
136 Picture transBlackPicture;
138 XserverRegion allDamage;
140 #if HAS_NAME_WINDOW_PIXMAP
143 int root_height, root_width;
144 ignore *ignore_head, **ignore_tail = &ignore_head;
145 int xfixes_event, xfixes_error;
146 int damage_event, damage_error;
147 int composite_event, composite_error;
148 int render_event, render_error;
150 int composite_opcode;
152 /* find these once and be done with it */
155 Atom winType[NUM_WINTYPES];
156 double winTypeOpacity[NUM_WINTYPES];
157 Bool winTypeShadow[NUM_WINTYPES];
158 Bool winTypeFade[NUM_WINTYPES];
160 /* opacity property name; sometime soon I'll write up an EWMH spec for it */
161 #define OPACITY_PROP "_NET_WM_WINDOW_OPACITY"
162 #define REGISTER_PROP "_NET_WM_CM_S"
164 #define TRANSLUCENT 0xe0000000
165 #define OPAQUE 0xffffffff
169 #define WINDOW_SOLID 0
170 #define WINDOW_TRANS 1
171 #define WINDOW_ARGB 2
173 #define TRANS_OPACITY 0.75
175 #define DEBUG_REPAINT 0
176 #define DEBUG_EVENTS 0
177 #define MONITOR_REPAINT 0
180 #define SHARP_SHADOW 0
182 typedef enum _compMode {
183 CompSimple, /* looks like a regular X server */
184 CompServerShadows, /* use window alpha for shadow; sharp, but precise */
185 CompClientShadows, /* use window extents for shadow, blurred */
189 determine_mode(Display *dpy, win *w);
192 get_opacity_percent(Display *dpy, win *w);
195 win_extents (Display *dpy, win *w);
197 CompMode compMode = CompSimple;
199 int shadowRadius = 12;
200 int shadowOffsetX = -15;
201 int shadowOffsetY = -15;
202 double shadowOpacity = .75;
204 double fade_in_step = 0.028;
205 double fade_out_step = 0.03;
208 Bool fadeTrans = False;
210 Bool autoRedirect = False;
212 /* For shadow precomputation */
214 unsigned char *shadowCorner = NULL;
215 unsigned char *shadowTop = NULL;
218 get_time_in_milliseconds ()
222 gettimeofday (&tv, NULL);
223 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
231 for (f = fades; f; f = f->next)
240 dequeue_fade (Display *dpy, fade *f)
244 for (prev = &fades; *prev; prev = &(*prev)->next)
249 (*f->callback) (dpy, f->w);
256 cleanup_fade (Display *dpy, win *w)
258 fade *f = find_fade (w);
260 dequeue_fade (dpy, f);
264 enqueue_fade (Display *dpy, fade *f)
267 fade_time = get_time_in_milliseconds () + fade_delta;
273 set_fade (Display *dpy, win *w, double start, double finish, double step,
274 void (*callback) (Display *dpy, win *w),
275 Bool exec_callback, Bool override)
282 f = malloc (sizeof (fade));
286 enqueue_fade (dpy, f);
294 (*f->callback)(dpy, f->w);
304 else if (f->cur > finish)
306 f->callback = callback;
307 w->opacity = f->cur * OPAQUE;
309 printf ("set_fade start %g step %g\n", f->cur, f->step);
311 determine_mode (dpy, w);
314 XRenderFreePicture (dpy, w->shadow);
317 if (w->extents != None)
318 XFixesDestroyRegion (dpy, w->extents);
320 /* rebuild the shadow */
321 w->extents = win_extents (dpy, w);
324 /* fading windows need to be drawn, mark them as damaged.
325 when a window maps, if it tries to fade in but it already at the right
326 opacity (map/unmap/map fast) then it will never get drawn without this
338 now = get_time_in_milliseconds();
339 delta = fade_time - now;
342 /* printf ("timeout %d\n", delta); */
347 run_fades (Display *dpy)
349 int now = get_time_in_milliseconds();
355 printf ("run fades\n");
357 if (fade_time - now > 0)
359 steps = 1 + (now - fade_time) / fade_delta;
366 f->cur += f->step * steps;
372 printf ("opacity now %g\n", f->cur);
374 w->opacity = f->cur * OPAQUE;
375 need_dequeue = False;
378 if (f->cur >= f->finish)
380 w->opacity = f->finish*OPAQUE;
386 if (f->cur <= f->finish)
388 w->opacity = f->finish*OPAQUE;
392 determine_mode (dpy, w);
395 XRenderFreePicture (dpy, w->shadow);
398 if (w->extents != None)
399 XFixesDestroyRegion (dpy, w->extents);
401 /* rebuild the shadow */
402 w->extents = win_extents(dpy, w);
404 /* Must do this last as it might destroy f->w in callbacks */
406 dequeue_fade (dpy, f);
408 fade_time = now + fade_delta;
412 gaussian (double r, double x, double y)
414 return ((1 / (sqrt (2 * M_PI * r))) *
415 exp ((- (x * x + y * y)) / (2 * r * r)));
420 make_gaussian_map (Display *dpy, double r)
423 int size = ((int) ceil ((r * 3)) + 1) & ~1;
424 int center = size / 2;
429 c = malloc (sizeof (conv) + size * size * sizeof (double));
431 c->data = (double *) (c + 1);
433 for (y = 0; y < size; y++)
434 for (x = 0; x < size; x++)
436 g = gaussian (r, (double) (x - center), (double) (y - center));
438 c->data[y * size + x] = g;
440 /* printf ("gaussian total %f\n", t); */
441 for (y = 0; y < size; y++)
442 for (x = 0; x < size; x++)
444 c->data[y*size + x] /= t;
450 * A picture will help
452 * -center 0 width width+center
453 * -center +-----+-------------------+-----+
456 * 0 +-----+-------------------+-----+
460 * height +-----+-------------------+-----+
463 * center +-----+-------------------+-----+
467 sum_gaussian (conv *map, double opacity, int x, int y, int width, int height)
471 double *g_line = map->data;
472 int g_size = map->size;
473 int center = g_size / 2;
474 int fx_start, fx_end;
475 int fy_start, fy_end;
479 * Compute set of filter values which are "in range",
480 * that's the set with:
481 * 0 <= x + (fx-center) && x + (fx-center) < width &&
482 * 0 <= y + (fy-center) && y + (fy-center) < height
484 * 0 <= x + (fx - center) x + fx - center < width
485 * center - x <= fx fx < width + center - x
488 fx_start = center - x;
491 fx_end = width + center - x;
495 fy_start = center - y;
498 fy_end = height + center - y;
502 g_line = g_line + fy_start * g_size + fx_start;
505 for (fy = fy_start; fy < fy_end; fy++)
510 for (fx = fx_start; fx < fx_end; fx++)
516 return ((unsigned char) (v * opacity * 255.0));
519 /* precompute shadow corners and sides to save time for large windows */
521 presum_gaussian (conv *map)
523 int center = map->size/2;
529 free ((void *)shadowCorner);
531 free ((void *)shadowTop);
533 shadowCorner = (unsigned char *)(malloc ((Gsize + 1) * (Gsize + 1) * 26));
534 shadowTop = (unsigned char *)(malloc ((Gsize + 1) * 26));
536 for (x = 0; x <= Gsize; x++)
538 shadowTop[25 * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, center, Gsize * 2, Gsize * 2);
539 for(opacity = 0; opacity < 25; opacity++)
540 shadowTop[opacity * (Gsize + 1) + x] = shadowTop[25 * (Gsize + 1) + x] * opacity / 25;
541 for(y = 0; y <= x; y++)
543 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
544 = sum_gaussian (map, 1, x - center, y - center, Gsize * 2, Gsize * 2);
545 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
546 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
547 for(opacity = 0; opacity < 25; opacity++)
548 shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
549 = shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
550 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] * opacity / 25;
556 make_shadow (Display *dpy, double opacity, int width, int height)
560 int gsize = gaussianMap->size;
562 int swidth = width + gsize;
563 int sheight = height + gsize;
564 int center = gsize / 2;
568 int opacity_int = (int)(opacity * 25);
569 data = malloc (swidth * sheight * sizeof (unsigned char));
572 ximage = XCreateImage (dpy,
573 DefaultVisual(dpy, DefaultScreen(dpy)),
578 swidth, sheight, 8, swidth * sizeof (unsigned char));
585 * Build the gaussian in sections
589 * center (fill the complete data array)
592 d = shadowTop[opacity_int * (Gsize + 1) + Gsize];
594 d = sum_gaussian (gaussianMap, opacity, center, center, width, height);
595 memset(data, d, sheight * swidth);
601 if (ylimit > sheight / 2)
602 ylimit = (sheight + 1) / 2;
604 if (xlimit > swidth / 2)
605 xlimit = (swidth + 1) / 2;
607 for (y = 0; y < ylimit; y++)
608 for (x = 0; x < xlimit; x++)
610 if (xlimit == Gsize && ylimit == Gsize)
611 d = shadowCorner[opacity_int * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
613 d = sum_gaussian (gaussianMap, opacity, x - center, y - center, width, height);
614 data[y * swidth + x] = d;
615 data[(sheight - y - 1) * swidth + x] = d;
616 data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d;
617 data[y * swidth + (swidth - x - 1)] = d;
623 x_diff = swidth - (gsize * 2);
624 if (x_diff > 0 && ylimit > 0)
626 for (y = 0; y < ylimit; y++)
629 d = shadowTop[opacity_int * (Gsize + 1) + y];
631 d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height);
632 memset (&data[y * swidth + gsize], d, x_diff);
633 memset (&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
641 for (x = 0; x < xlimit; x++)
644 d = shadowTop[opacity_int * (Gsize + 1) + x];
646 d = sum_gaussian (gaussianMap, opacity, x - center, center, width, height);
647 for (y = gsize; y < sheight - gsize; y++)
649 data[y * swidth + x] = d;
650 data[y * swidth + (swidth - x - 1)] = d;
658 shadow_picture (Display *dpy, double opacity, Picture alpha_pict, int width, int height, int *wp, int *hp)
662 Picture shadowPicture;
665 shadowImage = make_shadow (dpy, opacity, width, height);
668 shadowPixmap = XCreatePixmap (dpy, root,
674 XDestroyImage (shadowImage);
678 shadowPicture = XRenderCreatePicture (dpy, shadowPixmap,
679 XRenderFindStandardFormat (dpy, PictStandardA8),
683 XDestroyImage (shadowImage);
684 XFreePixmap (dpy, shadowPixmap);
688 gc = XCreateGC (dpy, shadowPixmap, 0, 0);
691 XDestroyImage (shadowImage);
692 XFreePixmap (dpy, shadowPixmap);
693 XRenderFreePicture (dpy, shadowPicture);
697 XPutImage (dpy, shadowPixmap, gc, shadowImage, 0, 0, 0, 0,
699 shadowImage->height);
700 *wp = shadowImage->width;
701 *hp = shadowImage->height;
703 XDestroyImage (shadowImage);
704 XFreePixmap (dpy, shadowPixmap);
705 return shadowPicture;
709 solid_picture (Display *dpy, Bool argb, double a, double r, double g, double b)
713 XRenderPictureAttributes pa;
716 pixmap = XCreatePixmap (dpy, root, 1, 1, argb ? 32 : 8);
721 picture = XRenderCreatePicture (dpy, pixmap,
722 XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8),
727 XFreePixmap (dpy, pixmap);
731 c.alpha = a * 0xffff;
733 c.green = g * 0xffff;
735 XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1);
736 XFreePixmap (dpy, pixmap);
741 discard_ignore (Display *dpy, unsigned long sequence)
745 if ((long) (sequence - ignore_head->sequence) > 0)
747 ignore *next = ignore_head->next;
751 ignore_tail = &ignore_head;
759 set_ignore (Display *dpy, unsigned long sequence)
761 ignore *i = malloc (sizeof (ignore));
764 i->sequence = sequence;
767 ignore_tail = &i->next;
771 should_ignore (Display *dpy, unsigned long sequence)
773 discard_ignore (dpy, sequence);
774 return ignore_head && ignore_head->sequence == sequence;
778 find_win (Display *dpy, Window id)
782 for (w = list; w; w = w->next)
783 if (w->id == id && !w->destroyed)
788 static const char *backgroundProps[] = {
795 root_tile (Display *dpy)
801 unsigned long nitems;
802 unsigned long bytes_after;
805 XRenderPictureAttributes pa;
809 for (p = 0; backgroundProps[p]; p++)
811 if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False),
812 0, 4, False, AnyPropertyType,
813 &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success &&
814 actual_type == XInternAtom (dpy, "PIXMAP", False) && actual_format == 32 && nitems == 1)
816 memcpy (&pixmap, prop, 4);
824 pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr));
828 picture = XRenderCreatePicture (dpy, pixmap,
829 XRenderFindVisualFormat (dpy,
830 DefaultVisual (dpy, scr)),
836 c.red = c.green = c.blue = 0x8080;
838 XRenderFillRectangle (dpy, PictOpSrc, picture, &c,
845 paint_root (Display *dpy)
848 rootTile = root_tile (dpy);
850 XRenderComposite (dpy, PictOpSrc,
851 rootTile, None, rootBuffer,
852 0, 0, 0, 0, 0, 0, root_width, root_height);
856 win_extents (Display *dpy, win *w)
862 r.width = w->a.width + w->a.border_width * 2;
863 r.height = w->a.height + w->a.border_width * 2;
864 if (winTypeShadow[w->windowType])
866 if (compMode == CompServerShadows || w->mode != WINDOW_ARGB)
870 if (compMode == CompServerShadows)
872 w->shadow_dx = shadowOffsetX;
873 w->shadow_dy = shadowOffsetY;
874 w->shadow_width = w->a.width;
875 w->shadow_height = w->a.height;
879 w->shadow_dx = shadowOffsetX;
880 w->shadow_dy = shadowOffsetY;
883 double opacity = shadowOpacity;
884 if (w->mode == WINDOW_TRANS)
885 opacity = opacity * ((double)w->opacity)/((double)OPAQUE);
886 w->shadow = shadow_picture (dpy, opacity, w->alphaPict,
887 w->a.width + w->a.border_width * 2,
888 w->a.height + w->a.border_width * 2,
889 &w->shadow_width, &w->shadow_height);
892 sr.x = w->a.x + w->shadow_dx;
893 sr.y = w->a.y + w->shadow_dy;
894 sr.width = w->shadow_width;
895 sr.height = w->shadow_height;
898 r.width = (r.x + r.width) - sr.x;
903 r.height = (r.y + r.height) - sr.y;
906 if (sr.x + sr.width > r.x + r.width)
907 r.width = sr.x + sr.width - r.x;
908 if (sr.y + sr.height > r.y + r.height)
909 r.height = sr.y + sr.height - r.y;
912 return XFixesCreateRegion (dpy, &r, 1);
916 border_size (Display *dpy, win *w)
918 XserverRegion border;
920 * if window doesn't exist anymore, this will generate an error
921 * as well as not generate a region. Perhaps a better XFixes
922 * architecture would be to have a request that copies instead
923 * of creates, that way you'd just end up with an empty region
924 * instead of an invalid XID.
926 set_ignore (dpy, NextRequest (dpy));
927 border = XFixesCreateRegionFromWindow (dpy, w->id, WindowRegionBounding);
929 set_ignore (dpy, NextRequest (dpy));
930 XFixesTranslateRegion (dpy, border,
931 w->a.x + w->a.border_width,
932 w->a.y + w->a.border_width);
937 paint_all (Display *dpy, XserverRegion region)
947 r.width = root_width;
948 r.height = root_height;
949 region = XFixesCreateRegion (dpy, &r, 1);
952 rootBuffer = rootPicture;
956 Pixmap rootPixmap = XCreatePixmap (dpy, root, root_width, root_height,
957 DefaultDepth (dpy, scr));
958 rootBuffer = XRenderCreatePicture (dpy, rootPixmap,
959 XRenderFindVisualFormat (dpy,
960 DefaultVisual (dpy, scr)),
962 XFreePixmap (dpy, rootPixmap);
965 XFixesSetPictureClipRegion (dpy, rootPicture, 0, 0, region);
967 XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture,
968 0, 0, 0, 0, 0, 0, root_width, root_height);
973 for (w = list; w; w = w->next)
979 /* never painted, ignore it */
982 /* if invisible, ignore it */
983 if (w->a.x + w->a.width < 1 || w->a.y + w->a.height < 1
984 || w->a.x >= root_width || w->a.y >= root_height)
988 XRenderPictureAttributes pa;
989 XRenderPictFormat *format;
990 Drawable draw = w->id;
992 #if HAS_NAME_WINDOW_PIXMAP
993 if (hasNamePixmap && !w->pixmap) {
994 set_ignore (dpy, NextRequest (dpy));
995 w->pixmap = XCompositeNameWindowPixmap (dpy, w->id);
1000 format = XRenderFindVisualFormat (dpy, w->a.visual);
1001 pa.subwindow_mode = IncludeInferiors;
1002 w->picture = XRenderCreatePicture (dpy, draw,
1008 printf (" 0x%x", w->id);
1014 set_ignore (dpy, NextRequest (dpy));
1015 XFixesDestroyRegion (dpy, w->borderSize);
1016 w->borderSize = None;
1020 XFixesDestroyRegion (dpy, w->extents);
1025 XFixesDestroyRegion (dpy, w->borderClip);
1026 w->borderClip = None;
1030 w->borderSize = border_size (dpy, w);
1032 w->extents = win_extents (dpy, w);
1033 if (w->mode == WINDOW_SOLID)
1036 #if HAS_NAME_WINDOW_PIXMAP
1039 wid = w->a.width + w->a.border_width * 2;
1040 hei = w->a.height + w->a.border_width * 2;
1042 x = w->a.x + w->a.border_width;
1043 y = w->a.y + w->a.border_width;
1047 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1048 set_ignore (dpy, NextRequest (dpy));
1049 XFixesSubtractRegion (dpy, region, region, w->borderSize);
1050 set_ignore (dpy, NextRequest (dpy));
1051 XRenderComposite (dpy, PictOpSrc, w->picture, None, rootBuffer,
1057 w->borderClip = XFixesCreateRegion (dpy, 0, 0);
1058 XFixesCopyRegion (dpy, w->borderClip, region);
1067 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1069 for (w = t; w; w = w->prev_trans)
1071 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, w->borderClip);
1072 if (winTypeShadow[w->windowType]) {
1076 case CompServerShadows:
1077 set_ignore (dpy, NextRequest (dpy));
1078 if (w->opacity != OPAQUE && !w->shadowPict)
1079 w->shadowPict = solid_picture (dpy, True,
1080 (double) w->opacity / OPAQUE * 0.3,
1082 XRenderComposite (dpy, PictOpOver,
1083 w->shadowPict ? w->shadowPict : transBlackPicture,
1084 w->picture, rootBuffer,
1086 w->a.x + w->shadow_dx,
1087 w->a.y + w->shadow_dy,
1088 w->shadow_width, w->shadow_height);
1090 case CompClientShadows:
1091 XRenderComposite (dpy, PictOpOver, blackPicture, w->shadow, rootBuffer,
1093 w->a.x + w->shadow_dx,
1094 w->a.y + w->shadow_dy,
1095 w->shadow_width, w->shadow_height);
1099 if (w->opacity != OPAQUE && !w->alphaPict)
1100 w->alphaPict = solid_picture (dpy, False,
1101 (double) w->opacity / OPAQUE, 0, 0, 0);
1102 if (w->mode == WINDOW_TRANS)
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 else if (w->mode == WINDOW_ARGB)
1124 #if HAS_NAME_WINDOW_PIXMAP
1127 wid = w->a.width + w->a.border_width * 2;
1128 hei = w->a.height + w->a.border_width * 2;
1130 x = w->a.x + w->a.border_width;
1131 y = w->a.y + w->a.border_width;
1135 set_ignore (dpy, NextRequest (dpy));
1136 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1140 XFixesDestroyRegion (dpy, w->borderClip);
1141 w->borderClip = None;
1143 XFixesDestroyRegion (dpy, region);
1144 if (rootBuffer != rootPicture)
1146 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, None);
1147 XRenderComposite (dpy, PictOpSrc, rootBuffer, None, rootPicture,
1148 0, 0, 0, 0, 0, 0, root_width, root_height);
1153 add_damage (Display *dpy, XserverRegion damage)
1157 XFixesUnionRegion (dpy, allDamage, allDamage, damage);
1158 XFixesDestroyRegion (dpy, damage);
1165 repair_win (Display *dpy, win *w)
1167 XserverRegion parts;
1171 parts = win_extents (dpy, w);
1172 set_ignore (dpy, NextRequest (dpy));
1173 XDamageSubtract (dpy, w->damage, None, None);
1178 parts = XFixesCreateRegion (dpy, 0, 0);
1179 set_ignore (dpy, NextRequest (dpy));
1180 XDamageSubtract (dpy, w->damage, None, parts);
1181 XFixesTranslateRegion (dpy, parts,
1182 w->a.x + w->a.border_width,
1183 w->a.y + w->a.border_width);
1184 if (compMode == CompServerShadows)
1186 o = XFixesCreateRegion (dpy, 0, 0);
1187 XFixesCopyRegion (dpy, o, parts);
1188 XFixesTranslateRegion (dpy, o, w->shadow_dx, w->shadow_dy);
1189 XFixesUnionRegion (dpy, parts, parts, o);
1190 XFixesDestroyRegion (dpy, o);
1193 add_damage (dpy, parts);
1198 wintype_name(wintype type)
1202 case WINTYPE_DESKTOP: t = "desktop"; break;
1203 case WINTYPE_DOCK: t = "dock"; break;
1204 case WINTYPE_TOOLBAR: t = "toolbar"; break;
1205 case WINTYPE_MENU: t = "menu"; break;
1206 case WINTYPE_UTILITY: t = "utility"; break;
1207 case WINTYPE_SPLASH: t = "slash"; break;
1208 case WINTYPE_DIALOG: t = "dialog"; break;
1209 case WINTYPE_NORMAL: t = "normal"; break;
1210 case WINTYPE_DROPDOWN_MENU: t = "dropdown"; break;
1211 case WINTYPE_POPUP_MENU: t = "popup"; break;
1212 case WINTYPE_TOOLTIP: t = "tooltip"; break;
1213 case WINTYPE_NOTIFY: t = "notification"; break;
1214 case WINTYPE_COMBO: t = "combo"; break;
1215 case WINTYPE_DND: t = "dnd"; break;
1216 default: t = "unknown"; break;
1222 get_wintype_prop(Display * dpy, Window w)
1227 unsigned long n, left, off;
1228 unsigned char *data;
1234 set_ignore (dpy, NextRequest (dpy));
1235 int result = XGetWindowProperty (dpy, w, winTypeAtom, off, 1L, False,
1236 XA_ATOM, &actual, &format,
1239 if (result != Success)
1245 for (i = 0; i < NUM_WINTYPES; ++i) {
1247 memcpy (&a, data, sizeof (Atom));
1248 if (a == winType[i]) {
1255 XFree ( (void *) data);
1259 } while (left >= 4 && ret == (wintype)-1);
1265 determine_wintype (Display *dpy, Window w, Window top)
1267 Window root_return, parent_return;
1268 Window *children = NULL;
1269 unsigned int nchildren, i;
1272 type = get_wintype_prop (dpy, w);
1273 if (type != (wintype)-1)
1276 set_ignore (dpy, NextRequest (dpy));
1277 if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
1280 /* XQueryTree failed. */
1282 XFree ((void *)children);
1286 for (i = 0;i < nchildren;i++)
1288 type = determine_wintype (dpy, children[i], top);
1289 if (type != (wintype)-1)
1294 XFree ((void *)children);
1299 return WINTYPE_NORMAL;
1303 get_opacity_prop (Display *dpy, win *w, unsigned int def);
1306 configure_win (Display *dpy, XConfigureEvent *ce);
1309 map_win (Display *dpy, Window id, unsigned long sequence, Bool fade)
1311 win *w = find_win (dpy, id);
1316 w->a.map_state = IsViewable;
1318 w->windowType = determine_wintype (dpy, w->id, w->id);
1320 printf("window 0x%x type %s\n", w->id, wintype_name(w->windowType));
1323 /* select before reading the property so that no property changes are lost */
1324 XSelectInput (dpy, id, PropertyChangeMask);
1325 w->opacity = get_opacity_prop (dpy, w, OPAQUE);
1327 determine_mode (dpy, w);
1330 w->damage_bounds.x = w->damage_bounds.y = 0;
1331 w->damage_bounds.width = w->damage_bounds.height = 0;
1335 if (fade && winTypeFade[w->windowType])
1336 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1338 /* if any configure events happened while the window was unmapped, then
1339 configure the window to its correct place */
1340 if (w->need_configure)
1341 configure_win (dpy, &w->queue_configure);
1345 finish_unmap_win (Display *dpy, win *w)
1351 if (w->extents != None)
1353 add_damage (dpy, w->extents); /* destroys region */
1357 #if HAS_NAME_WINDOW_PIXMAP
1360 XFreePixmap (dpy, w->pixmap);
1367 set_ignore (dpy, NextRequest (dpy));
1368 XRenderFreePicture (dpy, w->picture);
1374 set_ignore (dpy, NextRequest (dpy));
1375 XFixesDestroyRegion (dpy, w->borderSize);
1376 w->borderSize = None;
1380 XRenderFreePicture (dpy, w->shadow);
1385 XFixesDestroyRegion (dpy, w->borderClip);
1386 w->borderClip = None;
1392 #if HAS_NAME_WINDOW_PIXMAP
1394 unmap_callback (Display *dpy, win *w)
1396 finish_unmap_win (dpy, w);
1401 unmap_win (Display *dpy, Window id, Bool fade)
1403 win *w = find_win (dpy, id);
1406 w->a.map_state = IsUnmapped;
1408 /* don't care about properties anymore */
1409 set_ignore (dpy, NextRequest (dpy));
1410 XSelectInput(dpy, w->id, 0);
1412 #if HAS_NAME_WINDOW_PIXMAP
1413 if (w->pixmap && fade && winTypeFade[w->windowType])
1414 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step, unmap_callback, False, True);
1417 finish_unmap_win (dpy, w);
1420 /* Get the opacity prop from window
1425 get_opacity_prop(Display *dpy, win *w, unsigned int def)
1429 unsigned long n, left;
1431 unsigned char *data;
1432 int result = XGetWindowProperty(dpy, w->id, opacityAtom, 0L, 1L, False,
1433 XA_CARDINAL, &actual, &format,
1435 if (result == Success && data != NULL)
1438 memcpy (&i, data, sizeof (unsigned int));
1439 XFree( (void *) data);
1445 /* Get the opacity property from the window in a percent format
1447 otherwise: the value
1450 get_opacity_percent(Display *dpy, win *w)
1452 double def = winTypeOpacity[w->windowType];
1453 unsigned int opacity = get_opacity_prop (dpy, w, (unsigned int)(OPAQUE*def));
1455 return opacity*1.0/OPAQUE;
1459 determine_mode(Display *dpy, win *w)
1462 XRenderPictFormat *format;
1464 /* if trans prop == -1 fall back on previous tests*/
1468 XRenderFreePicture (dpy, w->alphaPict);
1469 w->alphaPict = None;
1473 XRenderFreePicture (dpy, w->shadowPict);
1474 w->shadowPict = None;
1477 if (w->a.class == InputOnly)
1483 format = XRenderFindVisualFormat (dpy, w->a.visual);
1486 if (format && format->type == PictTypeDirect && format->direct.alphaMask)
1490 else if (w->opacity != OPAQUE)
1492 mode = WINDOW_TRANS;
1496 mode = WINDOW_SOLID;
1501 XserverRegion damage;
1502 damage = XFixesCreateRegion (dpy, 0, 0);
1503 XFixesCopyRegion (dpy, damage, w->extents);
1504 add_damage (dpy, damage);
1509 add_win (Display *dpy, Window id, Window prev)
1511 win *new = malloc (sizeof (win));
1518 for (p = &list; *p; p = &(*p)->next)
1519 if ((*p)->id == prev && !(*p)->destroyed)
1525 set_ignore (dpy, NextRequest (dpy));
1526 if (!XGetWindowAttributes (dpy, id, &new->a))
1533 new->usable = False;
1535 #if HAS_NAME_WINDOW_PIXMAP
1538 new->picture = None;
1539 if (new->a.class == InputOnly)
1541 new->damage_sequence = 0;
1546 new->damage_sequence = NextRequest (dpy);
1547 set_ignore (dpy, NextRequest (dpy));
1548 new->damage = XDamageCreate (dpy, id, XDamageReportNonEmpty);
1550 new->alphaPict = None;
1551 new->shadowPict = None;
1552 new->borderSize = None;
1553 new->extents = None;
1557 new->shadow_width = 0;
1558 new->shadow_height = 0;
1559 new->opacity = OPAQUE;
1560 new->destroyed = False;
1561 new->need_configure = False;
1563 new->borderClip = None;
1564 new->prev_trans = 0;
1568 if (new->a.map_state == IsViewable)
1569 map_win (dpy, id, new->damage_sequence - 1, True);
1573 restack_win (Display *dpy, win *w, Window new_above)
1578 old_above = w->next->id;
1581 if (old_above != new_above)
1586 for (prev = &list; *prev; prev = &(*prev)->next)
1592 for (prev = &list; *prev; prev = &(*prev)->next)
1594 if ((*prev)->id == new_above && !(*prev)->destroyed)
1603 configure_win (Display *dpy, XConfigureEvent *ce)
1605 win *w = find_win (dpy, ce->window);
1606 XserverRegion damage = None;
1610 if (ce->window == root)
1614 XRenderFreePicture (dpy, rootBuffer);
1617 root_width = ce->width;
1618 root_height = ce->height;
1623 if (w->a.map_state == IsUnmapped) {
1624 /* save the configure event for when the window maps */
1625 w->need_configure = True;
1626 w->queue_configure = *ce;
1629 w->need_configure = False;
1635 damage = XFixesCreateRegion (dpy, 0, 0);
1636 if (w->extents != None)
1637 XFixesCopyRegion (dpy, damage, w->extents);
1642 if (w->a.width != ce->width || w->a.height != ce->height)
1644 #if HAS_NAME_WINDOW_PIXMAP
1647 XFreePixmap (dpy, w->pixmap);
1651 XRenderFreePicture (dpy, w->picture);
1658 XRenderFreePicture (dpy, w->shadow);
1662 w->a.width = ce->width;
1663 w->a.height = ce->height;
1664 w->a.border_width = ce->border_width;
1665 if (w->a.map_state != IsUnmapped && damage)
1667 XserverRegion extents = win_extents (dpy, w);
1668 XFixesUnionRegion (dpy, damage, damage, extents);
1669 XFixesDestroyRegion (dpy, extents);
1670 add_damage (dpy, damage);
1676 w->a.override_redirect = ce->override_redirect;
1677 restack_win (dpy, w, ce->above);
1681 circulate_win (Display *dpy, XCirculateEvent *ce)
1683 win *w = find_win (dpy, ce->window);
1689 if (ce->place == PlaceOnTop)
1690 new_above = list->id;
1693 restack_win (dpy, w, new_above);
1698 finish_destroy_win (Display *dpy, Window id)
1702 for (prev = &list; (w = *prev); prev = &w->next)
1703 if (w->id == id && w->destroyed)
1705 finish_unmap_win (dpy, w);
1709 XRenderFreePicture (dpy, w->alphaPict);
1710 w->alphaPict = None;
1714 XRenderFreePicture (dpy, w->shadowPict);
1715 w->shadowPict = None;
1717 if (w->damage != None)
1719 set_ignore (dpy, NextRequest (dpy));
1720 XDamageDestroy (dpy, w->damage);
1724 cleanup_fade (dpy, w);
1730 #if HAS_NAME_WINDOW_PIXMAP
1732 destroy_callback (Display *dpy, win *w)
1734 finish_destroy_win (dpy, w->id);
1739 destroy_win (Display *dpy, Window id, Bool fade)
1741 win *w = find_win (dpy, id);
1743 if (w) w->destroyed = True;
1745 #if HAS_NAME_WINDOW_PIXMAP
1746 if (w && w->pixmap && fade && winTypeFade[w->windowType])
1747 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step,
1748 destroy_callback, False, True);
1752 finish_destroy_win (dpy, id);
1760 printf ("\t%08lx: %d x %d + %d + %d (%d)\n", w->id,
1761 w->a.width, w->a.height, w->a.x, w->a.y, w->a.border_width);
1770 printf ("windows:\n");
1771 for (w = list; w; w = w->next)
1777 damage_win (Display *dpy, XDamageNotifyEvent *de)
1779 win *w = find_win (dpy, de->drawable);
1786 if (w->damage_bounds.width == 0 || w->damage_bounds.height == 0)
1788 w->damage_bounds = de->area;
1792 if (de->area.x < w->damage_bounds.x)
1794 w->damage_bounds.width += (w->damage_bounds.x - de->area.x);
1795 w->damage_bounds.x = de->area.x;
1797 if (de->area.y < w->damage_bounds.y)
1799 w->damage_bounds.height += (w->damage_bounds.y - de->area.y);
1800 w->damage_bounds.y = de->area.y;
1802 if (de->area.x + de->area.width > w->damage_bounds.x + w->damage_bounds.width)
1803 w->damage_bounds.width = de->area.x + de->area.width - w->damage_bounds.x;
1804 if (de->area.y + de->area.height > w->damage_bounds.y + w->damage_bounds.height)
1805 w->damage_bounds.height = de->area.y + de->area.height - w->damage_bounds.y;
1808 printf ("unusable damage %d, %d: %d x %d bounds %d, %d: %d x %d\n",
1815 w->damage_bounds.width,
1816 w->damage_bounds.height);
1818 if (w->damage_bounds.x <= 0 &&
1819 w->damage_bounds.y <= 0 &&
1820 w->a.width <= w->damage_bounds.x + w->damage_bounds.width &&
1821 w->a.height <= w->damage_bounds.y + w->damage_bounds.height)
1824 if (winTypeFade[w->windowType])
1825 set_fade (dpy, w, 0, get_opacity_percent (dpy, w), fade_in_step, 0, True, True);
1831 repair_win (dpy, w);
1835 error (Display *dpy, XErrorEvent *ev)
1838 const char *name = 0;
1840 if (should_ignore (dpy, ev->serial))
1843 if (ev->request_code == composite_opcode &&
1844 ev->minor_code == X_CompositeRedirectSubwindows)
1846 fprintf (stderr, "Another composite manager is already running\n");
1850 o = ev->error_code - xfixes_error;
1852 case BadRegion: name = "BadRegion"; break;
1855 o = ev->error_code - damage_error;
1857 case BadDamage: name = "BadDamage"; break;
1860 o = ev->error_code - render_error;
1862 case BadPictFormat: name ="BadPictFormat"; break;
1863 case BadPicture: name ="BadPicture"; break;
1864 case BadPictOp: name ="BadPictOp"; break;
1865 case BadGlyphSet: name ="BadGlyphSet"; break;
1866 case BadGlyph: name ="BadGlyph"; break;
1870 printf ("error %d request %d minor %d serial %lu\n",
1871 ev->error_code, ev->request_code, ev->minor_code, ev->serial);
1873 /* abort (); this is just annoying to most people */
1878 expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
1880 XserverRegion region = XFixesCreateRegion (dpy, rects, nrects);
1882 add_damage (dpy, region);
1887 ev_serial (XEvent *ev)
1889 if (ev->type & 0x7f != KeymapNotify)
1890 return ev->xany.serial;
1891 return NextRequest (ev->xany.display);
1895 ev_name (XEvent *ev)
1897 static char buf[128];
1898 switch (ev->type & 0x7f) {
1905 case ReparentNotify:
1907 case CirculateNotify:
1910 if (ev->type == damage_event + XDamageNotify)
1912 sprintf (buf, "Event %d", ev->type);
1918 ev_window (XEvent *ev)
1922 return ev->xexpose.window;
1924 return ev->xmap.window;
1926 return ev->xunmap.window;
1927 case ReparentNotify:
1928 return ev->xreparent.window;
1929 case CirculateNotify:
1930 return ev->xcirculate.window;
1932 if (ev->type == damage_event + XDamageNotify)
1933 return ((XDamageNotifyEvent *) ev)->drawable;
1940 usage (char *program)
1942 fprintf (stderr, "%s v1.1.3\n", program);
1943 fprintf (stderr, "usage: %s [options]\n", program);
1944 fprintf (stderr, "Options\n");
1945 fprintf (stderr, " -d display\n Specifies which display should be managed.\n");
1946 fprintf (stderr, " -r radius\n Specifies the blur radius for client-side shadows. (default 12)\n");
1947 fprintf (stderr, " -o opacity\n Specifies the translucency for client-side shadows. (default .75)\n");
1948 fprintf (stderr, " -l left-offset\n Specifies the left offset for shadows. (default -15)\n");
1949 fprintf (stderr, " -t top-offset\n Specifies the top offset for shadows. (default -15)\n");
1950 fprintf (stderr, " -I fade-in-step\n Specifies the opacity change between steps while fading in. (default 0.028)\n");
1951 fprintf (stderr, " -O fade-out-step\n Specifies the opacity change between steps while fading out. (default 0.03)\n");
1952 fprintf (stderr, " -D fade-delta-time\n Specifies the time between steps in a fade in milliseconds. (default 10)\n");
1953 fprintf (stderr, " -m opacity\n Specifies the opacity for menus. (default 1.0)\n");
1954 fprintf (stderr, " -a\n Use automatic server-side compositing. Faster, but no special effects.\n");
1955 fprintf (stderr, " -c\n Draw client-side shadows with fuzzy edges.\n");
1956 fprintf (stderr, " -C\n Avoid drawing shadows on dock/panel windows.\n");
1957 fprintf (stderr, " -f\n Fade windows in/out when opening/closing.\n");
1958 fprintf (stderr, " -F\n Fade windows during opacity changes.\n");
1959 fprintf (stderr, " -n\n Normal client-side compositing with transparency support\n");
1960 fprintf (stderr, " -s\n Draw server-side shadows with sharp edges.\n");
1961 fprintf (stderr, " -S\n Enable synchronous operation (for debugging).\n");
1966 register_cm (int scr)
1973 if (scr < 0) return;
1975 w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
1978 Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
1981 len = strlen(REGISTER_PROP) + 2;
1988 snprintf(buf, len, REGISTER_PROP"%d", scr);
1990 a = XInternAtom (dpy, buf, False);
1993 XSetSelectionOwner (dpy, a, w, 0);
1997 main (int argc, char **argv)
2000 Window root_return, parent_return;
2002 unsigned int nchildren;
2004 XRenderPictureAttributes pa;
2005 XRectangle *expose_rects = 0;
2006 int size_expose = 0;
2010 int composite_major, composite_minor;
2013 Bool noDockShadow = False;
2015 for (i = 0; i < NUM_WINTYPES; ++i) {
2016 winTypeFade[i] = False;
2017 winTypeShadow[i] = False;
2018 winTypeOpacity[i] = 1.0;
2021 /* don't bother to draw a shadow for the desktop */
2022 winTypeShadow[WINTYPE_DESKTOP] = False;
2024 while ((o = getopt (argc, argv, "D:I:O:d:r:o:m:l:t:scnfFCaS")) != -1)
2031 fade_delta = atoi (optarg);
2036 fade_in_step = atof (optarg);
2037 if (fade_in_step <= 0)
2038 fade_in_step = 0.01;
2041 fade_out_step = atof (optarg);
2042 if (fade_out_step <= 0)
2043 fade_out_step = 0.01;
2046 compMode = CompServerShadows;
2047 for (i = 0; i < NUM_WINTYPES; ++i)
2048 winTypeShadow[i] = True;
2051 compMode = CompClientShadows;
2052 for (i = 0; i < NUM_WINTYPES; ++i)
2053 winTypeShadow[i] = True;
2056 noDockShadow = True;
2059 compMode = CompSimple;
2060 for (i = 0; i < NUM_WINTYPES; ++i)
2061 winTypeShadow[i] = False;
2064 winTypeOpacity[WINTYPE_DROPDOWN_MENU] = atof (optarg);
2065 winTypeOpacity[WINTYPE_POPUP_MENU] = atof (optarg);
2068 for (i = 0; i < NUM_WINTYPES; ++i)
2069 winTypeFade[i] = True;
2075 autoRedirect = True;
2081 shadowRadius = atoi (optarg);
2084 shadowOpacity = atof (optarg);
2087 shadowOffsetX = atoi (optarg);
2090 shadowOffsetY = atoi (optarg);
2099 winTypeShadow[WINTYPE_DOCK] = False;
2101 dpy = XOpenDisplay (display);
2104 fprintf (stderr, "Can't open display\n");
2107 XSetErrorHandler (error);
2109 XSynchronize (dpy, 1);
2110 scr = DefaultScreen (dpy);
2111 root = RootWindow (dpy, scr);
2113 if (!XRenderQueryExtension (dpy, &render_event, &render_error))
2115 fprintf (stderr, "No render extension\n");
2118 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode,
2119 &composite_event, &composite_error))
2121 fprintf (stderr, "No composite extension\n");
2124 XCompositeQueryVersion (dpy, &composite_major, &composite_minor);
2125 #if HAS_NAME_WINDOW_PIXMAP
2126 if (composite_major > 0 || composite_minor >= 2)
2127 hasNamePixmap = True;
2130 if (!XDamageQueryExtension (dpy, &damage_event, &damage_error))
2132 fprintf (stderr, "No damage extension\n");
2135 if (!XFixesQueryExtension (dpy, &xfixes_event, &xfixes_error))
2137 fprintf (stderr, "No XFixes extension\n");
2144 opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
2145 winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
2146 winType[WINTYPE_DESKTOP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
2147 winType[WINTYPE_DOCK] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
2148 winType[WINTYPE_TOOLBAR] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
2149 winType[WINTYPE_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
2150 winType[WINTYPE_UTILITY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
2151 winType[WINTYPE_SPLASH] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
2152 winType[WINTYPE_DIALOG] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
2153 winType[WINTYPE_NORMAL] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
2154 winType[WINTYPE_DROPDOWN_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DROPDOWN_MENU", False);
2155 winType[WINTYPE_POPUP_MENU] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_POPUP_MENU", False);
2156 winType[WINTYPE_TOOLTIP] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLTIP", False);
2157 winType[WINTYPE_NOTIFY] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NOTIFICATION", False);
2158 winType[WINTYPE_COMBO] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_COMBO", False);
2159 winType[WINTYPE_DND] = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DND", False);
2161 pa.subwindow_mode = IncludeInferiors;
2163 if (compMode == CompClientShadows)
2165 gaussianMap = make_gaussian_map(dpy, shadowRadius);
2166 presum_gaussian (gaussianMap);
2169 root_width = DisplayWidth (dpy, scr);
2170 root_height = DisplayHeight (dpy, scr);
2172 rootPicture = XRenderCreatePicture (dpy, root,
2173 XRenderFindVisualFormat (dpy,
2174 DefaultVisual (dpy, scr)),
2177 blackPicture = solid_picture (dpy, True, 1, 0, 0, 0);
2178 if (compMode == CompServerShadows)
2179 transBlackPicture = solid_picture (dpy, True, 0.3, 0, 0, 0);
2184 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectAutomatic);
2187 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual);
2188 XSelectInput (dpy, root,
2189 SubstructureNotifyMask|
2191 StructureNotifyMask|
2192 PropertyChangeMask);
2193 XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren);
2194 for (i = 0; i < nchildren; i++)
2195 add_win (dpy, children[i], i ? children[i-1] : None);
2198 XUngrabServer (dpy);
2199 ufd.fd = ConnectionNumber (dpy);
2200 ufd.events = POLLIN;
2202 paint_all (dpy, None);
2211 if (poll (&ufd, 1, fade_timeout()) == 0)
2218 XNextEvent (dpy, &ev);
2219 if ((ev.type & 0x7f) != KeymapNotify)
2220 discard_ignore (dpy, ev.xany.serial);
2222 printf ("event %10.10s serial 0x%08x window 0x%08x\n",
2223 ev_name(&ev), ev_serial (&ev), ev_window (&ev));
2225 if (!autoRedirect) switch (ev.type) {
2227 add_win (dpy, ev.xcreatewindow.window, 0);
2229 case ConfigureNotify:
2230 configure_win (dpy, &ev.xconfigure);
2233 destroy_win (dpy, ev.xdestroywindow.window, True);
2236 map_win (dpy, ev.xmap.window, ev.xmap.serial, True);
2239 unmap_win (dpy, ev.xunmap.window, True);
2241 case ReparentNotify:
2242 if (ev.xreparent.parent == root)
2243 add_win (dpy, ev.xreparent.window, 0);
2245 destroy_win (dpy, ev.xreparent.window, True);
2247 case CirculateNotify:
2248 circulate_win (dpy, &ev.xcirculate);
2251 if (ev.xexpose.window == root)
2253 int more = ev.xexpose.count + 1;
2254 if (n_expose == size_expose)
2258 expose_rects = realloc (expose_rects,
2259 (size_expose + more) *
2260 sizeof (XRectangle));
2261 size_expose += more;
2265 expose_rects = malloc (more * sizeof (XRectangle));
2269 expose_rects[n_expose].x = ev.xexpose.x;
2270 expose_rects[n_expose].y = ev.xexpose.y;
2271 expose_rects[n_expose].width = ev.xexpose.width;
2272 expose_rects[n_expose].height = ev.xexpose.height;
2274 if (ev.xexpose.count == 0)
2276 expose_root (dpy, root, expose_rects, n_expose);
2281 case PropertyNotify:
2282 for (p = 0; backgroundProps[p]; p++)
2284 if (ev.xproperty.atom == XInternAtom (dpy, backgroundProps[p], False))
2288 XClearArea (dpy, root, 0, 0, 0, 0, True);
2289 XRenderFreePicture (dpy, rootTile);
2295 /* check if Trans property was changed */
2296 if (ev.xproperty.atom == opacityAtom)
2298 /* reset mode and redraw window */
2299 win * w = find_win(dpy, ev.xproperty.window);
2303 set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w),
2304 fade_out_step, 0, True, False);
2307 w->opacity = get_opacity_prop(dpy, w, OPAQUE);
2308 determine_mode(dpy, w);
2311 XRenderFreePicture (dpy, w->shadow);
2314 if (w->extents != None)
2315 XFixesDestroyRegion (dpy, w->extents);
2317 /* rebuild the shadow */
2318 w->extents = win_extents (dpy, w);
2325 if (ev.type == damage_event + XDamageNotify)
2326 damage_win (dpy, (XDamageNotifyEvent *) &ev);
2329 } while (QLength (dpy));
2330 if (allDamage && !autoRedirect)
2333 paint_all (dpy, allDamage);
2337 clipChanged = False;