annotate src/video/x11/SDL_x11events.c @ 4558:4d95152d9e39

Applied the same logic as the fix for bug 894. Anytime we enter the window, we gain the mouse focus. If we leave the window because of a normal LeaveNotify, then we lose mouse focus.
author Sam Lantinga <slouken@libsdl.org>
date Tue, 20 Jul 2010 00:05:32 -0700
parents cc06f306c053
children 95352c671a6e
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>
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
28 #include <limits.h> /* For INT_MAX */
2046
da8332c8f480 Replaced strncmp for SDL_VIDEODRIVER test with strcasecmp
Sam Lantinga <slouken@libsdl.org>
parents: 1951
diff changeset
29
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
30 #include "SDL_x11video.h"
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
31 #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
32 #include "../../events/SDL_mouse_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
33
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
34 #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
35 #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
36
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
37 /*#define DEBUG_XEVENTS*/
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
38
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
39 static void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
40 X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
41 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
42 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
43 Display *display = videodata->display;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
44 SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
45 XEvent xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
46 int i;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 SDL_zero(xevent); /* valgrind fix. --ryan. */
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
49 XNextEvent(display, &xevent);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50
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
51 /* 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
52 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
53 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
54 #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
55 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
56 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
57 #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
58 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
59 }
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
60
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
61 /* 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
62 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
63 SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
64
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
65 SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
66 wmmsg.subsystem = SDL_SYSWM_X11;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
67 wmmsg.event.xevent = xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 SDL_SendSysWMEvent(&wmmsg);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
69 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71 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
72 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
73 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
74 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
75 (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
76 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
77 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
78 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
79 }
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 if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
82 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
83 }
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
84
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
85 #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
86 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
87 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
88 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
91 /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
92 case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
93 #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
94 printf("EnterNotify! (%d,%d,%d)\n",
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
95 xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
96 xevent.xcrossing.y,
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
97 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
100 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
101 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
102 #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
103 SDL_SetMouseFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
109 #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
110 printf("LeaveNotify! (%d,%d,%d)\n",
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
111 xevent.xcrossing.x,
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
112 xevent.xcrossing.y,
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
113 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
115 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
116 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
117 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
118 #endif
4558
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
119 if (xevent.xcrossing.mode != NotifyGrab &&
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
120 xevent.xcrossing.mode != NotifyUngrab &&
4d95152d9e39 Applied the same logic as the fix for bug 894.
Sam Lantinga <slouken@libsdl.org>
parents: 4556
diff changeset
121 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
122 SDL_SetMouseFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 }
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 break;
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 /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 case FocusIn:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
129 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
130 printf("FocusIn!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 #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
132 SDL_SetKeyboardFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
135 XSetICFocus(data->ic);
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 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 case FocusOut:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
143 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
144 printf("FocusOut!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 #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
146 SDL_SetKeyboardFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
149 XUnsetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 break;
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 /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
156 case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 printf("KeymapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 */
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
166 /* Has the keyboard layout changed? */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
167 case MappingNotify:{
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
168 #ifdef DEBUG_XEVENTS
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
169 printf("MappingNotify!\n");
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
170 #endif
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
171 X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
172 }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
173 break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
174
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
175 /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
176 case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
177 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
178 KeySym keysym = NoSymbol;
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
179 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
180 Status status = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
181
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
182 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
183 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
184 #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
185 SDL_SendKeyboardKey(SDL_PRESSED, videodata->key_layout[keycode]);
4535
ce811c9247da Added back in a little more debugging for the X11 keyboard code
Sam Lantinga <slouken@libsdl.org>
parents: 4524
diff changeset
186 #if 1
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
187 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
188 int min_keycode, max_keycode;
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
189 XDisplayKeycodes(display, &min_keycode, &max_keycode);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
190 keysym = XKeycodeToKeysym(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
191 fprintf(stderr,
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
192 "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%lX (%s).\n",
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
193 keycode, keycode - min_keycode, keysym,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
194 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
195 }
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
196 #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
197 /* */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
198 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
199 #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
200 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
201 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
202 &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
203 }
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
204 #else
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
205 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
206 #endif
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
207 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
208 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
209 }
1951
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
212
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
213 /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 KeyCode keycode = xevent.xkey.keycode;
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 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 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
219 #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
220 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
221 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
223
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
224 /* Have we been iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
225 case UnmapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
226 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
227 printf("UnmapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
228 #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
229 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
230 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
231 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
232 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
233
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
234 /* Have we been restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
235 case MapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
236 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
237 printf("MapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
238 #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
239 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
240 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
241 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
243
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
244 /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
245 case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247 printf("ConfigureNotify! (resize: %dx%d)\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 #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
250 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 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
252 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 xevent.xconfigure.width,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
254 xevent.xconfigure.height);
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 requested to quit (or another client message?) */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
259 case ClientMessage:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
260 if ((xevent.xclient.format == 32) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
261 (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
262
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
263 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
264 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
266 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
267
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
268 /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
269 case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271 printf("Expose (count = %d)\n", xevent.xexpose.count);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 #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
273 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
274 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276
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
277 case MotionNotify:{
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
278 #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
279 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
280 #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
281 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
282 }
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 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
284
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
285 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
286 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
287 }
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 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
289
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
290 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
291 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
292 }
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
293 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
294
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
295 case PropertyNotify:{
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
296 #ifdef DEBUG_XEVENTS
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
297 unsigned char *propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
298 int status, real_format;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
299 Atom real_type;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
300 unsigned long items_read, items_left, i;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
301
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
302 char *name = XGetAtomName(display, xevent.xproperty.atom);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
303 if (name) {
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
304 printf("PropertyNotify: %s %s\n", name, (xevent.xproperty.state == PropertyDelete) ? "deleted" : "changed");
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
305 XFree(name);
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
306 }
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
307
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
308 status = XGetWindowProperty(display, data->xwindow, xevent.xproperty.atom, 0L, 8192L, False, AnyPropertyType, &real_type, &real_format, &items_read, &items_left, &propdata);
4556
cc06f306c053 Fixed X error when showing debug info about a deleted property
Sam Lantinga <slouken@libsdl.org>
parents: 4535
diff changeset
309 if (status == Success && items_read > 0) {
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
310 if (real_type == XA_INTEGER) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
311 int *values = (int *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
312
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
313 printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
314 for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
315 printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
316 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
317 printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
318 } else if (real_type == XA_CARDINAL) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
319 if (real_format == 32) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
320 Uint32 *values = (Uint32 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
321
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
322 printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
323 for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
324 printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
325 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
326 printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
327 } else if (real_format == 16) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
328 Uint16 *values = (Uint16 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
329
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
330 printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
331 for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
332 printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
333 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
334 printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
335 } else if (real_format == 8) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
336 Uint8 *values = (Uint8 *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
337
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
338 printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
339 for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
340 printf(" %d", values[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
341 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
342 printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
343 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
344 } else if (real_type == XA_STRING ||
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
345 real_type == videodata->UTF8_STRING) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
346 printf("{ \"%s\" }\n", propdata);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
347 } else if (real_type == XA_ATOM) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
348 Atom *atoms = (Atom *)propdata;
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
349
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
350 printf("{");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
351 for (i = 0; i < items_read; i++) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
352 char *name = XGetAtomName(display, atoms[i]);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
353 if (name) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
354 printf(" %s", name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
355 XFree(name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
356 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
357 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
358 printf(" }\n");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
359 } else {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
360 char *name = XGetAtomName(display, real_type);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
361 printf("Unknown type: %ld (%s)\n", real_type, name ? name : "UNKNOWN");
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
362 if (name) {
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
363 XFree(name);
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
364 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
365 }
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
366 }
4518
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
367 #endif
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
368 }
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
369 break;
a956a315fe67 Lots of prep for the "real" way to support fullscreen mode on modern window managers.
Sam Lantinga <slouken@libsdl.org>
parents: 4508
diff changeset
370
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
371 /* Copy the selection from XA_CUT_BUFFER0 to the requested property */
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
372 case SelectionRequest: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
373 XSelectionRequestEvent *req;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
374 XEvent sevent;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
375 int seln_format;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
376 unsigned long nbytes;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
377 unsigned long overflow;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
378 unsigned char *seln_data;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
379
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
380 req = &xevent.xselectionrequest;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
381 #ifdef DEBUG_XEVENTS
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
382 printf("SelectionRequest (requestor = %ld, target = %ld)\n",
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
383 req->requestor, req->target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
384 #endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
385
4524
a256e1dadf3f Zero any fields not explicitly filled in.
Sam Lantinga <slouken@libsdl.org>
parents: 4520
diff changeset
386 SDL_zero(sevent);
4520
0c67c4328678 Much better debugging of property changes
Sam Lantinga <slouken@libsdl.org>
parents: 4519
diff changeset
387 sevent.xany.type = SelectionNotify;
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
388 sevent.xselection.selection = req->selection;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
389 sevent.xselection.target = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
390 sevent.xselection.property = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
391 sevent.xselection.requestor = req->requestor;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
392 sevent.xselection.time = req->time;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
393 if (XGetWindowProperty(display, DefaultRootWindow(display),
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
394 XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
395 &sevent.xselection.target, &seln_format, &nbytes,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
396 &overflow, &seln_data) == Success) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
397 if (sevent.xselection.target == req->target) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
398 XChangeProperty(display, req->requestor, req->property,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
399 sevent.xselection.target, seln_format, PropModeReplace,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
400 seln_data, nbytes);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
401 sevent.xselection.property = req->property;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
402 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
403 XFree(seln_data);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
404 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
405 XSendEvent(display, req->requestor, False, 0, &sevent);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
406 XSync(display, False);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
407 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
408 break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
409
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
410 case SelectionNotify: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
411 #ifdef DEBUG_XEVENTS
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
412 printf("SelectionNotify (requestor = %ld, target = %ld)\n",
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
413 xevent.xselection.requestor, xevent.xselection.target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
414 #endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
415 videodata->selection_waiting = SDL_FALSE;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
416 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
417 break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
418
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
419 default:{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
420 #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
421 printf("Unhandled event %d\n", xevent.type);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
422 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
423 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
424 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
425 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
426 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
427
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
428 /* 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
429 static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
430 X11_Pending(Display * display)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
431 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
432 /* 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
433 XFlush(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
434 if (XEventsQueued(display, QueuedAlready)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
435 return (1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
436 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
437
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
438 /* 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
439 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
440 static struct timeval zero_time; /* static == 0 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
441 int x11_fd;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
442 fd_set fdset;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
443
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
444 x11_fd = ConnectionNumber(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
445 FD_ZERO(&fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
446 FD_SET(x11_fd, &fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
447 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
448 return (XPending(display));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
449 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
450 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
451
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
452 /* Oh well, nothing is ready .. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
453 return (0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
454 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
455
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
456 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
457 X11_PumpEvents(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
458 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
459 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
460
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
461 /* 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
462 if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
463 Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
464 if (!data->screensaver_activity ||
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
465 (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
466 XResetScreenSaver(data->display);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
467 data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
468 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
469 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
470
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
471 /* Keep processing pending events */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
472 while (X11_Pending(data->display)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
473 X11_DispatchEvent(_this);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
474 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
475 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
476
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
477 /* This is so wrong it hurts */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
478 #define GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
479 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
480 #include <unistd.h>
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
481 static pid_t screensaver_inhibit_pid;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
482 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
483 gnome_screensaver_disable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
484 {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
485 screensaver_inhibit_pid = fork();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
486 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
487 close(0);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
488 close(1);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
489 close(2);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
490 execl("/usr/bin/gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
491 "gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
492 "--inhibit",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
493 "--reason",
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
494 "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
495 exit(2);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
496 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
497 }
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
498 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
499 gnome_screensaver_enable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
500 {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
501 kill(screensaver_inhibit_pid, 15);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
502 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
503 #endif
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
504
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
505 void
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
506 X11_SuspendScreenSaver(_THIS)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 {
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
508 #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
509 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
510 int dummy;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
511 int major_version, minor_version;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
512
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
513 if (SDL_X11_HAVE_XSS) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
514 /* 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
515 if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
516 !XScreenSaverQueryVersion(data->display,
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
517 &major_version, &minor_version) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
518 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
519 return;
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
520 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
521
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
522 XScreenSaverSuspend(data->display, _this->suspend_screensaver);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
523 XResetScreenSaver(data->display);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
524 }
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
525 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
526
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
527 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
528 if (_this->suspend_screensaver) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
529 gnome_screensaver_disable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
530 } else {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
531 gnome_screensaver_enable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
532 }
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
533 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
534 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
535
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 /* vi: set ts=4 sw=4 expandtab: */