]> Pileus Git - wmpus/commitdiff
Add signal handlers
authorAndy Spencer <andy753421@gmail.com>
Mon, 10 Oct 2011 07:30:59 +0000 (07:30 +0000)
committerAndy Spencer <andy753421@gmail.com>
Mon, 10 Oct 2011 07:32:19 +0000 (07:32 +0000)
main.c
sys-win32.c

diff --git a/main.c b/main.c
index def49f1e85e27d19d9f0668e61b8830cb4060e1a..8ac32d046400835286ea866adb6a1ffffd3d51b1 100644 (file)
--- a/main.c
+++ b/main.c
 
 #include <stdlib.h>
 #include <stdio.h>
+#include <signal.h>
 
 #include "util.h"
 #include "conf.h"
 #include "sys.h"
 #include "wm.h"
 
+void on_sigint(int signum)
+{
+       sys_exit();
+}
+
 int main(int argc, char **argv)
 {
        setbuf(stdout, NULL); // debug
+       signal(SIGINT, on_sigint);
+
        conf_init(argc, argv);
        win_t *root = sys_init();
        wm_init(root);
index afacdd2ba99ec8d3b3ab83b923d1462a5e5d44fc..0e52935832df55bde60cefb551af5fa93210e4c7 100644 (file)
@@ -305,6 +305,12 @@ BOOL CALLBACK LoopProc(HWND hwnd, LPARAM user)
        return TRUE;
 }
 
+BOOL WINAPI CtrlProc(DWORD type)
+{
+       sys_exit();
+       return TRUE;
+}
+
 /********************
  * System functions *
  ********************/
@@ -429,6 +435,9 @@ win_t *sys_init(void)
        //if (!RegisterHotKey(NULL, 123, MOD_CONTROL, VK_LBUTTON))
        //      printf("sys_init: Error Registering Hotkey - %lu\n", GetLastError());
 
+       /* Capture ctrl-c and console widnow close */
+       SetConsoleCtrlHandler(CtrlProc, TRUE);
+
        return root = win_new(hwnd,0);
 }
 
@@ -446,7 +455,7 @@ void sys_run(win_t *root)
 
 void sys_exit(void)
 {
-       PostQuitMessage(0);
+       PostMessage(root->sys->hwnd, WM_QUIT, 0, 0);
 }
 
 void sys_free(win_t *root)