]> Pileus Git - wmpus/commitdiff
Support graceful shutdown
authorAndy Spencer <andy753421@gmail.com>
Wed, 5 Oct 2011 03:28:51 +0000 (03:28 +0000)
committerAndy Spencer <andy753421@gmail.com>
Wed, 5 Oct 2011 03:28:51 +0000 (03:28 +0000)
sys-x11.c
sys.h
wm-wmii.c

index 072216b76ca54c45550ae37be72c719e1d6a5aee..7222b462141d7f5eb5a38b22ca62ef6585bdeaff 100644 (file)
--- a/sys-x11.c
+++ b/sys-x11.c
@@ -55,6 +55,7 @@ typedef enum {
 } color_t;
 
 /* Global data */
 } color_t;
 
 /* Global data */
+static int   running;
 static void *cache;
 static Atom atoms[natoms];
 static int (*xerrorxlib)(Display *, XErrorEvent *);
 static void *cache;
 static Atom atoms[natoms];
 static int (*xerrorxlib)(Display *, XErrorEvent *);
@@ -569,10 +570,16 @@ void sys_run(win_t *root)
        wm_update(); // For struts
 
        /* Main loop */
        wm_update(); // For struts
 
        /* Main loop */
-       for(;;)
+       running = 1;
+       while (running)
        {
                XEvent ev;
                XNextEvent(root->sys->dpy, &ev);
                process_event(ev.type, &ev, root);
        }
 }
        {
                XEvent ev;
                XNextEvent(root->sys->dpy, &ev);
                process_event(ev.type, &ev, root);
        }
 }
+
+void sys_exit(void)
+{
+       running = 0;
+}
diff --git a/sys.h b/sys.h
index d2001225a1baee26218ec6ccb4a33b8948ae1c8c..c08b595d62956e9cef261531a8b5e9e70100a82f 100644 (file)
--- a/sys.h
+++ b/sys.h
@@ -119,3 +119,6 @@ win_t *sys_init(void);
 
 /* Starts the main loop */
 void sys_run(win_t *root);
 
 /* Starts the main loop */
 void sys_run(win_t *root);
+
+/* Exit main loop */
+void sys_exit(void);
index 06b71f67694830210204c2a374b23dd23c8d6f03..ea631242abfed36d5568910bce14734283f8ee1a 100644 (file)
--- a/wm-wmii.c
+++ b/wm-wmii.c
@@ -739,6 +739,7 @@ int wm_handle_key(win_t *win, Key_t key, mod_t mod, ptr_t ptr)
 #endif
                if (key == key_f5) return wm_update(),    1;
                if (key == key_f6) return print_txt(),    1;
 #endif
                if (key == key_f5) return wm_update(),    1;
                if (key == key_f6) return print_txt(),    1;
+               if (key == 'q')    return sys_exit(),     1;
        }
 
        /* Floating layer */
        }
 
        /* Floating layer */
@@ -902,7 +903,7 @@ void wm_init(win_t *root)
        wm->tags    = list_insert(NULL, wm->tag);
 
        Key_t keys_e[] = {key_enter, key_focus};
        wm->tags    = list_insert(NULL, wm->tag);
 
        Key_t keys_e[] = {key_enter, key_focus};
-       Key_t keys_s[] = {'h', 'j', 'k', 'l', ' ',
+       Key_t keys_s[] = {'h', 'j', 'k', 'l', 'q', ' ',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9'};
        Key_t keys_m[] = {'h', 'j', 'k', 'l', 'd', 's', 'm', 't', ' ',
                '0', '1', '2', '3', '4', '5', '6', '7', '8', '9',