src/events/SDL_windowevents.c
author Sam Lantinga
Tue, 01 Dec 2009 08:56:12 +0000
changeset 3502 98a819296cdc
parent 2875 91a7e08cd238
child 3573 41cd18e05965
permissions -rw-r--r--
Whenever a window becomes fullscreen, shown, unminimized, and has input focus it will change the display to the corresponding fullscreen video mode.
If it loses any of those properties the desktop mode will be restored.
     1 /*
     2     SDL - Simple DirectMedia Layer
     3     Copyright (C) 1997-2009 Sam Lantinga
     4 
     5     This library is free software; you can redistribute it and/or
     6     modify it under the terms of the GNU Lesser General Public
     7     License as published by the Free Software Foundation; either
     8     version 2.1 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     Lesser General Public License for more details.
    14 
    15     You should have received a copy of the GNU Lesser General Public
    16     License along with this library; if not, write to the Free Software
    17     Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
    18 
    19     Sam Lantinga
    20     slouken@libsdl.org
    21 */
    22 #include "SDL_config.h"
    23 
    24 /* Window event handling code for SDL */
    25 
    26 #include "SDL_events.h"
    27 #include "SDL_events_c.h"
    28 #include "SDL_mouse_c.h"
    29 #include "../video/SDL_sysvideo.h"
    30 
    31 int
    32 SDL_SendWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
    33                     int data2)
    34 {
    35     int posted;
    36     SDL_Window *window;
    37 
    38     window = SDL_GetWindowFromID(windowID);
    39     if (!window) {
    40         return 0;
    41     }
    42     switch (windowevent) {
    43     case SDL_WINDOWEVENT_SHOWN:
    44         if (window->flags & SDL_WINDOW_SHOWN) {
    45             return 0;
    46         }
    47         window->flags |= SDL_WINDOW_SHOWN;
    48         SDL_OnWindowShown(window);
    49         break;
    50     case SDL_WINDOWEVENT_HIDDEN:
    51         if (!(window->flags & SDL_WINDOW_SHOWN)) {
    52             return 0;
    53         }
    54         window->flags &= ~SDL_WINDOW_SHOWN;
    55         SDL_OnWindowHidden(window);
    56         break;
    57     case SDL_WINDOWEVENT_MOVED:
    58         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    59             return 0;
    60         }
    61         if (data1 == SDL_WINDOWPOS_UNDEFINED) {
    62             data1 = window->x;
    63         }
    64         if (data2 == SDL_WINDOWPOS_UNDEFINED) {
    65             data2 = window->y;
    66         }
    67         if (data1 == window->x && data2 == window->y) {
    68             return 0;
    69         }
    70         window->x = data1;
    71         window->y = data2;
    72         break;
    73     case SDL_WINDOWEVENT_RESIZED:
    74         if (window->flags & SDL_WINDOW_FULLSCREEN) {
    75             return 0;
    76         }
    77         if (data1 == window->w && data2 == window->h) {
    78             return 0;
    79         }
    80         window->w = data1;
    81         window->h = data2;
    82         SDL_OnWindowResized(window);
    83         break;
    84     case SDL_WINDOWEVENT_MINIMIZED:
    85         if (window->flags & SDL_WINDOW_MINIMIZED) {
    86             return 0;
    87         }
    88         window->flags |= SDL_WINDOW_MINIMIZED;
    89         SDL_OnWindowMinimized(window);
    90         break;
    91     case SDL_WINDOWEVENT_MAXIMIZED:
    92         if (window->flags & SDL_WINDOW_MAXIMIZED) {
    93             return 0;
    94         }
    95         window->flags |= SDL_WINDOW_MAXIMIZED;
    96         break;
    97     case SDL_WINDOWEVENT_RESTORED:
    98         if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
    99             return 0;
   100         }
   101         window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
   102         SDL_OnWindowRestored(window);
   103         break;
   104     case SDL_WINDOWEVENT_ENTER:
   105         if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
   106             return 0;
   107         }
   108         window->flags |= SDL_WINDOW_MOUSE_FOCUS;
   109         break;
   110     case SDL_WINDOWEVENT_LEAVE:
   111         if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
   112             return 0;
   113         }
   114         window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
   115         break;
   116     case SDL_WINDOWEVENT_FOCUS_GAINED:
   117         if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
   118             return 0;
   119         }
   120         window->flags |= SDL_WINDOW_INPUT_FOCUS;
   121         SDL_OnWindowFocusGained(window);
   122         break;
   123     case SDL_WINDOWEVENT_FOCUS_LOST:
   124         if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
   125             return 0;
   126         }
   127         window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
   128         SDL_OnWindowFocusLost(window);
   129         break;
   130     }
   131 
   132     /* Post the event, if desired */
   133     posted = 0;
   134     if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
   135         SDL_Event event;
   136         event.type = SDL_WINDOWEVENT;
   137         event.window.event = windowevent;
   138         event.window.data1 = data1;
   139         event.window.data2 = data2;
   140         event.window.windowID = windowID;
   141         posted = (SDL_PushEvent(&event) > 0);
   142     }
   143     return (posted);
   144 }
   145 
   146 /* vi: set ts=4 sw=4 expandtab: */