Bug #2703: Fixed a memory leak in the fading code.
[dana/xcompmgr.git] / xcompmgr.c
index c39b7b1..816123b 100644 (file)
@@ -322,6 +322,7 @@ run_fades (Display *dpy)
     int            now = get_time_in_milliseconds();
     fade    *f, *next;
     int            steps;
+    Bool    need_dequeue;
 
 #if 0
     printf ("run fades\n");
@@ -342,12 +343,13 @@ run_fades (Display *dpy)
        printf ("opacity now %g\n", f->cur);
 #endif
        w->opacity = f->cur * OPAQUE;
+       need_dequeue = False;
        if (f->step > 0)
        {
            if (f->cur >= f->finish)
            {
                w->opacity = f->finish*OPAQUE;
-               dequeue_fade (dpy, f);
+               need_dequeue = True;
            }
        }
        else
@@ -355,7 +357,7 @@ run_fades (Display *dpy)
            if (f->cur <= f->finish)
            {
                w->opacity = f->finish*OPAQUE;
-               dequeue_fade (dpy, f);
+               need_dequeue = True;
            }
        }
        determine_mode (dpy, w);
@@ -365,6 +367,9 @@ run_fades (Display *dpy)
            w->shadow = None;
            w->extents = win_extents(dpy, w);
        }
+       /* Must do this last as it might destroy f->w in callbacks */
+       if (need_dequeue)
+               dequeue_fade (dpy, f);
     }
     fade_time = now + fade_delta;
 }
@@ -1594,7 +1599,7 @@ finish_destroy_win (Display *dpy, Window id, Bool gone)
     for (prev = &list; (w = *prev); prev = &w->next)
        if (w->id == id)
        {
-           if (!gone)
+           if (gone)
                finish_unmap_win (dpy, w);
            *prev = w->next;
            if (w->picture)
@@ -1833,7 +1838,7 @@ ev_window (XEvent *ev)
 void
 usage (char *program)
 {
-    fprintf (stderr, "%s v1.1\n", program);
+    fprintf (stderr, "%s v1.1.2\n", program);
     fprintf (stderr, "usage: %s [options]\n", program);
     fprintf (stderr, "Options\n");
     fprintf (stderr, "   -d display\n      Specifies which display should be managed.\n");
@@ -1855,6 +1860,24 @@ usage (char *program)
     exit (1);
 }
 
+static void
+register_cm (void)
+{
+    Window w;
+    Atom a;
+
+    w = XCreateSimpleWindow (dpy, RootWindow (dpy, 0), 0, 0, 1, 1, 0, None,
+                            None);
+
+    Xutf8SetWMProperties (dpy, w, "xcompmgr", "xcompmgr", NULL, 0, NULL, NULL,
+                         NULL);
+
+    /* FIXME: Don't hard code the screen number */
+    a = XInternAtom (dpy, "_NET_WM_CM_S0", False);
+
+    XSetSelectionOwner (dpy, a, w, 0);
+}
+
 int
 main (int argc, char **argv)
 {
@@ -1981,6 +2004,9 @@ main (int argc, char **argv)
        fprintf (stderr, "No XFixes extension\n");
        exit (1);
     }
+
+    register_cm();
+
     /* get atoms */
     opacityAtom = XInternAtom (dpy, OPACITY_PROP, False);
     winTypeAtom = XInternAtom (dpy, "_NET_WM_WINDOW_TYPE", False);