libgnt/libgnt

Add a Windows signal handler.

2019-04-26, Elliott Sales de Andrade
19c1a4a2e5cc
Parents 9c0f0847ae76
Children 1eaceab078ca
Add a Windows signal handler.
  • +22 -0
    gntmain.c
  • --- a/gntmain.c Fri Apr 26 17:32:54 2019 -0400
    +++ b/gntmain.c Fri Apr 26 18:40:51 2019 -0400
    @@ -533,6 +533,21 @@
    static void (*org_winch_handler_sa)(int, siginfo_t *, void *);
    #endif
    +#ifdef _WIN32
    +static BOOL WINAPI
    +CtrlHandler(DWORD fdwCtrlType)
    +{
    + switch (fdwCtrlType) {
    + case CTRL_C_EVENT:
    + case CTRL_CLOSE_EVENT:
    + ask_before_exit();
    + return TRUE;
    +
    + default:
    + return FALSE;
    + }
    +}
    +#else
    static void
    sighandler(int sig, siginfo_t *info, void *data)
    {
    @@ -557,6 +572,7 @@
    break;
    }
    }
    +#endif
    static void
    init_wm(void)
    @@ -581,10 +597,12 @@
    {
    char *filename;
    const char *locale;
    +#ifndef _WIN32
    struct sigaction act;
    #ifdef SIGWINCH
    struct sigaction oact;
    #endif
    +#endif
    if (channel)
    return;
    @@ -636,6 +654,9 @@
    werase(stdscr);
    wrefresh(stdscr);
    +#ifdef _WIN32
    + SetConsoleCtrlHandler(CtrlHandler, TRUE);
    +#else
    act.sa_sigaction = sighandler;
    sigemptyset(&act.sa_mask);
    act.sa_flags = SA_SIGINFO;
    @@ -656,6 +677,7 @@
    sigaction(SIGCHLD, &act, NULL);
    sigaction(SIGINT, &act, NULL);
    signal(SIGPIPE, SIG_IGN);
    +#endif
    init_wm();
    refresh_screen();