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