From 52b06a9790e02381d11d9811c331ebf1121a2396 Mon Sep 17 00:00:00 2001 From: Andy Spencer Date: Mon, 10 Oct 2011 07:30:59 +0000 Subject: [PATCH] Add signal handlers --- main.c | 8 ++++++++ sys-win32.c | 11 ++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/main.c b/main.c index def49f1..8ac32d0 100644 --- a/main.c +++ b/main.c @@ -15,15 +15,23 @@ #include #include +#include #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); diff --git a/sys-win32.c b/sys-win32.c index afacdd2..0e52935 100644 --- a/sys-win32.c +++ b/sys-win32.c @@ -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) -- 2.43.2