2
SDL - Simple DirectMedia Layer
3
Copyright (C) 1997-2006 Sam Lantinga
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.
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.
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
22
#include "SDL_config.h"
24
/* Handle the event stream, converting Amiga events into SDL events */
27
#include "SDL_syswm.h"
28
#include "../SDL_sysvideo.h"
29
#include "../../events/SDL_sysevents.h"
30
#include "../../events/SDL_events_c.h"
31
#include "SDL_cgxvideo.h"
32
#include "SDL_cgxmodes_c.h"
33
#include "SDL_cgximage_c.h"
34
#include "SDL_cgxwm_c.h"
35
#include "SDL_amigaevents_c.h"
38
/* The translation tables from an Amiga keysym to a SDL keysym */
39
static SDLKey MISC_keymap[256];
40
SDL_keysym *amiga_TranslateKey(int code, SDL_keysym *keysym);
41
struct IOStdReq *ConReq=NULL;
42
struct MsgPort *ConPort=NULL;
44
/* Note: The X server buffers and accumulates mouse motion events, so
45
the motion event generated by the warp may not appear exactly as we
46
expect it to. We work around this (and improve performance) by only
47
warping the pointer when it reaches the edge, and then wait for it.
49
#define MOUSE_FUDGE_FACTOR 8
53
static inline int amiga_WarpedMotion(_THIS, struct IntuiMessage *m)
59
w = SDL_VideoSurface->w;
60
h = SDL_VideoSurface->h;
61
deltax = xevent->xmotion.x - mouse_last.x;
62
deltay = xevent->xmotion.y - mouse_last.y;
64
printf("Warped mouse motion: %d,%d\n", deltax, deltay);
66
mouse_last.x = xevent->xmotion.x;
67
mouse_last.y = xevent->xmotion.y;
68
posted = SDL_PrivateMouseMotion(0, 1, deltax, deltay);
70
if ( (xevent->xmotion.x < MOUSE_FUDGE_FACTOR) ||
71
(xevent->xmotion.x > (w-MOUSE_FUDGE_FACTOR)) ||
72
(xevent->xmotion.y < MOUSE_FUDGE_FACTOR) ||
73
(xevent->xmotion.y > (h-MOUSE_FUDGE_FACTOR)) ) {
74
/* Get the events that have accumulated */
75
while ( XCheckTypedEvent(SDL_Display, MotionNotify, xevent) ) {
76
deltax = xevent->xmotion.x - mouse_last.x;
77
deltay = xevent->xmotion.y - mouse_last.y;
79
printf("Extra mouse motion: %d,%d\n", deltax, deltay);
81
mouse_last.x = xevent->xmotion.x;
82
mouse_last.y = xevent->xmotion.y;
83
posted += SDL_PrivateMouseMotion(0, 1, deltax, deltay);
87
XWarpPointer(SDL_Display, None, SDL_Window, 0, 0, 0, 0,
88
mouse_last.x, mouse_last.y);
89
for ( i=0; i<10; ++i ) {
90
XMaskEvent(SDL_Display, PointerMotionMask, xevent);
91
if ( (xevent->xmotion.x >
92
(mouse_last.x-MOUSE_FUDGE_FACTOR)) &&
94
(mouse_last.x+MOUSE_FUDGE_FACTOR)) &&
96
(mouse_last.y-MOUSE_FUDGE_FACTOR)) &&
98
(mouse_last.y+MOUSE_FUDGE_FACTOR)) ) {
102
printf("Lost mouse motion: %d,%d\n", xevent->xmotion.x, xevent->xmotion.y);
107
printf("Warning: didn't detect mouse warp motion\n");
116
static int amiga_GetButton(int code)
121
return SDL_BUTTON_MIDDLE;
123
return SDL_BUTTON_RIGHT;
125
return SDL_BUTTON_LEFT;
129
static int amiga_DispatchEvent(_THIS,struct IntuiMessage *msg)
131
int class=msg->Class,code=msg->Code;
136
/* Gaining mouse coverage? */
137
case IDCMP_ACTIVEWINDOW:
138
posted = SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
141
/* Losing mouse coverage? */
142
case IDCMP_INACTIVEWINDOW:
143
posted = SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
146
/* Gaining input focus? */
147
case IDCMP_ACTIVEWINDOW:
148
posted = SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
150
/* Queue entry into fullscreen mode */
151
switch_waiting = 0x01 | SDL_FULLSCREEN;
152
switch_time = SDL_GetTicks() + 1500;
155
/* Losing input focus? */
156
case IDCMP_INACTIVEWINDOW:
157
posted = SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
159
/* Queue leaving fullscreen mode */
160
switch_waiting = 0x01;
161
switch_time = SDL_GetTicks() + 200;
165
case IDCMP_MOUSEMOVE:
166
if ( SDL_VideoSurface ) {
167
posted = SDL_PrivateMouseMotion(0, 0,
168
msg->MouseX-SDL_Window->BorderLeft,
169
msg->MouseY-SDL_Window->BorderTop);
173
/* Mouse button press? */
174
case IDCMP_MOUSEBUTTONS:
176
if(!(code&IECODE_UP_PREFIX))
178
posted = SDL_PrivateMouseButton(SDL_PRESSED,
179
amiga_GetButton(code), 0, 0);
181
/* Mouse button release? */
184
code&=~IECODE_UP_PREFIX;
185
posted = SDL_PrivateMouseButton(SDL_RELEASED,
186
amiga_GetButton(code), 0, 0);
194
if( !(code&IECODE_UP_PREFIX) )
197
posted = SDL_PrivateKeyboard(SDL_PRESSED,
198
amiga_TranslateKey(code, &keysym));
205
code&=~IECODE_UP_PREFIX;
207
/* Check to see if this is a repeated key */
208
/* if ( ! X11_KeyRepeat(SDL_Display, &xevent) ) */
210
posted = SDL_PrivateKeyboard(SDL_RELEASED,
211
amiga_TranslateKey(code, &keysym));
214
/* Have we been iconified? */
218
printf("UnmapNotify!\n");
220
posted=SDL_PrivateAppActive(0, SDL_APPACTIVE|SDL_APPINPUTFOCUS);
224
/* Have we been restored? */
228
printf("MapNotify!\n");
231
posted = SDL_PrivateAppActive(1, SDL_APPACTIVE);
233
if ( SDL_VideoSurface &&
234
(SDL_VideoSurface->flags & SDL_FULLSCREEN) )
236
CGX_EnterFullScreen(this);
238
X11_GrabInputNoLock(this, this->input_grab);
240
if ( SDL_VideoSurface ) {
241
CGX_RefreshDisplay(this);
246
if ( SDL_VideoSurface && (xevent.xexpose.count == 0) ) {
247
CGX_RefreshDisplay(this);
252
/* Have we been resized? */
254
SDL_PrivateResize(SDL_Window->Width-SDL_Window->BorderLeft-SDL_Window->BorderRight,
255
SDL_Window->Height-SDL_Window->BorderTop-SDL_Window->BorderBottom);
259
/* Have we been requested to quit? */
260
case IDCMP_CLOSEWINDOW:
261
posted = SDL_PrivateQuit();
264
/* Do we need to refresh ourselves? */
267
/* Only post the event if we're watching for it */
268
if ( SDL_ProcessEvents[SDL_SYSWMEVENT] == SDL_ENABLE ) {
271
SDL_VERSION(&wmmsg.version);
273
wmmsg.subsystem = SDL_SYSWM_CGX;
274
wmmsg.event.xevent = xevent;
276
posted = SDL_PrivateSysWMEvent(&wmmsg);
281
ReplyMsg((struct Message *)msg);
287
void amiga_PumpEvents(_THIS)
290
struct IntuiMessage *m;
292
/* Keep processing pending events */
294
while ( m=(struct IntuiMessage *)GetMsg(SDL_Window->UserPort) ) {
295
amiga_DispatchEvent(this,m);
300
void amiga_InitKeymap(void)
304
/* Map the miscellaneous keys */
305
for ( i=0; i<SDL_arraysize(MISC_keymap); ++i )
306
MISC_keymap[i] = SDLK_UNKNOWN;
308
/* These X keysyms have 0xFF as the high byte */
309
MISC_keymap[65] = SDLK_BACKSPACE;
310
MISC_keymap[66] = SDLK_TAB;
311
MISC_keymap[70] = SDLK_CLEAR;
312
MISC_keymap[70] = SDLK_DELETE;
313
MISC_keymap[68] = SDLK_RETURN;
314
// MISC_keymap[XK_Pause&0xFF] = SDLK_PAUSE;
315
MISC_keymap[69] = SDLK_ESCAPE;
316
MISC_keymap[70] = SDLK_DELETE;
362
MISC_keymap[15] = SDLK_KP0; /* Keypad 0-9 */
363
MISC_keymap[29] = SDLK_KP1;
364
MISC_keymap[30] = SDLK_KP2;
365
MISC_keymap[31] = SDLK_KP3;
366
MISC_keymap[45] = SDLK_KP4;
367
MISC_keymap[46] = SDLK_KP5;
368
MISC_keymap[47] = SDLK_KP6;
369
MISC_keymap[61] = SDLK_KP7;
370
MISC_keymap[62] = SDLK_KP8;
371
MISC_keymap[63] = SDLK_KP9;
372
MISC_keymap[60] = SDLK_KP_PERIOD;
373
MISC_keymap[92] = SDLK_KP_DIVIDE;
374
MISC_keymap[93] = SDLK_KP_MULTIPLY;
375
MISC_keymap[74] = SDLK_KP_MINUS;
376
MISC_keymap[94] = SDLK_KP_PLUS;
377
MISC_keymap[67] = SDLK_KP_ENTER;
378
// MISC_keymap[XK_KP_Equal&0xFF] = SDLK_KP_EQUALS;
380
MISC_keymap[76] = SDLK_UP;
381
MISC_keymap[77] = SDLK_DOWN;
382
MISC_keymap[78] = SDLK_RIGHT;
383
MISC_keymap[79] = SDLK_LEFT;
385
MISC_keymap[XK_Insert&0xFF] = SDLK_INSERT;
386
MISC_keymap[XK_Home&0xFF] = SDLK_HOME;
387
MISC_keymap[XK_End&0xFF] = SDLK_END;
389
// Mappati sulle parentesi del taastierino
390
MISC_keymap[90] = SDLK_PAGEUP;
391
MISC_keymap[91] = SDLK_PAGEDOWN;
393
MISC_keymap[80] = SDLK_F1;
394
MISC_keymap[81] = SDLK_F2;
395
MISC_keymap[82] = SDLK_F3;
396
MISC_keymap[83] = SDLK_F4;
397
MISC_keymap[84] = SDLK_F5;
398
MISC_keymap[85] = SDLK_F6;
399
MISC_keymap[86] = SDLK_F7;
400
MISC_keymap[87] = SDLK_F8;
401
MISC_keymap[88] = SDLK_F9;
402
MISC_keymap[89] = SDLK_F10;
403
// MISC_keymap[XK_F11&0xFF] = SDLK_F11;
404
// MISC_keymap[XK_F12&0xFF] = SDLK_F12;
405
// MISC_keymap[XK_F13&0xFF] = SDLK_F13;
406
// MISC_keymap[XK_F14&0xFF] = SDLK_F14;
407
// MISC_keymap[XK_F15&0xFF] = SDLK_F15;
409
// MISC_keymap[XK_Num_Lock&0xFF] = SDLK_NUMLOCK;
410
MISC_keymap[98] = SDLK_CAPSLOCK;
411
// MISC_keymap[XK_Scroll_Lock&0xFF] = SDLK_SCROLLOCK;
412
MISC_keymap[97] = SDLK_RSHIFT;
413
MISC_keymap[96] = SDLK_LSHIFT;
414
MISC_keymap[99] = SDLK_LCTRL;
415
MISC_keymap[99] = SDLK_LCTRL;
416
MISC_keymap[101] = SDLK_RALT;
417
MISC_keymap[100] = SDLK_LALT;
418
// MISC_keymap[XK_Meta_R&0xFF] = SDLK_RMETA;
419
// MISC_keymap[XK_Meta_L&0xFF] = SDLK_LMETA;
420
MISC_keymap[103] = SDLK_LSUPER; /* Left "Windows" */
421
MISC_keymap[102] = SDLK_RSUPER; /* Right "Windows */
423
MISC_keymap[95] = SDLK_HELP;
426
SDL_keysym *amiga_TranslateKey(int code, SDL_keysym *keysym)
429
static struct Library *KeymapBase=NULL; /* Linking failed in WOS version if ConsoleDevice was used */
431
static struct Library *ConsoleDevice=NULL;
434
/* Get the raw keyboard scancode */
435
keysym->scancode = code;
436
keysym->sym = MISC_keymap[code];
439
fprintf(stderr, "Translating key 0x%.4x (%d)\n", xsym, xkey->keycode);
441
/* Get the translated SDL virtual keysym */
442
if ( keysym->sym==SDLK_UNKNOWN )
451
KeymapBase=OpenLibrary("keymap.library", 0L);
453
if(ConPort=CreateMsgPort())
455
if(ConReq=CreateIORequest(ConPort,sizeof(struct IOStdReq)))
457
if(!OpenDevice("console.device",-1,(struct IORequest *)ConReq,0))
458
ConsoleDevice=(struct Library *)ConReq->io_Device;
461
DeleteIORequest(ConReq);
467
DeleteMsgPort(ConPort);
480
struct InputEvent event;
484
event.ie_Qualifier=0;
485
event.ie_Class=IECLASS_RAWKEY;
486
event.ie_SubClass=0L;
488
event.ie_X=event.ie_Y=0;
489
event.ie_EventAddress=NULL;
490
event.ie_NextEvent=NULL;
491
event.ie_Prev1DownCode=event.ie_Prev1DownQual=event.ie_Prev2DownCode=event.ie_Prev2DownQual=0;
494
if( (actual=MapRawKey(&event,buffer,5,NULL))>=0)
496
if( (actual=RawKeyConvert(&event,buffer,5,NULL))>=0)
501
D(bug("Warning (%ld) character conversion!\n",actual));
506
D(bug("Converted rawcode %ld to <%lc>\n",code,*buffer));
507
// Bufferizzo x le successive chiamate!
508
MISC_keymap[code]=*buffer;
514
keysym->mod = KMOD_NONE;
516
/* If UNICODE is on, get the UNICODE value for the key */
518
if ( SDL_TranslateUNICODE ) {
520
static XComposeStatus state;
521
/* Until we handle the IM protocol, use XLookupString() */
522
unsigned char keybuf[32];
523
if ( XLookupString(xkey, (char *)keybuf, sizeof(keybuf),
525
keysym->unicode = keybuf[0];
532
void amiga_InitOSKeymap(_THIS)