Skip to content

Latest commit

 

History

History
382 lines (327 loc) · 13.6 KB

SDL_nxevents.c

File metadata and controls

382 lines (327 loc) · 13.6 KB
 
1
2
/*
SDL - Simple DirectMedia Layer
Dec 31, 2011
Dec 31, 2011
3
Copyright (C) 1997-2012 Sam Lantinga
4
Copyright (C) 2001 Hsieh-Fu Tsai
Aug 25, 2002
Aug 25, 2002
5
Copyright (C) 2002 Greg Haerr <greg@censoft.com>
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Library General Public
License as published by the Free Software Foundation; either
version 2 of the License, or (at your option) any later version.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Library General Public License for more details.
You should have received a copy of the GNU Library General Public
License along with this library; if not, write to the Free
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
Sam Lantinga
Dec 14, 2001
Dec 14, 2001
22
slouken@libsdl.org
23
24
25
26
Hsieh-Fu Tsai
clare@setabox.com
*/
Feb 21, 2006
Feb 21, 2006
27
#include "SDL_config.h"
28
29
#include "SDL_keysym.h"
Feb 16, 2006
Feb 16, 2006
30
#include "../../events/SDL_events_c.h"
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include "SDL_nxevents_c.h"
#include "SDL_nximage_c.h"
// The translation tables from a nanox keysym to a SDL keysym
static SDLKey NX_NONASCII_keymap [MWKEY_LAST + 1] ;
void NX_InitOSKeymap (_THIS)
{
int i ;
Dprintf ("enter NX_InitOSKeymap\n") ;
// Map the nanox scancodes to SDL keysyms
Feb 19, 2006
Feb 19, 2006
45
for (i = 0; i < SDL_arraysize (NX_NONASCII_keymap); ++ i)
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
NX_NONASCII_keymap [i] = SDLK_UNKNOWN ;
NX_NONASCII_keymap [MWKEY_LEFT & 0xFF] = SDLK_LEFT ;
NX_NONASCII_keymap [MWKEY_RIGHT & 0xFF] = SDLK_RIGHT ;
NX_NONASCII_keymap [MWKEY_UP & 0xFF] = SDLK_UP ;
NX_NONASCII_keymap [MWKEY_DOWN & 0xFF] = SDLK_DOWN ;
NX_NONASCII_keymap [MWKEY_INSERT & 0xFF] = SDLK_INSERT ;
NX_NONASCII_keymap [MWKEY_DELETE & 0xFF] = SDLK_DELETE ;
NX_NONASCII_keymap [MWKEY_HOME & 0xFF] = SDLK_HOME ;
NX_NONASCII_keymap [MWKEY_END & 0xFF] = SDLK_END ;
NX_NONASCII_keymap [MWKEY_PAGEUP & 0xFF] = SDLK_PAGEUP ;
NX_NONASCII_keymap [MWKEY_PAGEDOWN & 0xFF] = SDLK_PAGEDOWN ;
NX_NONASCII_keymap [MWKEY_KP0 & 0xFF] = SDLK_KP0 ;
NX_NONASCII_keymap [MWKEY_KP1 & 0xFF] = SDLK_KP1 ;
NX_NONASCII_keymap [MWKEY_KP2 & 0xFF] = SDLK_KP2 ;
NX_NONASCII_keymap [MWKEY_KP3 & 0xFF] = SDLK_KP3 ;
NX_NONASCII_keymap [MWKEY_KP4 & 0xFF] = SDLK_KP4 ;
NX_NONASCII_keymap [MWKEY_KP5 & 0xFF] = SDLK_KP5 ;
NX_NONASCII_keymap [MWKEY_KP6 & 0xFF] = SDLK_KP6 ;
NX_NONASCII_keymap [MWKEY_KP7 & 0xFF] = SDLK_KP7 ;
NX_NONASCII_keymap [MWKEY_KP8 & 0xFF] = SDLK_KP8 ;
NX_NONASCII_keymap [MWKEY_KP9 & 0xFF] = SDLK_KP9 ;
NX_NONASCII_keymap [MWKEY_KP_PERIOD & 0xFF] = SDLK_KP_PERIOD ;
NX_NONASCII_keymap [MWKEY_KP_DIVIDE & 0xFF] = SDLK_KP_DIVIDE ;
NX_NONASCII_keymap [MWKEY_KP_MULTIPLY & 0xFF] = SDLK_KP_MULTIPLY ;
NX_NONASCII_keymap [MWKEY_KP_MINUS & 0xFF] = SDLK_KP_MINUS ;
NX_NONASCII_keymap [MWKEY_KP_PLUS & 0xFF] = SDLK_KP_PLUS ;
NX_NONASCII_keymap [MWKEY_KP_ENTER & 0xFF] = SDLK_KP_ENTER ;
NX_NONASCII_keymap [MWKEY_KP_EQUALS & 0xFF] = SDLK_KP_EQUALS ;
NX_NONASCII_keymap [MWKEY_F1 & 0xFF] = SDLK_F1 ;
NX_NONASCII_keymap [MWKEY_F2 & 0xFF] = SDLK_F2 ;
NX_NONASCII_keymap [MWKEY_F3 & 0xFF] = SDLK_F3 ;
NX_NONASCII_keymap [MWKEY_F4 & 0xFF] = SDLK_F4 ;
NX_NONASCII_keymap [MWKEY_F5 & 0xFF] = SDLK_F5 ;
NX_NONASCII_keymap [MWKEY_F6 & 0xFF] = SDLK_F6 ;
NX_NONASCII_keymap [MWKEY_F7 & 0xFF] = SDLK_F7 ;
NX_NONASCII_keymap [MWKEY_F8 & 0xFF] = SDLK_F8 ;
NX_NONASCII_keymap [MWKEY_F9 & 0xFF] = SDLK_F9 ;
NX_NONASCII_keymap [MWKEY_F10 & 0xFF] = SDLK_F10 ;
NX_NONASCII_keymap [MWKEY_F11 & 0xFF] = SDLK_F11 ;
NX_NONASCII_keymap [MWKEY_F12 & 0xFF] = SDLK_F12 ;
NX_NONASCII_keymap [MWKEY_NUMLOCK & 0xFF] = SDLK_NUMLOCK ;
NX_NONASCII_keymap [MWKEY_CAPSLOCK & 0xFF] = SDLK_CAPSLOCK ;
NX_NONASCII_keymap [MWKEY_SCROLLOCK & 0xFF] = SDLK_SCROLLOCK ;
NX_NONASCII_keymap [MWKEY_LSHIFT & 0xFF] = SDLK_LSHIFT ;
NX_NONASCII_keymap [MWKEY_RSHIFT & 0xFF] = SDLK_RSHIFT ;
NX_NONASCII_keymap [MWKEY_LCTRL & 0xFF] = SDLK_LCTRL ;
NX_NONASCII_keymap [MWKEY_RCTRL & 0xFF] = SDLK_RCTRL ;
NX_NONASCII_keymap [MWKEY_LALT & 0xFF] = SDLK_LALT ;
NX_NONASCII_keymap [MWKEY_RALT & 0xFF] = SDLK_RALT ;
NX_NONASCII_keymap [MWKEY_LMETA & 0xFF] = SDLK_LMETA ;
NX_NONASCII_keymap [MWKEY_RMETA & 0xFF] = SDLK_RMETA ;
NX_NONASCII_keymap [MWKEY_ALTGR & 0xFF] = SDLK_MODE ;
NX_NONASCII_keymap [MWKEY_PRINT & 0xFF] = SDLK_PRINT ;
NX_NONASCII_keymap [MWKEY_SYSREQ & 0xFF] = SDLK_SYSREQ ;
NX_NONASCII_keymap [MWKEY_PAUSE & 0xFF] = SDLK_PAUSE ;
NX_NONASCII_keymap [MWKEY_BREAK & 0xFF] = SDLK_BREAK ;
NX_NONASCII_keymap [MWKEY_MENU & 0xFF] = SDLK_MENU ;
Dprintf ("leave NX_InitOSKeymap\n") ;
}
SDL_keysym * NX_TranslateKey (GR_EVENT_KEYSTROKE * keystroke, SDL_keysym * keysym)
{
GR_KEY ch = keystroke -> ch ;
Dprintf ("enter NX_TranslateKey\n") ;
keysym -> scancode = keystroke -> scancode ;
keysym -> sym = SDLK_UNKNOWN ;
if (ch & MWKEY_NONASCII_MASK) {
keysym -> sym = NX_NONASCII_keymap [ch & 0xFF] ;
} else {
keysym -> sym = ch & 0x7F ;
}
keysym -> mod = KMOD_NONE ;
#if 1 // Retrieve more mode information
{
GR_KEYMOD mod = keystroke -> modifiers ;
if (mod & MWKMOD_LSHIFT)
keysym -> mod |= KMOD_LSHIFT ;
if (mod & MWKMOD_RSHIFT)
keysym -> mod |= KMOD_RSHIFT ;
if (mod & MWKMOD_LCTRL)
keysym -> mod |= KMOD_LCTRL ;
if (mod & MWKMOD_RCTRL)
keysym -> mod |= KMOD_RCTRL ;
if (mod & MWKMOD_LALT)
keysym -> mod |= KMOD_LALT ;
if (mod & MWKMOD_RALT)
keysym -> mod |= KMOD_RALT ;
if (mod & MWKMOD_LMETA)
keysym -> mod |= KMOD_LMETA ;
if (mod & MWKMOD_RMETA)
keysym -> mod |= KMOD_RMETA ;
if (mod & MWKMOD_NUM)
keysym -> mod |= KMOD_NUM ;
if (mod & MWKMOD_CAPS)
keysym -> mod |= KMOD_CAPS ;
if (mod & MWKMOD_ALTGR)
keysym -> mod |= KMOD_MODE ;
}
#endif
keysym -> unicode = ch ;
Dprintf ("leave NX_TranslateKey\n") ;
return keysym ;
}
static int check_boundary (_THIS, int x, int y)
{
if (x < OffsetX || y < OffsetY || x > OffsetX + this -> screen -> w ||
y > OffsetY + this -> screen -> h)
return 0 ;
return 1 ;
}
void NX_PumpEvents (_THIS)
{
GR_EVENT event ;
static GR_BUTTON last_button_down = 0 ;
GrCheckNextEvent (& event) ;
while (event.type != GR_EVENT_TYPE_NONE) {
// dispatch event
switch (event.type) {
case GR_EVENT_TYPE_MOUSE_ENTER :
{
Dprintf ("mouse enter\n") ;
SDL_PrivateAppActive (1, SDL_APPMOUSEFOCUS) ;
break ;
}
case GR_EVENT_TYPE_MOUSE_EXIT :
{
Dprintf ("mouse exit\n") ;
SDL_PrivateAppActive (0, SDL_APPMOUSEFOCUS) ;
break ;
}
case GR_EVENT_TYPE_FOCUS_IN :
{
Dprintf ("focus in\n") ;
SDL_PrivateAppActive (1, SDL_APPINPUTFOCUS) ;
break ;
}
case GR_EVENT_TYPE_FOCUS_OUT :
{
Dprintf ("focus out\n") ;
SDL_PrivateAppActive (0, SDL_APPINPUTFOCUS) ;
break ;
}
case GR_EVENT_TYPE_MOUSE_MOTION :
{
Dprintf ("mouse motion\n") ;
if (SDL_VideoSurface) {
if (currently_fullscreen) {
if (check_boundary (this, event.button.x, event.button.y)) {
SDL_PrivateMouseMotion (0, 0, event.button.x - OffsetX,
event.button.y - OffsetY) ;
}
} else {
SDL_PrivateMouseMotion (0, 0, event.button.x, event.button.y) ;
}
}
break ;
}
case GR_EVENT_TYPE_BUTTON_DOWN :
{
int button = event.button.buttons ;
Dprintf ("button down\n") ;
switch (button) {
case MWBUTTON_L :
button = 1 ;
break ;
case MWBUTTON_M :
button = 2 ;
break ;
case MWBUTTON_R :
button = 3 ;
break ;
default :
button = 0 ;
}
last_button_down = button ;
if (currently_fullscreen) {
if (check_boundary (this, event.button.x, event.button.y)) {
SDL_PrivateMouseButton (SDL_PRESSED, button,
event.button.x - OffsetX, event.button.y - OffsetY) ;
}
} else {
SDL_PrivateMouseButton (SDL_PRESSED, button,
event.button.x, event.button.y) ;
}
break ;
}
// do not konw which button is released
case GR_EVENT_TYPE_BUTTON_UP :
{
Dprintf ("button up\n") ;
if (currently_fullscreen) {
if (check_boundary (this, event.button.x, event.button.y)) {
SDL_PrivateMouseButton (SDL_RELEASED, last_button_down,
event.button.x - OffsetX, event.button.y - OffsetY) ;
}
} else {
SDL_PrivateMouseButton (SDL_RELEASED, last_button_down,
event.button.x, event.button.y) ;
}
last_button_down = 0 ;
break ;
}
case GR_EVENT_TYPE_KEY_DOWN :
{
SDL_keysym keysym ;
Dprintf ("key down\n") ;
SDL_PrivateKeyboard (SDL_PRESSED,
NX_TranslateKey (& event.keystroke, & keysym)) ;
break ;
}
case GR_EVENT_TYPE_KEY_UP :
{
SDL_keysym keysym ;
Dprintf ("key up\n") ;
SDL_PrivateKeyboard (SDL_RELEASED,
NX_TranslateKey (& event.keystroke, & keysym)) ;
break ;
}
case GR_EVENT_TYPE_CLOSE_REQ :
{
Dprintf ("close require\n") ;
SDL_PrivateQuit () ;
break ;
}
case GR_EVENT_TYPE_EXPOSURE :
{
Dprintf ("event_type_exposure\n") ;
if (SDL_VideoSurface) {
NX_RefreshDisplay (this) ;//, & event.exposure) ;
}
break ;
}
case GR_EVENT_TYPE_UPDATE :
{
switch (event.update.utype) {
case GR_UPDATE_MAP :
{
Dprintf ("GR_UPDATE_MAP\n") ;
// If we're not active, make ourselves active
if (!(SDL_GetAppState () & SDL_APPACTIVE)) {
// Send an internal activate event
SDL_PrivateAppActive (1, SDL_APPACTIVE) ;
}
if (SDL_VideoSurface) {
NX_RefreshDisplay (this) ;
}
break ;
}
case GR_UPDATE_UNMAP :
case GR_UPDATE_UNMAPTEMP :
{
Dprintf ("GR_UPDATE_UNMAP or GR_UPDATE_UNMAPTEMP\n") ;
// If we're active, make ourselves inactive
if (SDL_GetAppState () & SDL_APPACTIVE) {
// Send an internal deactivate event
SDL_PrivateAppActive (0, SDL_APPACTIVE | SDL_APPINPUTFOCUS) ;
}
break ;
}
case GR_UPDATE_SIZE :
{
Dprintf ("GR_UPDATE_SIZE\n") ;
SDL_PrivateResize (event.update.width, event.update.height) ;
break ;
}
Aug 25, 2002
Aug 25, 2002
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
case GR_UPDATE_MOVE :
case GR_UPDATE_REPARENT :
{
Dprintf ("GR_UPDATE_MOVE or GR_UPDATE_REPARENT\n") ;
#ifdef ENABLE_NANOX_DIRECT_FB
if (Clientfb) {
/* Get current window position and fb pointer*/
if (currently_fullscreen)
GrGetWindowFBInfo(FSwindow, &fbinfo);
else
GrGetWindowFBInfo(SDL_Window, &fbinfo);
}
#endif
break ;
}
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
default :
Dprintf ("unknown GR_EVENT_TYPE_UPDATE\n") ;
break ;
}
break ;
}
default :
{
Dprintf ("pump event default\n") ;
}
}
GrCheckNextEvent (& event) ;
}
}