src/events/SDL_quit.c
author Edgar Simo <bobbens@gmail.com>
Mon, 28 Jul 2008 10:26:21 +0000
branchgsoc2008_force_feedback
changeset 2549 491e43f427ee
parent 1895 c121d94672cb
child 2859 99210400e8b9
permissions -rw-r--r--
Put haptic defines in SDL_configs, patch by Alam.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2006 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 of the License, or (at your option) any later version.
     9 
    10     This library is distributed in the hope that it will be useful,
    11     but WITHOUT ANY WARRANTY; without even the implied warranty of
    12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    13     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* General quit handling code for SDL */
    25 
    26 #ifdef HAVE_SIGNAL_H
    27 #include <signal.h>
    28 #endif
    29 
    30 #include "SDL_events.h"
    31 #include "SDL_events_c.h"
    32 
    33 
    34 #ifdef HAVE_SIGNAL_H
    35 static void
    36 SDL_HandleSIG(int sig)
    37 {
    38     /* Reset the signal handler */
    39     signal(sig, SDL_HandleSIG);
    40 
    41     /* Signal a quit interrupt */
    42     SDL_SendQuit();
    43 }
    44 #endif /* HAVE_SIGNAL_H */
    45 
    46 /* Public functions */
    47 int
    48 SDL_QuitInit(void)
    49 {
    50 #ifdef HAVE_SIGNAL_H
    51     void (*ohandler) (int);
    52 
    53     /* Both SIGINT and SIGTERM are translated into quit interrupts */
    54     ohandler = signal(SIGINT, SDL_HandleSIG);
    55     if (ohandler != SIG_DFL)
    56         signal(SIGINT, ohandler);
    57     ohandler = signal(SIGTERM, SDL_HandleSIG);
    58     if (ohandler != SIG_DFL)
    59         signal(SIGTERM, ohandler);
    60 #endif /* HAVE_SIGNAL_H */
    61 
    62     /* That's it! */
    63     return (0);
    64 }
    65 
    66 void
    67 SDL_QuitQuit(void)
    68 {
    69 #ifdef HAVE_SIGNAL_H
    70     void (*ohandler) (int);
    71 
    72     ohandler = signal(SIGINT, SIG_DFL);
    73     if (ohandler != SDL_HandleSIG)
    74         signal(SIGINT, ohandler);
    75     ohandler = signal(SIGTERM, SIG_DFL);
    76     if (ohandler != SDL_HandleSIG)
    77         signal(SIGTERM, ohandler);
    78 #endif /* HAVE_SIGNAL_H */
    79 }
    80 
    81 /* This function returns 1 if it's okay to close the application window */
    82 int
    83 SDL_SendQuit(void)
    84 {
    85     int posted;
    86 
    87     posted = 0;
    88     if (SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE) {
    89         SDL_Event event;
    90         event.type = SDL_QUIT;
    91         posted = (SDL_PushEvent(&event) > 0);
    92     }
    93     return (posted);
    94 }
    95 
    96 /* vi: set ts=4 sw=4 expandtab: */