src/events/SDL_quit.c
author Paul Hunkin <paul@bieh.net>
Mon, 17 May 2010 15:14:34 +1200
changeset 4695 b7918263da92
parent 4429 faa9fc8e7f67
child 5262 b530ef003506
permissions -rw-r--r--
Initial commit, adding __ANDROID__ to the platform list
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@3697
     3
    Copyright (C) 1997-2010 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@1895
    35
static void
slouken@1895
    36
SDL_HandleSIG(int sig)
slouken@0
    37
{
slouken@1895
    38
    /* Reset the signal handler */
slouken@1895
    39
    signal(sig, SDL_HandleSIG);
slouken@0
    40
slouken@1895
    41
    /* Signal a quit interrupt */
slouken@1895
    42
    SDL_SendQuit();
slouken@0
    43
}
slouken@1330
    44
#endif /* HAVE_SIGNAL_H */
slouken@0
    45
slouken@0
    46
/* Public functions */
slouken@1895
    47
int
slouken@1895
    48
SDL_QuitInit(void)
slouken@0
    49
{
slouken@1330
    50
#ifdef HAVE_SIGNAL_H
slouken@1895
    51
    void (*ohandler) (int);
slouken@0
    52
slouken@1895
    53
    /* Both SIGINT and SIGTERM are translated into quit interrupts */
slouken@1895
    54
    ohandler = signal(SIGINT, SDL_HandleSIG);
slouken@1895
    55
    if (ohandler != SIG_DFL)
slouken@1895
    56
        signal(SIGINT, ohandler);
slouken@1895
    57
    ohandler = signal(SIGTERM, SDL_HandleSIG);
slouken@1895
    58
    if (ohandler != SIG_DFL)
slouken@1895
    59
        signal(SIGTERM, ohandler);
slouken@1330
    60
#endif /* HAVE_SIGNAL_H */
slouken@0
    61
slouken@1895
    62
    /* That's it! */
slouken@1895
    63
    return (0);
slouken@0
    64
}
slouken@1895
    65
slouken@1895
    66
void
slouken@1895
    67
SDL_QuitQuit(void)
slouken@1123
    68
{
slouken@1330
    69
#ifdef HAVE_SIGNAL_H
slouken@1895
    70
    void (*ohandler) (int);
slouken@1123
    71
slouken@1895
    72
    ohandler = signal(SIGINT, SIG_DFL);
slouken@1895
    73
    if (ohandler != SDL_HandleSIG)
slouken@1895
    74
        signal(SIGINT, ohandler);
slouken@1895
    75
    ohandler = signal(SIGTERM, SIG_DFL);
slouken@1895
    76
    if (ohandler != SDL_HandleSIG)
slouken@1895
    77
        signal(SIGTERM, ohandler);
slouken@1330
    78
#endif /* HAVE_SIGNAL_H */
slouken@1123
    79
}
slouken@0
    80
slouken@0
    81
/* This function returns 1 if it's okay to close the application window */
slouken@1895
    82
int
slouken@1895
    83
SDL_SendQuit(void)
slouken@0
    84
{
slouken@1895
    85
    int posted;
slouken@0
    86
slouken@1895
    87
    posted = 0;
slouken@4429
    88
    if (SDL_GetEventState(SDL_QUIT) == SDL_ENABLE) {
slouken@1895
    89
        SDL_Event event;
slouken@1895
    90
        event.type = SDL_QUIT;
slouken@1895
    91
        posted = (SDL_PushEvent(&event) > 0);
slouken@1895
    92
    }
slouken@1895
    93
    return (posted);
slouken@0
    94
}
slouken@1895
    95
slouken@1895
    96
/* vi: set ts=4 sw=4 expandtab: */