Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
5131 | clevermous | 1 | /* |
2 | SDL - Simple DirectMedia Layer |
||
3 | Copyright (C) 1997, 1998, 1999, 2000, 2001 Sam Lantinga |
||
4 | |||
5 | This library is free software; you can redistribute it and/or |
||
6 | modify it under the terms of the GNU Library General Public |
||
7 | License as published by the Free Software Foundation; either |
||
8 | version 2 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 | Library General Public License for more details. |
||
14 | |||
15 | You should have received a copy of the GNU Library General Public |
||
16 | License along with this library; if not, write to the Free |
||
17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
||
18 | |||
19 | Sam Lantinga |
||
20 | slouken@devolution.com |
||
21 | */ |
||
22 | |||
23 | /* General quit handling code for SDL */ |
||
24 | |||
25 | #include |
||
26 | #ifndef NO_SIGNAL_H |
||
27 | #include |
||
28 | #endif |
||
29 | |||
30 | #include "SDL_events.h" |
||
31 | #include "SDL_events_c.h" |
||
32 | |||
33 | |||
34 | #ifndef NO_SIGNAL_H |
||
35 | static void SDL_HandleSIG(int sig) |
||
36 | { |
||
37 | /* Reset the signal handler */ |
||
38 | signal(sig, SDL_HandleSIG); |
||
39 | |||
40 | /* Signal a quit interrupt */ |
||
41 | SDL_PrivateQuit(); |
||
42 | } |
||
43 | #endif /* NO_SIGNAL_H */ |
||
44 | |||
45 | /* Public functions */ |
||
46 | int SDL_QuitInit(void) |
||
47 | { |
||
48 | #ifndef NO_SIGNAL_H |
||
49 | void (*ohandler)(int); |
||
50 | |||
51 | /* Both SIGINT and SIGTERM are translated into quit interrupts */ |
||
52 | ohandler = signal(SIGINT, SDL_HandleSIG); |
||
53 | if ( ohandler != SIG_DFL ) |
||
54 | signal(SIGINT, ohandler); |
||
55 | ohandler = signal(SIGTERM, SDL_HandleSIG); |
||
56 | if ( ohandler != SIG_DFL ) |
||
57 | signal(SIGTERM, ohandler); |
||
58 | #endif /* NO_SIGNAL_H */ |
||
59 | |||
60 | /* That's it! */ |
||
61 | return(0); |
||
62 | } |
||
63 | |||
64 | /* This function returns 1 if it's okay to close the application window */ |
||
65 | int SDL_PrivateQuit(void) |
||
66 | { |
||
67 | int posted; |
||
68 | |||
69 | posted = 0; |
||
70 | if ( SDL_ProcessEvents[SDL_QUIT] == SDL_ENABLE ) { |
||
71 | SDL_Event event; |
||
72 | event.type = SDL_QUIT; |
||
73 | if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { |
||
74 | posted = 1; |
||
75 | SDL_PushEvent(&event); |
||
76 | } |
||
77 | } |
||
78 | return(posted); |
||
79 | } |