super fading
[dana/dcompmgr.git] / dcompmgr.c
index 52774fd..71f3eee 100644 (file)
@@ -1,10 +1,15 @@
+#include "efence.h"
+
 #include "screen.h"
 #include "window.h"
 #include "list.h"
 #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>
@@ -14,6 +19,7 @@
 #include <signal.h>
 #include <xcb/xcb.h>
 #include <xcb/damage.h>
+#include <xcb/shape.h>
 
 typedef struct {
     int foo;
@@ -53,11 +59,12 @@ event(d_display_t *dpy)
         {
             xcb_create_notify_event_t *cev;
             d_screen_t *sc;
+            d_window_t *w;
 
             cev = (xcb_create_notify_event_t*)ev;
             sc = display_screen_from_root(dpy, cev->parent);
             if (!sc) break;
-            screen_add_window(sc, cev->window);
+            w = screen_add_window(sc, cev->window);
             break;
         }
         case XCB_DESTROY_NOTIFY:
@@ -72,7 +79,10 @@ event(d_display_t *dpy)
             if (!sc) break;
             w = screen_find_window(sc, dev->window);
             vis = window_is_mapped(w);
-            sc->window_hide(w);
+            if (vis) {
+                sc->window_become_zombie(w);
+                sc->window_hide(w);
+            }
             screen_remove_window(sc, w);
             if (vis) screen_refresh(sc);
             break;
@@ -90,10 +100,13 @@ event(d_display_t *dpy)
             if (rev->parent == sc->super.root)
                 screen_add_window(sc, rev->window);
             else {
-                sc->window_hide(w);
+                if (window_is_mapped(w)) {
+                    sc->window_become_zombie(w);
+                    sc->window_hide(w);
+                }
                 screen_remove_window(sc, w);
             }
-            screen_refresh(w->sc);
+            screen_refresh(sc);
             break;
         }
         case XCB_MAP_NOTIFY:
@@ -120,10 +133,27 @@ 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;
         }
+        case XCB_CIRCULATE_NOTIFY:
+        {
+            xcb_circulate_notify_event_t *cev;
+            d_screen_t *sc;
+            d_window_t *w;
+
+            cev = (xcb_circulate_notify_event_t*)ev;
+            sc = display_screen_from_root(dpy, cev->event);
+            if (!sc) break;
+            w = screen_find_window(sc, cev->window);
+            if (cev->place == XCB_PLACE_ON_TOP)
+                screen_stacking_move_to_top(sc, w);
+            else
+                screen_stacking_move_to_bottom(sc, w);
+            screen_refresh(w->sc);
+        }
         case XCB_CONFIGURE_NOTIFY:
         {
             xcb_configure_notify_event_t *cev;
@@ -134,6 +164,7 @@ event(d_display_t *dpy)
             cev = (xcb_configure_notify_event_t*)ev;
             sc = display_screen_from_root(dpy, cev->event);
             if (!sc) break;
+            //printf("configure 0x%x", cev->window);
             w = screen_find_window(sc, cev->window);
             window_get_area(w, &x, &y, &width, &height, &bwidth);
             if (x != cev->x || y != cev->y || width != cev->width ||
@@ -142,16 +173,53 @@ event(d_display_t *dpy)
                 window_configure(w, cev->x, cev->y,
                                  cev->width, cev->height,
                                  cev->border_width);
-                if (window_is_mapped(w) &&
-                    (width != cev->width ||
-                     height != cev->height || bwidth != cev->border_width))
-                    sc->window_resize(w);
+                if (window_is_mapped(w)) {
+                    if (x != cev->x || y != cev->y)
+                        sc->window_move(w);
+                    if (width != cev->width ||
+                        height != cev->height || bwidth != cev->border_width)
+                        sc->window_resize(w);
+                }
             }
             above = screen_find_window(sc, cev->above_sibling);
             screen_stacking_move_above(sc, w, above);
             screen_refresh(w->sc);
             break;
         }
+        case XCB_PROPERTY_NOTIFY:
+        {
+            xcb_property_notify_event_t *pev;
+
+            pev = (xcb_property_notify_event_t*)ev;
+            if (pev->atom == dpy->a.xrootpmap_id ||
+                pev->atom == dpy->a.esetroot_pmap_id ||
+                pev->atom == dpy->a.xsetroot_id)
+            {
+                d_screen_t *sc;
+
+                sc = display_screen_from_root(dpy, pev->window);
+                if (sc) sc->screen_root_pixmap_change(sc);
+            }
+            else if (pev->atom == dpy->a.net_wm_window_opacity) {
+                d_list_it_t *it;
+
+                for (it = list_top(dpy->screens); it; it = it->next) {
+                    d_screen_t *sc = it->data;
+                    d_window_t *w;
+
+                    w = screen_find_window(sc, pev->window);
+                    if (w) {
+                        window_update_user_opacity(w);
+                        if (window_is_mapped(w)) {
+                            sc->window_opacity_change(w);
+                            screen_refresh(w->sc);
+                        }
+                    }
+                }
+                    
+            }
+            break;
+        }
         default:
             if (ev->response_type - dpy->damage.event == XCB_DAMAGE_NOTIFY) {
                 xcb_damage_notify_event_t *dev;
@@ -171,6 +239,25 @@ event(d_display_t *dpy)
                 xcb_damage_subtract(dpy->conn, dev->damage,
                                     XCB_NONE, XCB_NONE);
             }
+            else if (dpy->shape.present &&
+                     ev->response_type - dpy->shape.event == XCB_SHAPE_NOTIFY)
+            {
+                xcb_shape_notify_event_t *sev;
+                d_list_it_t *it;
+
+                sev = (xcb_shape_notify_event_t*)ev;
+                for (it = list_top(dpy->screens); it; it = it->next) {
+                    d_screen_t *sc = it->data;
+                    d_window_t *w;
+
+                    w = screen_find_window(sc, sev->affected_window);
+                    if (w) {
+                        sc->window_reshape(w);
+                        screen_refresh(w->sc);
+                        break;
+                    }
+                }
+            }
             break;
         }
         free(ev);
@@ -179,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;
@@ -199,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;
@@ -218,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) {
@@ -227,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;
         }
 
@@ -241,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);
         }
@@ -263,6 +388,7 @@ setup_functions(d_display_t *dpy)
         /* these can be plugins.. */
         id = 1;
         render_init(sc, id++);
+        fade_init(sc, id++);
     }
 }
 
@@ -275,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);
     }
 }
@@ -340,14 +467,28 @@ main(int argc, char **argv)
         for (sc_it = list_top(dpy->screens); sc_it; sc_it = sc_it->next) {
             d_screen_t *sc = sc_it->data;
             d_list_it_t *it;
-            for (it = list_top(sc->stacking); it; it = it->next)
-                if (window_is_mapped(it->data))
+            for (it = list_bottom(sc->stacking); it; it = it->prev)
+                if (window_is_attr_mapped(it->data))
                     sc->window_show(it->data);
         }
     }
 
     run(dpy);
 
+    {
+        /* make everything hidden */
+        d_list_it_t *sc_it;
+
+        for (sc_it = list_top(dpy->screens); sc_it; sc_it = sc_it->next) {
+            d_screen_t *sc = sc_it->data;
+            d_list_it_t *it;
+            for (it = list_top(sc->stacking); it; it = it->next) {
+                if (window_is_mapped(it->data))
+                    sc->window_hide(it->data);
+            }
+        }
+    }
+
     cleanup_functions(dpy);
 
     display_unref(dpy);