use the list for holding all the managed screens in the display. limit the number...
[dana/dcompmgr.git] / dcompmgr.c
index 2145dcb..f441f8a 100644 (file)
@@ -1,5 +1,6 @@
 #include "screen.h"
 #include "window.h"
+#include "list.h"
 #include "display.h"
 #include "gettext.h"
 #include "time.h"
@@ -33,7 +34,7 @@ event(d_display_t *dpy)
         if (!ev->response_type) {
             display_error(dpy, (xcb_generic_error_t*)ev);
             free(ev);
-            return;
+            continue;
         }
 
         switch (ev->response_type) {
@@ -60,6 +61,8 @@ event(d_display_t *dpy)
             w = screen_find_window(sc, dev->window);
             sc->window_hide(w);
             screen_remove_window(sc, w);
+            printf("** refresh needed **\n");
+            screen_refresh(sc);
             break;
         }
         case XCB_REPARENT_NOTIFY:
@@ -116,13 +119,13 @@ event(d_display_t *dpy)
 static void
 paint(d_display_t *dpy)
 {
-    int i;
+    d_list_it_t *it;
     struct timeval now;
 
     gettimeofday(&now, NULL);
     
-    for (i = 0; i < dpy->nscreens; ++i) {
-        d_screen_t *sc = display_screen_n(dpy, i);
+    for (it = list_top(dpy->screens); it; it = it->next) {
+        d_screen_t *sc = it->data;
 
         if (time_compare(&sc->next_repaint, &now) <= 0)
             sc->screen_paint(sc);
@@ -144,18 +147,51 @@ run(d_display_t *dpy)
 
     quit = FALSE;
     while (!quit) {
-        int r;
+        struct timeval next, now, *wait;
+        int            r, npaint;
+        d_list_it_t   *it;
+
+        npaint = 0;
+        for (it = list_top(dpy->screens); it; it = it->next) {
+            d_screen_t *sc = it->data;
+            if (sc->need_repaint &&
+                (!npaint || time_compare(&sc->next_repaint, &next) < 0))
+            {
+                next = sc->next_repaint;
+                ++npaint;
+            }
+        }
+
+        gettimeofday(&now, 0);
 
-        r = select(max+1, &fds, NULL, NULL, NULL);
+        printf("* loop paint %d *\n", npaint);
+
+        if (!npaint)
+            /* wait forever, there is nothing that needs drawing */
+            wait = NULL;
+        else if (time_compare(&next, &now) > 0) {
+            /* wait until the next allowed redraw time */
+            time_difference(&next, &now, &next);
+            wait = &next;
+        }
+        else {
+            /* don't wait cuz a redraw is due now already */
+            next.tv_sec = 0;
+            next.tv_usec = 1;
+            wait = &next;
+        }
+
+        r = select(max+1, &fds, NULL, NULL, wait);
         if (r < 0)
             printf("select error\n");
-        else if (r == 0)
+        else if (r == 0) {
             printf("select timeout\n");
+            paint(dpy);
+        }
         else {
             printf("select data\n");
             /*if (FD_ISSET(dpy->fd, &fds))*/ {
                 event(dpy);
-                paint(dpy);
             }
         }
 
@@ -167,10 +203,10 @@ run(d_display_t *dpy)
 static void
 setup_functions(d_display_t *dpy)
 {
-    int i;
+    d_list_it_t *it;
 
-    for (i = 0; i < dpy->nscreens; ++i) {
-        d_screen_t *sc = display_screen_n(dpy, i);
+    for (it = list_top(dpy->screens); it; it = it->next) {
+        d_screen_t *sc = it->data;
         screen_setup_default_functions(sc);
 
         /* these can be plugins.. */
@@ -181,10 +217,10 @@ setup_functions(d_display_t *dpy)
 static void
 cleanup_functions(d_display_t *dpy)
 {
-    int i;
+    d_list_it_t *it;
 
-    for (i = 0; i < dpy->nscreens; ++i) {
-        d_screen_t *sc = display_screen_n(dpy, i);
+    for (it = list_top(dpy->screens); it; it = it->next) {
+        d_screen_t *sc = it->data;
 
         /* these can be plugins.. */
         render_free(sc);