annotate src/video/x11/SDL_x11events.c @ 2035:c848c18684ab

Started update for 1.3
author Patrice Mandin <patmandin@gmail.com>
date Wed, 20 Sep 2006 22:09:19 +0000
parents 7177581dc9fa
children da8332c8f480
rev   line source
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
1 /*
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
2 SDL - Simple DirectMedia Layer
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
3 Copyright (C) 1997-2006 Sam Lantinga
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
4
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
5 This library is free software; you can redistribute it and/or
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
6 modify it under the terms of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
7 License as published by the Free Software Foundation; either
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
8 version 2.1 of the License, or (at your option) any later version.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
9
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
10 This library is distributed in the hope that it will be useful,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
13 Lesser General Public License for more details.
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
14
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
15 You should have received a copy of the GNU Lesser General Public
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
16 License along with this library; if not, write to the Free Software
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
17 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
18
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
19 Sam Lantinga
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
20 slouken@libsdl.org
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
21 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
22 #include "SDL_config.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
23
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
24 #include "SDL_syswm.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
25 #include "SDL_x11video.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
26 #include "../../events/SDL_events_c.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
27
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
28
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 static void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33 SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34 XEvent xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
35 int i;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 SDL_zero(xevent); /* valgrind fix. --ryan. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 XNextEvent(videodata->display, &xevent);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 /* Send a SDL_SYSWMEVENT if the application wants them */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 if (SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
43
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 wmmsg.subsystem = SDL_SYSWM_X11;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 wmmsg.event.xevent = xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 SDL_SendSysWMEvent(&wmmsg);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 data = NULL;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 for (i = 0; i < videodata->numwindows; ++i) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 if (videodata->windowlist[i]->window == xevent.xany.window) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 data = videodata->windowlist[i];
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
58 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60 switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 printf("EnterNotify! (%d,%d)\n", xevent.xcrossing.x,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 xevent.xcrossing.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 if ((xevent.xcrossing.mode != NotifyGrab) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 (xevent.xcrossing.mode != NotifyUngrab)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 SDL_SetMouseFocus(videodata->mouse, data->windowID);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 SDL_SendMouseMotion(videodata->mouse, 0, xevent.xcrossing.x,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 xevent.xcrossing.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
80
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
81 /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 printf("LeaveNotify! (%d,%d)\n", xevent.xcrossing.x,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85 xevent.xcrossing.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 if ((xevent.xcrossing.mode != NotifyGrab) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 (xevent.xcrossing.mode != NotifyUngrab) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 (xevent.xcrossing.detail != NotifyInferior)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 SDL_SendMouseMotion(videodata->mouse, 0,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 xevent.xcrossing.x, xevent.xcrossing.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 SDL_SetMouseFocus(videodata->mouse, 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 case FocusIn:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 printf("FocusIn!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 SDL_SetKeyboardFocus(videodata->keyboard, data->windowID);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 XSetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 case FocusOut:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 printf("FocusOut!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 SDL_SetKeyboardFocus(videodata->keyboard, 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 XUnsetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
125 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 printf("KeymapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 /* Mouse motion? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 case MotionNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 #ifdef DEBUG_MOTION
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 SDL_SendMouseMotion(videodata->mouse, 0, xevent.xmotion.x,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 xevent.xmotion.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 /* Mouse button press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 case ButtonPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 SDL_SendMouseButton(videodata->mouse, SDL_PRESSED,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 xevent.xbutton.button);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 /* Mouse button release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 case ButtonRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 SDL_SendMouseButton(videodata->mouse, SDL_RELEASED,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 xevent.xbutton.button);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 #if 0 /* FIXME */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 static SDL_keysym saved_keysym;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 SDL_keysym keysym;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 KeyCode keycode = xevent.xkey.keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
171 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
172 printf("KeyPress (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
173 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174 /* Get the translated SDL virtual keysym */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 if (keycode) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 keysym.scancode = keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 keysym.mod = KMOD_NONE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 keysym.unicode = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181 keysym = saved_keysym;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184 /* If we're not doing translation, we're done! */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 if (!SDL_TranslateUNICODE) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
187 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
188 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
189
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
190 if (XFilterEvent(&xevent, None)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
191 if (xevent.xkey.keycode) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
192 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
193 } else {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
194 /* Save event to be associated with IM text
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
195 In 1.3 we'll have a text event instead.. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
196 saved_keysym = keysym;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
197 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
198 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
199 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
200
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
201 /* Look up the translated value for the key event */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
202 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
203 if (data->ic != NULL) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 static Status state;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 /* A UTF-8 character can be at most 6 bytes */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206 char keybuf[6];
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 if (Xutf8LookupString(data->ic, &xevent.xkey,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 keybuf, sizeof(keybuf), NULL, &state)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 keysym.unicode = Utf8ToUcs4((Uint8 *) keybuf);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
210 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
211 } else
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 static XComposeStatus state;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 char keybuf[32];
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217 if (XLookupString(&xevent.xkey,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 keybuf, sizeof(keybuf), NULL, &state)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 /*
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 * FIXME: XLookupString() may yield more than one
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 * character, so we need a mechanism to allow for
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 * this (perhaps null keypress events with a
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223 * unicode value)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 keysym.unicode = (Uint8) keybuf[0];
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 posted = SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 #endif // 0
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233 /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 #if 0 /* FIXME */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 SDL_keysym keysym;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 KeyCode keycode = xevent.xkey.keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 printf("KeyRelease (X11 keycode = 0x%X)\n", xevent.xkey.keycode);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 /* Check to see if this is a repeated key */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 if (X11_KeyRepeat(SDL_Display, &xevent)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 /* Get the translated SDL virtual keysym */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 keysym.scancode = keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 keysym.sym = X11_TranslateKeycode(SDL_Display, keycode);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 keysym.mod = KMOD_NONE;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 keysym.unicode = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 posted = SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 #endif // 0
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
256 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 /* Have we been iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 case UnmapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 printf("UnmapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_HIDDEN, 0, 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MINIMIZED, 0,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 /* Have we been restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 case MapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 printf("MapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_SHOWN, 0, 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESTORED, 0,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
277 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
278 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280 /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
281 case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
282 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
283 printf("ConfigureNotify! (resize: %dx%d)\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
284 xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
285 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
286 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_MOVED,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
287 xevent.xconfigure.x, xevent.xconfigure.y);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
288 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_RESIZED,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
289 xevent.xconfigure.width,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
291 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
293
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
294 /* Have we been requested to quit (or another client message?) */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 case ClientMessage:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 if ((xevent.xclient.format == 32) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297 (xevent.xclient.data.l[0] == videodata->WM_DELETE_WINDOW)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
299 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_CLOSE, 0,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
301 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
302 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
303 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 printf("Expose (count = %d)\n", xevent.xexpose.count);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
309 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 SDL_SendWindowEvent(data->windowID, SDL_WINDOWEVENT_EXPOSED, 0,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 default:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 printf("Unhandled event %d\n", xevent.type);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
318 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
319 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
320 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
321 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
322 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 /* Ack! XPending() actually performs a blocking read if no events available */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325 int
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 X11_Pending(Display * display)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 /* Flush the display connection and look to see if events are queued */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 XFlush(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330 if (XEventsQueued(display, QueuedAlready)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
331 return (1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
332 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
333
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
334 /* More drastic measures are required -- see if X is ready to talk */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
335 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
336 static struct timeval zero_time; /* static == 0 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
337 int x11_fd;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
338 fd_set fdset;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
339
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
340 x11_fd = ConnectionNumber(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 FD_ZERO(&fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 FD_SET(x11_fd, &fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 if (select(x11_fd + 1, &fdset, NULL, NULL, &zero_time) == 1) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 return (XPending(display));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
345 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
346 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
347
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
348 /* Oh well, nothing is ready .. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 return (0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
350 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 X11_PumpEvents(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 /* Keep processing pending events */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
358 while (X11_Pending(data->display)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 X11_DispatchEvent(_this);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
362
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 X11_SaveScreenSaver(Display * display, int *saved_timeout, BOOL * dpms)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366 int timeout, interval, prefer_blank, allow_exp;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
368 *saved_timeout = timeout;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 #if SDL_VIDEO_DRIVER_X11_DPMS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 if (SDL_X11_HAVE_DPMS) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372 int dummy;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 if (DPMSQueryExtension(display, &dummy, &dummy)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 CARD16 state;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 DPMSInfo(display, &state, dpms);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 #else
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 *dpms = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384 X11_DisableScreenSaver(Display * display)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 int timeout, interval, prefer_blank, allow_exp;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 timeout = 0;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
390
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391 #if SDL_VIDEO_DRIVER_X11_DPMS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
392 if (SDL_X11_HAVE_DPMS) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
393 int dummy;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 if (DPMSQueryExtension(display, &dummy, &dummy)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
395 DPMSDisable(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
397 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
398 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
399 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 X11_RestoreScreenSaver(Display * display, int saved_timeout, BOOL dpms)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 int timeout, interval, prefer_blank, allow_exp;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405 XGetScreenSaver(display, &timeout, &interval, &prefer_blank, &allow_exp);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 timeout = saved_timeout;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
407 XSetScreenSaver(display, timeout, interval, prefer_blank, allow_exp);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
408
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
409 #if SDL_VIDEO_DRIVER_X11_DPMS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
410 if (SDL_X11_HAVE_DPMS) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
411 int dummy;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
412 if (DPMSQueryExtension(display, &dummy, &dummy)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
413 if (dpms) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
414 DPMSEnable(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
415 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
416 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
417 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
418 #endif /* SDL_VIDEO_DRIVER_X11_DPMS */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
419 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
421 /* vi: set ts=4 sw=4 expandtab: */