From 58d3b1388f3842290a047a89406438c53120b6ec Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Tue, 4 Mar 2008 18:33:52 -0500 Subject: [PATCH] add a next_repaint time to each screen --- screen.c | 13 +++++++++++++ screen.h | 5 +++++ time.c | 23 +++++++++++++++++++++++ time.h | 9 +++++++++ 4 files changed, 50 insertions(+) create mode 100644 time.c create mode 100644 time.h diff --git a/screen.c b/screen.c index e238bc7..cbaf13a 100644 --- 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); +} diff --git a/screen.h b/screen.h index bfa93ed..1e442f5 100644 --- a/screen.h +++ b/screen.h @@ -3,6 +3,7 @@ #include #include +#include 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 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 index 0000000..d8ac405 --- /dev/null +++ b/time.h @@ -0,0 +1,9 @@ +#ifndef dc__time_h +#define dc__time_h + +#include + +void time_add(struct timeval *tv, long microseconds); +long time_compare(struct timeval *a, struct timeval *b); + +#endif -- 2.34.1