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
40 #include <sys/types.h>
44 #include <X11/Xutil.h>
45 #include <X11/Xatom.h>
46 #include <X11/extensions/Xcomposite.h>
47 #include <X11/extensions/Xdamage.h>
48 #include <X11/extensions/Xrender.h>
50 #if COMPOSITE_MAJOR > 0 || COMPOSITE_MINOR >= 2
51 #define HAS_NAME_WINDOW_PIXMAP 1
54 #define CAN_DO_USABLE 0
56 typedef struct _ignore {
58 unsigned long sequence;
64 #if HAS_NAME_WINDOW_PIXMAP
66 pthread_t pixmap_thread;
68 pthread_mutex_t pixmap_lock;
72 Bool usable; /* mapped and all damaged at one point */
73 XRectangle damage_bounds; /* bounds of damage */
81 XserverRegion borderSize;
82 XserverRegion extents;
90 unsigned long damage_sequence; /* sequence when damage was created */
91 Bool unmapped_configure;
93 /* for drawing translucent windows */
94 XserverRegion borderClip;
95 struct _win *prev_trans;
98 typedef struct _conv {
103 typedef struct _fade {
109 void (*callback) (Display *dpy, win *w);
113 typedef struct _threaddata {
116 XserverRegion extents;
117 pthread_t prev_thread;
127 Picture blackPicture;
128 Picture transBlackPicture;
130 XserverRegion allDamage;
131 pthread_mutex_t damage_lock = PTHREAD_MUTEX_INITIALIZER;
133 #if HAS_NAME_WINDOW_PIXMAP
136 int root_height, root_width;
137 ignore *ignore_head, **ignore_tail = &ignore_head;
138 int xfixes_event, xfixes_error;
139 int damage_event, damage_error;
140 int composite_event, composite_error;
141 int render_event, render_error;
143 int composite_opcode;
145 /* find these once and be done with it */
157 /* opacity property name; sometime soon I'll write up an EWMH spec for it */
158 #define OPACITY_PROP "_NET_WM_WINDOW_OPACITY"
160 #define TRANSLUCENT 0xe0000000
161 #define OPAQUE 0xffffffff
165 #define WINDOW_SOLID 0
166 #define WINDOW_TRANS 1
167 #define WINDOW_ARGB 2
169 #define TRANS_OPACITY 0.75
171 #define DEBUG_REPAINT 0
172 #define DEBUG_EVENTS 0
173 #define MONITOR_REPAINT 0
176 #define SHARP_SHADOW 0
178 typedef enum _compMode {
179 CompSimple, /* looks like a regular X server */
180 CompServerShadows, /* use window alpha for shadow; sharp, but precise */
181 CompClientShadows, /* use window extents for shadow, blurred */
185 determine_mode(Display *dpy, win *w);
188 get_opacity_percent(Display *dpy, win *w, double def);
191 win_extents (Display *dpy, win *w);
193 CompMode compMode = CompSimple;
195 int shadowRadius = 12;
196 int shadowOffsetX = -15;
197 int shadowOffsetY = -15;
198 double shadowOpacity = .75;
200 double fade_in_step = 0.028;
201 double fade_out_step = 0.03;
204 Bool fadeWindows = False;
205 Bool excludeDockShadows = False;
206 Bool fadeTrans = False;
208 Bool autoRedirect = False;
210 /* For shadow precomputation */
212 unsigned char *shadowCorner = NULL;
213 unsigned char *shadowTop = NULL;
216 get_time_in_milliseconds ()
220 gettimeofday (&tv, NULL);
221 return tv.tv_sec * 1000 + tv.tv_usec / 1000;
229 for (f = fades; f; f = f->next)
238 dequeue_fade (Display *dpy, fade *f)
242 for (prev = &fades; *prev; prev = &(*prev)->next)
247 (*f->callback) (dpy, f->w);
254 cleanup_fade (Display *dpy, win *w)
256 fade *f = find_fade (w);
258 dequeue_fade (dpy, f);
262 enqueue_fade (Display *dpy, fade *f)
265 fade_time = get_time_in_milliseconds () + fade_delta;
271 set_fade (Display *dpy, win *w, double start, double finish, double step,
272 void (*callback) (Display *dpy, win *w),
273 Bool exec_callback, Bool override)
280 f = malloc (sizeof (fade));
284 enqueue_fade (dpy, f);
292 (*f->callback)(dpy, f->w);
302 else if (f->cur > finish)
304 f->callback = callback;
305 w->opacity = f->cur * OPAQUE;
307 printf ("set_fade start %g step %g\n", f->cur, f->step);
309 determine_mode (dpy, w);
312 XRenderFreePicture (dpy, w->shadow);
314 w->extents = win_extents (dpy, w);
325 now = get_time_in_milliseconds();
326 delta = fade_time - now;
329 /* printf ("timeout %d\n", delta); */
334 run_fades (Display *dpy)
336 int now = get_time_in_milliseconds();
342 printf ("run fades\n");
344 if (fade_time - now > 0)
346 steps = 1 + (now - fade_time) / fade_delta;
353 f->cur += f->step * steps;
359 printf ("opacity now %g\n", f->cur);
361 w->opacity = f->cur * OPAQUE;
362 need_dequeue = False;
365 if (f->cur >= f->finish)
367 w->opacity = f->finish*OPAQUE;
373 if (f->cur <= f->finish)
375 w->opacity = f->finish*OPAQUE;
379 determine_mode (dpy, w);
382 XRenderFreePicture (dpy, w->shadow);
384 w->extents = win_extents(dpy, w);
386 /* Must do this last as it might destroy f->w in callbacks */
388 dequeue_fade (dpy, f);
390 fade_time = now + fade_delta;
394 gaussian (double r, double x, double y)
396 return ((1 / (sqrt (2 * M_PI * r))) *
397 exp ((- (x * x + y * y)) / (2 * r * r)));
402 make_gaussian_map (Display *dpy, double r)
405 int size = ((int) ceil ((r * 3)) + 1) & ~1;
406 int center = size / 2;
411 c = malloc (sizeof (conv) + size * size * sizeof (double));
413 c->data = (double *) (c + 1);
415 for (y = 0; y < size; y++)
416 for (x = 0; x < size; x++)
418 g = gaussian (r, (double) (x - center), (double) (y - center));
420 c->data[y * size + x] = g;
422 /* printf ("gaussian total %f\n", t); */
423 for (y = 0; y < size; y++)
424 for (x = 0; x < size; x++)
426 c->data[y*size + x] /= t;
432 * A picture will help
434 * -center 0 width width+center
435 * -center +-----+-------------------+-----+
438 * 0 +-----+-------------------+-----+
442 * height +-----+-------------------+-----+
445 * center +-----+-------------------+-----+
449 sum_gaussian (conv *map, double opacity, int x, int y, int width, int height)
453 double *g_line = map->data;
454 int g_size = map->size;
455 int center = g_size / 2;
456 int fx_start, fx_end;
457 int fy_start, fy_end;
461 * Compute set of filter values which are "in range",
462 * that's the set with:
463 * 0 <= x + (fx-center) && x + (fx-center) < width &&
464 * 0 <= y + (fy-center) && y + (fy-center) < height
466 * 0 <= x + (fx - center) x + fx - center < width
467 * center - x <= fx fx < width + center - x
470 fx_start = center - x;
473 fx_end = width + center - x;
477 fy_start = center - y;
480 fy_end = height + center - y;
484 g_line = g_line + fy_start * g_size + fx_start;
487 for (fy = fy_start; fy < fy_end; fy++)
492 for (fx = fx_start; fx < fx_end; fx++)
498 return ((unsigned char) (v * opacity * 255.0));
501 /* precompute shadow corners and sides to save time for large windows */
503 presum_gaussian (conv *map)
505 int center = map->size/2;
511 free ((void *)shadowCorner);
513 free ((void *)shadowTop);
515 shadowCorner = (unsigned char *)(malloc ((Gsize + 1) * (Gsize + 1) * 26));
516 shadowTop = (unsigned char *)(malloc ((Gsize + 1) * 26));
518 for (x = 0; x <= Gsize; x++)
520 shadowTop[25 * (Gsize + 1) + x] = sum_gaussian (map, 1, x - center, center, Gsize * 2, Gsize * 2);
521 for(opacity = 0; opacity < 25; opacity++)
522 shadowTop[opacity * (Gsize + 1) + x] = shadowTop[25 * (Gsize + 1) + x] * opacity / 25;
523 for(y = 0; y <= x; y++)
525 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
526 = sum_gaussian (map, 1, x - center, y - center, Gsize * 2, Gsize * 2);
527 shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
528 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
529 for(opacity = 0; opacity < 25; opacity++)
530 shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x]
531 = shadowCorner[opacity * (Gsize + 1) * (Gsize + 1) + x * (Gsize + 1) + y]
532 = shadowCorner[25 * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x] * opacity / 25;
538 make_shadow (Display *dpy, double opacity, int width, int height)
542 int gsize = gaussianMap->size;
544 int swidth = width + gsize;
545 int sheight = height + gsize;
546 int center = gsize / 2;
550 int opacity_int = (int)(opacity * 25);
551 data = malloc (swidth * sheight * sizeof (unsigned char));
554 ximage = XCreateImage (dpy,
555 DefaultVisual(dpy, DefaultScreen(dpy)),
560 swidth, sheight, 8, swidth * sizeof (unsigned char));
567 * Build the gaussian in sections
571 * center (fill the complete data array)
574 d = shadowTop[opacity_int * (Gsize + 1) + Gsize];
576 d = sum_gaussian (gaussianMap, opacity, center, center, width, height);
577 memset(data, d, sheight * swidth);
583 if (ylimit > sheight / 2)
584 ylimit = (sheight + 1) / 2;
586 if (xlimit > swidth / 2)
587 xlimit = (swidth + 1) / 2;
589 for (y = 0; y < ylimit; y++)
590 for (x = 0; x < xlimit; x++)
592 if (xlimit == Gsize && ylimit == Gsize)
593 d = shadowCorner[opacity_int * (Gsize + 1) * (Gsize + 1) + y * (Gsize + 1) + x];
595 d = sum_gaussian (gaussianMap, opacity, x - center, y - center, width, height);
596 data[y * swidth + x] = d;
597 data[(sheight - y - 1) * swidth + x] = d;
598 data[(sheight - y - 1) * swidth + (swidth - x - 1)] = d;
599 data[y * swidth + (swidth - x - 1)] = d;
605 x_diff = swidth - (gsize * 2);
606 if (x_diff > 0 && ylimit > 0)
608 for (y = 0; y < ylimit; y++)
611 d = shadowTop[opacity_int * (Gsize + 1) + y];
613 d = sum_gaussian (gaussianMap, opacity, center, y - center, width, height);
614 memset (&data[y * swidth + gsize], d, x_diff);
615 memset (&data[(sheight - y - 1) * swidth + gsize], d, x_diff);
623 for (x = 0; x < xlimit; x++)
626 d = shadowTop[opacity_int * (Gsize + 1) + x];
628 d = sum_gaussian (gaussianMap, opacity, x - center, center, width, height);
629 for (y = gsize; y < sheight - gsize; y++)
631 data[y * swidth + x] = d;
632 data[y * swidth + (swidth - x - 1)] = d;
640 shadow_picture (Display *dpy, double opacity, Picture alpha_pict, int width, int height, int *wp, int *hp)
644 Picture shadowPicture;
647 shadowImage = make_shadow (dpy, opacity, width, height);
650 shadowPixmap = XCreatePixmap (dpy, root,
656 XDestroyImage (shadowImage);
660 shadowPicture = XRenderCreatePicture (dpy, shadowPixmap,
661 XRenderFindStandardFormat (dpy, PictStandardA8),
665 XDestroyImage (shadowImage);
666 XFreePixmap (dpy, shadowPixmap);
670 gc = XCreateGC (dpy, shadowPixmap, 0, 0);
673 XDestroyImage (shadowImage);
674 XFreePixmap (dpy, shadowPixmap);
675 XRenderFreePicture (dpy, shadowPicture);
679 XPutImage (dpy, shadowPixmap, gc, shadowImage, 0, 0, 0, 0,
681 shadowImage->height);
682 *wp = shadowImage->width;
683 *hp = shadowImage->height;
685 XDestroyImage (shadowImage);
686 XFreePixmap (dpy, shadowPixmap);
687 return shadowPicture;
691 solid_picture (Display *dpy, Bool argb, double a, double r, double g, double b)
695 XRenderPictureAttributes pa;
698 pixmap = XCreatePixmap (dpy, root, 1, 1, argb ? 32 : 8);
703 picture = XRenderCreatePicture (dpy, pixmap,
704 XRenderFindStandardFormat (dpy, argb ? PictStandardARGB32 : PictStandardA8),
709 XFreePixmap (dpy, pixmap);
713 c.alpha = a * 0xffff;
715 c.green = g * 0xffff;
717 XRenderFillRectangle (dpy, PictOpSrc, picture, &c, 0, 0, 1, 1);
718 XFreePixmap (dpy, pixmap);
723 discard_ignore (Display *dpy, unsigned long sequence)
727 if ((long) (sequence - ignore_head->sequence) > 0)
729 ignore *next = ignore_head->next;
733 ignore_tail = &ignore_head;
741 set_ignore (Display *dpy, unsigned long sequence)
743 ignore *i = malloc (sizeof (ignore));
746 i->sequence = sequence;
749 ignore_tail = &i->next;
753 should_ignore (Display *dpy, unsigned long sequence)
755 discard_ignore (dpy, sequence);
756 return ignore_head && ignore_head->sequence == sequence;
760 find_win (Display *dpy, Window id)
764 for (w = list; w; w = w->next)
770 static const char *backgroundProps[] = {
777 root_tile (Display *dpy)
783 unsigned long nitems;
784 unsigned long bytes_after;
787 XRenderPictureAttributes pa;
791 for (p = 0; backgroundProps[p]; p++)
793 if (XGetWindowProperty (dpy, root, XInternAtom (dpy, backgroundProps[p], False),
794 0, 4, False, AnyPropertyType,
795 &actual_type, &actual_format, &nitems, &bytes_after, &prop) == Success &&
796 actual_type == XInternAtom (dpy, "PIXMAP", False) && actual_format == 32 && nitems == 1)
798 memcpy (&pixmap, prop, 4);
806 pixmap = XCreatePixmap (dpy, root, 1, 1, DefaultDepth (dpy, scr));
810 picture = XRenderCreatePicture (dpy, pixmap,
811 XRenderFindVisualFormat (dpy,
812 DefaultVisual (dpy, scr)),
818 c.red = c.green = c.blue = 0x8080;
820 XRenderFillRectangle (dpy, PictOpSrc, picture, &c,
827 paint_root (Display *dpy)
830 rootTile = root_tile (dpy);
832 XRenderComposite (dpy, PictOpSrc,
833 rootTile, None, rootBuffer,
834 0, 0, 0, 0, 0, 0, root_width, root_height);
838 win_extents (Display *dpy, win *w)
844 r.width = w->a.width + w->a.border_width * 2;
845 r.height = w->a.height + w->a.border_width * 2;
846 if (compMode != CompSimple && !(w->windowType == winDockAtom && excludeDockShadows))
848 if (compMode == CompServerShadows || w->mode != WINDOW_ARGB)
852 if (compMode == CompServerShadows)
856 w->shadow_width = w->a.width;
857 w->shadow_height = w->a.height;
861 w->shadow_dx = shadowOffsetX;
862 w->shadow_dy = shadowOffsetY;
865 double opacity = shadowOpacity;
866 if (w->mode == WINDOW_TRANS)
867 opacity = opacity * ((double)w->opacity)/((double)OPAQUE);
868 w->shadow = shadow_picture (dpy, opacity, w->alphaPict,
869 w->a.width + w->a.border_width * 2,
870 w->a.height + w->a.border_width * 2,
871 &w->shadow_width, &w->shadow_height);
874 sr.x = w->a.x + w->shadow_dx;
875 sr.y = w->a.y + w->shadow_dy;
876 sr.width = w->shadow_width;
877 sr.height = w->shadow_height;
880 r.width = (r.x + r.width) - sr.x;
885 r.height = (r.y + r.height) - sr.y;
888 if (sr.x + sr.width > r.x + r.width)
889 r.width = sr.x + sr.width - r.x;
890 if (sr.y + sr.height > r.y + r.height)
891 r.height = sr.y + sr.height - r.y;
894 return XFixesCreateRegion (dpy, &r, 1);
898 border_size (Display *dpy, win *w)
900 XserverRegion border;
902 * if window doesn't exist anymore, this will generate an error
903 * as well as not generate a region. Perhaps a better XFixes
904 * architecture would be to have a request that copies instead
905 * of creates, that way you'd just end up with an empty region
906 * instead of an invalid XID.
908 set_ignore (dpy, NextRequest (dpy));
909 border = XFixesCreateRegionFromWindow (dpy, w->id, WindowRegionBounding);
911 set_ignore (dpy, NextRequest (dpy));
912 XFixesTranslateRegion (dpy, border,
913 w->a.x + w->a.border_width,
914 w->a.y + w->a.border_width);
919 add_damage (Display *dpy, XserverRegion damage)
921 pthread_mutex_lock (&damage_lock);
924 XFixesUnionRegion (dpy, allDamage, allDamage, damage);
925 XFixesDestroyRegion (dpy, damage);
929 pthread_mutex_unlock (&damage_lock);
933 repair_win (Display *dpy, win *w)
939 parts = win_extents (dpy, w);
940 set_ignore (dpy, NextRequest (dpy));
941 XDamageSubtract (dpy, w->damage, None, None);
946 parts = XFixesCreateRegion (dpy, 0, 0);
947 set_ignore (dpy, NextRequest (dpy));
948 XDamageSubtract (dpy, w->damage, None, parts);
949 XFixesTranslateRegion (dpy, parts,
950 w->a.x + w->a.border_width,
951 w->a.y + w->a.border_width);
952 if (compMode == CompServerShadows)
954 o = XFixesCreateRegion (dpy, 0, 0);
955 XFixesCopyRegion (dpy, o, parts);
956 XFixesTranslateRegion (dpy, o, w->shadow_dx, w->shadow_dy);
957 XFixesUnionRegion (dpy, parts, parts, o);
958 XFixesDestroyRegion (dpy, o);
962 printf("adding damage 0x%x 0x%x\n", w->id, w->picture);
963 add_damage (dpy, parts);
967 #if HAS_NAME_WINDOW_PIXMAP
969 get_pixmap_thread (void *vdata)
971 threaddata *d = vdata;
975 /* if another thread is already running for this window, then wait for it
976 to exit before start */
977 if (d->prev_thread != 0) {
980 pthread_join (d->prev_thread, &ret);
986 printf("getting pixmap for 0x%x\n", d->w->id);
988 /* this is the slow stuff */
989 XLockDisplay (d->dpy);
990 pix = XCompositeNameWindowPixmap (d->dpy, d->w->id);
992 XRenderPictureAttributes pa;
993 XRenderPictFormat *format;
995 format = XRenderFindVisualFormat (d->dpy, d->w->a.visual);
996 pa.subwindow_mode = IncludeInferiors;
997 pic = XRenderCreatePicture (d->dpy, pix,
1002 XUnlockDisplay (d->dpy);
1004 /* we're done the slow stuff so lock and set things */
1007 pthread_mutex_lock (&d->w->pixmap_lock);
1011 XFreePixmap (dpy, d->w->pixmap);
1012 d->w->pixmap = None;
1017 XRenderFreePicture (dpy, d->w->picture);
1018 d->w->picture = None;
1022 d->w->picture = pic;
1024 pthread_mutex_unlock (&d->w->pixmap_lock);
1026 /* make the window redraw */
1027 //add_damage(d->dpy, d->extents);
1028 /* wake up the main loop */
1029 kill(getpid(), SIGURG);
1034 pthread_mutex_lock (&d->w->pixmap_lock);
1035 d->w->pixmap_nthreads--;
1036 pthread_mutex_unlock (&d->w->pixmap_lock);
1042 #if HAS_NAME_WINDOW_PIXMAP
1044 start_get_pixmap_thread (Display *dpy, win *w, XserverRegion extents)
1046 if (hasNamePixmap) {
1049 pthread_mutex_lock (&w->pixmap_lock);
1050 w->pixmap_nthreads++;
1051 pthread_mutex_unlock (&w->pixmap_lock);
1053 data = malloc (sizeof (threaddata));
1056 data->extents = extents;
1057 data->prev_thread = w->pixmap_thread;
1058 if (pthread_create (&w->pixmap_thread, NULL, get_pixmap_thread, data))
1061 pthread_mutex_lock (&w->pixmap_lock);
1062 w->pixmap_nthreads--;
1063 pthread_mutex_unlock (&w->pixmap_lock);
1070 paint_all (Display *dpy, XserverRegion region)
1074 Bool pending = False;
1081 r.width = root_width;
1082 r.height = root_height;
1083 region = XFixesCreateRegion (dpy, &r, 1);
1086 rootBuffer = rootPicture;
1090 Pixmap rootPixmap = XCreatePixmap (dpy, root, root_width, root_height,
1091 DefaultDepth (dpy, scr));
1092 rootBuffer = XRenderCreatePicture (dpy, rootPixmap,
1093 XRenderFindVisualFormat (dpy,
1094 DefaultVisual (dpy, scr)),
1096 XFreePixmap (dpy, rootPixmap);
1099 XFixesSetPictureClipRegion (dpy, rootPicture, 0, 0, region);
1101 XRenderComposite (dpy, PictOpSrc, blackPicture, None, rootPicture,
1102 0, 0, 0, 0, 0, 0, root_width, root_height);
1107 for (w = list; w; w = w->next)
1113 /* never painted, ignore it */
1116 /* if invisible, ignore it */
1117 if (w->a.x + w->a.width < 1 || w->a.y + w->a.height < 1
1118 || w->a.x >= root_width || w->a.y >= root_height)
1121 #if HAS_NAME_WINDOW_PIXMAP
1122 pthread_mutex_lock (&w->pixmap_lock);
1126 XRenderPictureAttributes pa;
1127 XRenderPictFormat *format;
1129 format = XRenderFindVisualFormat (dpy, w->a.visual);
1130 pa.subwindow_mode = IncludeInferiors;
1131 w->picture = XRenderCreatePicture (dpy, w->id,
1135 printf("got temp picture for 0x%x\n", w->id);
1137 #if HAS_NAME_WINDOW_PIXMAP
1141 #if HAS_NAME_WINDOW_PIXMAP
1142 pthread_mutex_unlock (&w->pixmap_lock);
1146 printf (" 0x%x", w->id);
1152 set_ignore (dpy, NextRequest (dpy));
1153 XFixesDestroyRegion (dpy, w->borderSize);
1154 w->borderSize = None;
1158 XFixesDestroyRegion (dpy, w->extents);
1163 XFixesDestroyRegion (dpy, w->borderClip);
1164 w->borderClip = None;
1168 w->borderSize = border_size (dpy, w);
1170 w->extents = win_extents (dpy, w);
1171 if (w->mode == WINDOW_SOLID)
1174 #if HAS_NAME_WINDOW_PIXMAP
1177 wid = w->a.width + w->a.border_width * 2;
1178 hei = w->a.height + w->a.border_width * 2;
1180 x = w->a.x + w->a.border_width;
1181 y = w->a.y + w->a.border_width;
1185 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1186 set_ignore (dpy, NextRequest (dpy));
1187 XFixesSubtractRegion (dpy, region, region, w->borderSize);
1188 set_ignore (dpy, NextRequest (dpy));
1189 XRenderComposite (dpy, PictOpSrc, w->picture, None, rootBuffer,
1195 w->borderClip = XFixesCreateRegion (dpy, 0, 0);
1196 XFixesCopyRegion (dpy, w->borderClip, region);
1205 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, region);
1207 for (w = t; w; w = w->prev_trans)
1209 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, w->borderClip);
1213 case CompServerShadows:
1214 /* dont' bother drawing shadows on desktop windows */
1215 if (w->windowType == winDesktopAtom)
1217 set_ignore (dpy, NextRequest (dpy));
1218 if (w->opacity != OPAQUE && !w->shadowPict)
1219 w->shadowPict = solid_picture (dpy, True,
1220 (double) w->opacity / OPAQUE * 0.3,
1222 XRenderComposite (dpy, PictOpOver,
1223 w->shadowPict ? w->shadowPict : transBlackPicture,
1224 w->picture, rootBuffer,
1226 w->a.x + w->shadow_dx,
1227 w->a.y + w->shadow_dy,
1228 w->shadow_width, w->shadow_height);
1230 case CompClientShadows:
1231 /* don't bother drawing shadows on desktop windows */
1232 if (w->shadow && w->windowType != winDesktopAtom)
1234 XRenderComposite (dpy, PictOpOver, blackPicture, w->shadow, rootBuffer,
1236 w->a.x + w->shadow_dx,
1237 w->a.y + w->shadow_dy,
1238 w->shadow_width, w->shadow_height);
1242 if (w->opacity != OPAQUE && !w->alphaPict)
1243 w->alphaPict = solid_picture (dpy, False,
1244 (double) w->opacity / OPAQUE, 0, 0, 0);
1245 if (w->mode == WINDOW_TRANS)
1248 #if HAS_NAME_WINDOW_PIXMAP
1251 wid = w->a.width + w->a.border_width * 2;
1252 hei = w->a.height + w->a.border_width * 2;
1254 x = w->a.x + w->a.border_width;
1255 y = w->a.y + w->a.border_width;
1259 set_ignore (dpy, NextRequest (dpy));
1260 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1264 else if (w->mode == WINDOW_ARGB)
1267 #if HAS_NAME_WINDOW_PIXMAP
1270 wid = w->a.width + w->a.border_width * 2;
1271 hei = w->a.height + w->a.border_width * 2;
1273 x = w->a.x + w->a.border_width;
1274 y = w->a.y + w->a.border_width;
1278 set_ignore (dpy, NextRequest (dpy));
1279 XRenderComposite (dpy, PictOpOver, w->picture, w->alphaPict, rootBuffer,
1283 XFixesDestroyRegion (dpy, w->borderClip);
1284 w->borderClip = None;
1286 XFixesDestroyRegion (dpy, region);
1287 if (rootBuffer != rootPicture)
1289 XFixesSetPictureClipRegion (dpy, rootBuffer, 0, 0, None);
1290 XRenderComposite (dpy, PictOpSrc, rootBuffer, None, rootPicture,
1291 0, 0, 0, 0, 0, 0, root_width, root_height);
1298 get_opacity_prop (Display *dpy, win *w, unsigned int def);
1301 map_win (Display *dpy, Window id, unsigned long sequence, Bool fade)
1303 win *w = find_win (dpy, id);
1308 w->a.map_state = IsViewable;
1310 /* This needs to be here or else we lose transparency messages */
1311 XSelectInput (dpy, id, PropertyChangeMask);
1313 /* This needs to be here since we don't get PropertyNotify when unmapped */
1314 w->opacity = get_opacity_prop (dpy, w, OPAQUE);
1315 determine_mode (dpy, w);
1318 w->damage_bounds.x = w->damage_bounds.y = 0;
1319 w->damage_bounds.width = w->damage_bounds.height = 0;
1323 if (fade && fadeWindows)
1324 set_fade (dpy, w, 0, get_opacity_percent (dpy, w, 1.0), fade_in_step, 0, True, True);
1326 #if HAS_NAME_WINDOW_PIXMAP
1327 start_get_pixmap_thread (dpy, w, 0);
1332 finish_unmap_win (Display *dpy, win *w)
1338 if (w->extents != None)
1340 add_damage (dpy, w->extents); /* destroys region */
1344 if (w->unmapped_configure) {
1345 #if HAS_NAME_WINDOW_PIXMAP
1346 pthread_mutex_lock (&w->pixmap_lock);
1349 XFreePixmap (dpy, w->pixmap);
1353 XRenderFreePicture (dpy, w->picture);
1357 pthread_mutex_unlock (&w->pixmap_lock);
1361 /* don't care about properties anymore */
1362 set_ignore (dpy, NextRequest (dpy));
1363 XSelectInput(dpy, w->id, 0);
1367 set_ignore (dpy, NextRequest (dpy));
1368 XFixesDestroyRegion (dpy, w->borderSize);
1369 w->borderSize = None;
1373 XRenderFreePicture (dpy, w->shadow);
1378 XFixesDestroyRegion (dpy, w->borderClip);
1379 w->borderClip = None;
1385 #if HAS_NAME_WINDOW_PIXMAP
1387 unmap_callback (Display *dpy, win *w)
1389 finish_unmap_win (dpy, w);
1394 unmap_win (Display *dpy, Window id, Bool fade)
1396 win *w = find_win (dpy, id);
1399 w->a.map_state = IsUnmapped;
1400 #if HAS_NAME_WINDOW_PIXMAP
1401 if (w->pixmap && fade && fadeWindows)
1402 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step, unmap_callback, False, True);
1405 finish_unmap_win (dpy, w);
1408 /* Get the opacity prop from window
1413 get_opacity_prop(Display *dpy, win *w, unsigned int def)
1417 unsigned long n, left;
1419 unsigned char *data;
1420 int result = XGetWindowProperty(dpy, w->id, opacityAtom, 0L, 1L, False,
1421 XA_CARDINAL, &actual, &format,
1423 if (result == Success && data != NULL)
1426 memcpy (&i, data, sizeof (unsigned int));
1427 XFree( (void *) data);
1433 /* Get the opacity property from the window in a percent format
1435 otherwise: the value
1438 get_opacity_percent(Display *dpy, win *w, double def)
1440 unsigned int opacity = get_opacity_prop (dpy, w, (unsigned int)(OPAQUE*def));
1442 return opacity*1.0/OPAQUE;
1445 /* determine mode for window all in one place.
1446 Future might check for menu flag and other cool things
1450 get_wintype_prop(Display * dpy, Window w)
1454 unsigned long n, left;
1456 unsigned char *data;
1457 int result = XGetWindowProperty (dpy, w, winTypeAtom, 0L, 1L, False,
1458 XA_ATOM, &actual, &format,
1461 if (result == Success && data != None)
1464 memcpy (&a, data, sizeof (Atom));
1465 XFree ( (void *) data);
1468 return winNormalAtom;
1472 determine_mode(Display *dpy, win *w)
1475 XRenderPictFormat *format;
1477 /* if trans prop == -1 fall back on previous tests*/
1481 XRenderFreePicture (dpy, w->alphaPict);
1482 w->alphaPict = None;
1486 XRenderFreePicture (dpy, w->shadowPict);
1487 w->shadowPict = None;
1490 if (w->a.class == InputOnly)
1496 format = XRenderFindVisualFormat (dpy, w->a.visual);
1499 if (format && format->type == PictTypeDirect && format->direct.alphaMask)
1503 else if (w->opacity != OPAQUE)
1505 mode = WINDOW_TRANS;
1509 mode = WINDOW_SOLID;
1514 XserverRegion damage;
1515 damage = XFixesCreateRegion (dpy, 0, 0);
1516 XFixesCopyRegion (dpy, damage, w->extents);
1517 add_damage (dpy, damage);
1522 determine_wintype (Display *dpy, Window w)
1524 Window root_return, parent_return;
1525 Window *children = NULL;
1526 unsigned int nchildren, i;
1529 type = get_wintype_prop (dpy, w);
1530 if (type != winNormalAtom)
1533 if (!XQueryTree (dpy, w, &root_return, &parent_return, &children,
1536 /* XQueryTree failed. */
1538 XFree ((void *)children);
1539 return winNormalAtom;
1542 for (i = 0;i < nchildren;i++)
1544 type = determine_wintype (dpy, children[i]);
1545 if (type != winNormalAtom)
1550 XFree ((void *)children);
1552 return winNormalAtom;
1556 add_win (Display *dpy, Window id, Window prev)
1558 win *new = malloc (sizeof (win));
1565 for (p = &list; *p; p = &(*p)->next)
1566 if ((*p)->id == prev)
1572 set_ignore (dpy, NextRequest (dpy));
1573 if (!XGetWindowAttributes (dpy, id, &new->a))
1580 new->usable = False;
1582 #if HAS_NAME_WINDOW_PIXMAP
1584 new->pixmap_thread = 0;
1585 new->pixmap_nthreads = 0;
1586 pthread_mutex_init(&new->pixmap_lock, NULL);
1588 new->picture = None;
1589 if (new->a.class == InputOnly)
1591 new->damage_sequence = 0;
1596 new->damage_sequence = NextRequest (dpy);
1597 new->damage = XDamageCreate (dpy, id, XDamageReportNonEmpty);
1599 new->alphaPict = None;
1600 new->shadowPict = None;
1601 new->borderSize = None;
1602 new->extents = None;
1606 new->shadow_width = 0;
1607 new->shadow_height = 0;
1608 new->opacity = OPAQUE;
1609 new->unmapped_configure = False;
1611 new->borderClip = None;
1612 new->prev_trans = 0;
1614 new->windowType = determine_wintype (dpy, new->id);
1618 if (new->a.map_state == IsViewable)
1619 map_win (dpy, id, new->damage_sequence - 1, True);
1623 restack_win (Display *dpy, win *w, Window new_above)
1628 old_above = w->next->id;
1631 if (old_above != new_above)
1636 for (prev = &list; *prev; prev = &(*prev)->next)
1642 for (prev = &list; *prev; prev = &(*prev)->next)
1644 if ((*prev)->id == new_above)
1653 configure_win (Display *dpy, XConfigureEvent *ce)
1655 win *w = find_win (dpy, ce->window);
1656 XserverRegion damage = None;
1660 if (ce->window == root)
1664 XRenderFreePicture (dpy, rootBuffer);
1667 root_width = ce->width;
1668 root_height = ce->height;
1676 damage = XFixesCreateRegion (dpy, 0, 0);
1677 if (w->extents != None)
1678 XFixesCopyRegion (dpy, damage, w->extents);
1682 /* Only destroy the pixmap if the window is mapped */
1683 if (w->a.width != ce->width || w->a.height != ce->height)
1685 if (w->a.map_state == IsUnmapped)
1686 w->unmapped_configure = True;
1688 #if HAS_NAME_WINDOW_PIXMAP
1689 start_get_pixmap_thread (dpy, w, 0);
1693 XRenderFreePicture (dpy, w->shadow);
1698 w->a.width = ce->width;
1699 w->a.height = ce->height;
1700 w->a.border_width = ce->border_width;
1701 w->a.override_redirect = ce->override_redirect;
1702 restack_win (dpy, w, ce->above);
1703 if (w->a.map_state != IsUnmapped && damage)
1705 XserverRegion extents = win_extents (dpy, w);
1706 XFixesUnionRegion (dpy, damage, damage, extents);
1707 XFixesDestroyRegion (dpy, extents);
1708 add_damage (dpy, damage);
1714 circulate_win (Display *dpy, XCirculateEvent *ce)
1716 win *w = find_win (dpy, ce->window);
1722 if (ce->place == PlaceOnTop)
1723 new_above = list->id;
1726 restack_win (dpy, w, new_above);
1731 finish_destroy_win (Display *dpy, Window id)
1736 for (prev = &list; (w = *prev); prev = &w->next)
1739 /* join before freeing stuff so nothing leaks */
1740 if (w->pixmap_nthreads > 0)
1741 pthread_join (w->pixmap_thread, &ret);
1743 finish_unmap_win (dpy, w);
1745 #if HAS_NAME_WINDOW_PIXMAP
1748 XFreePixmap (dpy, w->pixmap);
1754 set_ignore (dpy, NextRequest (dpy));
1755 XRenderFreePicture (dpy, w->picture);
1760 XRenderFreePicture (dpy, w->alphaPict);
1761 w->alphaPict = None;
1765 XRenderFreePicture (dpy, w->shadowPict);
1766 w->shadowPict = None;
1768 if (w->damage != None)
1770 set_ignore (dpy, NextRequest (dpy));
1771 XDamageDestroy (dpy, w->damage);
1774 cleanup_fade (dpy, w);
1775 pthread_mutex_destroy(&w->pixmap_lock);
1781 #if HAS_NAME_WINDOW_PIXMAP
1783 destroy_callback (Display *dpy, win *w)
1785 finish_destroy_win (dpy, w->id);
1790 destroy_win (Display *dpy, Window id, Bool fade)
1792 win *w = find_win (dpy, id);
1793 #if HAS_NAME_WINDOW_PIXMAP
1794 if (w && w->pixmap && fade && fadeWindows)
1795 set_fade (dpy, w, w->opacity*1.0/OPAQUE, 0.0, fade_out_step,
1796 destroy_callback, False, (w->a.map_state != IsUnmapped));
1800 finish_destroy_win (dpy, id);
1808 printf ("\t%08lx: %d x %d + %d + %d (%d)\n", w->id,
1809 w->a.width, w->a.height, w->a.x, w->a.y, w->a.border_width);
1818 printf ("windows:\n");
1819 for (w = list; w; w = w->next)
1825 damage_win (Display *dpy, XDamageNotifyEvent *de)
1827 win *w = find_win (dpy, de->drawable);
1834 if (w->damage_bounds.width == 0 || w->damage_bounds.height == 0)
1836 w->damage_bounds = de->area;
1840 if (de->area.x < w->damage_bounds.x)
1842 w->damage_bounds.width += (w->damage_bounds.x - de->area.x);
1843 w->damage_bounds.x = de->area.x;
1845 if (de->area.y < w->damage_bounds.y)
1847 w->damage_bounds.height += (w->damage_bounds.y - de->area.y);
1848 w->damage_bounds.y = de->area.y;
1850 if (de->area.x + de->area.width > w->damage_bounds.x + w->damage_bounds.width)
1851 w->damage_bounds.width = de->area.x + de->area.width - w->damage_bounds.x;
1852 if (de->area.y + de->area.height > w->damage_bounds.y + w->damage_bounds.height)
1853 w->damage_bounds.height = de->area.y + de->area.height - w->damage_bounds.y;
1856 printf ("unusable damage %d, %d: %d x %d bounds %d, %d: %d x %d\n",
1863 w->damage_bounds.width,
1864 w->damage_bounds.height);
1866 if (w->damage_bounds.x <= 0 &&
1867 w->damage_bounds.y <= 0 &&
1868 w->a.width <= w->damage_bounds.x + w->damage_bounds.width &&
1869 w->a.height <= w->damage_bounds.y + w->damage_bounds.height)
1873 set_fade (dpy, w, 0, get_opacity_percent (dpy, w, 1.0), fade_in_step, 0, True, True);
1879 repair_win (dpy, w);
1883 error (Display *dpy, XErrorEvent *ev)
1886 const char *name = 0;
1888 if (should_ignore (dpy, ev->serial))
1891 if (ev->request_code == composite_opcode &&
1892 ev->minor_code == X_CompositeRedirectSubwindows)
1894 fprintf (stderr, "Another composite manager is already running\n");
1898 o = ev->error_code - xfixes_error;
1900 case BadRegion: name = "BadRegion"; break;
1903 o = ev->error_code - damage_error;
1905 case BadDamage: name = "BadDamage"; break;
1908 o = ev->error_code - render_error;
1910 case BadPictFormat: name ="BadPictFormat"; break;
1911 case BadPicture: name ="BadPicture"; break;
1912 case BadPictOp: name ="BadPictOp"; break;
1913 case BadGlyphSet: name ="BadGlyphSet"; break;
1914 case BadGlyph: name ="BadGlyph"; break;
1918 printf ("error %d request %d minor %d serial %lu\n",
1919 ev->error_code, ev->request_code, ev->minor_code, ev->serial);
1921 /* abort (); this is just annoying to most people */
1926 expose_root (Display *dpy, Window root, XRectangle *rects, int nrects)
1928 XserverRegion region = XFixesCreateRegion (dpy, rects, nrects);
1930 add_damage (dpy, region);
1935 ev_serial (XEvent *ev)
1937 if (ev->type & 0x7f != KeymapNotify)
1938 return ev->xany.serial;
1939 return NextRequest (ev->xany.display);
1943 ev_name (XEvent *ev)
1945 static char buf[128];
1946 switch (ev->type & 0x7f) {
1953 case ReparentNotify:
1955 case CirculateNotify:
1958 if (ev->type == damage_event + XDamageNotify)
1960 sprintf (buf, "Event %d", ev->type);
1966 ev_window (XEvent *ev)
1970 return ev->xexpose.window;
1972 return ev->xmap.window;
1974 return ev->xunmap.window;
1975 case ReparentNotify:
1976 return ev->xreparent.window;
1977 case CirculateNotify:
1978 return ev->xcirculate.window;
1980 if (ev->type == damage_event + XDamageNotify)
1981 return ((XDamageNotifyEvent *) ev)->drawable;
1988 usage (char *program)
1990 fprintf (stderr, "%s v1.1.3\n", program);
1991 fprintf (stderr, "usage: %s [options]\n", program);
1992 fprintf (stderr, "Options\n");
1993 fprintf (stderr, " -d display\n Specifies which display should be managed.\n");
1994 fprintf (stderr, " -r radius\n Specifies the blur radius for client-side shadows. (default 12)\n");
1995 fprintf (stderr, " -o opacity\n Specifies the translucency for client-side shadows. (default .75)\n");
1996 fprintf (stderr, " -l left-offset\n Specifies the left offset for client-side shadows. (default -15)\n");
1997 fprintf (stderr, " -t top-offset\n Specifies the top offset for clinet-side shadows. (default -15)\n");
1998 fprintf (stderr, " -I fade-in-step\n Specifies the opacity change between steps while fading in. (default 0.028)\n");
1999 fprintf (stderr, " -O fade-out-step\n Specifies the opacity change between steps while fading out. (default 0.03)\n");
2000 fprintf (stderr, " -D fade-delta-time\n Specifies the time between steps in a fade in milliseconds. (default 10)\n");
2001 fprintf (stderr, " -a\n Use automatic server-side compositing. Faster, but no special effects.\n");
2002 fprintf (stderr, " -c\n Draw client-side shadows with fuzzy edges.\n");
2003 fprintf (stderr, " -C\n Avoid drawing shadows on dock/panel windows.\n");
2004 fprintf (stderr, " -f\n Fade windows in/out when opening/closing.\n");
2005 fprintf (stderr, " -F\n Fade windows during opacity changes.\n");
2006 fprintf (stderr, " -n\n Normal client-side compositing with transparency support\n");
2007 fprintf (stderr, " -s\n Draw server-side shadows with sharp edges.\n");
2008 fprintf (stderr, " -S\n Enable synchronous operation (for debugging).\n");
2018 w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
2021 Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
2024 /* FIXME: Don't hard code the screen number */
2025 a = XInternAtom (dpy, "_NET_WM_CM_S0", False);
2027 XSetSelectionOwner (dpy, a, w, 0);
2031 main (int argc, char **argv)
2034 Window root_return, parent_return;
2036 unsigned int nchildren;
2038 XRenderPictureAttributes pa;
2039 XRectangle *expose_rects = 0;
2040 int size_expose = 0;
2044 int composite_major, composite_minor;
2048 while ((o = getopt (argc, argv, "D:I:O:d:r:o:l:t:scnfFCaS")) != -1)
2055 fade_delta = atoi (optarg);
2060 fade_in_step = atof (optarg);
2061 if (fade_in_step <= 0)
2062 fade_in_step = 0.01;
2065 fade_out_step = atof (optarg);
2066 if (fade_out_step <= 0)
2067 fade_out_step = 0.01;
2070 compMode = CompServerShadows;
2073 compMode = CompClientShadows;
2076 excludeDockShadows = True;
2079 compMode = CompSimple;
2088 autoRedirect = True;
2094 shadowRadius = atoi (optarg);
2097 shadowOpacity = atof (optarg);
2100 shadowOffsetX = atoi (optarg);
2103 shadowOffsetY = atoi (optarg);
2112 dpy = XOpenDisplay (display);
2115 fprintf (stderr, "Can't open display\n");
2118 XSetErrorHandler (error);
2120 XSynchronize (dpy, 1);
2121 scr = DefaultScreen (dpy);
2122 root = RootWindow (dpy, scr);
2124 if (!XRenderQueryExtension (dpy, &render_event, &render_error))
2126 fprintf (stderr, "No render extension\n");
2129 if (!XQueryExtension (dpy, COMPOSITE_NAME, &composite_opcode,
2130 &composite_event, &composite_error))
2132 fprintf (stderr, "No composite extension\n");
2135 XCompositeQueryVersion (dpy, &composite_major, &composite_minor);
2136 #if HAS_NAME_WINDOW_PIXMAP
2137 if (composite_major > 0 || composite_minor >= 2)
2138 hasNamePixmap = True;
2141 if (!XDamageQueryExtension (dpy, &damage_event, &damage_error))
2143 fprintf (stderr, "No damage extension\n");
2146 if (!XFixesQueryExtension (dpy, &xfixes_event, &xfixes_error))
2148 fprintf (stderr, "No XFixes extension\n");
2155 opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
2156 winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);
2157 winDesktopAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DESKTOP", False);
2158 winDockAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DOCK", False);
2159 winToolbarAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_TOOLBAR", False);
2160 winMenuAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_MENU", False);
2161 winUtilAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_UTILITY", False);
2162 winSplashAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_SPLASH", False);
2163 winDialogAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_DIALOG", False);
2164 winNormalAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE_NORMAL", False);
2166 pa.subwindow_mode = IncludeInferiors;
2168 if (compMode == CompClientShadows)
2170 gaussianMap = make_gaussian_map(dpy, shadowRadius);
2171 presum_gaussian (gaussianMap);
2174 root_width = DisplayWidth (dpy, scr);
2175 root_height = DisplayHeight (dpy, scr);
2177 rootPicture = XRenderCreatePicture (dpy, root,
2178 XRenderFindVisualFormat (dpy,
2179 DefaultVisual (dpy, scr)),
2182 blackPicture = solid_picture (dpy, True, 1, 0, 0, 0);
2183 if (compMode == CompServerShadows)
2184 transBlackPicture = solid_picture (dpy, True, 0.3, 0, 0, 0);
2189 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectAutomatic);
2192 XCompositeRedirectSubwindows (dpy, root, CompositeRedirectManual);
2193 XSelectInput (dpy, root,
2194 SubstructureNotifyMask|
2196 StructureNotifyMask|
2197 PropertyChangeMask);
2198 XQueryTree (dpy, root, &root_return, &parent_return, &children, &nchildren);
2199 for (i = 0; i < nchildren; i++)
2200 add_win (dpy, children[i], i ? children[i-1] : None);
2203 XUngrabServer (dpy);
2204 ufd.fd = ConnectionNumber (dpy);
2205 ufd.events = POLLIN;
2207 paint_all (dpy, None);
2216 if (poll (&ufd, 1, fade_timeout()) == 0)
2223 XNextEvent (dpy, &ev);
2224 if ((ev.type & 0x7f) != KeymapNotify)
2225 discard_ignore (dpy, ev.xany.serial);
2227 printf ("event %10.10s serial 0x%08x window 0x%08x\n",
2228 ev_name(&ev), ev_serial (&ev), ev_window (&ev));
2230 if (!autoRedirect) switch (ev.type) {
2232 add_win (dpy, ev.xcreatewindow.window, 0);
2234 case ConfigureNotify:
2235 configure_win (dpy, &ev.xconfigure);
2238 destroy_win (dpy, ev.xdestroywindow.window, True);
2241 map_win (dpy, ev.xmap.window, ev.xmap.serial, True);
2244 unmap_win (dpy, ev.xunmap.window, True);
2246 case ReparentNotify:
2247 if (ev.xreparent.parent == root)
2248 add_win (dpy, ev.xreparent.window, 0);
2250 destroy_win (dpy, ev.xreparent.window, True);
2252 case CirculateNotify:
2253 circulate_win (dpy, &ev.xcirculate);
2256 if (ev.xexpose.window == root)
2258 int more = ev.xexpose.count + 1;
2259 if (n_expose == size_expose)
2263 expose_rects = realloc (expose_rects,
2264 (size_expose + more) *
2265 sizeof (XRectangle));
2266 size_expose += more;
2270 expose_rects = malloc (more * sizeof (XRectangle));
2274 expose_rects[n_expose].x = ev.xexpose.x;
2275 expose_rects[n_expose].y = ev.xexpose.y;
2276 expose_rects[n_expose].width = ev.xexpose.width;
2277 expose_rects[n_expose].height = ev.xexpose.height;
2279 if (ev.xexpose.count == 0)
2281 expose_root (dpy, root, expose_rects, n_expose);
2286 case PropertyNotify:
2287 for (p = 0; backgroundProps[p]; p++)
2289 if (ev.xproperty.atom == XInternAtom (dpy, backgroundProps[p], False))
2293 XClearArea (dpy, root, 0, 0, 0, 0, True);
2294 XRenderFreePicture (dpy, rootTile);
2300 /* check if Trans property was changed */
2301 if (ev.xproperty.atom == opacityAtom)
2303 /* reset mode and redraw window */
2304 win * w = find_win(dpy, ev.xproperty.window);
2308 set_fade (dpy, w, w->opacity*1.0/OPAQUE, get_opacity_percent (dpy, w, 1.0),
2309 fade_out_step, 0, True, False);
2312 w->opacity = get_opacity_prop(dpy, w, OPAQUE);
2313 determine_mode(dpy, w);
2316 XRenderFreePicture (dpy, w->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 pthread_mutex_lock (&damage_lock);
2331 if (allDamage && !autoRedirect)
2334 if (!paint_all (dpy, allDamage))
2338 clipChanged = False;
2340 pthread_mutex_unlock (&damage_lock);