src/video/gem/SDL_gemevents.c
changeset 319 189a6a3416c7
parent 297 f6ffac90895c
child 736 028e03e273c8
     1.1 --- a/src/video/gem/SDL_gemevents.c	Sun Mar 24 21:44:06 2002 +0000
     1.2 +++ b/src/video/gem/SDL_gemevents.c	Tue Mar 26 17:37:31 2002 +0000
     1.3 @@ -43,7 +43,8 @@
     1.4  #include "SDL_events_c.h"
     1.5  #include "SDL_gemvideo.h"
     1.6  #include "SDL_gemevents_c.h"
     1.7 -#include "../ataricommon/SDL_atarikeys.h"	/* for keyboard scancodes */
     1.8 +#include "SDL_atarikeys.h"	/* for keyboard scancodes */
     1.9 +#include "SDL_xbiosinterrupt_s.h"
    1.10  
    1.11  /* Defines */
    1.12  
    1.13 @@ -55,8 +56,6 @@
    1.14  static unsigned char gem_previouskeyboard[ATARIBIOS_MAXKEYS];
    1.15  static unsigned char gem_currentascii[ATARIBIOS_MAXKEYS];
    1.16  
    1.17 -static short prevmousex, prevmousey, prevmouseb;
    1.18 -
    1.19  /* The translation tables from a console scancode to a SDL keysym */
    1.20  static SDLKey keymap[ATARIBIOS_MAXKEYS];
    1.21  
    1.22 @@ -65,7 +64,7 @@
    1.23  static SDL_keysym *TranslateKey(int scancode, int asciicode, SDL_keysym *keysym);
    1.24  static int do_messages(_THIS, short *message);
    1.25  static void do_keyboard(short kc, short ks);
    1.26 -static void do_mouse(_THIS, short mx, short my, short mb);
    1.27 +static void do_mouse(_THIS, short mx, short my, short mb, short ks);
    1.28  
    1.29  /* Functions */
    1.30  
    1.31 @@ -124,22 +123,23 @@
    1.32  	keymap[SCANCODE_CAPSLOCK] = SDLK_CAPSLOCK;
    1.33  
    1.34  	/* Mouse init */
    1.35 -	prevmousex = prevmousey = prevmouseb = 0;
    1.36  	GEM_mouse_relative = SDL_FALSE;
    1.37  }
    1.38  
    1.39  void GEM_PumpEvents(_THIS)
    1.40  {
    1.41 -	short mx, my, mb, dummy;
    1.42 +	short mousex, mousey, mouseb, dummy;
    1.43 +	short kstate, prevkc, prevks;
    1.44  	int i;
    1.45  	SDL_keysym	keysym;
    1.46  
    1.47  	memset(gem_currentkeyboard,0,sizeof(gem_currentkeyboard));
    1.48 +	prevkc = prevks = 0;
    1.49  	
    1.50  	for (;;)
    1.51  	{
    1.52  		int quit, resultat;
    1.53 -		short buffer[8], kc, ks;
    1.54 +		short buffer[8], kc;
    1.55  
    1.56  		quit = 0;
    1.57  
    1.58 @@ -150,7 +150,7 @@
    1.59  			0,0,0,0,0,
    1.60  			buffer,
    1.61  			10,
    1.62 -			&dummy,&dummy,&dummy,&ks,&kc,&dummy
    1.63 +			&dummy,&dummy,&dummy,&kstate,&kc,&dummy
    1.64  		);
    1.65  
    1.66  		/* Message event ? */
    1.67 @@ -158,10 +158,14 @@
    1.68  			quit = do_messages(this, buffer);
    1.69  
    1.70  		/* Keyboard event ? */
    1.71 -		if (resultat & MU_KEYBD)
    1.72 -			do_keyboard(kc,ks);
    1.73 -		else
    1.74 -			do_keyboard(0,0);
    1.75 +		if (resultat & MU_KEYBD) {
    1.76 +			if ((prevkc != kc) || (prevks != kstate)) {
    1.77 +				do_keyboard(kc,kstate);
    1.78 +			} else {
    1.79 +				/* Avoid looping, if repeating same key */
    1.80 +				break;
    1.81 +			}
    1.82 +		}
    1.83  
    1.84  		/* Timer event ? */
    1.85  		if ((resultat & MU_TIMER) || quit)
    1.86 @@ -169,10 +173,10 @@
    1.87  	}
    1.88  
    1.89  	/* Update mouse */
    1.90 -	graf_mkstate(&mx, &my, &mb, &dummy);
    1.91 -	do_mouse(this, mx, my, mb);
    1.92 +	graf_mkstate(&mousex, &mousey, &mouseb, &kstate);
    1.93 +	do_mouse(this, mousex, mousey, mouseb, kstate);
    1.94  
    1.95 -	/* Now generates keyboard events */
    1.96 +	/* Now generate keyboard events */
    1.97  	for (i=0; i<ATARIBIOS_MAXKEYS; i++) {
    1.98  		/* Key pressed ? */
    1.99  		if (gem_currentkeyboard[i] && !gem_previouskeyboard[i])
   1.100 @@ -259,7 +263,6 @@
   1.101  static void do_keyboard(short kc, short ks)
   1.102  {
   1.103  	int			scancode, asciicode;
   1.104 -	short		dummy;
   1.105  
   1.106  	if (kc) {
   1.107  		scancode=(kc>>8) & 127;
   1.108 @@ -269,9 +272,6 @@
   1.109  		gem_currentascii[scancode]=asciicode;
   1.110  	}
   1.111  
   1.112 -	if (!ks)
   1.113 -		graf_mkstate(&dummy, &dummy, &dummy, &ks);
   1.114 -
   1.115  	/* Read special keys */
   1.116  	if (ks & K_RSHIFT)
   1.117  		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   1.118 @@ -283,16 +283,15 @@
   1.119  		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   1.120  }
   1.121  
   1.122 -static void do_mouse(_THIS, short mx, short my, short mb)
   1.123 +static void do_mouse(_THIS, short mx, short my, short mb, short ks)
   1.124  {
   1.125 +	static short prevmousex=0, prevmousey=0, prevmouseb=0;
   1.126 +
   1.127  	/* Mouse motion ? */
   1.128  	if ((prevmousex!=mx) || (prevmousey!=my)) {
   1.129  		if (GEM_mouse_relative) {
   1.130 -			short wind_pxy[8];
   1.131 -
   1.132 -			wind_get(GEM_handle, WF_WORKXYWH, &wind_pxy[0], &wind_pxy[1], &wind_pxy[2], &wind_pxy[3]);
   1.133 -
   1.134 -			SDL_PrivateMouseMotion(0, 1, mx-wind_pxy[0], my-wind_pxy[1]);
   1.135 +			SDL_PrivateMouseMotion(0, 1, SDL_AtariXbios_mousex, SDL_AtariXbios_mousey);
   1.136 +			SDL_AtariXbios_mousex = SDL_AtariXbios_mousey = 0;
   1.137  		} else {
   1.138  			SDL_PrivateMouseMotion(0, 1, mx, my);
   1.139  		}
   1.140 @@ -304,19 +303,29 @@
   1.141  	if (prevmouseb!=mb) {
   1.142  		int i;
   1.143  
   1.144 -		for (i=0;i<3;i++) {
   1.145 +		for (i=0;i<2;i++) {
   1.146  			int curbutton, prevbutton;
   1.147  		
   1.148  			curbutton = mb & (1<<i);
   1.149  			prevbutton = prevmouseb & (1<<i);
   1.150  		
   1.151 -			if (curbutton & !prevbutton) {
   1.152 -				SDL_PrivateMouseButton(SDL_PRESSED, i, 0, 0);
   1.153 +			if (curbutton && !prevbutton) {
   1.154 +				SDL_PrivateMouseButton(SDL_PRESSED, i+1, 0, 0);
   1.155  			}
   1.156 -			if (!curbutton & prevbutton) {
   1.157 -				SDL_PrivateMouseButton(SDL_RELEASED, i, 0, 0);
   1.158 +			if (!curbutton && prevbutton) {
   1.159 +				SDL_PrivateMouseButton(SDL_RELEASED, i+1, 0, 0);
   1.160  			}
   1.161  		}
   1.162  		prevmouseb = mb;
   1.163  	}
   1.164 +
   1.165 +	/* Read special keys */
   1.166 +	if (ks & K_RSHIFT)
   1.167 +		gem_currentkeyboard[SCANCODE_RIGHTSHIFT]=0xFF;
   1.168 +	if (ks & K_LSHIFT)
   1.169 +		gem_currentkeyboard[SCANCODE_LEFTSHIFT]=0xFF;
   1.170 +	if (ks & K_CTRL)
   1.171 +		gem_currentkeyboard[SCANCODE_LEFTCONTROL]=0xFF;
   1.172 +	if (ks & K_ALT)
   1.173 +		gem_currentkeyboard[SCANCODE_LEFTALT]=0xFF;
   1.174  }