add a signal handler
authorDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 06:09:56 +0000 (01:09 -0500)
committerDana Jansens <danakj@orodu.net>
Wed, 5 Mar 2008 06:09:56 +0000 (01:09 -0500)
dcompmgr.c
screen.c

index d2cfc92..52774fd 100644 (file)
@@ -11,6 +11,7 @@
 #include <sys/select.h>
 #include <stdlib.h>
 #include <string.h>
+#include <signal.h>
 #include <xcb/xcb.h>
 #include <xcb/damage.h>
 
@@ -18,6 +19,8 @@ typedef struct {
     int foo;
 } d_options_t;
 
+static gboolean quit = FALSE;
+
 static void
 read_options(int argc, char **argv, d_options_t *opts)
 {
@@ -25,11 +28,18 @@ read_options(int argc, char **argv, d_options_t *opts)
 }
 
 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);
 
     {
index b800817..7045104 100644 (file)
--- 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;
 }