annotate src/video/x11/SDL_x11events.c @ 4486:237b1eb53e4d

Fixed fullscreen window position Fixed position calculation for centered windows
author Sam Lantinga <slouken@libsdl.org>
date Tue, 06 Jul 2010 08:22:36 -0700
parents 9322f7db8603
children 15d2c6f40c48
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
3697
f7b03b6838cb Fixed bug #926
Sam Lantinga <slouken@libsdl.org>
parents: 3685
diff changeset
3 Copyright (C) 1997-2010 Sam Lantinga
1951
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
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
24 #include <sys/types.h>
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
25 #include <sys/time.h>
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
26 #include <signal.h>
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
27 #include <unistd.h>
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
28
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
29 #include "SDL_x11video.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "../../events/SDL_events_c.h"
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
31 #include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
32
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
33 #include "SDL_timer.h"
3241
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3195
diff changeset
34 #include "SDL_syswm.h"
08c5964f2a34 Fixed a few issues compiling with Mac OS X 10.6
Sam Lantinga <slouken@libsdl.org>
parents: 3195
diff changeset
35
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
36 static void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
37 X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
38 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 XEvent xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 int i;
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_zero(xevent); /* valgrind fix. --ryan. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 XNextEvent(videodata->display, &xevent);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
47 /* filter events catchs XIM events and sends them to the correct
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
48 handler */
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
49 if (XFilterEvent(&xevent, None) == True) {
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2326
diff changeset
50 #if 0
2328
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
51 printf("Filtered event type = %d display = %d window = %d\n",
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
52 xevent.type, xevent.xany.display, xevent.xany.window);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
53 #endif
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
54 return;
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
55 }
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
56
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57 /* Send a SDL_SYSWMEVENT if the application wants them */
4429
faa9fc8e7f67 General improvements for user custom event registration
Sam Lantinga <slouken@libsdl.org>
parents: 3697
diff changeset
58 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
59 SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
60
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
62 wmmsg.subsystem = SDL_SYSWM_X11;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 wmmsg.event.xevent = xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64 SDL_SendSysWMEvent(&wmmsg);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 data = NULL;
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
68 if (videodata && videodata->windowlist) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
69 for (i = 0; i < videodata->numwindows; ++i) {
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
70 if ((videodata->windowlist[i] != NULL) &&
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: 3322
diff changeset
71 (videodata->windowlist[i]->xwindow == xevent.xany.window)) {
2324
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
72 data = videodata->windowlist[i];
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
73 break;
3202e4826c57 more valgrind errors fixed. Plus I ran make indent which changed a few files.
Bob Pendleton <bob@pendleton.com>
parents: 2323
diff changeset
74 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
76 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
77 if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 }
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2326
diff changeset
80 #if 0
2328
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
81 printf("type = %d display = %d window = %d\n",
91e601d9df8b re: bug#563. checking in some commented out trace code and a fix so that the in testalpha.c the background only flashes when alpha == 255. The problem that is being
Bob Pendleton <bob@pendleton.com>
parents: 2327
diff changeset
82 xevent.type, xevent.xany.display, xevent.xany.window);
2327
7b53a8401195 In testdyngl.c the event type was being anded (&) with SDL_KEYDOWN and if the result was none zero the program was quiting. This is very weird because it was
Bob Pendleton <bob@pendleton.com>
parents: 2326
diff changeset
83 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
84 switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
85
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 #ifdef DEBUG_XEVENTS
3195
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
89 printf("EnterNotify! (%d,%d,%d)\n",
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
90 xevent.xcrossing.x,
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
91 xevent.xcrossing.y,
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
92 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
94 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 #endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
98 SDL_SetMouseFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
103 case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 #ifdef DEBUG_XEVENTS
3195
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
105 printf("LeaveNotify! (%d,%d,%d)\n",
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
106 xevent.xcrossing.x,
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
107 xevent.xcrossing.y,
08747e24a50f Mouse events now report the correct window id and window enter/leave events are now reported.
Bob Pendleton <bob@pendleton.com>
parents: 3188
diff changeset
108 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 #endif
3322
d9dd6cbba4c0 Fixed bug #716
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
114 if (xevent.xcrossing.detail != NotifyInferior) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
115 SDL_SetMouseFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 case FocusIn:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 printf("FocusIn!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
124 #endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
125 SDL_SetKeyboardFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
126 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
127 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 XSetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 case FocusOut:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 printf("FocusOut!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 #endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
139 SDL_SetKeyboardFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 XUnsetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 }
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 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 break;
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 /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 printf("KeymapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
155 */
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
159 /* Has the keyboard layout changed? */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
160 case MappingNotify:{
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
161 #ifdef DEBUG_XEVENTS
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
162 printf("MappingNotify!\n");
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
163 #endif
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
164 X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
165 }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
166 break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
167
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168 /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
169 case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
170 KeyCode keycode = xevent.xkey.keycode;
2300
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2299
diff changeset
171 KeySym keysym = NoSymbol;
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
172 char text[SDL_TEXTINPUTEVENT_TEXT_SIZE];
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
173 Status status = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
174
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 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
177 #endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
178 SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
179 #if 0
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
180 if (videodata->key_layout[keycode] == SDLK_UNKNOWN) {
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
181 int min_keycode, max_keycode;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
182 XDisplayKeycodes(videodata->display, &min_keycode,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
183 &max_keycode);
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
184 keysym = XKeycodeToKeysym(videodata->display, keycode, 0);
2299
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
185 fprintf(stderr,
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
186 "The key you just pressed is not recognized by SDL. To help get this fixed, please report this to the SDL mailing list <sdl@libsdl.org> X11 KeyCode %d (%d), X11 KeySym 0x%X (%s).\n",
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
187 keycode, keycode - min_keycode, keysym,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
188 XKeysymToString(keysym));
2299
a7cbc25071b6 Enabled key board auto repeat in X11_InitKeyboard.c. Had to add a couple of new Xlib symbols.
Bob Pendleton <bob@pendleton.com>
parents: 2295
diff changeset
189 }
2295
dbc6d1893869 Checking in Christian Walther's patch for x11 keyboard input. Minor code tweaks by Bob.
Bob Pendleton <bob@pendleton.com>
parents: 2046
diff changeset
190 #endif
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
191 /* */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
192 SDL_zero(text);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
193 #ifdef X_HAVE_UTF8_STRING
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
194 if (data->ic) {
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
195 Xutf8LookupString(data->ic, &xevent.xkey, text, sizeof(text),
2738
79c1bd651f04 Fixed a bunch of compile warnings on Mac OS X
Sam Lantinga <slouken@libsdl.org>
parents: 2710
diff changeset
196 &keysym, &status);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
197 }
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
198 #else
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
199 XLookupString(&xevent.xkey, text, sizeof(text), &keysym, NULL);
2325
c7bcf84ba1b9 Next version of internationalized input for X11. On my machine (famous last words :-) with a US English keyboard and locale I can compose ` and e and get a text
Bob Pendleton <bob@pendleton.com>
parents: 2324
diff changeset
200 #endif
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
201 if (*text) {
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
202 SDL_SendKeyboardText(text);
2300
c97ad1abe05b Minimal implementation of textinput events for x11. It only works for latin-1.
Bob Pendleton <bob@pendleton.com>
parents: 2299
diff changeset
203 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
204 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
205 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
206
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
207 /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
208 case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
209 KeyCode keycode = xevent.xkey.keycode;
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 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212 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
213 #endif
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
214 SDL_SendKeyboardKey(SDL_RELEASED, videodata->key_layout[keycode]);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
216 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
217
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 /* Have we been iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 case UnmapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 printf("UnmapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 #endif
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: 3322
diff changeset
223 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_HIDDEN, 0, 0);
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: 3322
diff changeset
224 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MINIMIZED, 0, 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 break;
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 /* Have we been restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 case MapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
230 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
231 printf("MapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 #endif
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: 3322
diff changeset
233 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_SHOWN, 0, 0);
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: 3322
diff changeset
234 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESTORED, 0, 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
240 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
241 printf("ConfigureNotify! (resize: %dx%d)\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243 #endif
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: 3322
diff changeset
244 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 xevent.xconfigure.x, xevent.xconfigure.y);
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: 3322
diff changeset
246 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 xevent.xconfigure.width,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 /* 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
253 case ClientMessage:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 if ((xevent.xclient.format == 32) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 (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
256
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: 3322
diff changeset
257 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_CLOSE, 0, 0);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
262 /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
263 case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 printf("Expose (count = %d)\n", xevent.xexpose.count);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 #endif
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: 3322
diff changeset
267 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_EXPOSED, 0, 0);
1951
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
271 case MotionNotify:{
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
272 #ifdef DEBUG_MOTION
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
273 printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y);
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
274 #endif
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
275 SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y);
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
276 }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
277 break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
278
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
279 case ButtonPress:{
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
280 SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button);
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
281 }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
282 break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
283
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
284 case ButtonRelease:{
4484
9322f7db8603 Cleaned up the mouse window focus handling: you always pass in the relative window when sending a mouse event.
Sam Lantinga <slouken@libsdl.org>
parents: 4472
diff changeset
285 SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button);
4465
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
286 }
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
287 break;
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
288
3e69e077cb95 Removed multi-mouse / multi-keyboard support in anticipation of a real multi-mouse and multi-touch API.
Sam Lantinga <slouken@libsdl.org>
parents: 4429
diff changeset
289 default:{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
290 #ifdef DEBUG_XEVENTS
2940
b93965a16fe0 Fixed X11 mouse motion/button events - it's not actually safe to cast mouse events to device events.
Sam Lantinga <slouken@libsdl.org>
parents: 2859
diff changeset
291 printf("Unhandled event %d\n", xevent.type);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
292 #endif
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
295 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
296 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
297
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
298 /* Ack! XPending() actually performs a blocking read if no events available */
4472
791b3256fb22 Mostly cleaned up warnings with -Wmissing-prototypes
Sam Lantinga <slouken@libsdl.org>
parents: 4465
diff changeset
299 static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
300 X11_Pending(Display * display)
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 /* 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
303 XFlush(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
304 if (XEventsQueued(display, QueuedAlready)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
305 return (1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
306 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
307
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
308 /* 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
309 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
310 static struct timeval zero_time; /* static == 0 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
311 int x11_fd;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
312 fd_set fdset;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
313
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
314 x11_fd = ConnectionNumber(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
315 FD_ZERO(&fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
316 FD_SET(x11_fd, &fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
317 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
318 return (XPending(display));
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 }
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 /* Oh well, nothing is ready .. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
323 return (0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
324 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
325
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
326 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
327 X11_PumpEvents(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
328 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
329 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
330
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
331 /* Update activity every 30 seconds to prevent screensaver */
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
332 if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
333 Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
334 if (!data->screensaver_activity ||
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
335 (int) (now - data->screensaver_activity) >= 30000) {
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
336 XResetScreenSaver(data->display);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
337 data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
338 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
339 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
340
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
341 /* Keep processing pending events */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
342 while (X11_Pending(data->display)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
343 X11_DispatchEvent(_this);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
344 }
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
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
347 /* This is so wrong it hurts */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
348 #define GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
349 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
350 #include <unistd.h>
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
351 static pid_t screensaver_inhibit_pid;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
352 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
353 gnome_screensaver_disable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
354 {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
355 screensaver_inhibit_pid = fork();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
356 if (screensaver_inhibit_pid == 0) {
3031
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
357 close(0);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
358 close(1);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
359 close(2);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
360 execl("/usr/bin/gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
361 "gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
362 "--inhibit",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
363 "--reason",
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
364 "GNOME screensaver doesn't respect MIT-SCREEN-SAVER", NULL);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
365 exit(2);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
366 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
367 }
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
368 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
369 gnome_screensaver_enable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
370 {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
371 kill(screensaver_inhibit_pid, 15);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
372 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
373 #endif
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
374
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 void
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
376 X11_SuspendScreenSaver(_THIS)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
377 {
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
378 #if SDL_VIDEO_DRIVER_X11_SCRNSAVER
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
379 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
380 int dummy;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
381 int major_version, minor_version;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
383 if (SDL_X11_HAVE_XSS) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
384 /* XScreenSaverSuspend was introduced in MIT-SCREEN-SAVER 1.1 */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
385 if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
386 !XScreenSaverQueryVersion(data->display,
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
387 &major_version, &minor_version) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
388 major_version < 1 || (major_version == 1 && minor_version < 1)) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
389 return;
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
390 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
391
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
392 XScreenSaverSuspend(data->display, _this->suspend_screensaver);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
393 XResetScreenSaver(data->display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
394 }
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
395 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
396
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
397 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
398 if (_this->suspend_screensaver) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
399 gnome_screensaver_disable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
400 } else {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
401 gnome_screensaver_enable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
402 }
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
403 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
404 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
405
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
406 /* vi: set ts=4 sw=4 expandtab: */