src/events/SDL_active.c
author Sam Lantinga <slouken@libsdl.org>
Mon, 21 Sep 2009 08:58:51 +0000
branchSDL-1.2
changeset 4214 4250beeb5ad1
parent 4159 a1b03ba2fcd0
child 4252 052dc40d917f
permissions -rw-r--r--
Oh yeah, we have GLX support too.
slouken@0
     1
/*
slouken@0
     2
    SDL - Simple DirectMedia Layer
slouken@4159
     3
    Copyright (C) 1997-2009 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
/* Application focus/iconification handling code for SDL */
slouken@0
    25
slouken@0
    26
#include "SDL_events.h"
slouken@0
    27
#include "SDL_events_c.h"
slouken@0
    28
slouken@0
    29
slouken@0
    30
/* These are static for our active event handling code */
slouken@0
    31
static Uint8 SDL_appstate = 0;
slouken@0
    32
slouken@0
    33
/* Public functions */
slouken@0
    34
int SDL_AppActiveInit(void)
slouken@0
    35
{
slouken@0
    36
	/* Start completely active */
slouken@0
    37
	SDL_appstate = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS);
slouken@0
    38
slouken@0
    39
	/* That's it! */
slouken@0
    40
	return(0);
slouken@0
    41
}
slouken@1123
    42
void SDL_AppActiveQuit(void)
slouken@1123
    43
{
slouken@1123
    44
}
slouken@0
    45
slouken@0
    46
Uint8 SDL_GetAppState(void)
slouken@0
    47
{
slouken@0
    48
	return(SDL_appstate);
slouken@0
    49
}
slouken@0
    50
slouken@0
    51
/* This is global for SDL_eventloop.c */
slouken@0
    52
int SDL_PrivateAppActive(Uint8 gain, Uint8 state)
slouken@0
    53
{
slouken@0
    54
	int posted;
slouken@0
    55
	Uint8 new_state;
slouken@0
    56
slouken@0
    57
	/* Modify the current state with the given mask */
slouken@0
    58
	if ( gain ) {
slouken@0
    59
		new_state = (SDL_appstate | state);
slouken@0
    60
	} else {
slouken@0
    61
		new_state = (SDL_appstate & ~state);
slouken@0
    62
	}
slouken@0
    63
slouken@0
    64
	/* Drop events that don't change state */
slouken@0
    65
	if ( new_state == SDL_appstate ) {
slouken@0
    66
		return(0);
slouken@0
    67
	}
slouken@0
    68
slouken@0
    69
	/* Update internal active state */
slouken@0
    70
	SDL_appstate = new_state;
slouken@0
    71
slouken@0
    72
	/* Post the event, if desired */
slouken@0
    73
	posted = 0;
slouken@0
    74
	if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) {
slouken@0
    75
		SDL_Event event;
slouken@1336
    76
		SDL_memset(&event, 0, sizeof(event));
slouken@0
    77
		event.type = SDL_ACTIVEEVENT;
slouken@0
    78
		event.active.gain = gain;
slouken@0
    79
		event.active.state = state;
slouken@0
    80
		if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) {
slouken@0
    81
			posted = 1;
slouken@0
    82
			SDL_PushEvent(&event);
slouken@0
    83
		}
slouken@0
    84
	}
slouken@0
    85
slouken@0
    86
	/* If we lost keyboard focus, post key-up events */
slouken@0
    87
	if ( (state & SDL_APPINPUTFOCUS) && !gain ) {
slouken@0
    88
		SDL_ResetKeyboard();
slouken@0
    89
	}
slouken@0
    90
	return(posted);
slouken@0
    91
}