add a next_repaint time to each screen
authorDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 23:33:52 +0000 (18:33 -0500)
committerDana Jansens <danakj@orodu.net>
Tue, 4 Mar 2008 23:33:52 +0000 (18:33 -0500)
screen.c
screen.h
time.c [new file with mode: 0644]
time.h [new file with mode: 0644]

index e238bc7..cbaf13a 100644 (file)
--- a/screen.c
+++ b/screen.c
@@ -1,6 +1,7 @@
 #include "screen.h"
 #include "display.h"
 #include "list.h"
+#include "time.h"
 #include "window.h"
 #include "render.h"
 #include "gettext.h"
@@ -92,6 +93,7 @@ static gboolean
 screen_init(d_screen_t *sc)
 {
     uint32_t mask;
+#if DO_COMP
     xcb_generic_error_t *err;
     xcb_void_cookie_t redir_ck;
     xcb_composite_get_overlay_window_cookie_t overlay_ck;
@@ -122,6 +124,7 @@ screen_init(d_screen_t *sc)
     }
     sc->overlay = overlay_rep->overlay_win;
     free(overlay_rep);
+#endif
 
     mask = SELECTION_MASK;
     xcb_change_window_attributes(sc->dpy->conn, sc->selwin,
@@ -133,6 +136,8 @@ screen_init(d_screen_t *sc)
     /* use the render backend */
     sc->paint = render_paint_screen;
 
+    gettimeofday(&sc->next_repaint, NULL);
+
     sc->winhash = g_hash_table_new((GHashFunc)xcb_window_hash,
                                    (GCompareFunc)xcb_window_compare);
     sc->stacking = list_new();
@@ -243,3 +248,11 @@ screen_stacking_remove(d_screen_t *sc, struct d_window *w)
 {
     list_remove(sc->stacking, w);
 }
+
+void
+screen_set_next_repaint(d_screen_t *sc)
+{
+    gettimeofday(&sc->next_repaint, NULL);
+    /* add time for the refresh rate (60 hz) */
+    time_add(&sc->next_repaint, 1000000/60);
+}
index bfa93ed..1e442f5 100644 (file)
--- a/screen.h
+++ b/screen.h
@@ -3,6 +3,7 @@
 
 #include <xcb/xcb.h>
 #include <glib.h>
+#include <sys/time.h>
 
 struct d_window;
 struct d_display;
@@ -19,6 +20,8 @@ typedef struct d_screen {
 
     xcb_window_t      overlay;
 
+    struct timeval    next_repaint;
+
     GHashTable       *winhash;
     struct d_list    *stacking;
 
@@ -39,4 +42,6 @@ struct d_window* screen_find_window(d_screen_t *sc, xcb_window_t id);
 void screen_stacking_add(d_screen_t *sc, struct d_window *w);
 void screen_stacking_remove(d_screen_t *sc, struct d_window *w);
 
+void screen_set_next_repaint(d_screen_t *sc);
+
 #endif
diff --git a/time.c b/time.c
new file mode 100644 (file)
index 0000000..38b60b2
--- /dev/null
+++ b/time.c
@@ -0,0 +1,23 @@
+#include "time.h"
+
+void
+time_add(struct timeval *tv, long microseconds)
+{
+    tv->tv_usec += microseconds;
+    while (tv->tv_usec >= 1000000) {
+        tv->tv_usec -= 1000000;
+        ++tv->tv_sec;
+    }
+    while (tv->tv_usec < 0) {
+        tv->tv_usec += 1000000;
+        --tv->tv_sec;
+    }
+}
+
+long
+time_compare(struct timeval *a, struct timeval *b)
+{
+    long r;
+    if ((r = a->tv_sec - b->tv_sec)) return r;
+    return a->tv_usec - b->tv_usec;
+}
diff --git a/time.h b/time.h
new file mode 100644 (file)
index 0000000..d8ac405
--- /dev/null
+++ b/time.h
@@ -0,0 +1,9 @@
+#ifndef dc__time_h
+#define dc__time_h
+
+#include <sys/time.h>
+
+void time_add(struct timeval *tv, long microseconds);
+long time_compare(struct timeval *a, struct timeval *b);
+
+#endif