From 6864b3cbbce3b4a84ba44dbfb244bc1848f562f7 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Wed, 5 Mar 2008 01:09:56 -0500 Subject: [PATCH] add a signal handler --- dcompmgr.c | 26 ++++++++++++++++++-------- screen.c | 4 ++-- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/dcompmgr.c b/dcompmgr.c index d2cfc92..52774fd 100644 --- a/dcompmgr.c +++ b/dcompmgr.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include @@ -18,18 +19,27 @@ typedef struct { int foo; } d_options_t; +static gboolean quit = FALSE; + static void read_options(int argc, char **argv, d_options_t *opts) { opts->foo = argc && argv; } +static void +signal_quit_handler(int sig) +{ + printf("caught signal %d, quitting\n", sig); + quit = TRUE; +} + static void event(d_display_t *dpy) { xcb_generic_event_t *ev; - while ((ev = xcb_poll_for_event(dpy->conn))) { + while ((ev = xcb_poll_for_event(dpy->conn)) && !quit) { //printf("event %d\n", ev->response_type); if (!ev->response_type) { @@ -187,9 +197,6 @@ paint(d_display_t *dpy) static void run(d_display_t *dpy) { - gboolean quit; - - quit = FALSE; while (!quit) { struct timeval next, now, *wait; int r, npaint; @@ -222,7 +229,7 @@ run(d_display_t *dpy) else { /* don't wait cuz a redraw is due now already */ next.tv_sec = 0; - next.tv_usec = 1; + next.tv_usec = 100; wait = &next; } @@ -232,9 +239,7 @@ run(d_display_t *dpy) //printf("select %d\n", npaint); r = select(dpy->fd+1, &fds, NULL, NULL, wait); - if (r < 0) - printf("select error\n"); - else if (r == 0) { + if (r == 0) { //printf("select timeout\n"); paint(dpy); xcb_flush(dpy->conn); @@ -321,6 +326,11 @@ main(int argc, char **argv) return 0; } + signal(SIGINT, signal_quit_handler); + signal(SIGHUP, signal_quit_handler); + signal(SIGTERM, signal_quit_handler); + signal(SIGQUIT, signal_quit_handler); + setup_functions(dpy); { diff --git a/screen.c b/screen.c index b800817..7045104 100644 --- a/screen.c +++ b/screen.c @@ -310,8 +310,8 @@ static void screen_set_next_repaint(d_screen_t *sc) { gettimeofday(&sc->next_repaint, NULL); - /* add time for the refresh rate (30 hz) */ - time_add(&sc->next_repaint, 1000000/30); + /* add time for the refresh rate (60 hz) */ + time_add(&sc->next_repaint, 1000000/60); sc->need_repaint = FALSE; } -- 2.34.1