19682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* 29682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL - Simple DirectMedia Layer 39682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Copyright (C) 1997-2012 Sam Lantinga 49682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 59682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is free software; you can redistribute it and/or 69682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall modify it under the terms of the GNU Lesser General Public 79682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License as published by the Free Software Foundation; either 89682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall version 2.1 of the License, or (at your option) any later version. 99682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 109682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall This library is distributed in the hope that it will be useful, 119682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall but WITHOUT ANY WARRANTY; without even the implied warranty of 129682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 139682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Lesser General Public License for more details. 149682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 159682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall You should have received a copy of the GNU Lesser General Public 169682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall License along with this library; if not, write to the Free Software 179682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA 189682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 199682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Sam Lantinga 209682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall slouken@libsdl.org 219682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall*/ 229682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_config.h" 239682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 249682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Application focus/iconification handling code for SDL */ 259682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 269682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_events.h" 279682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall#include "SDL_events_c.h" 289682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 299682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 309682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* These are static for our active event handling code */ 319682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallstatic Uint8 SDL_appstate = 0; 329682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 339682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* Public functions */ 349682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_AppActiveInit(void) 359682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 369682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Start completely active */ 379682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_appstate = (SDL_APPACTIVE|SDL_APPINPUTFOCUS|SDL_APPMOUSEFOCUS); 389682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 399682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* That's it! */ 409682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 419682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 429682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallvoid SDL_AppActiveQuit(void) 439682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 449682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 459682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 469682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse HallUint8 SDL_GetAppState(void) 479682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 489682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(SDL_appstate); 499682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 509682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 519682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall/* This is global for SDL_eventloop.c */ 529682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hallint SDL_PrivateAppActive(Uint8 gain, Uint8 state) 539682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall{ 549682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall int posted; 559682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall Uint8 new_state; 569682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 579682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Modify the current state with the given mask */ 589682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( gain ) { 599682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_state = (SDL_appstate | state); 609682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } else { 619682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall new_state = (SDL_appstate & ~state); 629682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 639682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 649682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Drop events that don't change state */ 659682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( new_state == SDL_appstate ) { 669682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(0); 679682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 689682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 699682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Update internal active state */ 709682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_appstate = new_state; 719682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 729682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* Post the event, if desired */ 739682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted = 0; 749682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( SDL_ProcessEvents[SDL_ACTIVEEVENT] == SDL_ENABLE ) { 759682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_Event event; 769682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_memset(&event, 0, sizeof(event)); 779682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event.type = SDL_ACTIVEEVENT; 789682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event.active.gain = gain; 799682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall event.active.state = state; 809682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (SDL_EventOK == NULL) || (*SDL_EventOK)(&event) ) { 819682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall posted = 1; 829682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_PushEvent(&event); 839682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 849682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 859682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall 869682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we lost keyboard focus, post key-up events */ 879682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (state & SDL_APPINPUTFOCUS) && !gain ) { 889682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ResetKeyboard(); 899682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 909682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall /* If we were minimized, post button-up events */ 919682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall if ( (state & SDL_APPACTIVE) && !gain ) { 929682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall SDL_ResetMouse(); 939682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall } 949682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall return(posted); 959682c8870b8ff5e4ac2e4c70b759f791c6f38c1fJesse Hall} 96