src/video/gem/SDL_gemevents.c
author Patrice Mandin <patmandin@gmail.com>
Thu, 07 Sep 2006 20:52:31 +0000
branchSDL-1.2
changeset 3854 f1816773a309
parent 1857 417f2af2bd52
child 3861 c3625a895caf
permissions -rw-r--r--
/me dumb, sizeof(keymap) != number of elements
slouken@281
     1
/*
slouken@281
     2
    SDL - Simple DirectMedia Layer
slouken@1312
     3
    Copyright (C) 1997-2006 Sam Lantinga
slouken@281
     4
slouken@281
     5
    This library is free software; you can redistribute it and/or
slouken@1312
     6
    modify it under the terms of the GNU Lesser General Public
slouken@281
     7
    License as published by the Free Software Foundation; either
slouken@1312
     8
    version 2.1 of the License, or (at your option) any later version.
slouken@281
     9
slouken@281
    10
    This library is distributed in the hope that it will be useful,
slouken@281
    11
    but WITHOUT ANY WARRANTY; without even the implied warranty of
slouken@281
    12
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
slouken@1312
    13
    Lesser General Public License for more details.
slouken@281
    14
slouken@1312
    15
    You should have received a copy of the GNU Lesser General Public
slouken@1312
    16
    License along with this library; if not, write to the Free Software
slouken@1312
    17
    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
slouken@281
    18
slouken@281
    19
    Sam Lantinga
slouken@281
    20
    slouken@libsdl.org
slouken@281
    21
*/
slouken@1402
    22
#include "SDL_config.h"
slouken@281
    23
slouken@281
    24
/*
slouken@281
    25
 * GEM SDL video driver implementation
slouken@281
    26
 * inspired from the Dummy SDL driver
slouken@281
    27
 * 
slouken@281
    28
 * Patrice Mandin
slouken@281
    29
 * and work from
slouken@281
    30
 * Olivier Landemarre, Johan Klockars, Xavier Joubert, Claude Attard
slouken@281
    31
 */
slouken@281
    32
slouken@281
    33
#include <gem.h>
slouken@281
    34
slouken@1361
    35
#include "../../events/SDL_sysevents.h"
slouken@1361
    36
#include "../../events/SDL_events_c.h"
slouken@281
    37
#include "SDL_gemvideo.h"
slouken@281
    38
#include "SDL_gemevents_c.h"
patmandin@1412
    39
#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
patmandin@1412
    40
#include "../ataricommon/SDL_atarievents_c.h"
patmandin@1412
    41
#include "../ataricommon/SDL_xbiosevents_c.h"
patmandin@1420
    42
#include "../ataricommon/SDL_ataridevmouse_c.h"
slouken@281
    43
slouken@281
    44
/* Defines */
slouken@281
    45
slouken@281
    46
#define ATARIBIOS_MAXKEYS 128
slouken@281
    47
slouken@281
    48
/* Variables */
slouken@281
    49
slouken@281
    50
static unsigned char gem_currentkeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    51
static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
slouken@281
    52
static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
slouken@281
    53
slouken@281
    54
/* The translation tables from a console scancode to a SDL keysym */
slouken@281
    55
static SDLKey keymap[ATARIBIOS_MAXKEYS];
slouken@281
    56
slouken@281
    57
/* Functions prototypes */
slouken@281
    58
patmandin@1209
    59
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
patmandin@1209
    60
	SDL_bool pressed);
slouken@281
    61
static int do_messages(_THIS, short *message);
slouken@281
    62
static void do_keyboard(short kc, short ks);
slouken@319
    63
static void do_mouse(_THIS, short mx, short my, short mb, short ks);
slouken@281
    64
slouken@281
    65
/* Functions */
slouken@281
    66
patmandin@1209
    67
static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym,
patmandin@1209
    68
	SDL_bool pressed)
slouken@281
    69
{
slouken@281
    70
	/* Set the keysym information */
slouken@281
    71
	keysym->scancode = scancode;
slouken@281
    72
slouken@281
    73
	if (asciicode)
slouken@281
    74
		keysym->sym = asciicode;		
slouken@281
    75
	else
slouken@281
    76
		keysym->sym = keymap[scancode];
slouken@281
    77
slouken@281
    78
	keysym->mod = KMOD_NONE;
slouken@281
    79
	keysym->unicode = 0;
patmandin@1221
    80
	if (SDL_TranslateUNICODE && pressed) {
patmandin@1221
    81
		keysym->unicode = SDL_AtariToUnicodeTable[asciicode];
patmandin@1209
    82
	}
slouken@281
    83
slouken@281
    84
	return(keysym);
slouken@281
    85
}
slouken@281
    86
slouken@281
    87
void GEM_InitOSKeymap(_THIS)
slouken@281
    88
{
slouken@281
    89
	int i;
slouken@281
    90
slouken@1336
    91
	SDL_memset(gem_currentkeyboard, 0, sizeof(gem_currentkeyboard));
slouken@1336
    92
	SDL_memset(gem_previouskeyboard, 0, sizeof(gem_previouskeyboard));
slouken@1336
    93
	SDL_memset(gem_currentascii, 0, sizeof(gem_currentascii));
slouken@281
    94
slouken@281
    95
	/* Initialize keymap */
patmandin@3854
    96
	for ( i=0; i<ATARIBIOS_MAXKEYS; i++ )
slouken@281
    97
		keymap[i] = SDLK_UNKNOWN;
slouken@281
    98
slouken@281
    99
	/* Functions keys */
slouken@281
   100
	for ( i = 0; i<10; i++ )
slouken@281
   101
		keymap[SCANCODE_F1 + i] = SDLK_F1+i;
slouken@281
   102
slouken@281
   103
	/* Cursor keypad */
slouken@281
   104
	keymap[SCANCODE_HELP] = SDLK_HELP;
slouken@281
   105
	keymap[SCANCODE_UNDO] = SDLK_UNDO;
slouken@281
   106
	keymap[SCANCODE_INSERT] = SDLK_INSERT;
slouken@281
   107
	keymap[SCANCODE_CLRHOME] = SDLK_HOME;
slouken@281
   108
	keymap[SCANCODE_UP] = SDLK_UP;
slouken@281
   109
	keymap[SCANCODE_DOWN] = SDLK_DOWN;
slouken@281
   110
	keymap[SCANCODE_RIGHT] = SDLK_RIGHT;
slouken@281
   111
	keymap[SCANCODE_LEFT] = SDLK_LEFT;
slouken@281
   112
slouken@281
   113
	/* Special keys */
slouken@281
   114
	keymap[SCANCODE_ESCAPE] = SDLK_ESCAPE;
slouken@281
   115
	keymap[SCANCODE_BACKSPACE] = SDLK_BACKSPACE;
slouken@281
   116
	keymap[SCANCODE_TAB] = SDLK_TAB;
slouken@281
   117
	keymap[SCANCODE_ENTER] = SDLK_RETURN;
slouken@281
   118
	keymap[SCANCODE_DELETE] = SDLK_DELETE;
slouken@281
   119
	keymap[SCANCODE_LEFTCONTROL] = SDLK_LCTRL;
slouken@281
   120
	keymap[SCANCODE_LEFTSHIFT] = SDLK_LSHIFT;
slouken@281
   121
	keymap[SCANCODE_RIGHTSHIFT] = SDLK_RSHIFT;
slouken@281
   122
	keymap[SCANCODE_LEFTALT] = SDLK_LALT;
slouken@281
   123
	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
slouken@281
   124
slouken@281
   125
	/* Mouse init */
slouken@281
   126
	GEM_mouse_relative = SDL_FALSE;
slouken@281
   127
}
slouken@281
   128
slouken@281
   129
void GEM_PumpEvents(_THIS)
slouken@281
   130
{
slouken@319
   131
	short mousex, mousey, mouseb, dummy;
slouken@319
   132
	short kstate, prevkc, prevks;
slouken@281
   133
	int i;
slouken@281
   134
	SDL_keysym	keysym;
slouken@281
   135
slouken@1336
   136
	SDL_memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
slouken@319
   137
	prevkc = prevks = 0;
slouken@281
   138
	
slouken@281
   139
	for (;;)
slouken@281
   140
	{
patmandin@1092
   141
		int quit, resultat, event_mask, mouse_event;
slouken@319
   142
		short buffer[8], kc;
patmandin@1067
   143
		short x2,y2,w2,h2;
slouken@281
   144
patmandin@1089
   145
		quit =
patmandin@1089
   146
			mouse_event =
patmandin@1089
   147
			x2=y2=w2=h2 = 0;
slouken@281
   148
patmandin@1067
   149
		event_mask = MU_MESAG|MU_TIMER|MU_KEYBD;
patmandin@1067
   150
		if (!GEM_fullscreen && (GEM_handle>=0)) {
patmandin@1067
   151
			wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@1089
   152
			event_mask |= MU_M1;
patmandin@1089
   153
			if ( (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
patmandin@1089
   154
				mouse_event = MO_LEAVE;				
patmandin@1089
   155
			} else {
patmandin@1089
   156
				mouse_event = MO_ENTER;				
patmandin@1089
   157
			}
patmandin@1067
   158
		}
patmandin@1067
   159
slouken@281
   160
		resultat = evnt_multi(
patmandin@1067
   161
			event_mask,
slouken@281
   162
			0,0,0,
patmandin@1089
   163
			mouse_event,x2,y2,w2,h2,
patmandin@1089
   164
			0,0,0,0,0,
slouken@281
   165
			buffer,
slouken@281
   166
			10,
slouken@319
   167
			&dummy,&dummy,&dummy,&kstate,&kc,&dummy
slouken@281
   168
		);
slouken@281
   169
slouken@281
   170
		/* Message event ? */
slouken@281
   171
		if (resultat & MU_MESAG)
slouken@281
   172
			quit = do_messages(this, buffer);
slouken@281
   173
slouken@281
   174
		/* Keyboard event ? */
slouken@319
   175
		if (resultat & MU_KEYBD) {
slouken@319
   176
			if ((prevkc != kc) || (prevks != kstate)) {
slouken@319
   177
				do_keyboard(kc,kstate);
slouken@319
   178
			} else {
slouken@319
   179
				/* Avoid looping, if repeating same key */
slouken@319
   180
				break;
slouken@319
   181
			}
slouken@319
   182
		}
slouken@281
   183
patmandin@1067
   184
		/* Mouse entering/leaving window */
patmandin@1067
   185
		if (resultat & MU_M1) {
patmandin@1067
   186
			if (this->input_grab == SDL_GRAB_OFF) {
patmandin@1089
   187
				if (SDL_GetAppState() & SDL_APPMOUSEFOCUS) {
patmandin@1089
   188
					SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
patmandin@1857
   189
					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
patmandin@1857
   190
						graf_mouse(ARROW, NULL);
patmandin@1857
   191
					}
patmandin@1089
   192
				} else {
patmandin@1088
   193
					SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
patmandin@1857
   194
					if (SDL_GetAppState() & SDL_APPINPUTFOCUS) {
patmandin@1857
   195
						if (GEM_cursor == (void *) -1) {
patmandin@1857
   196
							graf_mouse(M_OFF, NULL);
patmandin@1857
   197
						} else if (GEM_cursor) {
patmandin@1857
   198
							graf_mouse(USER_DEF, GEM_cursor->mform_p);
patmandin@1857
   199
						}
patmandin@1857
   200
					}
patmandin@1088
   201
				}
patmandin@1067
   202
			}
patmandin@1067
   203
		}
patmandin@1067
   204
slouken@281
   205
		/* Timer event ? */
slouken@281
   206
		if ((resultat & MU_TIMER) || quit)
slouken@281
   207
			break;
slouken@281
   208
	}
slouken@281
   209
slouken@281
   210
	/* Update mouse */
slouken@319
   211
	graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
slouken@319
   212
	do_mouse(this, mousex, mousey, mouseb, kstate);
slouken@281
   213
slouken@319
   214
	/* Now generate keyboard events */
slouken@281
   215
	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
slouken@281
   216
		/* Key pressed ? */
slouken@281
   217
		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
patmandin@1209
   218
			SDL_PrivateKeyboard(SDL_PRESSED,
patmandin@1209
   219
				TranslateKey(i, gem_currentascii[i], &keysym, SDL_TRUE));
slouken@281
   220
			
slouken@281
   221
		/* Key unpressed ? */
slouken@281
   222
		if (gem_previouskeyboard[i] && !gem_currentkeyboard[i])
patmandin@1209
   223
			SDL_PrivateKeyboard(SDL_RELEASED,
patmandin@1209
   224
				TranslateKey(i, gem_currentascii[i], &keysym, SDL_FALSE));
slouken@281
   225
	}
slouken@281
   226
slouken@1336
   227
	SDL_memcpy(gem_previouskeyboard,gem_currentkeyboard,sizeof(gem_previouskeyboard));
patmandin@996
   228
patmandin@996
   229
	/* Refresh window name ? */
patmandin@996
   230
	if (GEM_refresh_name) {
patmandin@996
   231
		if ( SDL_GetAppState() & SDL_APPACTIVE ) {
patmandin@996
   232
			/* Fullscreen/windowed */
patmandin@996
   233
			if (GEM_title_name) {
patmandin@996
   234
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
patmandin@996
   235
			}
patmandin@996
   236
		} else {
patmandin@996
   237
			/* Iconified */
patmandin@996
   238
			if (GEM_icon_name) {
patmandin@996
   239
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
patmandin@996
   240
			}
patmandin@996
   241
		}
patmandin@996
   242
		GEM_refresh_name = SDL_FALSE;
patmandin@996
   243
	}
slouken@281
   244
}
slouken@281
   245
slouken@281
   246
static int do_messages(_THIS, short *message)
slouken@281
   247
{
slouken@281
   248
	int quit, posted;
patmandin@922
   249
	short x2,y2,w2,h2;
slouken@281
   250
slouken@281
   251
	quit=0;
slouken@281
   252
	switch (message[0]) {
slouken@281
   253
		case WM_CLOSED:
slouken@281
   254
		case AP_TERM:    
slouken@281
   255
			posted = SDL_PrivateQuit();
slouken@281
   256
			quit=1;
slouken@281
   257
			break;
slouken@281
   258
		case WM_MOVED:
slouken@281
   259
			wind_set(message[3],WF_CURRXYWH,message[4],message[5],message[6],message[7]);
slouken@281
   260
			break;
slouken@281
   261
		case WM_TOPPED:
slouken@281
   262
			wind_set(message[3],WF_TOP,message[4],0,0,0);
patmandin@1091
   263
			/* Continue with TOP event processing */
patmandin@1091
   264
		case WM_ONTOP:
slouken@281
   265
			SDL_PrivateAppActive(1, SDL_APPINPUTFOCUS);
patmandin@1074
   266
			if (VDI_setpalette) {
patmandin@1074
   267
				VDI_setpalette(this, VDI_curpalette);
patmandin@1074
   268
			}
slouken@281
   269
			break;
slouken@281
   270
		case WM_REDRAW:
patmandin@964
   271
			if (!GEM_lock_redraw) {
patmandin@964
   272
				GEM_wind_redraw(this, message[3],&message[4]);
patmandin@964
   273
			}
slouken@281
   274
			break;
slouken@281
   275
		case WM_ICONIFY:
slouken@281
   276
		case WM_ALLICONIFY:
slouken@281
   277
			wind_set(message[3],WF_ICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   278
			/* If we're active, make ourselves inactive */
slouken@281
   279
			if ( SDL_GetAppState() & SDL_APPACTIVE ) {
slouken@281
   280
				/* Send an internal deactivate event */
patmandin@1088
   281
				SDL_PrivateAppActive(0, SDL_APPACTIVE);
slouken@281
   282
			}
patmandin@736
   283
			/* Update window title */
patmandin@736
   284
			if (GEM_refresh_name && GEM_icon_name) {
patmandin@736
   285
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_icon_name)>>16),(short)(((unsigned long)GEM_icon_name) & 0xffff),0,0);
patmandin@736
   286
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   287
			}
slouken@281
   288
			break;
slouken@281
   289
		case WM_UNICONIFY:
slouken@281
   290
			wind_set(message[3],WF_UNICONIFY,message[4],message[5],message[6],message[7]);
slouken@281
   291
			/* If we're not active, make ourselves active */
slouken@281
   292
			if ( !(SDL_GetAppState() & SDL_APPACTIVE) ) {
slouken@281
   293
				/* Send an internal activate event */
slouken@281
   294
				SDL_PrivateAppActive(1, SDL_APPACTIVE);
slouken@281
   295
			}
patmandin@736
   296
			if (GEM_refresh_name && GEM_title_name) {
patmandin@736
   297
				wind_set(GEM_handle,WF_NAME,(short)(((unsigned long)GEM_title_name)>>16),(short)(((unsigned long)GEM_title_name) & 0xffff),0,0);
patmandin@736
   298
				GEM_refresh_name = SDL_FALSE;
patmandin@736
   299
			}
slouken@281
   300
			break;
slouken@281
   301
		case WM_SIZED:
slouken@281
   302
			wind_set (message[3], WF_CURRXYWH, message[4], message[5], message[6], message[7]);
patmandin@964
   303
			wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
slouken@281
   304
			GEM_win_fulled = SDL_FALSE;		/* Cancel maximized flag */
patmandin@964
   305
			GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   306
			SDL_PrivateResize(w2, h2);
slouken@281
   307
			break;
slouken@281
   308
		case WM_FULLED:
slouken@281
   309
			{
slouken@281
   310
				short x,y,w,h;
slouken@281
   311
slouken@281
   312
				if (GEM_win_fulled) {
slouken@281
   313
					wind_get (message[3], WF_PREVXYWH, &x, &y, &w, &h);
slouken@281
   314
					GEM_win_fulled = SDL_FALSE;
slouken@281
   315
				} else {
slouken@281
   316
					x = GEM_desk_x;
slouken@281
   317
					y = GEM_desk_y;
slouken@281
   318
					w = GEM_desk_w;
slouken@281
   319
					h = GEM_desk_h;
slouken@281
   320
					GEM_win_fulled = SDL_TRUE;
slouken@281
   321
				}
slouken@281
   322
				wind_set (message[3], WF_CURRXYWH, x, y, w, h);
patmandin@922
   323
				wind_get (message[3], WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@964
   324
				GEM_lock_redraw = SDL_TRUE;		/* Prevent redraw till buffers resized */
patmandin@922
   325
				SDL_PrivateResize(w2, h2);
slouken@281
   326
			}
slouken@281
   327
			break;
slouken@281
   328
		case WM_BOTTOMED:
patmandin@1091
   329
			wind_set(message[3],WF_BOTTOM,0,0,0,0);
patmandin@1091
   330
			/* Continue with BOTTOM event processing */
slouken@281
   331
		case WM_UNTOPPED:
slouken@281
   332
			SDL_PrivateAppActive(0, SDL_APPINPUTFOCUS);
patmandin@1074
   333
			if (VDI_setpalette) {
patmandin@1074
   334
				VDI_setpalette(this, VDI_oldpalette);
patmandin@1074
   335
			}
slouken@281
   336
			break;
slouken@281
   337
	}
slouken@281
   338
	
slouken@281
   339
	return quit;
slouken@281
   340
}
slouken@281
   341
slouken@281
   342
static void do_keyboard(short kc, short ks)
slouken@281
   343
{
slouken@281
   344
	int			scancode, asciicode;
slouken@281
   345
slouken@281
   346
	if (kc) {
slouken@281
   347
		scancode=(kc>>8) & 127;
slouken@281
   348
		asciicode=kc & 255;
slouken@281
   349
slouken@281
   350
		gem_currentkeyboard[scancode]=0xFF;
slouken@281
   351
		gem_currentascii[scancode]=asciicode;
slouken@281
   352
	}
slouken@281
   353
slouken@281
   354
	/* Read special keys */
slouken@281
   355
	if (ks & K_RSHIFT)
slouken@281
   356
		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
slouken@281
   357
	if (ks & K_LSHIFT)
slouken@281
   358
		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
slouken@281
   359
	if (ks & K_CTRL)
slouken@281
   360
		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
slouken@281
   361
	if (ks & K_ALT)
slouken@281
   362
		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
slouken@281
   363
}
slouken@281
   364
slouken@319
   365
static void do_mouse(_THIS, short mx, short my, short mb, short ks)
slouken@281
   366
{
slouken@319
   367
	static short prevmousex=0, prevmousey=0, prevmouseb=0;
patmandin@926
   368
	short x2, y2, w2, h2;
patmandin@926
   369
patmandin@1067
   370
	/* Don't return mouse events if out of window */
patmandin@1067
   371
	if ((SDL_GetAppState() & SDL_APPMOUSEFOCUS)==0) {
patmandin@1067
   372
		return;
patmandin@1067
   373
	}
patmandin@1067
   374
patmandin@926
   375
	/* Retrieve window coords, and generate mouse events accordingly */
patmandin@926
   376
	x2 = y2 = 0;
patmandin@928
   377
	w2 = VDI_w;
patmandin@928
   378
	h2 = VDI_h;
patmandin@926
   379
	if ((!GEM_fullscreen) && (GEM_handle>=0)) {
patmandin@926
   380
		wind_get (GEM_handle, WF_WORKXYWH, &x2, &y2, &w2, &h2);
patmandin@926
   381
patmandin@926
   382
		/* Do not generate mouse button event if out of window working area */
patmandin@926
   383
		if ((mx<x2) || (mx>=x2+w2) || (my<y2) || (my>=y2+h2)) {
patmandin@926
   384
			mb=prevmouseb;
patmandin@926
   385
		}
patmandin@926
   386
	}
slouken@319
   387
slouken@281
   388
	/* Mouse motion ? */
patmandin@1267
   389
	if (GEM_mouse_relative) {
patmandin@1420
   390
		if (GEM_usedevmouse) {
patmandin@1420
   391
			SDL_AtariDevMouse_PostMouseEvents(this, SDL_FALSE);
patmandin@1420
   392
		} else {
patmandin@1420
   393
			SDL_AtariXbios_PostMouseEvents(this, SDL_FALSE);
patmandin@1420
   394
		}
patmandin@1267
   395
	} else {
patmandin@1267
   396
		if ((prevmousex!=mx) || (prevmousey!=my)) {
patmandin@926
   397
			int posx, posy;
patmandin@926
   398
patmandin@926
   399
			/* Give mouse position relative to window position */
patmandin@926
   400
			posx = mx - x2;
patmandin@927
   401
			if (posx<0) posx = 0;
patmandin@926
   402
			if (posx>w2) posx = w2-1;
patmandin@926
   403
			posy = my - y2;
patmandin@927
   404
			if (posy<0) posy = 0;
patmandin@926
   405
			if (posy>h2) posy = h2-1;
patmandin@926
   406
patmandin@926
   407
			SDL_PrivateMouseMotion(0, 0, posx, posy);
slouken@281
   408
		}
slouken@281
   409
		prevmousex = mx;
slouken@281
   410
		prevmousey = my;
slouken@281
   411
	}
slouken@281
   412
slouken@281
   413
	/* Mouse button ? */
slouken@281
   414
	if (prevmouseb!=mb) {
slouken@281
   415
		int i;
slouken@281
   416
slouken@319
   417
		for (i=0;i<2;i++) {
slouken@281
   418
			int curbutton, prevbutton;
slouken@281
   419
		
slouken@281
   420
			curbutton = mb & (1<<i);
slouken@281
   421
			prevbutton = prevmouseb & (1<<i);
slouken@281
   422
		
slouken@319
   423
			if (curbutton && !prevbutton) {
slouken@319
   424
				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
slouken@281
   425
			}
slouken@319
   426
			if (!curbutton && prevbutton) {
slouken@319
   427
				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
slouken@281
   428
			}
slouken@281
   429
		}
slouken@281
   430
		prevmouseb = mb;
slouken@281
   431
	}
slouken@319
   432
slouken@319
   433
	/* Read special keys */
slouken@319
   434
	if (ks & K_RSHIFT)
slouken@319
   435
		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
slouken@319
   436
	if (ks & K_LSHIFT)
slouken@319
   437
		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
slouken@319
   438
	if (ks & K_CTRL)
slouken@319
   439
		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
slouken@319
   440
	if (ks & K_ALT)
slouken@319
   441
		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
slouken@281
   442
}