annotate src/events/SDL_windowevents.c @ 1722:5daa04d862f1 SDL-1.3

Added a userdata parameter for event filters. Added a function to filter the existing queued events. Added explicit support for relative mouse mode to the API.
author Sam Lantinga <slouken@libsdl.org>
date Fri, 30 Jun 2006 08:18:44 +0000
parents 4da1ee79c9af
children 6c63fc2bd986
rev   line source
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 /* Window event handling code for SDL */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "SDL_events.h"
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27 #include "SDL_events_c.h"
1722
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
28 #include "../video/SDL_sysvideo.h"
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 int
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
31 SDL_PrivateWindowEvent(SDL_WindowID windowID, Uint8 windowevent, int data1,
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
32 int data2)
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 int posted;
1722
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
35 SDL_Window *window;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
36
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
37 window = SDL_GetWindowFromID(windowID);
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
38 if (!window) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
39 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
40 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
41 switch (windowevent) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
42 case SDL_WINDOWEVENT_SHOWN:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
43 if (window->flags & SDL_WINDOW_SHOWN) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
44 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
45 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
46 window->flags |= SDL_WINDOW_SHOWN;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
47 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
48 case SDL_WINDOWEVENT_HIDDEN:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
49 if (!(window->flags & SDL_WINDOW_SHOWN)) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
50 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
51 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
52 window->flags &= ~SDL_WINDOW_SHOWN;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
53 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
54 case SDL_WINDOWEVENT_MINIMIZED:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
55 if (window->flags & SDL_WINDOW_MINIMIZED) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
56 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
57 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
58 window->flags |= SDL_WINDOW_MINIMIZED;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
59 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
60 case SDL_WINDOWEVENT_MAXIMIZED:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
61 if (window->flags & SDL_WINDOW_MAXIMIZED) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
62 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
63 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
64 window->flags |= SDL_WINDOW_MAXIMIZED;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
65 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
66 case SDL_WINDOWEVENT_RESTORED:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
67 if (!(window->flags & (SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED))) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
68 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
69 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
70 window->flags &= ~(SDL_WINDOW_MINIMIZED | SDL_WINDOW_MAXIMIZED);
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
71 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
72 case SDL_WINDOWEVENT_ENTER:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
73 if (window->flags & SDL_WINDOW_MOUSE_FOCUS) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
74 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
75 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
76 window->flags |= SDL_WINDOW_MOUSE_FOCUS;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
77 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
78 case SDL_WINDOWEVENT_LEAVE:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
79 if (!(window->flags & SDL_WINDOW_MOUSE_FOCUS)) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
80 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
81 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
82 window->flags &= ~SDL_WINDOW_MOUSE_FOCUS;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
83 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
84 case SDL_WINDOWEVENT_FOCUS_GAINED:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
85 if (window->flags & SDL_WINDOW_KEYBOARD_FOCUS) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
86 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
87 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
88 window->flags |= SDL_WINDOW_KEYBOARD_FOCUS;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
89 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
90 case SDL_WINDOWEVENT_FOCUS_LOST:
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
91 if (!(window->flags & SDL_WINDOW_KEYBOARD_FOCUS)) {
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
92 return 0;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
93 }
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
94 window->flags &= ~SDL_WINDOW_KEYBOARD_FOCUS;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
95 break;
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
96 }
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 /* Post the event, if desired */
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 posted = 0;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 if (SDL_ProcessEvents[SDL_WINDOWEVENT] == SDL_ENABLE) {
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 SDL_Event event;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 event.type = SDL_WINDOWEVENT;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 event.window.event = windowevent;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 event.window.data1 = data1;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 event.window.data2 = data2;
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 event.window.windowID = windowID;
1722
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
107 if ((SDL_EventOK == NULL)
5daa04d862f1 Added a userdata parameter for event filters.
Sam Lantinga <slouken@libsdl.org>
parents: 1668
diff changeset
108 || (*SDL_EventOK) (SDL_EventOKParam, &event)) {
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 posted = 1;
1668
4da1ee79c9af more tweaking indent options
Sam Lantinga <slouken@libsdl.org>
parents: 1662
diff changeset
110 SDL_PushEvent(&event);
1662
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 return (posted);
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 }
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115
782fd950bd46 Revamp of the video system in progress - adding support for multiple displays, multiple windows, and a full video mode selection API.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 /* vi: set ts=4 sw=4 expandtab: */