Date: Mon, 21 Jun 2004 16:52:47 +0200
authorSam Lantinga <slouken@libsdl.org>
Sun, 18 Jul 2004 19:36:06 +0000
changeset 9073bd4d7a1ee04
parent 906 a48acf6ee48f
child 908 6104bfff77ba
Date: Mon, 21 Jun 2004 16:52:47 +0200
From: Marcin Konicki
Subject: SDL 1.2.7 patch for BeOS (new input handling code)

I rewrote input handling code for BeOS. It should be faster now (i got
report that mouse is faster, keyboard should be too, but it's harder to
observe).

I'll try to add mouse wheel support too, soon.

Stefano Ceccherini (a.k.a Jack Burton) helped me beautify code (working
version was less clean), and it was he who asked me to write this thing ;).
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_lowvideo.h
src/video/bwindow/SDL_sysevents.cc
     1.1 --- a/src/video/bwindow/SDL_BWin.h	Sun Jul 18 19:14:33 2004 +0000
     1.2 +++ b/src/video/bwindow/SDL_BWin.h	Sun Jul 18 19:36:06 2004 +0000
     1.3 @@ -35,6 +35,7 @@
     1.4  #ifdef HAVE_OPENGL
     1.5  #include <be/opengl/GLView.h>
     1.6  #endif
     1.7 +#include <support/UTF8.h>
     1.8  
     1.9  #include "SDL_BeApp.h"
    1.10  #include "SDL_events.h"
    1.11 @@ -49,6 +50,9 @@
    1.12  public:
    1.13  	SDL_BWin(BRect bounds) :
    1.14  			BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) {
    1.15 +		InitKeyboard();
    1.16 +		last_buttons = 0;
    1.17 +
    1.18  		the_view = NULL;
    1.19  #ifdef HAVE_OPENGL
    1.20  		SDL_GLView = NULL;
    1.21 @@ -58,6 +62,7 @@
    1.22  		shown = false;
    1.23  		inhibit_resize = false;
    1.24  	}
    1.25 +
    1.26  	virtual ~SDL_BWin() {
    1.27  		Lock();
    1.28  		if ( the_view ) {
    1.29 @@ -79,6 +84,119 @@
    1.30  			delete SDL_View;
    1.31  		}
    1.32  	}
    1.33 +	
    1.34 +	virtual void InitKeyboard(void) {
    1.35 +		for ( uint i=0; i<SDL_TABLESIZE(keymap); ++i )
    1.36 +			keymap[i] = SDLK_UNKNOWN;
    1.37 +
    1.38 +		keymap[0x01]		= SDLK_ESCAPE;
    1.39 +		keymap[B_F1_KEY]	= SDLK_F1;
    1.40 +		keymap[B_F2_KEY]	= SDLK_F2;
    1.41 +		keymap[B_F3_KEY]	= SDLK_F3;
    1.42 +		keymap[B_F4_KEY]	= SDLK_F4;
    1.43 +		keymap[B_F5_KEY]	= SDLK_F5;
    1.44 +		keymap[B_F6_KEY]	= SDLK_F6;
    1.45 +		keymap[B_F7_KEY]	= SDLK_F7;
    1.46 +		keymap[B_F8_KEY]	= SDLK_F8;
    1.47 +		keymap[B_F9_KEY]	= SDLK_F9;
    1.48 +		keymap[B_F10_KEY]	= SDLK_F10;
    1.49 +		keymap[B_F11_KEY]	= SDLK_F11;
    1.50 +		keymap[B_F12_KEY]	= SDLK_F12;
    1.51 +		keymap[B_PRINT_KEY]	= SDLK_PRINT;
    1.52 +		keymap[B_SCROLL_KEY]	= SDLK_SCROLLOCK;
    1.53 +		keymap[B_PAUSE_KEY]	= SDLK_PAUSE;
    1.54 +		keymap[0x11]		= SDLK_BACKQUOTE;
    1.55 +		keymap[0x12]		= SDLK_1;
    1.56 +		keymap[0x13]		= SDLK_2;
    1.57 +		keymap[0x14]		= SDLK_3;
    1.58 +		keymap[0x15]		= SDLK_4;
    1.59 +		keymap[0x16]		= SDLK_5;
    1.60 +		keymap[0x17]		= SDLK_6;
    1.61 +		keymap[0x18]		= SDLK_7;
    1.62 +		keymap[0x19]		= SDLK_8;
    1.63 +		keymap[0x1a]		= SDLK_9;
    1.64 +		keymap[0x1b]		= SDLK_0;
    1.65 +		keymap[0x1c]		= SDLK_MINUS;
    1.66 +		keymap[0x1d]		= SDLK_EQUALS;
    1.67 +		keymap[0x1e]		= SDLK_BACKSPACE;
    1.68 +		keymap[0x1f]		= SDLK_INSERT;
    1.69 +		keymap[0x20]		= SDLK_HOME;
    1.70 +		keymap[0x21]		= SDLK_PAGEUP;
    1.71 +		keymap[0x22]		= SDLK_NUMLOCK;
    1.72 +		keymap[0x23]		= SDLK_KP_DIVIDE;
    1.73 +		keymap[0x24]		= SDLK_KP_MULTIPLY;
    1.74 +		keymap[0x25]		= SDLK_KP_MINUS;
    1.75 +		keymap[0x26]		= SDLK_TAB;
    1.76 +		keymap[0x27]		= SDLK_q;
    1.77 +		keymap[0x28]		= SDLK_w;
    1.78 +		keymap[0x29]		= SDLK_e;
    1.79 +		keymap[0x2a]		= SDLK_r;
    1.80 +		keymap[0x2b]		= SDLK_t;
    1.81 +		keymap[0x2c]		= SDLK_y;
    1.82 +		keymap[0x2d]		= SDLK_u;
    1.83 +		keymap[0x2e]		= SDLK_i;
    1.84 +		keymap[0x2f]		= SDLK_o;
    1.85 +		keymap[0x30]		= SDLK_p;
    1.86 +		keymap[0x31]		= SDLK_LEFTBRACKET;
    1.87 +		keymap[0x32]		= SDLK_RIGHTBRACKET;
    1.88 +		keymap[0x33]		= SDLK_BACKSLASH;
    1.89 +		keymap[0x34]		= SDLK_DELETE;
    1.90 +		keymap[0x35]		= SDLK_END;
    1.91 +		keymap[0x36]		= SDLK_PAGEDOWN;
    1.92 +		keymap[0x37]		= SDLK_KP7;
    1.93 +		keymap[0x38]		= SDLK_KP8;
    1.94 +		keymap[0x39]		= SDLK_KP9;
    1.95 +		keymap[0x3a]		= SDLK_KP_PLUS;
    1.96 +		keymap[0x3b]		= SDLK_CAPSLOCK;
    1.97 +		keymap[0x3c]		= SDLK_a;
    1.98 +		keymap[0x3d]		= SDLK_s;
    1.99 +		keymap[0x3e]		= SDLK_d;
   1.100 +		keymap[0x3f]		= SDLK_f;
   1.101 +		keymap[0x40]		= SDLK_g;
   1.102 +		keymap[0x41]		= SDLK_h;
   1.103 +		keymap[0x42]		= SDLK_j;
   1.104 +		keymap[0x43]		= SDLK_k;
   1.105 +		keymap[0x44]		= SDLK_l;
   1.106 +		keymap[0x45]		= SDLK_SEMICOLON;
   1.107 +		keymap[0x46]		= SDLK_QUOTE;
   1.108 +		keymap[0x47]		= SDLK_RETURN;
   1.109 +		keymap[0x48]		= SDLK_KP4;
   1.110 +		keymap[0x49]		= SDLK_KP5;
   1.111 +		keymap[0x4a]		= SDLK_KP6;
   1.112 +		keymap[0x4b]		= SDLK_LSHIFT;
   1.113 +		keymap[0x4c]		= SDLK_z;
   1.114 +		keymap[0x4d]		= SDLK_x;
   1.115 +		keymap[0x4e]		= SDLK_c;
   1.116 +		keymap[0x4f]		= SDLK_v;
   1.117 +		keymap[0x50]		= SDLK_b;
   1.118 +		keymap[0x51]		= SDLK_n;
   1.119 +		keymap[0x52]		= SDLK_m;
   1.120 +		keymap[0x53]		= SDLK_COMMA;
   1.121 +		keymap[0x54]		= SDLK_PERIOD;
   1.122 +		keymap[0x55]		= SDLK_SLASH;
   1.123 +		keymap[0x56]		= SDLK_RSHIFT;
   1.124 +		keymap[0x57]		= SDLK_UP;
   1.125 +		keymap[0x58]		= SDLK_KP1;
   1.126 +		keymap[0x59]		= SDLK_KP2;
   1.127 +		keymap[0x5a]		= SDLK_KP3;
   1.128 +		keymap[0x5b]		= SDLK_KP_ENTER;
   1.129 +		keymap[0x5c]		= SDLK_LCTRL;
   1.130 +		keymap[0x5d]		= SDLK_LALT;
   1.131 +		keymap[0x5e]		= SDLK_SPACE;
   1.132 +		keymap[0x5f]		= SDLK_RALT;
   1.133 +		keymap[0x60]		= SDLK_RCTRL;
   1.134 +		keymap[0x61]		= SDLK_LEFT;
   1.135 +		keymap[0x62]		= SDLK_DOWN;
   1.136 +		keymap[0x63]		= SDLK_RIGHT;
   1.137 +		keymap[0x64]		= SDLK_KP0;
   1.138 +		keymap[0x65]		= SDLK_KP_PERIOD;
   1.139 +		keymap[0x66]		= SDLK_LMETA;
   1.140 +		keymap[0x67]		= SDLK_RMETA;
   1.141 +		keymap[0x68]		= SDLK_MENU;
   1.142 +		keymap[0x69]		= SDLK_EURO;
   1.143 +		keymap[0x6a]		= SDLK_KP_EQUALS;
   1.144 +		keymap[0x6b]		= SDLK_POWER;
   1.145 +	}
   1.146  
   1.147  	/* Override the Show() method so we can tell when we've been shown */
   1.148  	virtual void Show(void) {
   1.149 @@ -211,6 +329,214 @@
   1.150  		BDirectWindow::Quit();
   1.151  	}
   1.152  
   1.153 +	virtual int16 Translate2Unicode(const char *buf) {
   1.154 +		int32 state, srclen, dstlen;
   1.155 +		unsigned char destbuf[2];
   1.156 +		Uint16 unicode = 0;
   1.157 +
   1.158 +		if ((uchar)buf[0] > 127) {
   1.159 +			state = 0;
   1.160 +			srclen = strlen(buf);
   1.161 +			dstlen = sizeof(destbuf);
   1.162 +			convert_from_utf8(B_UNICODE_CONVERSION, buf, &srclen, (char *)destbuf, &dstlen, &state);
   1.163 +			unicode = destbuf[0];
   1.164 +			unicode <<= 8;
   1.165 +			unicode |= destbuf[1];
   1.166 +		} else
   1.167 +			unicode = buf[0];
   1.168 +
   1.169 +		/* For some reason function keys map to control characters */
   1.170 +# define CTRL(X)	((X)-'@')
   1.171 +		switch (unicode) {
   1.172 +		    case CTRL('A'):
   1.173 +		    case CTRL('B'):
   1.174 +		    case CTRL('C'):
   1.175 +		    case CTRL('D'):
   1.176 +		    case CTRL('E'):
   1.177 +		    case CTRL('K'):
   1.178 +		    case CTRL('L'):
   1.179 +		    case CTRL('P'):
   1.180 +			if ( ! (SDL_GetModState() & KMOD_CTRL) )
   1.181 +				unicode = 0;
   1.182 +			break;
   1.183 +			/* Keyboard input maps newline to carriage return */
   1.184 +			case '\n':
   1.185 +				unicode = '\r';
   1.186 +			break;
   1.187 +		    default:
   1.188 +			break;
   1.189 +		}
   1.190 +
   1.191 +		return unicode;
   1.192 +	}
   1.193 +
   1.194 +	virtual void DispatchMessage(BMessage *msg, BHandler *target) {
   1.195 +		switch (msg->what) {
   1.196 +			case B_MOUSE_MOVED:
   1.197 +			{
   1.198 +				BPoint where;
   1.199 +				int32 transit;
   1.200 +				if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
   1.201 +					if (transit == B_EXITED_VIEW) {
   1.202 +						if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
   1.203 +							SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   1.204 +							be_app->SetCursor(B_HAND_CURSOR);
   1.205 +						}
   1.206 +					} else {
   1.207 +						int x, y;
   1.208 +						if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   1.209 +							SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   1.210 +							SDL_SetCursor(NULL);
   1.211 +						}
   1.212 +						GetXYOffset(x, y);
   1.213 +						x = (int)where.x - x;
   1.214 +						y = (int)where.y - y;
   1.215 +						SDL_PrivateMouseMotion(0, 0, x, y);
   1.216 +					}
   1.217 +				}
   1.218 +				break;
   1.219 +			}
   1.220 +
   1.221 +			case B_MOUSE_DOWN:
   1.222 +			{
   1.223 +				/*	it looks like mouse down is send only for first clicked
   1.224 +					button, each next is not send while last one is holded */
   1.225 +				int32 buttons;
   1.226 +				int sdl_buttons = 0;
   1.227 +				if (msg->FindInt32("buttons", &buttons) == B_OK) {
   1.228 +					/* Add any mouse button events */
   1.229 +					if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   1.230 +						sdl_buttons |= SDL_BUTTON_LEFT;
   1.231 +					}
   1.232 +					if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   1.233 +						sdl_buttons |= SDL_BUTTON_RIGHT;
   1.234 +					}
   1.235 +					if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   1.236 +						sdl_buttons |= SDL_BUTTON_MIDDLE;
   1.237 +					}
   1.238 +					SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
   1.239 +
   1.240 +					last_buttons = buttons;
   1.241 +				}
   1.242 +				break;
   1.243 +			}
   1.244 +
   1.245 +			case B_MOUSE_UP:
   1.246 +			{
   1.247 +				/*	mouse up doesn't give which button was released,
   1.248 +					only state of buttons (after release, so it's always = 0),
   1.249 +					which is is not what we need ;]
   1.250 +					So we need to store button in mouse down, and restore
   1.251 +					in mouse up :(
   1.252 +					mouse up is (similarly to mouse down) send only when
   1.253 +					no more buttons are down */
   1.254 +				int32 buttons;
   1.255 +				int sdl_buttons = 0;
   1.256 +				if (msg->FindInt32("buttons", &buttons) == B_OK) {
   1.257 +					/* Add any mouse button events */
   1.258 +					if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   1.259 +						sdl_buttons |= SDL_BUTTON_LEFT;
   1.260 +					}
   1.261 +					if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   1.262 +						sdl_buttons |= SDL_BUTTON_RIGHT;
   1.263 +					}
   1.264 +					if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   1.265 +						sdl_buttons |= SDL_BUTTON_MIDDLE;
   1.266 +					}
   1.267 +					SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
   1.268 +
   1.269 +					last_buttons = buttons;
   1.270 +				}
   1.271 +				break;
   1.272 +			}
   1.273 +
   1.274 +			case B_MOUSE_WHEEL_CHANGED:
   1.275 +			{
   1.276 +				float x, y;
   1.277 +				x = y = 0;
   1.278 +				if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   1.279 +					if (x < 0 || y < 0) {
   1.280 +						SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   1.281 +						SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   1.282 +					} else if (x > 0 || y > 0) {
   1.283 +						SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   1.284 +						SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   1.285 +					}
   1.286 +				}
   1.287 +				break;
   1.288 +			}
   1.289 +
   1.290 +			case B_KEY_DOWN:
   1.291 +			case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
   1.292 +			{
   1.293 +				int32 key;
   1.294 +				int32 modifiers;
   1.295 +				if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   1.296 +					SDL_keysym keysym;
   1.297 +					keysym.scancode = key;
   1.298 +					if (key < 128) {
   1.299 +						keysym.sym = keymap[key];
   1.300 +					} else {
   1.301 +						keysym.sym = SDLK_UNKNOWN;
   1.302 +					}
   1.303 +					/*	FIX THIS?
   1.304 +						it seems SDL_PrivateKeyboard() changes mod value
   1.305 +						anyway, and doesn't care about what we setup here */
   1.306 +					keysym.mod = KMOD_NONE;
   1.307 +					keysym.unicode = 0;
   1.308 +					if (SDL_TranslateUNICODE) {
   1.309 +						const char *bytes;
   1.310 +						if (msg->FindString("bytes", &bytes) == B_OK) {
   1.311 +							/*	FIX THIS?
   1.312 +								this cares only about first "letter",
   1.313 +								so if someone maps some key to print
   1.314 +								"BeOS rulez!" only "B" will be used. */
   1.315 +							keysym.unicode = Translate2Unicode(bytes);
   1.316 +						}
   1.317 +					}
   1.318 +					SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   1.319 +				}
   1.320 +				break;
   1.321 +			}
   1.322 +
   1.323 +			case B_KEY_UP:
   1.324 +			case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
   1.325 +			{
   1.326 +				int32 key;
   1.327 +				int32 modifiers;
   1.328 +				if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   1.329 +					SDL_keysym keysym;
   1.330 +					keysym.scancode = key;
   1.331 +					if (key < 128) {
   1.332 +						keysym.sym = keymap[key];
   1.333 +					} else {
   1.334 +						keysym.sym = SDLK_UNKNOWN;
   1.335 +					}
   1.336 +					keysym.mod = KMOD_NONE; /* FIX THIS? */
   1.337 +					keysym.unicode = 0;
   1.338 +					if (SDL_TranslateUNICODE) {
   1.339 +						const char *bytes;
   1.340 +						if (msg->FindString("bytes", &bytes) == B_OK) {
   1.341 +							keysym.unicode = Translate2Unicode(bytes);
   1.342 +						}
   1.343 +					}
   1.344 +					SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   1.345 +				}
   1.346 +				break;
   1.347 +			}
   1.348 +
   1.349 +			default:
   1.350 +				/* move it after switch{} so it's always handled
   1.351 +					that way we keep BeOS feautures like:
   1.352 +					- CTRL+Q to close window (and other shortcuts)
   1.353 +					- PrintScreen to make screenshot into /boot/home
   1.354 +					- etc.. */
   1.355 +				//BDirectWindow::DispatchMessage(msg, target);
   1.356 +				break;
   1.357 +		}
   1.358 +		BDirectWindow::DispatchMessage(msg, target);
   1.359 +	}
   1.360 +
   1.361  private:
   1.362  #ifdef HAVE_OPENGL
   1.363  	BGLView *SDL_GLView;
   1.364 @@ -220,6 +546,9 @@
   1.365  
   1.366  	bool shown;
   1.367  	bool inhibit_resize;
   1.368 +
   1.369 +	int32 last_buttons;
   1.370 +	SDLKey keymap[128];
   1.371  };
   1.372  
   1.373  #endif /* _SDL_BWin_h */
     2.1 --- a/src/video/bwindow/SDL_lowvideo.h	Sun Jul 18 19:14:33 2004 +0000
     2.2 +++ b/src/video/bwindow/SDL_lowvideo.h	Sun Jul 18 19:36:06 2004 +0000
     2.3 @@ -49,14 +49,6 @@
     2.4  	/* A completely clear cursor */
     2.5  	WMcursor *BlankCursor;
     2.6  
     2.7 -	/* Mouse state variables */
     2.8 -	uint32 last_buttons;
     2.9 -	BPoint last_point;
    2.10 -
    2.11 -	/* Keyboard state variables */
    2.12 -	int key_flip;
    2.13 -	struct key_info keyinfo[2];
    2.14 -	
    2.15  	SDL_Overlay *overlay;
    2.16  };
    2.17  /* Old variable names */
    2.18 @@ -65,10 +57,6 @@
    2.19  #define SDL_nummodes	(_this->hidden->SDL_nummodes)
    2.20  #define SDL_modelist	(_this->hidden->SDL_modelist)
    2.21  #define SDL_BlankCursor	(_this->hidden->BlankCursor)
    2.22 -#define last_buttons	(_this->hidden->last_buttons)
    2.23 -#define last_point	(_this->hidden->last_point)
    2.24 -#define key_flip	(_this->hidden->key_flip)
    2.25 -#define keyinfo		(_this->hidden->keyinfo)
    2.26  #define current_overlay (_this->hidden->overlay)
    2.27  
    2.28  #endif /* _SDL_lowvideo_h */
     3.1 --- a/src/video/bwindow/SDL_sysevents.cc	Sun Jul 18 19:14:33 2004 +0000
     3.2 +++ b/src/video/bwindow/SDL_sysevents.cc	Sun Jul 18 19:36:06 2004 +0000
     3.3 @@ -39,403 +39,12 @@
     3.4  #include "SDL_sysevents.h"
     3.5  #include "SDL_sysevents_c.h"
     3.6  
     3.7 -/* A note on why the polling loops are necessary.
     3.8 -   The BeOS Preview 2 implementation of BView->MouseMoved() only notifies
     3.9 -   the view when the mouse enters or leaves the view.  The documentation 
    3.10 -   says that you should loop and use GetMouse() to detect mouse motion.
    3.11 -   The BeOS Preview 2 implementation of BView->KeyDown() and BView->KeyUp()
    3.12 -   are only called for keys that generate ASCII characters.  Since we want
    3.13 -   to act like a low level raw keyboard, we need to poll the state of the
    3.14 -   keys instead of catching the keys in callbacks.
    3.15 -   These are documented portions of the BeBook for Preview Release 2
    3.16 -*/
    3.17 - 
    3.18 -/* Table to convert scancodes to SDL virtual keys */
    3.19 -static SDLKey keymap[128];
    3.20 -
    3.21 -/* Function to convert from a key scancode to a UNICODE character */
    3.22 -static key_map *be_keymap;
    3.23 -static int32 *option_caps_map[2], *option_map[2], *caps_map[2], *normal_map[2];
    3.24 -static char *unicode_map;
    3.25 -static Uint16 TranslateScancode(int scancode)
    3.26 -{
    3.27 -	SDLMod modstate;
    3.28 -	int shifted;
    3.29 -	int32 index;		/* Index into system unicode map */
    3.30 -	Uint16 unicode;
    3.31 -
    3.32 -	/* Set the default character -- no character */
    3.33 -	unicode = 0;
    3.34 -
    3.35 -	/* See whether or not the shift state is set */
    3.36 -	modstate = SDL_GetModState();
    3.37 -	if ( modstate & KMOD_SHIFT ) {
    3.38 -		shifted = 1;
    3.39 -	} else {
    3.40 -		shifted = 0;
    3.41 -	}
    3.42 -
    3.43 -	if ( modstate & KMOD_NUM ) {
    3.44 -	/* If numlock is on, numeric keypad keys have shift state inverted */
    3.45 -		switch (keymap[scancode]) {
    3.46 -		    case SDLK_KP0:
    3.47 -		    case SDLK_KP1:
    3.48 -		    case SDLK_KP2:
    3.49 -		    case SDLK_KP3:
    3.50 -		    case SDLK_KP4:
    3.51 -		    case SDLK_KP5:
    3.52 -		    case SDLK_KP6:
    3.53 -		    case SDLK_KP7:
    3.54 -		    case SDLK_KP8:
    3.55 -		    case SDLK_KP9:
    3.56 -		    case SDLK_KP_PERIOD:
    3.57 -		    case SDLK_KP_DIVIDE:
    3.58 -		    case SDLK_KP_MULTIPLY:
    3.59 -		    case SDLK_KP_MINUS:
    3.60 -		    case SDLK_KP_PLUS:
    3.61 -		    case SDLK_KP_ENTER:
    3.62 -		    case SDLK_KP_EQUALS:
    3.63 -			shifted = !shifted;
    3.64 -			break;
    3.65 -		    default:
    3.66 -			break;
    3.67 -		}
    3.68 -	}
    3.69 -
    3.70 -	/* Get the index based on modifier state */
    3.71 -	if ( modstate & KMOD_CTRL )
    3.72 -		index = be_keymap->control_map[scancode];
    3.73 -	else
    3.74 -	if ( (modstate & KMOD_META) && (modstate & KMOD_CAPS) )
    3.75 -		index = option_caps_map[shifted][scancode];
    3.76 -	else
    3.77 -	if ( modstate & KMOD_META )
    3.78 -		index = option_map[shifted][scancode];
    3.79 -	else
    3.80 -	if ( modstate & KMOD_CAPS )
    3.81 -		index = caps_map[shifted][scancode];
    3.82 -	else
    3.83 -		index = normal_map[shifted][scancode];
    3.84 -
    3.85 -	/* If there is a mapping, convert character from UTF-8 to UNICODE */
    3.86 -	if ( unicode_map[index] ) {
    3.87 -		int32 state, srclen, dstlen;
    3.88 -		unsigned char destbuf[2];
    3.89 -
    3.90 -		state = 0;
    3.91 -		srclen = unicode_map[index++];
    3.92 -		dstlen = sizeof(destbuf);
    3.93 -		convert_from_utf8(B_UNICODE_CONVERSION,
    3.94 -			&unicode_map[index], &srclen, (char *)destbuf, &dstlen,
    3.95 -									&state);
    3.96 -		unicode = destbuf[0];
    3.97 -		unicode <<= 8;
    3.98 -		unicode |= destbuf[1];
    3.99 -
   3.100 -		/* Keyboard input maps newline to carriage return */
   3.101 -		if ( unicode == '\n' ) {
   3.102 -			unicode = '\r';
   3.103 -		}
   3.104 -
   3.105 -		/* For some reason function keys map to control characters */
   3.106 -# define CTRL(X)	((X)-'@')
   3.107 -		switch (unicode) {
   3.108 -		    case CTRL('A'):
   3.109 -		    case CTRL('B'):
   3.110 -		    case CTRL('C'):
   3.111 -		    case CTRL('D'):
   3.112 -		    case CTRL('E'):
   3.113 -		    case CTRL('K'):
   3.114 -		    case CTRL('L'):
   3.115 -		    case CTRL('P'):
   3.116 -			if ( ! (modstate & KMOD_CTRL) )
   3.117 -				unicode = 0;
   3.118 -			break;
   3.119 -		    default:
   3.120 -			break;
   3.121 -		}
   3.122 -	}
   3.123 -	return(unicode);
   3.124 -}
   3.125 -
   3.126 -/* Function to translate a keyboard transition and queue the key event */
   3.127 -static void QueueKey(int scancode, int pressed)
   3.128 -{
   3.129 -	SDL_keysym keysym;
   3.130 -
   3.131 -	/* Set the keysym information */
   3.132 -	keysym.scancode = scancode;
   3.133 -	keysym.sym = keymap[scancode];
   3.134 -	keysym.mod = KMOD_NONE;
   3.135 -	if ( SDL_TranslateUNICODE ) {
   3.136 -		keysym.unicode = TranslateScancode(scancode);
   3.137 -	} else {
   3.138 -		keysym.unicode = 0;
   3.139 -	}
   3.140 -
   3.141 -	/* NUMLOCK and CAPSLOCK are implemented as double-presses in reality */
   3.142 -	if ( (keysym.sym == SDLK_NUMLOCK) || (keysym.sym == SDLK_CAPSLOCK) ) {
   3.143 -		pressed = 1;
   3.144 -	}
   3.145 -
   3.146 -	/* Queue the key event */
   3.147 -	if ( pressed ) {
   3.148 -		SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   3.149 -	} else {
   3.150 -		SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   3.151 -	}
   3.152 -}
   3.153 -
   3.154 -/* This is special because we know it will be run in a loop in a separate
   3.155 -   thread.  Normally this function should loop as long as there are input
   3.156 -   states changing, i.e. new events arriving.
   3.157 -*/
   3.158  void BE_PumpEvents(_THIS)
   3.159  {
   3.160 -	BView *view;
   3.161 -	BRect bounds;
   3.162 -	BPoint point;
   3.163 -	uint32 buttons;
   3.164 -	const uint32 button_masks[3] = {
   3.165 -		B_PRIMARY_MOUSE_BUTTON,
   3.166 -		B_TERTIARY_MOUSE_BUTTON, 
   3.167 -		B_SECONDARY_MOUSE_BUTTON,
   3.168 -	};
   3.169 -	unsigned int    i, j;
   3.170 -
   3.171 -	/* Check out the mouse buttons and position (slight race condition) */
   3.172 -	if ( SDL_Win->Lock() ) {
   3.173 -		/* Don't do anything if we have no view */
   3.174 -		view = SDL_Win->View();
   3.175 -		if ( ! view ) {
   3.176 -			SDL_Win->Unlock();
   3.177 -			return;
   3.178 -		}
   3.179 -		bounds = view->Bounds();
   3.180 -		/* Get new input state, if still active */
   3.181 -		if ( SDL_Win->IsActive() ) {
   3.182 -			key_flip = !key_flip;
   3.183 -			get_key_info(&keyinfo[key_flip]);
   3.184 -			view->GetMouse(&point, &buttons, true);
   3.185 -		} else {
   3.186 -			key_flip = key_flip;
   3.187 -			point = last_point;
   3.188 -			buttons = last_buttons;
   3.189 -		}
   3.190 -		SDL_Win->Unlock();
   3.191 -	} else {
   3.192 -		return;
   3.193 -	}
   3.194 -
   3.195 -	/* If our view is active, we'll find key changes here */
   3.196 -	if ( memcmp(keyinfo[0].key_states, keyinfo[1].key_states, 16) != 0 ) {
   3.197 -		for ( i=0; i<16; ++i ) {
   3.198 -			Uint8 new_state, transition;
   3.199 -
   3.200 -			new_state = keyinfo[key_flip].key_states[i];
   3.201 -			transition = keyinfo[!key_flip].key_states[i] ^
   3.202 -					keyinfo[ key_flip].key_states[i];
   3.203 -			for ( j=0; j<8; ++j ) {
   3.204 -				if ( transition&0x80 )
   3.205 -					QueueKey(i*8+j, new_state&0x80);
   3.206 -				transition <<= 1;
   3.207 -				new_state <<= 1;
   3.208 -			}
   3.209 -		}
   3.210 -	}
   3.211 -
   3.212 -	/* We check keyboard, but not mouse if mouse isn't in window */
   3.213 -	if ( ! bounds.Contains(point) ) {
   3.214 -		/* Mouse moved outside our view? */
   3.215 -		if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
   3.216 -			SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   3.217 -			be_app->SetCursor(B_HAND_CURSOR);
   3.218 -		}
   3.219 -		return;
   3.220 -	}
   3.221 -	/* Has the mouse moved back into our view? */
   3.222 -	if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   3.223 -		/* Reset the B_HAND_CURSOR to our own */
   3.224 -		SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   3.225 -		SDL_SetCursor(NULL);
   3.226 -	}
   3.227 -
   3.228 -	/* Check for mouse motion */
   3.229 -	if ( point != last_point ) {
   3.230 -		int x, y;
   3.231 -
   3.232 -		SDL_Win->GetXYOffset(x, y);
   3.233 -		x = (int)point.x - x;
   3.234 -		y = (int)point.y - y;
   3.235 -		SDL_PrivateMouseMotion(0, 0, x, y);
   3.236 -	}
   3.237 -	last_point = point;
   3.238 -
   3.239 -	/* Add any mouse button events */
   3.240 -	for ( i=0; i<SDL_TABLESIZE(button_masks); ++i ) {
   3.241 -		if ( (buttons ^ last_buttons) & button_masks[i] ) {
   3.242 -			if ( buttons & button_masks[i] ) {
   3.243 -				SDL_PrivateMouseButton(SDL_PRESSED, 1+i, 0, 0);
   3.244 -			} else {
   3.245 -				SDL_PrivateMouseButton(SDL_RELEASED, 1+i, 0, 0);
   3.246 -			}
   3.247 -		}
   3.248 -	}
   3.249 -	last_buttons = buttons;
   3.250  }
   3.251  
   3.252  void BE_InitOSKeymap(_THIS)
   3.253  {
   3.254 -	unsigned int i;
   3.255 -
   3.256 -	/* Initialize the keyboard state */
   3.257 -	key_flip = 0;
   3.258 -	get_key_info(&keyinfo[key_flip]);
   3.259 -	memcpy(keyinfo[!key_flip].key_states,
   3.260 -	       keyinfo[key_flip].key_states,
   3.261 -	       SDL_TABLESIZE(keyinfo[key_flip].key_states));
   3.262 -
   3.263 -	/* Initialize the BeOS key translation table */
   3.264 -	/* Source: <be/interface/InterfaceDefs.h> and BeOS keyboard info */
   3.265 -	for ( i=0; i<SDL_TABLESIZE(keymap); ++i )
   3.266 -		keymap[i] = SDLK_UNKNOWN;
   3.267 -
   3.268 -	keymap[0x01]		= SDLK_ESCAPE;
   3.269 -	keymap[B_F1_KEY]	= SDLK_F1;
   3.270 -	keymap[B_F2_KEY]	= SDLK_F2;
   3.271 -	keymap[B_F3_KEY]	= SDLK_F3;
   3.272 -	keymap[B_F4_KEY]	= SDLK_F4;
   3.273 -	keymap[B_F5_KEY]	= SDLK_F5;
   3.274 -	keymap[B_F6_KEY]	= SDLK_F6;
   3.275 -	keymap[B_F7_KEY]	= SDLK_F7;
   3.276 -	keymap[B_F8_KEY]	= SDLK_F8;
   3.277 -	keymap[B_F9_KEY]	= SDLK_F9;
   3.278 -	keymap[B_F10_KEY]	= SDLK_F10;
   3.279 -	keymap[B_F11_KEY]	= SDLK_F11;
   3.280 -	keymap[B_F12_KEY]	= SDLK_F12;
   3.281 -	keymap[B_PRINT_KEY]	= SDLK_PRINT;
   3.282 -	//keymap[B_SCROLL_KEY]	= SDLK_SCROLLOCK;
   3.283 -	keymap[B_PAUSE_KEY]	= SDLK_PAUSE;
   3.284 -	keymap[0x11]		= SDLK_BACKQUOTE;
   3.285 -	keymap[0x12]		= SDLK_1;
   3.286 -	keymap[0x13]		= SDLK_2;
   3.287 -	keymap[0x14]		= SDLK_3;
   3.288 -	keymap[0x15]		= SDLK_4;
   3.289 -	keymap[0x16]		= SDLK_5;
   3.290 -	keymap[0x17]		= SDLK_6;
   3.291 -	keymap[0x18]		= SDLK_7;
   3.292 -	keymap[0x19]		= SDLK_8;
   3.293 -	keymap[0x1a]		= SDLK_9;
   3.294 -	keymap[0x1b]		= SDLK_0;
   3.295 -	keymap[0x1c]		= SDLK_MINUS;
   3.296 -	keymap[0x1d]		= SDLK_EQUALS;
   3.297 -	keymap[0x1e]		= SDLK_BACKSPACE;
   3.298 -	keymap[0x1f]		= SDLK_INSERT;
   3.299 -	keymap[0x20]		= SDLK_HOME;
   3.300 -	keymap[0x21]		= SDLK_PAGEUP;
   3.301 -	//keymap[0x22]		= SDLK_NUMLOCK;
   3.302 -	keymap[0x23]		= SDLK_KP_DIVIDE;
   3.303 -	keymap[0x24]		= SDLK_KP_MULTIPLY;
   3.304 -	keymap[0x25]		= SDLK_KP_MINUS;
   3.305 -	keymap[0x26]		= SDLK_TAB;
   3.306 -	keymap[0x27]		= SDLK_q;
   3.307 -	keymap[0x28]		= SDLK_w;
   3.308 -	keymap[0x29]		= SDLK_e;
   3.309 -	keymap[0x2a]		= SDLK_r;
   3.310 -	keymap[0x2b]		= SDLK_t;
   3.311 -	keymap[0x2c]		= SDLK_y;
   3.312 -	keymap[0x2d]		= SDLK_u;
   3.313 -	keymap[0x2e]		= SDLK_i;
   3.314 -	keymap[0x2f]		= SDLK_o;
   3.315 -	keymap[0x30]		= SDLK_p;
   3.316 -	keymap[0x31]		= SDLK_LEFTBRACKET;
   3.317 -	keymap[0x32]		= SDLK_RIGHTBRACKET;
   3.318 -	keymap[0x33]		= SDLK_BACKSLASH;
   3.319 -	keymap[0x34]		= SDLK_DELETE;
   3.320 -	keymap[0x35]		= SDLK_END;
   3.321 -	keymap[0x36]		= SDLK_PAGEDOWN;
   3.322 -	keymap[0x37]		= SDLK_KP7;
   3.323 -	keymap[0x38]		= SDLK_KP8;
   3.324 -	keymap[0x39]		= SDLK_KP9;
   3.325 -	keymap[0x3a]		= SDLK_KP_PLUS;
   3.326 -	//keymap[0x3b]		= SDLK_CAPSLOCK;
   3.327 -	keymap[0x3c]		= SDLK_a;
   3.328 -	keymap[0x3d]		= SDLK_s;
   3.329 -	keymap[0x3e]		= SDLK_d;
   3.330 -	keymap[0x3f]		= SDLK_f;
   3.331 -	keymap[0x40]		= SDLK_g;
   3.332 -	keymap[0x41]		= SDLK_h;
   3.333 -	keymap[0x42]		= SDLK_j;
   3.334 -	keymap[0x43]		= SDLK_k;
   3.335 -	keymap[0x44]		= SDLK_l;
   3.336 -	keymap[0x45]		= SDLK_SEMICOLON;
   3.337 -	keymap[0x46]		= SDLK_QUOTE;
   3.338 -	keymap[0x47]		= SDLK_RETURN;
   3.339 -	keymap[0x48]		= SDLK_KP4;
   3.340 -	keymap[0x49]		= SDLK_KP5;
   3.341 -	keymap[0x4a]		= SDLK_KP6;
   3.342 -	keymap[0x4b]		= SDLK_LSHIFT;
   3.343 -	keymap[0x4c]		= SDLK_z;
   3.344 -	keymap[0x4d]		= SDLK_x;
   3.345 -	keymap[0x4e]		= SDLK_c;
   3.346 -	keymap[0x4f]		= SDLK_v;
   3.347 -	keymap[0x50]		= SDLK_b;
   3.348 -	keymap[0x51]		= SDLK_n;
   3.349 -	keymap[0x52]		= SDLK_m;
   3.350 -	keymap[0x53]		= SDLK_COMMA;
   3.351 -	keymap[0x54]		= SDLK_PERIOD;
   3.352 -	keymap[0x55]		= SDLK_SLASH;
   3.353 -	keymap[0x56]		= SDLK_RSHIFT;
   3.354 -	keymap[0x57]		= SDLK_UP;
   3.355 -	keymap[0x58]		= SDLK_KP1;
   3.356 -	keymap[0x59]		= SDLK_KP2;
   3.357 -	keymap[0x5a]		= SDLK_KP3;
   3.358 -	keymap[0x5b]		= SDLK_KP_ENTER;
   3.359 -	//keymap[0x5c]		= SDLK_LCTRL;
   3.360 -	//keymap[0x5d]		= SDLK_LALT;
   3.361 -	keymap[0x5e]		= SDLK_SPACE;
   3.362 -	//keymap[0x5f]		= SDLK_RALT;
   3.363 -	//keymap[0x60]		= SDLK_RCTRL;
   3.364 -	keymap[0x61]		= SDLK_LEFT;
   3.365 -	keymap[0x62]		= SDLK_DOWN;
   3.366 -	keymap[0x63]		= SDLK_RIGHT;
   3.367 -	keymap[0x64]		= SDLK_KP0;
   3.368 -	keymap[0x65]		= SDLK_KP_PERIOD;
   3.369 -	//keymap[0x66]		= SDLK_LMETA;
   3.370 -	//keymap[0x67]		= SDLK_RMETA;
   3.371 -	//keymap[0x68]		= SDLK_MENU;
   3.372 -	keymap[0x69]		= SDLK_EURO;
   3.373 -	keymap[0x6a]		= SDLK_KP_EQUALS;
   3.374 -	keymap[0x6b]		= SDLK_POWER;
   3.375 -
   3.376 -	/* Get the system keymap and UNICODE table.
   3.377 -	   Note that this leaks memory since the maps are never freed.
   3.378 -	 */
   3.379 -	get_key_map(&be_keymap, &unicode_map);
   3.380 -
   3.381 -	/* Set the modifier keys from the system keymap */
   3.382 -	keymap[be_keymap->caps_key] = SDLK_CAPSLOCK;
   3.383 -	keymap[be_keymap->scroll_key] = SDLK_SCROLLOCK;
   3.384 -	keymap[be_keymap->num_key] = SDLK_NUMLOCK;
   3.385 -	keymap[be_keymap->left_shift_key] = SDLK_LSHIFT;
   3.386 -	keymap[be_keymap->right_shift_key] = SDLK_RSHIFT;
   3.387 -	keymap[be_keymap->left_command_key] = SDLK_LALT;
   3.388 -	keymap[be_keymap->right_command_key] = SDLK_RALT;
   3.389 -	keymap[be_keymap->left_control_key] = SDLK_LCTRL;
   3.390 -	keymap[be_keymap->right_control_key] = SDLK_RCTRL;
   3.391 -	keymap[be_keymap->left_option_key] = SDLK_LMETA;
   3.392 -	keymap[be_keymap->right_option_key] = SDLK_RMETA;
   3.393 -	keymap[be_keymap->menu_key] = SDLK_MENU;
   3.394 -
   3.395 -	/* Set the modifier map pointers */
   3.396 -	option_caps_map[0] = be_keymap->option_caps_map;
   3.397 -	option_caps_map[1] = be_keymap->option_caps_shift_map;
   3.398 -	option_map[0] = be_keymap->option_map;
   3.399 -	option_map[1] = be_keymap->option_shift_map;
   3.400 -	caps_map[0] = be_keymap->caps_map;
   3.401 -	caps_map[1] = be_keymap->caps_shift_map;
   3.402 -	normal_map[0] = be_keymap->normal_map;
   3.403 -	normal_map[1] = be_keymap->shift_map;
   3.404  }
   3.405  
   3.406  }; /* Extern C */