src/events/SDL_windowevents.c
author Sam Lantinga <slouken@libsdl.org>
Fri, 08 Apr 2011 13:03:26 -0700
changeset 5535 96594ac5fd1a
parent 5525 e427bb6266a4
child 6138 4c64952a58fb
permissions -rw-r--r--
SDL 1.3 is now under the zlib license.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     1
/*
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     2
  Simple DirectMedia Layer
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     3
  Copyright (C) 1997-2011 Sam Lantinga <slouken@libsdl.org>
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     4
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     5
  This software is provided 'as-is', without any express or implied
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     6
  warranty.  In no event will the authors be held liable for any damages
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     7
  arising from the use of this software.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
     8
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
     9
  Permission is granted to anyone to use this software for any purpose,
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    10
  including commercial applications, and to alter it and redistribute it
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    11
  freely, subject to the following restrictions:
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    12
5535
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    13
  1. The origin of this software must not be misrepresented; you must not
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    14
     claim that you wrote the original software. If you use this software
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    15
     in a product, an acknowledgment in the product documentation would be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    16
     appreciated but is not required.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    17
  2. Altered source versions must be plainly marked as such, and must not be
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    18
     misrepresented as being the original software.
96594ac5fd1a SDL 1.3 is now under the zlib license.
Sam Lantinga <slouken@libsdl.org>
parents: 5525
diff changeset
    19
  3. This notice may not be removed or altered from any source distribution.
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    20
*/
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    21
#include "SDL_config.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    22
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    23
/* Window event handling code for SDL */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    24
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    25
#include "SDL_events.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    26
#include "SDL_events_c.h"
2794
f7872b7a8732 Fixed mouse coordinate range on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 1970
diff changeset
    27
#include "SDL_mouse_c.h"
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    28
#include "../video/SDL_sysvideo.h"
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    29
3573
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    30
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    31
static int
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    32
RemovePendingSizeEvents(void * userdata, SDL_Event *event)
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    33
{
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    34
    SDL_Event *new_event = (SDL_Event *)userdata;
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    35
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    36
    if (event->type == SDL_WINDOWEVENT &&
5276
8e421890cdb8 Fixed bug #1117
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    37
        (event->window.event == SDL_WINDOWEVENT_RESIZED ||
8e421890cdb8 Fixed bug #1117
Sam Lantinga <slouken@libsdl.org>
parents: 5262
diff changeset
    38
         event->window.event == SDL_WINDOWEVENT_SIZE_CHANGED) &&
3573
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    39
        event->window.windowID == new_event->window.windowID) {
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    40
        /* We're about to post a new size event, drop the old one */
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    41
        return 0;
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    42
    }
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    43
    return 1;
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    44
}
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
    45
5042
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    46
static int
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    47
RemovePendingMoveEvents(void * userdata, SDL_Event *event)
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    48
{
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    49
    SDL_Event *new_event = (SDL_Event *)userdata;
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    50
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    51
    if (event->type == SDL_WINDOWEVENT &&
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    52
        event->window.event == SDL_WINDOWEVENT_MOVED &&
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    53
        event->window.windowID == new_event->window.windowID) {
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    54
        /* We're about to post a new move event, drop the old one */
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    55
        return 0;
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    56
    }
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    57
    return 1;
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    58
}
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
    59
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    60
int
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3573
diff changeset
    61
SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1,
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    62
                    int data2)
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    63
{
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    64
    int posted;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    65
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    66
    if (!window) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    67
        return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    68
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    69
    switch (windowevent) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    70
    case SDL_WINDOWEVENT_SHOWN:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    71
        if (window->flags & SDL_WINDOW_SHOWN) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    72
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    73
        }
5383
40c76519000e Clear the hidden flag when shown and the shown flag when hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
    74
        window->flags &= ~SDL_WINDOW_HIDDEN;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    75
        window->flags |= SDL_WINDOW_SHOWN;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    76
        SDL_OnWindowShown(window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    77
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    78
    case SDL_WINDOWEVENT_HIDDEN:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    79
        if (!(window->flags & SDL_WINDOW_SHOWN)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    80
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    81
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    82
        window->flags &= ~SDL_WINDOW_SHOWN;
5383
40c76519000e Clear the hidden flag when shown and the shown flag when hidden.
Sam Lantinga <slouken@libsdl.org>
parents: 5276
diff changeset
    83
        window->flags |= SDL_WINDOW_HIDDEN;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    84
        SDL_OnWindowHidden(window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    85
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    86
    case SDL_WINDOWEVENT_MOVED:
5249
7a963be087ef Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
    87
        if (SDL_WINDOWPOS_ISUNDEFINED(data1) ||
7a963be087ef Mostly fixed fullscreen mode on Mac OS X, and you can toggle it on and off.
Sam Lantinga <slouken@libsdl.org>
parents: 5166
diff changeset
    88
            SDL_WINDOWPOS_ISUNDEFINED(data2)) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    89
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    90
        }
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
    91
        if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
    92
            window->windowed.x = data1;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
    93
            window->windowed.y = data2;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
    94
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    95
        if (data1 == window->x && data2 == window->y) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    96
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
    97
        }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    98
        window->x = data1;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
    99
        window->y = data2;
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   100
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   101
    case SDL_WINDOWEVENT_RESIZED:
5398
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
   102
        if (!(window->flags & SDL_WINDOW_FULLSCREEN)) {
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
   103
            window->windowed.w = data1;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
   104
            window->windowed.h = data2;
83816c8a2b58 Restore the windowed position and size when coming back from fullscreen.
Sam Lantinga <slouken@libsdl.org>
parents: 5383
diff changeset
   105
        }
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   106
        if (data1 == window->w && data2 == window->h) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   107
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   108
        }
1915
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   109
        window->w = data1;
a228436a2404 Implemented multi-window OpenGL program with test framework.
Sam Lantinga <slouken@libsdl.org>
parents: 1895
diff changeset
   110
        window->h = data2;
5166
4d39eeaad00b Added a way to get a framebuffer interface for a window, and also a way to create a software renderer for an arbitrary surface.
Sam Lantinga <slouken@libsdl.org>
parents: 5147
diff changeset
   111
        SDL_OnWindowResized(window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   112
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   113
    case SDL_WINDOWEVENT_MINIMIZED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   114
        if (window->flags & SDL_WINDOW_MINIMIZED) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   115
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   116
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   117
        window->flags |= SDL_WINDOW_MINIMIZED;
3502
98a819296cdc Whenever a window becomes fullscreen, shown, unminimized, and has input focus it will change the display to the corresponding fullscreen video mode.
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   118
        SDL_OnWindowMinimized(window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   119
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   120
    case SDL_WINDOWEVENT_MAXIMIZED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   121
        if (window->flags & SDL_WINDOW_MAXIMIZED) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   122
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   123
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   124
        window->flags |= SDL_WINDOW_MAXIMIZED;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   125
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   126
    case SDL_WINDOWEVENT_RESTORED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   127
        if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   128
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   129
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   130
        window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
3502
98a819296cdc Whenever a window becomes fullscreen, shown, unminimized, and has input focus it will change the display to the corresponding fullscreen video mode.
Sam Lantinga <slouken@libsdl.org>
parents: 2875
diff changeset
   131
        SDL_OnWindowRestored(window);
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   132
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   133
    case SDL_WINDOWEVENT_ENTER:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   134
        if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   135
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   136
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   137
        window->flags |= SDL_WINDOW_MOUSE_FOCUS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   138
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   139
    case SDL_WINDOWEVENT_LEAVE:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   140
        if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   141
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   142
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   143
        window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   144
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   145
    case SDL_WINDOWEVENT_FOCUS_GAINED:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   146
        if (window->flags & SDL_WINDOW_INPUT_FOCUS) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   147
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   148
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   149
        window->flags |= SDL_WINDOW_INPUT_FOCUS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   150
        SDL_OnWindowFocusGained(window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   151
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   152
    case SDL_WINDOWEVENT_FOCUS_LOST:
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   153
        if (!(window->flags & SDL_WINDOW_INPUT_FOCUS)) {
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   154
            return 0;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   155
        }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   156
        window->flags &= ~SDL_WINDOW_INPUT_FOCUS;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   157
        SDL_OnWindowFocusLost(window);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   158
        break;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   159
    }
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   160
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   161
    /* Post the event, if desired */
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   162
    posted = 0;
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
   163
    if (SDL_GetEventState(SDL_WINDOWEVENT) == SDL_ENABLE) {
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   164
        SDL_Event event;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   165
        event.type = SDL_WINDOWEVENT;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   166
        event.window.event = windowevent;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   167
        event.window.data1 = data1;
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   168
        event.window.data2 = data2;
3685
64ce267332c6 Switched from SDL_WindowID and SDL_TextureID to SDL_Window* and SDL_Texture* for code simplicity and improved performance.
Sam Lantinga <slouken@libsdl.org>
parents: 3573
diff changeset
   169
        event.window.windowID = window->id;
3573
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
   170
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
   171
        /* Fixes queue overflow with resize events that aren't processed */
5524
b7f53a566ef1 Filter out SDL_WINDOWEVENT_SIZE_CHANGED events too
Sam Lantinga <slouken@libsdl.org>
parents: 5398
diff changeset
   172
        if (windowevent == SDL_WINDOWEVENT_RESIZED ||
5525
e427bb6266a4 Fixed compile error.
Sam Lantinga <slouken@libsdl.org>
parents: 5524
diff changeset
   173
            windowevent == SDL_WINDOWEVENT_SIZE_CHANGED) {
3573
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
   174
            SDL_FilterEvents(RemovePendingSizeEvents, &event);
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
   175
        }
5042
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   176
        if (windowevent == SDL_WINDOWEVENT_MOVED) {
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   177
            SDL_FilterEvents(RemovePendingMoveEvents, &event);
8c39b82dc7b0 Window move events have the same problem as size events on Windows
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
   178
        }
3573
41cd18e05965 Fixed bug #666
Sam Lantinga <slouken@libsdl.org>
parents: 3502
diff changeset
   179
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   180
        posted = (SDL_PushEvent(&event) > 0);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   181
    }
5113
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   182
	
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   183
	if (windowevent == SDL_WINDOWEVENT_CLOSE) {
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   184
		if ( !window->prev && !window->next ) {
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   185
			// This is the last window in the list so send the SDL_QUIT event
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   186
			SDL_SendQuit();
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   187
		}
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   188
	}
686d795b1b29 When the last window is closed and the SDL_WINDOWEVENT_CLOSE event is sent, send the SDL_QUIT event.
krogoway
parents: 5042
diff changeset
   189
1895
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   190
    return (posted);
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   191
}
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   192
c121d94672cb SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
   193
/* vi: set ts=4 sw=4 expandtab: */