super fading
[dana/dcompmgr.git] / dcompmgr.c
index f6b7019..71f3eee 100644 (file)
@@ -6,7 +6,10 @@
 #include "display.h"
 #include "gettext.h"
 #include "time.h"
+
+/* these can be plugins */
 #include "render.h"
+#include "fade.h"
 
 #include <glib.h>
 #include <stdio.h>
@@ -76,8 +79,10 @@ event(d_display_t *dpy)
             if (!sc) break;
             w = screen_find_window(sc, dev->window);
             vis = window_is_mapped(w);
-            if (vis)
+            if (vis) {
+                sc->window_become_zombie(w);
                 sc->window_hide(w);
+            }
             screen_remove_window(sc, w);
             if (vis) screen_refresh(sc);
             break;
@@ -95,8 +100,10 @@ event(d_display_t *dpy)
             if (rev->parent == sc->super.root)
                 screen_add_window(sc, rev->window);
             else {
-                if (window_is_mapped(w))
+                if (window_is_mapped(w)) {
+                    sc->window_become_zombie(w);
                     sc->window_hide(w);
+                }
                 screen_remove_window(sc, w);
             }
             screen_refresh(sc);
@@ -126,6 +133,7 @@ event(d_display_t *dpy)
             sc = display_screen_from_root(dpy, mev->event);
             if (!sc) break;
             w = screen_find_window(sc, mev->window);
+            sc->window_become_zombie(w);
             sc->window_hide(w);
             screen_refresh(w->sc);
             break;
@@ -258,6 +266,22 @@ event(d_display_t *dpy)
 }
 
 static void
+timeouts(d_display_t *dpy)
+{
+    d_list_it_t *it;
+    struct timeval now;
+
+    gettimeofday(&now, NULL);
+    
+    for (it = list_top(dpy->screens); it; it = it->next) {
+        d_screen_t *sc = it->data;
+
+        render_timeout(sc, &now);
+        fade_timeout(sc, &now);
+    }
+}
+
+static void
 paint(d_display_t *dpy)
 {
     d_list_it_t *it;
@@ -278,17 +302,38 @@ run(d_display_t *dpy)
 {
     while (!quit) {
         struct timeval next, now, *wait;
-        int            r, npaint;
+        int            r, npaint, ntime;
         d_list_it_t   *it;
         fd_set         fds;
 
         event(dpy);
 
         npaint = 0;
+        ntime = 0;
         for (it = list_top(dpy->screens); it; it = it->next) {
             d_screen_t *sc = it->data;
+            struct timeval next_timeout;
+
+            if (render_next_timeout(sc, &next_timeout)) {
+                if ((!npaint && !ntime) ||
+                    time_compare(&next_timeout, &next) < 0)
+                {
+                    next = next_timeout;
+                    ++ntime;
+                }
+            }
+            if (fade_next_timeout(sc, &next_timeout)) {
+                if ((!npaint && !ntime) ||
+                    time_compare(&next_timeout, &next) < 0)
+                {
+                    next = next_timeout;
+                    ++ntime;
+                }
+            }
+
             if (sc->need_repaint &&
-                (!npaint || time_compare(&sc->next_repaint, &next) < 0))
+                ((!npaint && !ntime) ||
+                 time_compare(&sc->next_repaint, &next) < 0))
             {
                 next = sc->next_repaint;
                 ++npaint;
@@ -297,7 +342,7 @@ run(d_display_t *dpy)
 
         gettimeofday(&now, 0);
 
-        if (!npaint)
+        if (!npaint && !ntime)
             /* wait forever, there is nothing that needs drawing */
             wait = NULL;
         else if (time_compare(&next, &now) > 0) {
@@ -306,9 +351,9 @@ run(d_display_t *dpy)
             wait = &next;
         }
         else {
-            /* don't wait cuz a redraw is due now already */
+            /* don't wait cuz a timer is due now already */
             next.tv_sec = 0;
-            next.tv_usec = 100;
+            next.tv_usec = 0;
             wait = &next;
         }
 
@@ -320,6 +365,7 @@ run(d_display_t *dpy)
         r = select(dpy->fd+1, &fds, NULL, NULL, wait);
         if (r == 0) {
             //printf("select timeout\n");
+            timeouts(dpy);
             paint(dpy);
             xcb_flush(dpy->conn);
         }
@@ -342,6 +388,7 @@ setup_functions(d_display_t *dpy)
         /* these can be plugins.. */
         id = 1;
         render_init(sc, id++);
+        fade_init(sc, id++);
     }
 }
 
@@ -354,6 +401,7 @@ cleanup_functions(d_display_t *dpy)
         d_screen_t *sc = it->data;
 
         /* these can be plugins.. */
+        fade_free(sc);
         render_free(sc);
     }
 }