Skip to content
This repository
Browse code

Merge pull request #33 from jgranick/emulate

Push BPS events using SDL_SysWMEvent
  • Loading branch information...
commit 084e8d8e66ff585cbac9cc91b1e4b7c2418bec54 2 parents 7cbcab0 + 2e87028
Jeremy Nicholl authored November 04, 2012
480  include/SDL_syswm.h
... ...
@@ -1,239 +1,241 @@
1  
-/*
2  
-    SDL - Simple DirectMedia Layer
3  
-    Copyright (C) 1997-2009 Sam Lantinga
4  
-
5  
-    This library is free software; you can redistribute it and/or
6  
-    modify it under the terms of the GNU Lesser General Public
7  
-    License as published by the Free Software Foundation; either
8  
-    version 2.1 of the License, or (at your option) any later version.
9  
-
10  
-    This library is distributed in the hope that it will be useful,
11  
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
12  
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  
-    Lesser General Public License for more details.
14  
-
15  
-    You should have received a copy of the GNU Lesser General Public
16  
-    License along with this library; if not, write to the Free Software
17  
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  
-
19  
-    Sam Lantinga
20  
-    slouken@libsdl.org
21  
-*/
22  
-
23  
-/** @file SDL_syswm.h
24  
- *  Include file for SDL custom system window manager hooks
25  
- */
26  
-
27  
-#ifndef _SDL_syswm_h
28  
-#define _SDL_syswm_h
29  
-
30  
-#include "SDL_stdinc.h"
31  
-#include "SDL_error.h"
32  
-#include "SDL_version.h"
33  
-
34  
-#include "begin_code.h"
35  
-/* Set up for C function definitions, even when using C++ */
36  
-#ifdef __cplusplus
37  
-extern "C" {
38  
-#endif
39  
-
40  
-/** @file SDL_syswm.h
41  
- *  Your application has access to a special type of event 'SDL_SYSWMEVENT',
42  
- *  which contains window-manager specific information and arrives whenever
43  
- *  an unhandled window event occurs.  This event is ignored by default, but
44  
- *  you can enable it with SDL_EventState()
45  
- */
46  
-#ifdef SDL_PROTOTYPES_ONLY
47  
-struct SDL_SysWMinfo;
48  
-typedef struct SDL_SysWMinfo SDL_SysWMinfo;
49  
-#else
50  
-
51  
-/* This is the structure for custom window manager events */
52  
-#if defined(SDL_VIDEO_DRIVER_X11)
53  
-#if defined(__APPLE__) && defined(__MACH__)
54  
-/* conflicts with Quickdraw.h */
55  
-#define Cursor X11Cursor
56  
-#endif
57  
-
58  
-#include <X11/Xlib.h>
59  
-#include <X11/Xatom.h>
60  
-
61  
-#if defined(__APPLE__) && defined(__MACH__)
62  
-/* matches the re-define above */
63  
-#undef Cursor
64  
-#endif
65  
-
66  
-/** These are the various supported subsystems under UNIX */
67  
-typedef enum {
68  
-	SDL_SYSWM_X11
69  
-} SDL_SYSWM_TYPE;
70  
-
71  
-/** The UNIX custom event structure */
72  
-struct SDL_SysWMmsg {
73  
-	SDL_version version;
74  
-	SDL_SYSWM_TYPE subsystem;
75  
-	union {
76  
-	    XEvent xevent;
77  
-	} event;
78  
-};
79  
-
80  
-/** The UNIX custom window manager information structure.
81  
- *  When this structure is returned, it holds information about which
82  
- *  low level system it is using, and will be one of SDL_SYSWM_TYPE.
83  
- */
84  
-typedef struct SDL_SysWMinfo {
85  
-	SDL_version version;
86  
-	SDL_SYSWM_TYPE subsystem;
87  
-	union {
88  
-	    struct {
89  
-	    	Display *display;	/**< The X11 display */
90  
-	    	Window window;		/**< The X11 display window */
91  
-		/** These locking functions should be called around
92  
-                 *  any X11 functions using the display variable, 
93  
-                 *  but not the gfxdisplay variable.
94  
-                 *  They lock the event thread, so should not be
95  
-		 *  called around event functions or from event filters.
96  
-		 */
97  
-                /*@{*/
98  
-		void (*lock_func)(void);
99  
-		void (*unlock_func)(void);
100  
-                /*@}*/
101  
-
102  
-		/** @name Introduced in SDL 1.0.2 */
103  
-                /*@{*/
104  
-	    	Window fswindow;	/**< The X11 fullscreen window */
105  
-	    	Window wmwindow;	/**< The X11 managed input window */
106  
-                /*@}*/
107  
-
108  
-		/** @name Introduced in SDL 1.2.12 */
109  
-                /*@{*/
110  
-		Display *gfxdisplay;	/**< The X11 display to which rendering is done */
111  
-                /*@}*/
112  
-	    } x11;
113  
-	} info;
114  
-} SDL_SysWMinfo;
115  
-
116  
-#elif defined(SDL_VIDEO_DRIVER_NANOX)
117  
-#include <microwin/nano-X.h>
118  
-
119  
-/** The generic custom event structure */
120  
-struct SDL_SysWMmsg {
121  
-	SDL_version version;
122  
-	int data;
123  
-};
124  
-
125  
-/** The windows custom window manager information structure */
126  
-typedef struct SDL_SysWMinfo {
127  
-	SDL_version version ;
128  
-	GR_WINDOW_ID window ;	/* The display window */
129  
-} SDL_SysWMinfo;
130  
-
131  
-#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
132  
-#define WIN32_LEAN_AND_MEAN
133  
-#include <windows.h>
134  
-
135  
-/** The windows custom event structure */
136  
-struct SDL_SysWMmsg {
137  
-	SDL_version version;
138  
-	HWND hwnd;			/**< The window for the message */
139  
-	UINT msg;			/**< The type of message */
140  
-	WPARAM wParam;			/**< WORD message parameter */
141  
-	LPARAM lParam;			/**< LONG message parameter */
142  
-};
143  
-
144  
-/** The windows custom window manager information structure */
145  
-typedef struct SDL_SysWMinfo {
146  
-	SDL_version version;
147  
-	HWND window;			/**< The Win32 display window */
148  
-	HGLRC hglrc;			/**< The OpenGL context, if any */
149  
-} SDL_SysWMinfo;
150  
-
151  
-#elif defined(SDL_VIDEO_DRIVER_RISCOS)
152  
-
153  
-/** RISC OS custom event structure */
154  
-struct SDL_SysWMmsg {
155  
-	SDL_version version;
156  
-	int eventCode;		/**< The window for the message */
157  
-	int pollBlock[64];
158  
-};
159  
-
160  
-/** The RISC OS custom window manager information structure */
161  
-typedef struct SDL_SysWMinfo {
162  
-	SDL_version version;
163  
-	int wimpVersion;    /**< Wimp version running under */
164  
-	int taskHandle;     /**< The RISC OS task handle */
165  
-	int window;		/**< The RISC OS display window */
166  
-} SDL_SysWMinfo;
167  
-
168  
-#elif defined(SDL_VIDEO_DRIVER_PHOTON)
169  
-#include <sys/neutrino.h>
170  
-#include <Ph.h>
171  
-
172  
-/** The QNX custom event structure */
173  
-struct SDL_SysWMmsg {
174  
-	SDL_version version;
175  
-	int data;
176  
-};
177  
-
178  
-/** The QNX custom window manager information structure */
179  
-typedef struct SDL_SysWMinfo {
180  
-	SDL_version version;
181  
-	int data;
182  
-} SDL_SysWMinfo;
183  
-
184  
-#elif defined(SDL_VIDEO_DRIVER_PLAYBOOK)
185  
-#include <screen/screen.h>
186  
-
187  
-struct SDL_SysWMmsg {
188  
-	SDL_version version;
189  
-	int data;
190  
-};
191  
-
192  
-typedef struct SDL_SysWMinfo {
193  
-	SDL_version version;
194  
-	screen_context_t context;
195  
-	screen_window_t window;
196  
-} SDL_SysWMinfo;
197  
-
198  
-#else
199  
-
200  
-/** The generic custom event structure */
201  
-struct SDL_SysWMmsg {
202  
-	SDL_version version;
203  
-	int data;
204  
-};
205  
-
206  
-/** The generic custom window manager information structure */
207  
-typedef struct SDL_SysWMinfo {
208  
-	SDL_version version;
209  
-	int data;
210  
-} SDL_SysWMinfo;
211  
-
212  
-#endif /* video driver type */
213  
-
214  
-#endif /* SDL_PROTOTYPES_ONLY */
215  
-
216  
-/* Function prototypes */
217  
-/**
218  
- * This function gives you custom hooks into the window manager information.
219  
- * It fills the structure pointed to by 'info' with custom information and
220  
- * returns 1 if the function is implemented.  If it's not implemented, or
221  
- * the version member of the 'info' structure is invalid, it returns 0. 
222  
- *
223  
- * You typically use this function like this:
224  
- * @code
225  
- * SDL_SysWMInfo info;
226  
- * SDL_VERSION(&info.version);
227  
- * if ( SDL_GetWMInfo(&info) ) { ... }
228  
- * @endcode
229  
- */
230  
-extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info);
231  
-
232  
-
233  
-/* Ends C function definitions when using C++ */
234  
-#ifdef __cplusplus
235  
-}
236  
-#endif
237  
-#include "close_code.h"
238  
-
239  
-#endif /* _SDL_syswm_h */
  1
+/*
  2
+    SDL - Simple DirectMedia Layer
  3
+    Copyright (C) 1997-2009 Sam Lantinga
  4
+
  5
+    This library is free software; you can redistribute it and/or
  6
+    modify it under the terms of the GNU Lesser General Public
  7
+    License as published by the Free Software Foundation; either
  8
+    version 2.1 of the License, or (at your option) any later version.
  9
+
  10
+    This library is distributed in the hope that it will be useful,
  11
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
  12
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  13
+    Lesser General Public License for more details.
  14
+
  15
+    You should have received a copy of the GNU Lesser General Public
  16
+    License along with this library; if not, write to the Free Software
  17
+    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
  18
+
  19
+    Sam Lantinga
  20
+    slouken@libsdl.org
  21
+*/
  22
+
  23
+/** @file SDL_syswm.h
  24
+ *  Include file for SDL custom system window manager hooks
  25
+ */
  26
+
  27
+#ifndef _SDL_syswm_h
  28
+#define _SDL_syswm_h
  29
+
  30
+#include "SDL_stdinc.h"
  31
+#include "SDL_error.h"
  32
+#include "SDL_version.h"
  33
+
  34
+#include "begin_code.h"
  35
+/* Set up for C function definitions, even when using C++ */
  36
+#ifdef __cplusplus
  37
+extern "C" {
  38
+#endif
  39
+
  40
+/** @file SDL_syswm.h
  41
+ *  Your application has access to a special type of event 'SDL_SYSWMEVENT',
  42
+ *  which contains window-manager specific information and arrives whenever
  43
+ *  an unhandled window event occurs.  This event is ignored by default, but
  44
+ *  you can enable it with SDL_EventState()
  45
+ */
  46
+#ifdef SDL_PROTOTYPES_ONLY
  47
+struct SDL_SysWMinfo;
  48
+typedef struct SDL_SysWMinfo SDL_SysWMinfo;
  49
+#else
  50
+
  51
+/* This is the structure for custom window manager events */
  52
+#if defined(SDL_VIDEO_DRIVER_X11)
  53
+#if defined(__APPLE__) && defined(__MACH__)
  54
+/* conflicts with Quickdraw.h */
  55
+#define Cursor X11Cursor
  56
+#endif
  57
+
  58
+#include <X11/Xlib.h>
  59
+#include <X11/Xatom.h>
  60
+
  61
+#if defined(__APPLE__) && defined(__MACH__)
  62
+/* matches the re-define above */
  63
+#undef Cursor
  64
+#endif
  65
+
  66
+/** These are the various supported subsystems under UNIX */
  67
+typedef enum {
  68
+	SDL_SYSWM_X11
  69
+} SDL_SYSWM_TYPE;
  70
+
  71
+/** The UNIX custom event structure */
  72
+struct SDL_SysWMmsg {
  73
+	SDL_version version;
  74
+	SDL_SYSWM_TYPE subsystem;
  75
+	union {
  76
+	    XEvent xevent;
  77
+	} event;
  78
+};
  79
+
  80
+/** The UNIX custom window manager information structure.
  81
+ *  When this structure is returned, it holds information about which
  82
+ *  low level system it is using, and will be one of SDL_SYSWM_TYPE.
  83
+ */
  84
+typedef struct SDL_SysWMinfo {
  85
+	SDL_version version;
  86
+	SDL_SYSWM_TYPE subsystem;
  87
+	union {
  88
+	    struct {
  89
+	    	Display *display;	/**< The X11 display */
  90
+	    	Window window;		/**< The X11 display window */
  91
+		/** These locking functions should be called around
  92
+                 *  any X11 functions using the display variable, 
  93
+                 *  but not the gfxdisplay variable.
  94
+                 *  They lock the event thread, so should not be
  95
+		 *  called around event functions or from event filters.
  96
+		 */
  97
+                /*@{*/
  98
+		void (*lock_func)(void);
  99
+		void (*unlock_func)(void);
  100
+                /*@}*/
  101
+
  102
+		/** @name Introduced in SDL 1.0.2 */
  103
+                /*@{*/
  104
+	    	Window fswindow;	/**< The X11 fullscreen window */
  105
+	    	Window wmwindow;	/**< The X11 managed input window */
  106
+                /*@}*/
  107
+
  108
+		/** @name Introduced in SDL 1.2.12 */
  109
+                /*@{*/
  110
+		Display *gfxdisplay;	/**< The X11 display to which rendering is done */
  111
+                /*@}*/
  112
+	    } x11;
  113
+	} info;
  114
+} SDL_SysWMinfo;
  115
+
  116
+#elif defined(SDL_VIDEO_DRIVER_NANOX)
  117
+#include <microwin/nano-X.h>
  118
+
  119
+/** The generic custom event structure */
  120
+struct SDL_SysWMmsg {
  121
+	SDL_version version;
  122
+	int data;
  123
+};
  124
+
  125
+/** The windows custom window manager information structure */
  126
+typedef struct SDL_SysWMinfo {
  127
+	SDL_version version ;
  128
+	GR_WINDOW_ID window ;	/* The display window */
  129
+} SDL_SysWMinfo;
  130
+
  131
+#elif defined(SDL_VIDEO_DRIVER_WINDIB) || defined(SDL_VIDEO_DRIVER_DDRAW) || defined(SDL_VIDEO_DRIVER_GAPI)
  132
+#define WIN32_LEAN_AND_MEAN
  133
+#include <windows.h>
  134
+
  135
+/** The windows custom event structure */
  136
+struct SDL_SysWMmsg {
  137
+	SDL_version version;
  138
+	HWND hwnd;			/**< The window for the message */
  139
+	UINT msg;			/**< The type of message */
  140
+	WPARAM wParam;			/**< WORD message parameter */
  141
+	LPARAM lParam;			/**< LONG message parameter */
  142
+};
  143
+
  144
+/** The windows custom window manager information structure */
  145
+typedef struct SDL_SysWMinfo {
  146
+	SDL_version version;
  147
+	HWND window;			/**< The Win32 display window */
  148
+	HGLRC hglrc;			/**< The OpenGL context, if any */
  149
+} SDL_SysWMinfo;
  150
+
  151
+#elif defined(SDL_VIDEO_DRIVER_RISCOS)
  152
+
  153
+/** RISC OS custom event structure */
  154
+struct SDL_SysWMmsg {
  155
+	SDL_version version;
  156
+	int eventCode;		/**< The window for the message */
  157
+	int pollBlock[64];
  158
+};
  159
+
  160
+/** The RISC OS custom window manager information structure */
  161
+typedef struct SDL_SysWMinfo {
  162
+	SDL_version version;
  163
+	int wimpVersion;    /**< Wimp version running under */
  164
+	int taskHandle;     /**< The RISC OS task handle */
  165
+	int window;		/**< The RISC OS display window */
  166
+} SDL_SysWMinfo;
  167
+
  168
+#elif defined(SDL_VIDEO_DRIVER_PHOTON)
  169
+#include <sys/neutrino.h>
  170
+#include <Ph.h>
  171
+
  172
+/** The QNX custom event structure */
  173
+struct SDL_SysWMmsg {
  174
+	SDL_version version;
  175
+	int data;
  176
+};
  177
+
  178
+/** The QNX custom window manager information structure */
  179
+typedef struct SDL_SysWMinfo {
  180
+	SDL_version version;
  181
+	int data;
  182
+} SDL_SysWMinfo;
  183
+
  184
+#elif defined(SDL_VIDEO_DRIVER_PLAYBOOK)
  185
+#include <screen/screen.h>
  186
+#include <bps/event.h>
  187
+
  188
+/** The PlayBook custom event structure */
  189
+struct SDL_SysWMmsg {
  190
+	SDL_version version;
  191
+	bps_event_t *event;
  192
+};
  193
+
  194
+typedef struct SDL_SysWMinfo {
  195
+	SDL_version version;
  196
+	screen_context_t context;
  197
+	screen_window_t window;
  198
+} SDL_SysWMinfo;
  199
+
  200
+#else
  201
+
  202
+/** The generic custom event structure */
  203
+struct SDL_SysWMmsg {
  204
+	SDL_version version;
  205
+	int data;
  206
+};
  207
+
  208
+/** The generic custom window manager information structure */
  209
+typedef struct SDL_SysWMinfo {
  210
+	SDL_version version;
  211
+	int data;
  212
+} SDL_SysWMinfo;
  213
+
  214
+#endif /* video driver type */
  215
+
  216
+#endif /* SDL_PROTOTYPES_ONLY */
  217
+
  218
+/* Function prototypes */
  219
+/**
  220
+ * This function gives you custom hooks into the window manager information.
  221
+ * It fills the structure pointed to by 'info' with custom information and
  222
+ * returns 1 if the function is implemented.  If it's not implemented, or
  223
+ * the version member of the 'info' structure is invalid, it returns 0. 
  224
+ *
  225
+ * You typically use this function like this:
  226
+ * @code
  227
+ * SDL_SysWMInfo info;
  228
+ * SDL_VERSION(&info.version);
  229
+ * if ( SDL_GetWMInfo(&info) ) { ... }
  230
+ * @endcode
  231
+ */
  232
+extern DECLSPEC int SDLCALL SDL_GetWMInfo(SDL_SysWMinfo *info);
  233
+
  234
+
  235
+/* Ends C function definitions when using C++ */
  236
+#ifdef __cplusplus
  237
+}
  238
+#endif
  239
+#include "close_code.h"
  240
+
  241
+#endif /* _SDL_syswm_h */
2,004  src/video/playbook/SDL_playbookevents.c
... ...
@@ -1,996 +1,1008 @@
1  
-/*
2  
-    SDL - Simple DirectMedia Layer
3  
-    Copyright (C) 1997-2009 Sam Lantinga
4  
-
5  
-    This library is free software; you can redistribute it and/or
6  
-    modify it under the terms of the GNU Lesser General Public
7  
-    License as published by the Free Software Foundation; either
8  
-    version 2.1 of the License, or (at your option) any later version.
9  
-
10  
-    This library is distributed in the hope that it will be useful,
11  
-    but WITHOUT ANY WARRANTY; without even the implied warranty of
12  
-    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13  
-    Lesser General Public License for more details.
14  
-
15  
-    You should have received a copy of the GNU Lesser General Public
16  
-    License along with this library; if not, write to the Free Software
17  
-    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
18  
-
19  
-    Sam Lantinga
20  
-    slouken@libsdl.org
21  
-*/
22  
-#include "SDL_config.h"
23  
-#include "SDL.h"
24  
-#include "../../events/SDL_sysevents.h"
25  
-#include "../../events/SDL_events_c.h"
26  
-#include "SDL_keysym.h"
27  
-
28  
-#include "SDL_playbookvideo.h"
29  
-#include "SDL_playbookevents_c.h"
30  
-
31  
-#include <bps/bps.h>
32  
-#include <bps/screen.h>
33  
-#include <bps/event.h>
34  
-#include <bps/orientation.h>
35  
-#include <bps/navigator.h>
36  
-#include "touchcontroloverlay.h"
37  
-
38  
-#define SDLK_PB_TILDE 160 // Conflicts with SDLK_WORLD_0.
39  
-static SDL_keysym Playbook_Keycodes[256];
40  
-static SDLKey *Playbook_specialsyms;
41  
-
42  
-//#define TOUCHPAD_SIMULATE 1 // Still experimental
43  
-#ifdef TOUCHPAD_SIMULATE
44  
-struct TouchState {
45  
-	int oldPos[2];
46  
-	int pending[2];
47  
-	int mask;
48  
-	int moveId;
49  
-	int leftDown;
50  
-	int leftId;
51  
-	int rightDown;
52  
-	int rightId;
53  
-};
54  
-
55  
-static struct TouchState state = { {0, 0}, {0, 0}, 0, -1, 0, -1, 0, -1};
56  
-#endif
57  
-struct TouchEvent {
58  
-	int pending;
59  
-	int touching;
60  
-	int pos[2];
61  
-};
62  
-static struct TouchEvent moveEvent;
63  
-
64  
-
65  
-static void handlePointerEvent(screen_event_t event, screen_window_t window)
66  
-{
67  
-	int buttonState = 0;
68  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_BUTTONS, &buttonState);
69  
-
70  
-	int coords[2];
71  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, coords);
72  
-
73  
-	int screen_coords[2];
74  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, screen_coords);
75  
-
76  
-	int wheel_delta;
77  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_MOUSE_WHEEL, &wheel_delta);
78  
-
79  
-	if (coords[1] < 0) {
80  
-		fprintf(stderr, "Detected pointer swipe event: %d,%d\n", coords[0], coords[1]);
81  
-		return;
82  
-	}
83  
-	//fprintf(stderr, "Pointer: %d,(%d,%d),(%d,%d),%d\n", buttonState, coords[0], coords[1], screen_coords[0], screen_coords[1], wheel_delta);
84  
-	if (wheel_delta != 0) {
85  
-		int button;
86  
-		if ( wheel_delta > 0 )
87  
-			button = SDL_BUTTON_WHEELDOWN;
88  
-		else if ( wheel_delta < 0 )
89  
-			button = SDL_BUTTON_WHEELUP;
90  
-		SDL_PrivateMouseButton(
91  
-			SDL_PRESSED, button, 0, 0);
92  
-		SDL_PrivateMouseButton(
93  
-			SDL_RELEASED, button, 0, 0);
94  
-	}
95  
-
96  
-	// FIXME: Pointer events have never been tested.
97  
-	static int lastButtonState = 0;
98  
-	if (lastButtonState == buttonState) {
99  
-		moveEvent.touching = buttonState;
100  
-		moveEvent.pos[0] = coords[0];
101  
-		moveEvent.pos[1] = coords[1];
102  
-		moveEvent.pending = 1;
103  
-		return;
104  
-	}
105  
-	lastButtonState = buttonState;
106  
-
107  
-	SDL_PrivateMouseButton(buttonState ? SDL_PRESSED : SDL_RELEASED, SDL_BUTTON_LEFT, coords[0], coords[1]); // FIXME: window
108  
-	moveEvent.pending = 0;
109  
-}
110  
-
111  
-static int TranslateBluetoothKeyboard(int sym, int mods, int flags, int scan, int cap, SDL_keysym *keysym)
112  
-{
113  
-	if (flags == 32) {
114  
-		return 0; // No translation for this - this is an addition message sent
115  
-		// with arrow keys, right ctrl, right ctrl and pause
116  
-	}
117  
-	// FIXME: Figure out how to separate left and right modifiers
118  
-	if (scan > 128)
119  
-		scan -= 128; // Keyup events have the high bit set, but we want to have the same scan for down and up.
120  
-	keysym->scancode = scan;
121  
-	keysym->mod = 0;
122  
-	if (mods & (0x1))
123  
-		keysym->mod |= KMOD_LSHIFT;
124  
-	if (mods & (0x2))
125  
-		keysym->mod |= KMOD_LCTRL;
126  
-	if (mods & (0x4))
127  
-		keysym->mod |= KMOD_LALT;
128  
-	if (mods & (0x10000))
129  
-		keysym->mod |= KMOD_CAPS;
130  
-	if (mods & (0x20000)) // FIXME: guessing
131  
-		keysym->mod |= KMOD_NUM;
132  
-	//if (mods & (0x40000))
133  
-		//keysym.mod |= SCROLL LOCK; // SDL has no scroll lock
134  
-
135  
-	if (sym & 0xf000) {
136  
-		sym = sym & 0xff;
137  
-		keysym->sym = Playbook_specialsyms[sym];
138  
-	} else {
139  
-		keysym->sym = Playbook_Keycodes[sym].sym;
140  
-	}
141  
-
142  
-	return 1;
143  
-}
144  
-
145  
-static int TranslateVKB(int sym, int mods, int flags, int scan, int cap, SDL_keysym *keysym)
146  
-{
147  
-	int shifted = 0;
148  
-	// FIXME: Keyboard handling (modifiers are currently ignored, some keys are as well)
149  
-	if (sym & 0xf000) {
150  
-		sym = sym & 0xff;
151  
-		keysym->sym = Playbook_specialsyms[sym];
152  
-	} else {
153  
-		keysym->sym = Playbook_Keycodes[sym].sym;
154  
-	}
155  
-
156  
-	if (mods & (0x1))
157  
-		shifted = 1;
158  
-
159  
-	// FIXME: These scancodes are really just implemented this way for dosbox.
160  
-	// See keyboard.cpp inside dosbox (KEYBOARD_AddKey) for a reference.
161  
-	switch (keysym->sym)
162  
-	{
163  
-	case SDLK_EXCLAIM:
164  
-		shifted = 1;
165  
-	case SDLK_1:
166  
-		keysym->scancode = 2;
167  
-		break;
168  
-	case SDLK_AT:
169  
-		shifted = 1;
170  
-	case SDLK_2:
171  
-		keysym->scancode = 3;
172  
-		break;
173  
-	case SDLK_HASH:
174  
-		shifted = 1;
175  
-	case SDLK_3:
176  
-		keysym->scancode = 4;
177  
-		break;
178  
-	case SDLK_DOLLAR:
179  
-		shifted = 1;
180  
-	case SDLK_4:
181  
-		keysym->scancode = 5;
182  
-		break;
183  
-	case SDLK_5:
184  
-		keysym->scancode = 6;
185  
-		break;
186  
-	case SDLK_CARET:
187  
-		shifted = 1;
188  
-	case SDLK_6:
189  
-		keysym->scancode = 7;
190  
-		break;
191  
-	case SDLK_AMPERSAND:
192  
-		shifted = 1;
193  
-	case SDLK_7:
194  
-		keysym->scancode = 8;
195  
-		break;
196  
-	case SDLK_ASTERISK:
197  
-		shifted = 1;
198  
-	case SDLK_8:
199  
-		keysym->scancode = 9;
200  
-		break;
201  
-	case SDLK_LEFTPAREN:
202  
-		shifted = 1;
203  
-	case SDLK_9:
204  
-		keysym->scancode = 10;
205  
-		break;
206  
-	case SDLK_RIGHTPAREN:
207  
-		shifted = 1;
208  
-	case SDLK_0:
209  
-		keysym->scancode = 11;
210  
-		break;
211  
-	case SDLK_UNDERSCORE:
212  
-		shifted = 1;
213  
-	case SDLK_MINUS:
214  
-		keysym->scancode = 12;
215  
-		break;
216  
-	case SDLK_PLUS:
217  
-		shifted = 1;
218  
-	case SDLK_EQUALS:
219  
-		keysym->scancode = 13;
220  
-		break;
221  
-	case SDLK_BACKSPACE:
222  
-		keysym->scancode = 14;
223  
-		break;
224  
-	case SDLK_TAB:
225  
-		keysym->scancode = 15;
226  
-		break;
227  
-	case SDLK_q:
228  
-		keysym->scancode = 16;
229  
-		break;
230  
-	case SDLK_w:
231  
-		keysym->scancode = 17;
232  
-		break;
233  
-	case SDLK_e:
234  
-		keysym->scancode = 18;
235  
-		break;
236  
-	case SDLK_r:
237  
-		keysym->scancode = 19;
238  
-		break;
239  
-	case SDLK_t:
240  
-		keysym->scancode = 20;
241  
-		break;
242  
-	case SDLK_y:
243  
-		keysym->scancode = 21;
244  
-		break;
245  
-	case SDLK_u:
246  
-		keysym->scancode = 22;
247  
-		break;
248  
-	case SDLK_i:
249  
-		keysym->scancode = 23;
250  
-		break;
251  
-	case SDLK_o:
252  
-		keysym->scancode = 24;
253  
-		break;
254  
-	case SDLK_p:
255  
-		keysym->scancode = 25;
256  
-		break;
257  
-	case SDLK_LEFTBRACKET:
258  
-		keysym->scancode = 26;
259  
-		break;
260  
-	case SDLK_RIGHTBRACKET:
261  
-		keysym->scancode = 27;
262  
-		break;
263  
-	case SDLK_RETURN:
264  
-		keysym->scancode = 28;
265  
-		break;
266  
-	case SDLK_a:
267  
-		keysym->scancode = 30;
268  
-		break;
269  
-	case SDLK_s:
270  
-		keysym->scancode = 31;
271  
-		break;
272  
-	case SDLK_d:
273  
-		keysym->scancode = 32;
274  
-		break;
275  
-	case SDLK_f:
276  
-		keysym->scancode = 33;
277  
-		break;
278  
-	case SDLK_g:
279  
-		keysym->scancode = 34;
280  
-		break;
281  
-	case SDLK_h:
282  
-		keysym->scancode = 35;
283  
-		break;
284  
-	case SDLK_j:
285  
-		keysym->scancode = 36;
286  
-		break;
287  
-	case SDLK_k:
288  
-		keysym->scancode = 37;
289  
-		break;
290  
-	case SDLK_l:
291  
-		keysym->scancode = 38;
292  
-		break;
293  
-	case SDLK_COLON:
294  
-		shifted = 1;
295  
-	case SDLK_SEMICOLON:
296  
-		keysym->scancode = 39;
297  
-		break;
298  
-	case SDLK_QUOTEDBL:
299  
-		shifted = 1;
300  
-	case SDLK_QUOTE:
301  
-		keysym->scancode = 40;
302  
-		break;
303  
-	case SDLK_PB_TILDE:
304  
-		shifted = 1;
305  
-	case SDLK_BACKQUOTE:
306  
-		keysym->scancode = 41;
307  
-		break;
308  
-	case SDLK_BACKSLASH:
309  
-		keysym->scancode = 43;
310  
-		break;
311  
-	case SDLK_z:
312  
-		keysym->scancode = 44;
313  
-		break;
314  
-	case SDLK_x:
315  
-		keysym->scancode = 45;
316  
-		break;
317  
-	case SDLK_c:
318  
-		keysym->scancode = 46;
319  
-		break;
320  
-	case SDLK_v:
321  
-		keysym->scancode = 47;
322  
-		break;
323  
-	case SDLK_b:
324  
-		keysym->scancode = 48;
325  
-		break;
326  
-	case SDLK_n:
327  
-		keysym->scancode = 49;
328  
-		break;
329  
-	case SDLK_m:
330  
-		keysym->scancode = 50;
331  
-		break;
332  
-	case SDLK_LESS:
333  
-		shifted = 1;
334  
-	case SDLK_COMMA:
335  
-		keysym->scancode = 51;
336  
-		break;
337  
-	case SDLK_GREATER:
338  
-		shifted = 1;
339  
-	case SDLK_PERIOD:
340  
-		keysym->scancode = 52;
341  
-		break;
342  
-	case SDLK_QUESTION:
343  
-		shifted = 1;
344  
-	case SDLK_SLASH:
345  
-		keysym->scancode = 53;
346  
-		break;
347  
-	case SDLK_SPACE:
348  
-		keysym->scancode = 57;
349  
-		break;
350  
-	}
351  
-
352  
-	switch (keysym->sym)
353  
-	{
354  
-	case SDLK_a:
355  
-		keysym->unicode = 'a';
356  
-		break;
357  
-	case SDLK_b:
358  
-		keysym->unicode = 'b';
359  
-		break;
360  
-	case SDLK_c:
361  
-		keysym->unicode = 'c';
362  
-		break;
363  
-	case SDLK_d:
364  
-		keysym->unicode = 'd';
365  
-		break;
366  
-	case SDLK_e:
367  
-		keysym->unicode = 'e';
368  
-		break;
369  
-	case SDLK_f:
370  
-		keysym->unicode = 'f';
371  
-		break;
372  
-	case SDLK_g:
373  
-		keysym->unicode = 'g';
374  
-		break;
375  
-	case SDLK_h:
376  
-		keysym->unicode = 'h';
377  
-		break;
378  
-	case SDLK_i:
379  
-		keysym->unicode = 'i';
380  
-		break;
381  
-	case SDLK_j:
382  
-		keysym->unicode = 'j';
383  
-		break;
384  
-	case SDLK_k:
385  
-		keysym->unicode = 'k';
386  
-		break;
387  
-	case SDLK_l:
388  
-		keysym->unicode = 'l';
389  
-		break;
390  
-	case SDLK_m:
391  
-		keysym->unicode = 'm';
392  
-		break;
393  
-	case SDLK_n:
394  
-		keysym->unicode = 'n';
395  
-		break;
396  
-	case SDLK_o:
397  
-		keysym->unicode = 'o';
398  
-		break;
399  
-	case SDLK_p:
400  
-		keysym->unicode = 'p';
401  
-		break;
402  
-	case SDLK_q:
403  
-		keysym->unicode = 'q';
404  
-		break;
405  
-	case SDLK_r:
406  
-		keysym->unicode = 'r';
407  
-		break;
408  
-	case SDLK_s:
409  
-		keysym->unicode = 's';
410  
-		break;
411  
-	case SDLK_t:
412  
-		keysym->unicode = 't';
413  
-		break;
414  
-	case SDLK_u:
415  
-		keysym->unicode = 'u';
416  
-		break;
417  
-	case SDLK_v:
418  
-		keysym->unicode = 'v';
419  
-		break;
420  
-	case SDLK_w:
421  
-		keysym->unicode = 'w';
422  
-		break;
423  
-	case SDLK_x:
424  
-		keysym->unicode = 'x';
425  
-		break;
426  
-	case SDLK_y:
427  
-		keysym->unicode = 'y';
428  
-		break;
429  
-	case SDLK_z:
430  
-		keysym->unicode = 'z';
431  
-		break;
432  
-	case SDLK_1:
433  
-		keysym->unicode = '1';
434  
-		break;
435  
-	case SDLK_2:
436  
-		keysym->unicode = '2';
437  
-		break;
438  
-	case SDLK_3:
439  
-		keysym->unicode = '3';
440  
-		break;
441  
-	case SDLK_4:
442  
-		keysym->unicode = '4';
443  
-		break;
444  
-	case SDLK_5:
445  
-		keysym->unicode = '5';
446  
-		break;
447  
-	case SDLK_6:
448  
-		keysym->unicode = '6';
449  
-		break;
450  
-	case SDLK_7:
451  
-		keysym->unicode = '7';
452  
-		break;
453  
-	case SDLK_8:
454  
-		keysym->unicode = '8';
455  
-		break;
456  
-	case SDLK_9:
457  
-		keysym->unicode = '9';
458  
-		break;
459  
-	case SDLK_0:
460  
-		keysym->unicode = '0';
461  
-		break;
462  
-	case SDLK_COMMA:
463  
-		keysym->unicode = ',';
464  
-		break;
465  
-	case SDLK_PERIOD:
466  
-		keysym->unicode = '.';
467  
-		break;
468  
-	case SDLK_COLON:
469  
-		keysym->unicode = ':';
470  
-		break;
471  
-	case SDLK_SLASH:
472  
-		keysym->unicode = '/';
473  
-		break;
474  
-	case SDLK_BACKSPACE:
475  
-		keysym->unicode = SDLK_BACKSPACE;
476  
-		break;
477  
-	case SDLK_DELETE:
478  
-		keysym->unicode = SDLK_DELETE;
479  
-		break;
480  
-	case SDLK_ESCAPE:
481  
-		keysym->unicode = SDLK_ESCAPE;
482  
-		break;
483  
-	case SDLK_RETURN:
484  
-		keysym->unicode = SDLK_RETURN;
485  
-		break;
486  
-	case SDLK_DOLLAR:
487  
-		keysym->unicode = '$';
488  
-		break;
489  
-	case SDLK_SPACE:
490  
-		keysym->unicode = ' ';
491  
-		break;
492  
-	case SDLK_MINUS:
493  
-		keysym->unicode = '-';
494  
-		break;
495  
-	case SDLK_EXCLAIM:
496  
-		keysym->unicode = '!';
497  
-		break;
498  
-	case SDLK_QUESTION:
499  
-		keysym->unicode = '?';
500  
-		break;
501  
-	case SDLK_HASH:
502  
-		keysym->unicode = '#';
503  
-		break;
504  
-	case SDLK_AT:
505  
-		keysym->unicode = '@';
506  
-		break;
507  
-	case SDLK_ASTERISK:
508  
-		keysym->unicode = '*';
509  
-		break;
510  
-	case SDLK_LEFTPAREN:
511  
-		keysym->unicode = '(';
512  
-		break;
513  
-	case SDLK_RIGHTPAREN:
514  
-		keysym->unicode = ')';
515  
-		break;
516  
-	case SDLK_EQUALS:
517  
-		keysym->unicode = '=';
518  
-		break;
519  
-	case SDLK_PLUS:
520  
-		keysym->unicode = '+';
521  
-		break;
522  
-	case SDLK_LESS:
523  
-		keysym->unicode = '<';
524  
-		break;
525  
-	case SDLK_GREATER:
526  
-		keysym->unicode = '>';
527  
-		break;
528  
-	case SDLK_SEMICOLON:
529  
-		keysym->unicode = ';';
530  
-		break;
531  
-	case SDLK_QUOTEDBL:
532  
-		keysym->unicode = '"';
533  
-		break;
534  
-	case SDLK_QUOTE:
535  
-		keysym->unicode = '\'';
536  
-		break;
537  
-	}
538  
-	keysym->mod = KMOD_NONE;
539  
-	return shifted;
540  
-}
541  
-
542  
-static void handleKeyboardEvent(screen_event_t event)
543  
-{
544  
-	static const int KEYBOARD_TYPE_MASK = 0x20;
545  
-    int sym = 0;
546  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SYM, &sym);
547  
-    int modifiers = 0;
548  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_MODIFIERS, &modifiers);
549  
-    int flags = 0;
550  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_FLAGS, &flags);
551  
-    int scan = 0;
552  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_SCAN, &scan);
553  
-    int cap = 0;
554  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_KEY_CAP, &cap);
555  
-
556  
-	int shifted = 0;
557  
-	SDL_keysym keysym;
558  
-    if (flags & KEYBOARD_TYPE_MASK) {
559  
-    	if (!TranslateBluetoothKeyboard(sym, modifiers, flags, scan, cap, &keysym))
560  
-    	{
561  
-    		return; // No translation
562  
-    	}
563  
-    } else {
564  
-		shifted = TranslateVKB(sym, modifiers, flags, scan, cap, &keysym);
565  
-    }
566  
-
567  
-    if (shifted) {
568  
-		SDL_keysym temp;
569  
-		temp.scancode = 42;
570  
-		temp.sym = SDLK_LSHIFT;
571  
-		SDL_PrivateKeyboard(SDL_PRESSED, &temp);
572  
-    }
573  
-
574  
-    SDL_PrivateKeyboard((flags & 0x1)?SDL_PRESSED:SDL_RELEASED, &keysym);
575  
-
576  
-    if (shifted) {
577  
-		SDL_keysym temp;
578  
-		temp.scancode = 42;
579  
-		temp.sym = SDLK_LSHIFT;
580  
-		SDL_PrivateKeyboard(SDL_RELEASED, &temp);
581  
-    }
582  
-}
583  
-
584  
-static void handleMtouchEvent(screen_event_t event, screen_window_t window, int type)
585  
-{
586  
-#ifdef TOUCHPAD_SIMULATE
587  
-
588  
-	unsigned buttonWidth = 200;
589  
-	unsigned buttonHeight = 300;
590  
-
591  
-	int contactId;
592  
-	int pos[2];
593  
-	int screenPos[2];
594  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contactId);
595  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos);
596  
-	screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, screenPos);
597  
-
598  
-	int mouseX, mouseY;
599  
-	SDL_GetMouseState(&mouseX, &mouseY);
600  
-
601  
-	if (state.leftId == contactId) {
602  
-		if (type == SCREEN_EVENT_MTOUCH_RELEASE) {
603  
-			state.leftId = -1;
604  
-			SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT, mouseX, mouseY);
605  
-		}
606  
-		return;
607  
-	}
608  
-	if (state.rightId == contactId) {
609  
-		if (type == SCREEN_EVENT_MTOUCH_RELEASE) {
610  
-			state.rightId = -1;
611  
-			SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_RIGHT, mouseX, mouseY);
612  
-		}
613  
-		return;
614  
-	}
615  
-
616  
-	if (screenPos[0] < buttonWidth && contactId != state.moveId) {
617  
-		// Special handling for buttons
618  
-
619  
-		if (screenPos[1] < buttonHeight) {
620  
-			// Left button
621  
-			if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
622  
-				if (state.leftId == -1 && contactId != state.rightId) {
623  
-					SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT, mouseX, mouseY);
624  
-					state.leftId = contactId;
625  
-				}
626  
-			}
627  
-		} else {
628  
-			// Right button
629  
-			if (type == SCREEN_EVENT_MTOUCH_TOUCH) {
630  
-				if (state.rightId == -1 && contactId != state.leftId) {
631  
-					SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_RIGHT, mouseX, mouseY);
632  
-					state.rightId = contactId;
633  
-				}
634  
-			}
635  
-		}
636  
-	} else {
637  
-		// Can only generate motion events
638  
-		int doMove = 0;
639  
-		switch (type) {
640  
-		case SCREEN_EVENT_MTOUCH_TOUCH:
641  
-			if (state.moveId == -1 || state.moveId == contactId) {
642  
-				state.moveId = contactId;
643  
-			}
644  
-			break;
645  
-		case SCREEN_EVENT_MTOUCH_RELEASE:
646  
-			if (state.moveId == contactId) {
647  
-				doMove = 1;
648  
-				state.moveId = -1;
649  
-			}
650  
-			break;
651  
-		case SCREEN_EVENT_MTOUCH_MOVE:
652  
-			if (state.moveId == contactId) {
653  
-				doMove = 1;
654  
-			}
655  
-			break;
656  
-		}
657  
-
658  
-		if (doMove) {
659  
-			int mask = 0;
660  
-			if (state.leftDown)
661  
-				mask |= SDL_BUTTON_LEFT;
662  
-			if (state.rightDown)
663  
-				mask |= SDL_BUTTON_RIGHT;
664  
-			state.mask = mask;
665  
-			state.pending[0] += pos[0] - state.oldPos[0];
666  
-			state.pending[1] += pos[1] - state.oldPos[1];
667  
-			//SDL_PrivateMouseMotion(mask, 1, pos[0] - state.oldPos[0], pos[1] - state.oldPos[1]);
668  
-		}
669  
-		state.oldPos[0] = pos[0];
670  
-		state.oldPos[1] = pos[1];
671  
-	}
672  
-#else
673  
-    int contactId;
674  
-    int pos[2];
675  
-    int screenPos[2];
676  
-    int orientation;
677  
-    int pressure;
678  
-    long long timestamp;
679  
-    int sequenceId;
680  
-
681  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ID, (int*)&contactId);
682  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_SOURCE_POSITION, pos);
683  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_POSITION, screenPos);
684  
-    screen_get_event_property_iv(event, SCREEN_PROPERTY_TOUCH_ORIENTATION, (int*)&orientation);
685