annotate src/video/x11/SDL_x11events.c @ 4683:15dfe42edbfd

Fixed gestureMulti. Disabled dollar gesture temporarily.
author Jim Grandpre <jim.tla@gmail.com>
date Wed, 04 Aug 2010 23:17:30 -0400
parents 5378f2d0754f
children c24ba2cc9583
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>
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
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"
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
33 #include "../../events/SDL_touch_c.h"
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
34
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
35 #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
36 #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
37
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
38 #include <stdio.h>
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
39
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4669
diff changeset
40 #ifdef SDL_INPUT_LINUXEV
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
41 //Touch Input/event* includes
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
42 #include <linux/input.h>
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
43 #include <fcntl.h>
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4661
diff changeset
44 #endif
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
45 /*#define DEBUG_XEVENTS*/
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
46
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
47 static void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
48 X11_DispatchEvent(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
49 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
50 SDL_VideoData *videodata = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
51 SDL_WindowData *data;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
52 XEvent xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
53 int i;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
54
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
55 SDL_zero(xevent); /* valgrind fix. --ryan. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
56 XNextEvent(videodata->display, &xevent);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
57
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
58 /* 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
59 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
60 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
61 #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
62 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
63 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
64 #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
65 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
66 }
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
67
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
68 /* 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
69 if (SDL_GetEventState(SDL_SYSWMEVENT) == SDL_ENABLE) {
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
70 SDL_SysWMmsg wmmsg;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
71
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
72 SDL_VERSION(&wmmsg.version);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
73 wmmsg.subsystem = SDL_SYSWM_X11;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
74 wmmsg.event.xevent = xevent;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
75 SDL_SendSysWMEvent(&wmmsg);
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
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
78 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
79 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
80 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
81 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
82 (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
83 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
84 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
85 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
86 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
87 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
88 if (!data) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
89 return;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
90 }
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
91 #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
92 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
93 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
94 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
95 switch (xevent.type) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
96
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
97 /* Gaining mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
98 case EnterNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
99 #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
100 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
101 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
102 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
103 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
104 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
105 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
106 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
107 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
108 #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
109 SDL_SetMouseFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
110 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
111 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
112 /* Losing mouse coverage? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
113 case LeaveNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
114 #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
115 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
116 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
117 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
118 xevent.xcrossing.mode);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
119 if (xevent.xcrossing.mode == NotifyGrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
120 printf("Mode: NotifyGrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
121 if (xevent.xcrossing.mode == NotifyUngrab)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
122 printf("Mode: NotifyUngrab\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
123 #endif
3322
d9dd6cbba4c0 Fixed bug #716
Sam Lantinga <slouken@libsdl.org>
parents: 3241
diff changeset
124 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
125 SDL_SetMouseFocus(NULL);
1951
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 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
128 break;
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 /* Gaining input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
131 case FocusIn:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
132 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
133 printf("FocusIn!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
134 #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
135 SDL_SetKeyboardFocus(data->window);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
136 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
137 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
138 XSetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
139 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
140 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
141 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
142 break;
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 /* Losing input focus? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
145 case FocusOut:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
146 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
147 printf("FocusOut!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
148 #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
149 SDL_SetKeyboardFocus(NULL);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
150 #ifdef X_HAVE_UTF8_STRING
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
151 if (data->ic) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
152 XUnsetICFocus(data->ic);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
153 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
154 #endif
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 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
157
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
158 /* Generated upon EnterWindow and FocusIn */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
159 case KeymapNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
160 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
161 printf("KeymapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
162 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
163 /* FIXME:
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
164 X11_SetKeyboardState(SDL_Display, xevent.xkeymap.key_vector);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
165 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
166 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
167 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
168
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
169 /* Has the keyboard layout changed? */
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
170 case MappingNotify:{
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
171 #ifdef DEBUG_XEVENTS
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
172 printf("MappingNotify!\n");
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
173 #endif
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
174 X11_UpdateKeymap(_this);
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
175 }
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
176 break;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
177
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
178 /* Key press? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
179 case KeyPress:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
180 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
181 KeySym keysym = NoSymbol;
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
182 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
183 Status status = 0;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
184
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
185 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
186 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
187 #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
188 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
189 #if 0
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
190 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
191 int min_keycode, max_keycode;
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
192 XDisplayKeycodes(videodata->display, &min_keycode,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
193 &max_keycode);
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
194 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
195 fprintf(stderr,
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
196 "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
197 keycode, keycode - min_keycode, keysym,
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
198 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
199 }
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
200 #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
201 /* */
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
202 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
203 #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
204 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
205 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
206 &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
207 }
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
208 #else
2306
1a8bab15a45d Fixed compile errors
Sam Lantinga <slouken@libsdl.org>
parents: 2305
diff changeset
209 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
210 #endif
2305
fbe8ff44c519 First pass of new SDL scancode concept for X11.
Sam Lantinga <slouken@libsdl.org>
parents: 2300
diff changeset
211 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
212 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
213 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
214 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
215 break;
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 /* Key release? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
218 case KeyRelease:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
219 KeyCode keycode = xevent.xkey.keycode;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
220
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
221 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
222 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
223 #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
224 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
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 iconified? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
229 case UnmapNotify:{
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("UnmapNotify!\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_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
234 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
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 restored? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
239 case MapNotify:{
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("MapNotify!\n");
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
242 #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
243 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
244 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
245 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
246 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
247
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
248 /* Have we been resized or moved? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
249 case ConfigureNotify:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
250 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
251 printf("ConfigureNotify! (resize: %dx%d)\n",
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
252 xevent.xconfigure.width, xevent.xconfigure.height);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
253 #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
254 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_MOVED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
255 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
256 SDL_SendWindowEvent(data->window, SDL_WINDOWEVENT_RESIZED,
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
257 xevent.xconfigure.width,
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
258 xevent.xconfigure.height);
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 /* 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
263 case ClientMessage:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
264 if ((xevent.xclient.format == 32) &&
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
265 (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
266
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_CLOSE, 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 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
270 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
271
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
272 /* Do we need to refresh ourselves? */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
273 case Expose:{
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
274 #ifdef DEBUG_XEVENTS
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
275 printf("Expose (count = %d)\n", xevent.xexpose.count);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
276 #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
277 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
278 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
279 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
280
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 case MotionNotify:{
2710
44e49d3fa6cf Final merge of Google Summer of Code 2008 work...
Sam Lantinga <slouken@libsdl.org>
parents: 2328
diff changeset
282 #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
283 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
284 #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
285 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
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 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
290 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
291 }
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 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
293
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 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
295 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
296 }
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
297 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
298
4508
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
299 /* 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
300 case SelectionRequest: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
301 Display *display = videodata->display;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
302 XSelectionRequestEvent *req;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
303 XEvent sevent;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
304 int seln_format;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
305 unsigned long nbytes;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
306 unsigned long overflow;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
307 unsigned char *seln_data;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
308
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
309 req = &xevent.xselectionrequest;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
310 #ifdef DEBUG_XEVENTS
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
311 printf("SelectionRequest (requestor = %ld, target = %ld)\n",
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
312 req->requestor, req->target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
313 #endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
314
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
315 sevent.xselection.type = SelectionNotify;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
316 sevent.xselection.display = req->display;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
317 sevent.xselection.selection = req->selection;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
318 sevent.xselection.target = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
319 sevent.xselection.property = None;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
320 sevent.xselection.requestor = req->requestor;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
321 sevent.xselection.time = req->time;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
322 if (XGetWindowProperty(display, DefaultRootWindow(display),
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
323 XA_CUT_BUFFER0, 0, INT_MAX/4, False, req->target,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
324 &sevent.xselection.target, &seln_format, &nbytes,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
325 &overflow, &seln_data) == Success) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
326 if (sevent.xselection.target == req->target) {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
327 XChangeProperty(display, req->requestor, req->property,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
328 sevent.xselection.target, seln_format, PropModeReplace,
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
329 seln_data, nbytes);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
330 sevent.xselection.property = req->property;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
331 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
332 XFree(seln_data);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
333 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
334 XSendEvent(display, req->requestor, False, 0, &sevent);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
335 XSync(display, False);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
336 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
337 break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
338
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
339 case SelectionNotify: {
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
340 #ifdef DEBUG_XEVENTS
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
341 printf("SelectionNotify (requestor = %ld, target = %ld)\n",
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
342 xevent.xselection.requestor, xevent.xselection.target);
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
343 #endif
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
344 videodata->selection_waiting = SDL_FALSE;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
345 }
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
346 break;
15d2c6f40c48 Added X11 clipboard support.
Sam Lantinga <slouken@libsdl.org>
parents: 4484
diff changeset
347
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
348 default:{
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
349 #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
350 printf("Unhandled event %d\n", xevent.type);
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
351 #endif
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
352 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
353 break;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
354 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
355 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
356
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
357 /* 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
358 static int
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
359 X11_Pending(Display * display)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
360 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
361 /* 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
362 XFlush(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
363 if (XEventsQueued(display, QueuedAlready)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
364 return (1);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
365 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
366
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
367 /* 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
368 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
369 static struct timeval zero_time; /* static == 0 */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
370 int x11_fd;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
371 fd_set fdset;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
372
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
373 x11_fd = ConnectionNumber(display);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
374 FD_ZERO(&fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
375 FD_SET(x11_fd, &fdset);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
376 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
377 return (XPending(display));
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
378 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
379 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
380
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
381 /* Oh well, nothing is ready .. */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
382 return (0);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
383 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
384
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
385 void
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
386 X11_PumpEvents(_THIS)
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
387 {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
388 SDL_VideoData *data = (SDL_VideoData *) _this->driverdata;
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
389
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
390 /* 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
391 if (_this->suspend_screensaver) {
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
392 Uint32 now = SDL_GetTicks();
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
393 if (!data->screensaver_activity ||
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
394 (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
395 XResetScreenSaver(data->display);
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
396 data->screensaver_activity = now;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
397 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
398 }
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
399
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
400 /* Keep processing pending events */
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
401 while (X11_Pending(data->display)) {
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
402 X11_DispatchEvent(_this);
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
403 }
4640
f068a6dfc858 Added SDL_touch.c/SDL_touch_c.h as slightly modifeind SDL_mouse*. Made reads in touchSimp non-blocking.
Jim Grandpre <jim.tla@gmail.com>
parents: 4429
diff changeset
404
4681
5378f2d0754f Fixed some Gesture bugs
Jim Grandpre <jim.tla@gmail.com>
parents: 4669
diff changeset
405 #ifdef SDL_INPUT_LINUXEV
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
406 /* Process Touch events - TODO When X gets touch support, use that instead*/
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
407 int i = 0,rd;
4643
8806b78988f7 Bug fixes. Basic touch events (finger up, finger down, finger move) supported.
Jim Grandpre <jim.tla@gmail.com>
parents: 4642
diff changeset
408 char name[256];
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
409 struct input_event ev[64];
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
410 int size = sizeof (struct input_event);
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
411
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
412 for(i = 0;i < SDL_GetNumTouch();++i) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
413 SDL_Touch* touch = SDL_GetTouchIndex(i);
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
414 if(!touch) printf("Touch %i/%i DNE\n",i,SDL_GetNumTouch());
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
415 EventTouchData* data;
4645
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
416 data = (EventTouchData*)(touch->driverdata);
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
417 if(data == NULL) {
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
418 printf("No driver data\n");
0375d020e7e3 Auto-detects Wacom touch devices.
Jim Grandpre <jim.tla@gmail.com>
parents: 4644
diff changeset
419 continue;
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
420 }
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
421 if(data->eventStream <= 0)
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
422 printf("Error: Couldn't open stream\n");
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
423 rd = read(data->eventStream, ev, size * 64);
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
424 //printf("Got %i/%i bytes\n",rd,size);
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
425 if(rd >= size) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
426 for (i = 0; i < rd / sizeof(struct input_event); i++) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
427 switch (ev[i].type) {
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
428 case EV_ABS:
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
429 //printf("Got position x: %i!\n",data->x);
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
430 switch (ev[i].code) {
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
431 case ABS_X:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
432 data->x = ev[i].value;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
433 break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
434 case ABS_Y:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
435 data->y = ev[i].value;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
436 break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
437 case ABS_PRESSURE:
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
438 data->pressure = ev[i].value;
4646
eea1bf53effa Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents: 4645
diff changeset
439 if(data->pressure < 0) data->pressure = 0;
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
440 break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
441 case ABS_MISC:
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
442 if(ev[i].value == 0)
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
443 data->up = SDL_TRUE;
4644
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
444 break;
fb500b3e1717 Added pressure support for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4643
diff changeset
445 }
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
446 break;
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
447 case EV_MSC:
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
448 if(ev[i].code == MSC_SERIAL)
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
449 data->finger = ev[i].value;
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
450 break;
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
451 case EV_SYN:
4646
eea1bf53effa Added include/touch.h Now reading in resolution of touch pad.
Jim Grandpre <jim.tla@gmail.com>
parents: 4645
diff changeset
452 //printf("Id: %i\n",touch->id);
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
453 if(data->up) {
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
454 SDL_SendFingerDown(touch->id,data->finger,
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
455 SDL_FALSE,data->x,data->y,
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
456 data->pressure);
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
457 }
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
458 else if(data->x >= 0 || data->y >= 0)
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
459 SDL_SendTouchMotion(touch->id,data->finger,
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
460 SDL_FALSE,data->x,data->y,
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
461 data->pressure);
4655
4c94f2023d62 Fixed bugs in input, cleaned up $1
Jim Grandpre <jim.tla@gmail.com>
parents: 4646
diff changeset
462
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
463 //printf("Synched: %i tx: %i, ty: %i\n",
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
464 // data->finger,data->x,data->y);
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
465 data->x = -1;
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
466 data->y = -1;
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
467 data->pressure = -1;
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
468 data->finger = 0;
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
469 data->up = SDL_FALSE;
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
470
4683
15dfe42edbfd Fixed gestureMulti. Disabled dollar gesture temporarily.
Jim Grandpre <jim.tla@gmail.com>
parents: 4681
diff changeset
471 break;
4642
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
472 }
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
473 }
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
474 }
057e8762d2a1 Added reading of event* for touch events.
Jim Grandpre <jim.tla@gmail.com>
parents: 4640
diff changeset
475 }
4669
62e6a6e9720b Fixed x11 compile bugs.
jimtla
parents: 4661
diff changeset
476 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
477 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
478
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
479 /* This is so wrong it hurts */
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
480 #define GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
481 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
482 #include <unistd.h>
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
483 static pid_t screensaver_inhibit_pid;
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
484 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
485 gnome_screensaver_disable()
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
486 {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
487 screensaver_inhibit_pid = fork();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
488 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
489 close(0);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
490 close(1);
86918831452f Don't complain when the GNOME screensaver isn't running (or available)
Sam Lantinga <slouken@libsdl.org>
parents: 3030
diff changeset
491 close(2);
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
492 execl("/usr/bin/gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
493 "gnome-screensaver-command",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
494 "--inhibit",
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
495 "--reason",
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
496 "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
497 exit(2);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
498 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
499 }
3040
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
500 static void
Sam Lantinga <slouken@libsdl.org>
parents: 3031
diff changeset
501 gnome_screensaver_enable()
3030
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 kill(screensaver_inhibit_pid, 15);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
504 }
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
505 #endif
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
506
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
507 void
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
508 X11_SuspendScreenSaver(_THIS)
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
509 {
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
510 #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
511 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
512 int dummy;
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
513 int major_version, minor_version;
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
514
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
515 if (SDL_X11_HAVE_XSS) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
516 /* 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
517 if (!XScreenSaverQueryExtension(data->display, &dummy, &dummy) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
518 !XScreenSaverQueryVersion(data->display,
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
519 &major_version, &minor_version) ||
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
520 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
521 return;
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
522 }
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
523
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
524 XScreenSaverSuspend(data->display, _this->suspend_screensaver);
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
525 XResetScreenSaver(data->display);
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 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
528
3030
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
529 #ifdef GNOME_SCREENSAVER_HACK
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
530 if (_this->suspend_screensaver) {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
531 gnome_screensaver_disable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
532 } else {
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
533 gnome_screensaver_enable();
f13ad181f5b2 This is so wrong, it hurts.
Sam Lantinga <slouken@libsdl.org>
parents: 3025
diff changeset
534 }
3025
54fac87e1f34 Added an API to enable/disable the screen saver.
Sam Lantinga <slouken@libsdl.org>
parents: 3015
diff changeset
535 #endif
1951
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
536 }
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
537
7177581dc9fa Initial work on X11 window code in.
Sam Lantinga <slouken@libsdl.org>
parents:
diff changeset
538 /* vi: set ts=4 sw=4 expandtab: */