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