Fixed bug #286 SDL-1.2
authorSam Lantinga <slouken@libsdl.org>
Sun, 24 Sep 2006 15:31:42 +0000
branchSDL-1.2
changeset 3878678576473849
parent 3877 81f66f258d77
child 3879 c82c1870c77a
Fixed bug #286
Date: Thu, 9 Feb 2006 17:06:51 +0300
From: "Oleg K [BeSman]"
Subject: BeOS SDL patches

Hello all. My name is Oleg K. [BeSman], Im a BeOS user from Russia.This mail
contain a BeOs-specific patches to SDL (implementation of InputGrabbing and
mouse_relative mode). See the source in attached file for details.
src/video/bwindow/SDL_BView.h
src/video/bwindow/SDL_BWin.h
src/video/bwindow/SDL_sysevents.cc
src/video/bwindow/SDL_sysmouse.cc
src/video/bwindow/SDL_sysmouse_c.h
src/video/bwindow/SDL_sysvideo.cc
src/video/bwindow/SDL_syswm.cc
src/video/bwindow/SDL_syswm_c.h
     1.1 --- a/src/video/bwindow/SDL_BView.h	Sun Sep 24 01:27:40 2006 +0000
     1.2 +++ b/src/video/bwindow/SDL_BView.h	Sun Sep 24 15:31:42 2006 +0000
     1.3 @@ -37,22 +37,12 @@
     1.4  		BView(frame, "SDL View", B_FOLLOW_ALL_SIDES,
     1.5  					(B_WILL_DRAW|B_FRAME_EVENTS)) {
     1.6  		image = NULL;
     1.7 -		xoff = yoff = 0;
     1.8  		SetViewColor(0,0,0,0);
     1.9  		SetHighColor(0,0,0,0);
    1.10  	}
    1.11  	virtual ~SDL_BView() {
    1.12  		SetBitmap(NULL);
    1.13  	}
    1.14 -	/* Set drawing offsets for fullscreen mode */
    1.15 -	virtual void SetXYOffset(int x, int y) {
    1.16 -		xoff = x;
    1.17 -		yoff = y;
    1.18 -	}
    1.19 -	virtual void GetXYOffset(int &x, int &y) {
    1.20 -		x = xoff;
    1.21 -		y = yoff;
    1.22 -	}
    1.23  	/* The view changed size. If it means we're in fullscreen, we
    1.24  	 * draw a nice black box in the entire view to get black borders.
    1.25  	 */
    1.26 @@ -62,14 +52,14 @@
    1.27  		bounds.right = width;
    1.28  		bounds.bottom = height;
    1.29  		/* Fill the entire view with black */ 
    1.30 -		FillRect(bounds, B_SOLID_HIGH);
    1.31 +//		FillRect(bounds, B_SOLID_HIGH);
    1.32  		/* And if there's an image, redraw it. */
    1.33  		if( image ) {
    1.34  			bounds = image->Bounds();
    1.35  			Draw(bounds);
    1.36  		}
    1.37  	}
    1.38 -	
    1.39 +
    1.40  	/* Drawing portion of this complete breakfast. :) */
    1.41  	virtual void SetBitmap(BBitmap *bitmap) {
    1.42  		if ( image ) {
    1.43 @@ -79,34 +69,17 @@
    1.44  	}
    1.45  	virtual void Draw(BRect updateRect) {
    1.46  		if ( image ) {
    1.47 -			if(xoff || yoff) {	
    1.48 -				BRect dest;
    1.49 -				dest.top    = updateRect.top + yoff;
    1.50 -				dest.left   = updateRect.left + xoff;
    1.51 -				dest.bottom = updateRect.bottom + yoff;
    1.52 -				dest.right  = updateRect.right + xoff;
    1.53 -				DrawBitmap(image, updateRect, dest);
    1.54 -			} else {
    1.55 -				DrawBitmap(image, updateRect, updateRect);
    1.56 -			}
    1.57 +			DrawBitmap(image, updateRect, updateRect);
    1.58  		}
    1.59  	}
    1.60  	virtual void DrawAsync(BRect updateRect) {
    1.61 -		if(xoff || yoff) {	
    1.62 -			BRect dest;
    1.63 -			dest.top    = updateRect.top + yoff;
    1.64 -			dest.left   = updateRect.left + xoff;
    1.65 -			dest.bottom = updateRect.bottom + yoff;
    1.66 -			dest.right  = updateRect.right + xoff;;
    1.67 -			DrawBitmapAsync(image, updateRect, dest);
    1.68 -		} else {
    1.69 +		if ( image ) {
    1.70  			DrawBitmapAsync(image, updateRect, updateRect);
    1.71  		}
    1.72  	}
    1.73  
    1.74  private:
    1.75  	BBitmap *image;
    1.76 -	int xoff, yoff;
    1.77  };
    1.78  
    1.79  #endif /* _SDL_BView_h */
     2.1 --- a/src/video/bwindow/SDL_BWin.h	Sun Sep 24 01:27:40 2006 +0000
     2.2 +++ b/src/video/bwindow/SDL_BWin.h	Sun Sep 24 15:31:42 2006 +0000
     2.3 @@ -40,6 +40,8 @@
     2.4  
     2.5  extern "C" {
     2.6  #include "../../events/SDL_events_c.h"
     2.7 +
     2.8 +extern int mouse_relative;
     2.9  };
    2.10  
    2.11  class SDL_BWin : public BDirectWindow
    2.12 @@ -47,9 +49,7 @@
    2.13  public:
    2.14  	SDL_BWin(BRect bounds) :
    2.15  			BDirectWindow(bounds, "Untitled", B_TITLED_WINDOW, 0) {
    2.16 -		InitKeyboard();
    2.17  		last_buttons = 0;
    2.18 -
    2.19  		the_view = NULL;
    2.20  #if SDL_VIDEO_OPENGL
    2.21  		SDL_GLView = NULL;
    2.22 @@ -82,118 +82,6 @@
    2.23  		}
    2.24  	}
    2.25  	
    2.26 -	virtual void InitKeyboard(void) {
    2.27 -		for ( uint i=0; i<SDL_TABLESIZE(keymap); ++i )
    2.28 -			keymap[i] = SDLK_UNKNOWN;
    2.29 -
    2.30 -		keymap[0x01]		= SDLK_ESCAPE;
    2.31 -		keymap[B_F1_KEY]	= SDLK_F1;
    2.32 -		keymap[B_F2_KEY]	= SDLK_F2;
    2.33 -		keymap[B_F3_KEY]	= SDLK_F3;
    2.34 -		keymap[B_F4_KEY]	= SDLK_F4;
    2.35 -		keymap[B_F5_KEY]	= SDLK_F5;
    2.36 -		keymap[B_F6_KEY]	= SDLK_F6;
    2.37 -		keymap[B_F7_KEY]	= SDLK_F7;
    2.38 -		keymap[B_F8_KEY]	= SDLK_F8;
    2.39 -		keymap[B_F9_KEY]	= SDLK_F9;
    2.40 -		keymap[B_F10_KEY]	= SDLK_F10;
    2.41 -		keymap[B_F11_KEY]	= SDLK_F11;
    2.42 -		keymap[B_F12_KEY]	= SDLK_F12;
    2.43 -		keymap[B_PRINT_KEY]	= SDLK_PRINT;
    2.44 -		keymap[B_SCROLL_KEY]	= SDLK_SCROLLOCK;
    2.45 -		keymap[B_PAUSE_KEY]	= SDLK_PAUSE;
    2.46 -		keymap[0x11]		= SDLK_BACKQUOTE;
    2.47 -		keymap[0x12]		= SDLK_1;
    2.48 -		keymap[0x13]		= SDLK_2;
    2.49 -		keymap[0x14]		= SDLK_3;
    2.50 -		keymap[0x15]		= SDLK_4;
    2.51 -		keymap[0x16]		= SDLK_5;
    2.52 -		keymap[0x17]		= SDLK_6;
    2.53 -		keymap[0x18]		= SDLK_7;
    2.54 -		keymap[0x19]		= SDLK_8;
    2.55 -		keymap[0x1a]		= SDLK_9;
    2.56 -		keymap[0x1b]		= SDLK_0;
    2.57 -		keymap[0x1c]		= SDLK_MINUS;
    2.58 -		keymap[0x1d]		= SDLK_EQUALS;
    2.59 -		keymap[0x1e]		= SDLK_BACKSPACE;
    2.60 -		keymap[0x1f]		= SDLK_INSERT;
    2.61 -		keymap[0x20]		= SDLK_HOME;
    2.62 -		keymap[0x21]		= SDLK_PAGEUP;
    2.63 -		keymap[0x22]		= SDLK_NUMLOCK;
    2.64 -		keymap[0x23]		= SDLK_KP_DIVIDE;
    2.65 -		keymap[0x24]		= SDLK_KP_MULTIPLY;
    2.66 -		keymap[0x25]		= SDLK_KP_MINUS;
    2.67 -		keymap[0x26]		= SDLK_TAB;
    2.68 -		keymap[0x27]		= SDLK_q;
    2.69 -		keymap[0x28]		= SDLK_w;
    2.70 -		keymap[0x29]		= SDLK_e;
    2.71 -		keymap[0x2a]		= SDLK_r;
    2.72 -		keymap[0x2b]		= SDLK_t;
    2.73 -		keymap[0x2c]		= SDLK_y;
    2.74 -		keymap[0x2d]		= SDLK_u;
    2.75 -		keymap[0x2e]		= SDLK_i;
    2.76 -		keymap[0x2f]		= SDLK_o;
    2.77 -		keymap[0x30]		= SDLK_p;
    2.78 -		keymap[0x31]		= SDLK_LEFTBRACKET;
    2.79 -		keymap[0x32]		= SDLK_RIGHTBRACKET;
    2.80 -		keymap[0x33]		= SDLK_BACKSLASH;
    2.81 -		keymap[0x34]		= SDLK_DELETE;
    2.82 -		keymap[0x35]		= SDLK_END;
    2.83 -		keymap[0x36]		= SDLK_PAGEDOWN;
    2.84 -		keymap[0x37]		= SDLK_KP7;
    2.85 -		keymap[0x38]		= SDLK_KP8;
    2.86 -		keymap[0x39]		= SDLK_KP9;
    2.87 -		keymap[0x3a]		= SDLK_KP_PLUS;
    2.88 -		keymap[0x3b]		= SDLK_CAPSLOCK;
    2.89 -		keymap[0x3c]		= SDLK_a;
    2.90 -		keymap[0x3d]		= SDLK_s;
    2.91 -		keymap[0x3e]		= SDLK_d;
    2.92 -		keymap[0x3f]		= SDLK_f;
    2.93 -		keymap[0x40]		= SDLK_g;
    2.94 -		keymap[0x41]		= SDLK_h;
    2.95 -		keymap[0x42]		= SDLK_j;
    2.96 -		keymap[0x43]		= SDLK_k;
    2.97 -		keymap[0x44]		= SDLK_l;
    2.98 -		keymap[0x45]		= SDLK_SEMICOLON;
    2.99 -		keymap[0x46]		= SDLK_QUOTE;
   2.100 -		keymap[0x47]		= SDLK_RETURN;
   2.101 -		keymap[0x48]		= SDLK_KP4;
   2.102 -		keymap[0x49]		= SDLK_KP5;
   2.103 -		keymap[0x4a]		= SDLK_KP6;
   2.104 -		keymap[0x4b]		= SDLK_LSHIFT;
   2.105 -		keymap[0x4c]		= SDLK_z;
   2.106 -		keymap[0x4d]		= SDLK_x;
   2.107 -		keymap[0x4e]		= SDLK_c;
   2.108 -		keymap[0x4f]		= SDLK_v;
   2.109 -		keymap[0x50]		= SDLK_b;
   2.110 -		keymap[0x51]		= SDLK_n;
   2.111 -		keymap[0x52]		= SDLK_m;
   2.112 -		keymap[0x53]		= SDLK_COMMA;
   2.113 -		keymap[0x54]		= SDLK_PERIOD;
   2.114 -		keymap[0x55]		= SDLK_SLASH;
   2.115 -		keymap[0x56]		= SDLK_RSHIFT;
   2.116 -		keymap[0x57]		= SDLK_UP;
   2.117 -		keymap[0x58]		= SDLK_KP1;
   2.118 -		keymap[0x59]		= SDLK_KP2;
   2.119 -		keymap[0x5a]		= SDLK_KP3;
   2.120 -		keymap[0x5b]		= SDLK_KP_ENTER;
   2.121 -		keymap[0x5c]		= SDLK_LCTRL;
   2.122 -		keymap[0x5d]		= SDLK_LALT;
   2.123 -		keymap[0x5e]		= SDLK_SPACE;
   2.124 -		keymap[0x5f]		= SDLK_RALT;
   2.125 -		keymap[0x60]		= SDLK_RCTRL;
   2.126 -		keymap[0x61]		= SDLK_LEFT;
   2.127 -		keymap[0x62]		= SDLK_DOWN;
   2.128 -		keymap[0x63]		= SDLK_RIGHT;
   2.129 -		keymap[0x64]		= SDLK_KP0;
   2.130 -		keymap[0x65]		= SDLK_KP_PERIOD;
   2.131 -		keymap[0x66]		= SDLK_LMETA;
   2.132 -		keymap[0x67]		= SDLK_RMETA;
   2.133 -		keymap[0x68]		= SDLK_MENU;
   2.134 -		keymap[0x69]		= SDLK_EURO;
   2.135 -		keymap[0x6a]		= SDLK_KP_EQUALS;
   2.136 -		keymap[0x6b]		= SDLK_POWER;
   2.137 -	}
   2.138  
   2.139  	/* Override the Show() method so we can tell when we've been shown */
   2.140  	virtual void Show(void) {
   2.141 @@ -261,24 +149,6 @@
   2.142  	virtual void SetBitmap(BBitmap *bitmap) {
   2.143  		SDL_View->SetBitmap(bitmap);
   2.144  	}
   2.145 -	virtual void SetXYOffset(int x, int y) {
   2.146 -#if SDL_VIDEO_OPENGL
   2.147 -		if ( the_view == SDL_GLView ) {
   2.148 -			return;
   2.149 -		}
   2.150 -#endif
   2.151 -		SDL_View->SetXYOffset(x, y);		
   2.152 -	}
   2.153 -	virtual void GetXYOffset(int &x, int &y) {
   2.154 -#if SDL_VIDEO_OPENGL
   2.155 -		if ( the_view == SDL_GLView ) {
   2.156 -			x = 0;
   2.157 -			y = 0;
   2.158 -			return;
   2.159 -		}
   2.160 -#endif
   2.161 -		SDL_View->GetXYOffset(x, y);
   2.162 -	}
   2.163  	virtual bool BeginDraw(void) {
   2.164  		return(Lock());
   2.165  	}
   2.166 @@ -367,179 +237,7 @@
   2.167  		return unicode;
   2.168  	}
   2.169  
   2.170 -	virtual void DispatchMessage(BMessage *msg, BHandler *target) {
   2.171 -		switch (msg->what) {
   2.172 -			case B_MOUSE_MOVED:
   2.173 -			{
   2.174 -				BPoint where;
   2.175 -				int32 transit;
   2.176 -				if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
   2.177 -					if (transit == B_EXITED_VIEW) {
   2.178 -						if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
   2.179 -							SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   2.180 -							be_app->SetCursor(B_HAND_CURSOR);
   2.181 -						}
   2.182 -					} else {
   2.183 -						int x, y;
   2.184 -						if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   2.185 -							SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   2.186 -							SDL_SetCursor(NULL);
   2.187 -						}
   2.188 -						GetXYOffset(x, y);
   2.189 -						x = (int)where.x - x;
   2.190 -						y = (int)where.y - y;
   2.191 -						SDL_PrivateMouseMotion(0, 0, x, y);
   2.192 -					}
   2.193 -				}
   2.194 -				break;
   2.195 -			}
   2.196 -
   2.197 -			case B_MOUSE_DOWN:
   2.198 -			{
   2.199 -				/*	it looks like mouse down is send only for first clicked
   2.200 -					button, each next is not send while last one is holded */
   2.201 -				int32 buttons;
   2.202 -				int sdl_buttons = 0;
   2.203 -				if (msg->FindInt32("buttons", &buttons) == B_OK) {
   2.204 -					/* Add any mouse button events */
   2.205 -					if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   2.206 -						sdl_buttons |= SDL_BUTTON_LEFT;
   2.207 -					}
   2.208 -					if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   2.209 -						sdl_buttons |= SDL_BUTTON_RIGHT;
   2.210 -					}
   2.211 -					if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   2.212 -						sdl_buttons |= SDL_BUTTON_MIDDLE;
   2.213 -					}
   2.214 -					SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
   2.215 -
   2.216 -					last_buttons = buttons;
   2.217 -				}
   2.218 -				break;
   2.219 -			}
   2.220 -
   2.221 -			case B_MOUSE_UP:
   2.222 -			{
   2.223 -				/*	mouse up doesn't give which button was released,
   2.224 -					only state of buttons (after release, so it's always = 0),
   2.225 -					which is not what we need ;]
   2.226 -					So we need to store button in mouse down, and restore
   2.227 -					in mouse up :(
   2.228 -					mouse up is (similarly to mouse down) send only for
   2.229 -					first button down (ie. it's no send if we click another button
   2.230 -					without releasing previous one first) - but that's probably
   2.231 -					because of how drivers are written?, not BeOS itself. */
   2.232 -				int32 buttons;
   2.233 -				int sdl_buttons = 0;
   2.234 -				if (msg->FindInt32("buttons", &buttons) == B_OK) {
   2.235 -					/* Add any mouse button events */
   2.236 -					if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   2.237 -						sdl_buttons |= SDL_BUTTON_LEFT;
   2.238 -					}
   2.239 -					if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   2.240 -						sdl_buttons |= SDL_BUTTON_RIGHT;
   2.241 -					}
   2.242 -					if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   2.243 -						sdl_buttons |= SDL_BUTTON_MIDDLE;
   2.244 -					}
   2.245 -					SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
   2.246 -
   2.247 -					last_buttons = buttons;
   2.248 -				}
   2.249 -				break;
   2.250 -			}
   2.251 -
   2.252 -			case B_MOUSE_WHEEL_CHANGED:
   2.253 -			{
   2.254 -				float x, y;
   2.255 -				x = y = 0;
   2.256 -				if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   2.257 -					if (x < 0 || y < 0) {
   2.258 -						SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   2.259 -						SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   2.260 -					} else if (x > 0 || y > 0) {
   2.261 -						SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   2.262 -						SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   2.263 -					}
   2.264 -				}
   2.265 -				break;
   2.266 -			}
   2.267 -
   2.268 -			case B_KEY_DOWN:
   2.269 -			case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
   2.270 -			{
   2.271 -				int32 key;
   2.272 -				int32 modifiers;
   2.273 -				int32 key_repeat;
   2.274 -				/* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
   2.275 -				if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK && key_repeat > 0)
   2.276 -					break;
   2.277 -
   2.278 -				if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   2.279 -					SDL_keysym keysym;
   2.280 -					keysym.scancode = key;
   2.281 -					if ((key > 0) && (key < 128)) {
   2.282 -						keysym.sym = keymap[key];
   2.283 -					} else {
   2.284 -						keysym.sym = SDLK_UNKNOWN;
   2.285 -					}
   2.286 -					/*	FIX THIS?
   2.287 -						it seems SDL_PrivateKeyboard() changes mod value
   2.288 -						anyway, and doesn't care about what we setup here */
   2.289 -					keysym.mod = KMOD_NONE;
   2.290 -					keysym.unicode = 0;
   2.291 -					if (SDL_TranslateUNICODE) {
   2.292 -						const char *bytes;
   2.293 -						if (msg->FindString("bytes", &bytes) == B_OK) {
   2.294 -							/*	FIX THIS?
   2.295 -								this cares only about first "letter",
   2.296 -								so if someone maps some key to print
   2.297 -								"BeOS rulez!" only "B" will be used. */
   2.298 -							keysym.unicode = Translate2Unicode(bytes);
   2.299 -						}
   2.300 -					}
   2.301 -					SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   2.302 -				}
   2.303 -				break;
   2.304 -			}
   2.305 -
   2.306 -			case B_KEY_UP:
   2.307 -			case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
   2.308 -			{
   2.309 -				int32 key;
   2.310 -				int32 modifiers;
   2.311 -				if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   2.312 -					SDL_keysym keysym;
   2.313 -					keysym.scancode = key;
   2.314 -					if ((key > 0) && (key < 128)) {
   2.315 -						keysym.sym = keymap[key];
   2.316 -					} else {
   2.317 -						keysym.sym = SDLK_UNKNOWN;
   2.318 -					}
   2.319 -					keysym.mod = KMOD_NONE; /* FIX THIS? */
   2.320 -					keysym.unicode = 0;
   2.321 -					if (SDL_TranslateUNICODE) {
   2.322 -						const char *bytes;
   2.323 -						if (msg->FindString("bytes", &bytes) == B_OK) {
   2.324 -							keysym.unicode = Translate2Unicode(bytes);
   2.325 -						}
   2.326 -					}
   2.327 -					SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   2.328 -				}
   2.329 -				break;
   2.330 -			}
   2.331 -
   2.332 -			default:
   2.333 -				/* move it after switch{} so it's always handled
   2.334 -					that way we keep BeOS feautures like:
   2.335 -					- CTRL+Q to close window (and other shortcuts)
   2.336 -					- PrintScreen to make screenshot into /boot/home
   2.337 -					- etc.. */
   2.338 -				//BDirectWindow::DispatchMessage(msg, target);
   2.339 -				break;
   2.340 -		}
   2.341 -		BDirectWindow::DispatchMessage(msg, target);
   2.342 -	}
   2.343 +	virtual void DispatchMessage(BMessage *msg, BHandler *target);
   2.344  
   2.345  private:
   2.346  #if SDL_VIDEO_OPENGL
   2.347 @@ -547,12 +245,9 @@
   2.348  #endif
   2.349  	SDL_BView *SDL_View;
   2.350  	BView *the_view;
   2.351 -
   2.352  	bool shown;
   2.353  	bool inhibit_resize;
   2.354 -
   2.355  	int32 last_buttons;
   2.356 -	SDLKey keymap[128];
   2.357  };
   2.358  
   2.359  #endif /* _SDL_BWin_h */
     3.1 --- a/src/video/bwindow/SDL_sysevents.cc	Sun Sep 24 01:27:40 2006 +0000
     3.2 +++ b/src/video/bwindow/SDL_sysevents.cc	Sun Sep 24 15:31:42 2006 +0000
     3.3 @@ -29,6 +29,8 @@
     3.4  #include "SDL_BWin.h"
     3.5  #include "SDL_lowvideo.h"
     3.6  
     3.7 +static SDLKey keymap[128];
     3.8 +int mouse_relative = 0;
     3.9  extern "C" {
    3.10  
    3.11  #include "../../events/SDL_sysevents.h"
    3.12 @@ -41,6 +43,340 @@
    3.13  
    3.14  void BE_InitOSKeymap(_THIS)
    3.15  {
    3.16 +		for ( uint i=0; i<SDL_TABLESIZE(keymap); ++i )
    3.17 +			keymap[i] = SDLK_UNKNOWN;
    3.18 +
    3.19 +		keymap[0x01]		= SDLK_ESCAPE;
    3.20 +		keymap[B_F1_KEY]	= SDLK_F1;
    3.21 +		keymap[B_F2_KEY]	= SDLK_F2;
    3.22 +		keymap[B_F3_KEY]	= SDLK_F3;
    3.23 +		keymap[B_F4_KEY]	= SDLK_F4;
    3.24 +		keymap[B_F5_KEY]	= SDLK_F5;
    3.25 +		keymap[B_F6_KEY]	= SDLK_F6;
    3.26 +		keymap[B_F7_KEY]	= SDLK_F7;
    3.27 +		keymap[B_F8_KEY]	= SDLK_F8;
    3.28 +		keymap[B_F9_KEY]	= SDLK_F9;
    3.29 +		keymap[B_F10_KEY]	= SDLK_F10;
    3.30 +		keymap[B_F11_KEY]	= SDLK_F11;
    3.31 +		keymap[B_F12_KEY]	= SDLK_F12;
    3.32 +		keymap[B_PRINT_KEY]	= SDLK_PRINT;
    3.33 +		keymap[B_SCROLL_KEY]	= SDLK_SCROLLOCK;
    3.34 +		keymap[B_PAUSE_KEY]	= SDLK_PAUSE;
    3.35 +		keymap[0x11]		= SDLK_BACKQUOTE;
    3.36 +		keymap[0x12]		= SDLK_1;
    3.37 +		keymap[0x13]		= SDLK_2;
    3.38 +		keymap[0x14]		= SDLK_3;
    3.39 +		keymap[0x15]		= SDLK_4;
    3.40 +		keymap[0x16]		= SDLK_5;
    3.41 +		keymap[0x17]		= SDLK_6;
    3.42 +		keymap[0x18]		= SDLK_7;
    3.43 +		keymap[0x19]		= SDLK_8;
    3.44 +		keymap[0x1a]		= SDLK_9;
    3.45 +		keymap[0x1b]		= SDLK_0;
    3.46 +		keymap[0x1c]		= SDLK_MINUS;
    3.47 +		keymap[0x1d]		= SDLK_EQUALS;
    3.48 +		keymap[0x1e]		= SDLK_BACKSPACE;
    3.49 +		keymap[0x1f]		= SDLK_INSERT;
    3.50 +		keymap[0x20]		= SDLK_HOME;
    3.51 +		keymap[0x21]		= SDLK_PAGEUP;
    3.52 +		keymap[0x22]		= SDLK_NUMLOCK;
    3.53 +		keymap[0x23]		= SDLK_KP_DIVIDE;
    3.54 +		keymap[0x24]		= SDLK_KP_MULTIPLY;
    3.55 +		keymap[0x25]		= SDLK_KP_MINUS;
    3.56 +		keymap[0x26]		= SDLK_TAB;
    3.57 +		keymap[0x27]		= SDLK_q;
    3.58 +		keymap[0x28]		= SDLK_w;
    3.59 +		keymap[0x29]		= SDLK_e;
    3.60 +		keymap[0x2a]		= SDLK_r;
    3.61 +		keymap[0x2b]		= SDLK_t;
    3.62 +		keymap[0x2c]		= SDLK_y;
    3.63 +		keymap[0x2d]		= SDLK_u;
    3.64 +		keymap[0x2e]		= SDLK_i;
    3.65 +		keymap[0x2f]		= SDLK_o;
    3.66 +		keymap[0x30]		= SDLK_p;
    3.67 +		keymap[0x31]		= SDLK_LEFTBRACKET;
    3.68 +		keymap[0x32]		= SDLK_RIGHTBRACKET;
    3.69 +		keymap[0x33]		= SDLK_BACKSLASH;
    3.70 +		keymap[0x34]		= SDLK_DELETE;
    3.71 +		keymap[0x35]		= SDLK_END;
    3.72 +		keymap[0x36]		= SDLK_PAGEDOWN;
    3.73 +		keymap[0x37]		= SDLK_KP7;
    3.74 +		keymap[0x38]		= SDLK_KP8;
    3.75 +		keymap[0x39]		= SDLK_KP9;
    3.76 +		keymap[0x3a]		= SDLK_KP_PLUS;
    3.77 +		keymap[0x3b]		= SDLK_CAPSLOCK;
    3.78 +		keymap[0x3c]		= SDLK_a;
    3.79 +		keymap[0x3d]		= SDLK_s;
    3.80 +		keymap[0x3e]		= SDLK_d;
    3.81 +		keymap[0x3f]		= SDLK_f;
    3.82 +		keymap[0x40]		= SDLK_g;
    3.83 +		keymap[0x41]		= SDLK_h;
    3.84 +		keymap[0x42]		= SDLK_j;
    3.85 +		keymap[0x43]		= SDLK_k;
    3.86 +		keymap[0x44]		= SDLK_l;
    3.87 +		keymap[0x45]		= SDLK_SEMICOLON;
    3.88 +		keymap[0x46]		= SDLK_QUOTE;
    3.89 +		keymap[0x47]		= SDLK_RETURN;
    3.90 +		keymap[0x48]		= SDLK_KP4;
    3.91 +		keymap[0x49]		= SDLK_KP5;
    3.92 +		keymap[0x4a]		= SDLK_KP6;
    3.93 +		keymap[0x4b]		= SDLK_LSHIFT;
    3.94 +		keymap[0x4c]		= SDLK_z;
    3.95 +		keymap[0x4d]		= SDLK_x;
    3.96 +		keymap[0x4e]		= SDLK_c;
    3.97 +		keymap[0x4f]		= SDLK_v;
    3.98 +		keymap[0x50]		= SDLK_b;
    3.99 +		keymap[0x51]		= SDLK_n;
   3.100 +		keymap[0x52]		= SDLK_m;
   3.101 +		keymap[0x53]		= SDLK_COMMA;
   3.102 +		keymap[0x54]		= SDLK_PERIOD;
   3.103 +		keymap[0x55]		= SDLK_SLASH;
   3.104 +		keymap[0x56]		= SDLK_RSHIFT;
   3.105 +		keymap[0x57]		= SDLK_UP;
   3.106 +		keymap[0x58]		= SDLK_KP1;
   3.107 +		keymap[0x59]		= SDLK_KP2;
   3.108 +		keymap[0x5a]		= SDLK_KP3;
   3.109 +		keymap[0x5b]		= SDLK_KP_ENTER;
   3.110 +		keymap[0x5c]		= SDLK_LCTRL;
   3.111 +		keymap[0x5d]		= SDLK_LALT;
   3.112 +		keymap[0x5e]		= SDLK_SPACE;
   3.113 +		keymap[0x5f]		= SDLK_RALT;
   3.114 +		keymap[0x60]		= SDLK_RCTRL;
   3.115 +		keymap[0x61]		= SDLK_LEFT;
   3.116 +		keymap[0x62]		= SDLK_DOWN;
   3.117 +		keymap[0x63]		= SDLK_RIGHT;
   3.118 +		keymap[0x64]		= SDLK_KP0;
   3.119 +		keymap[0x65]		= SDLK_KP_PERIOD;
   3.120 +		keymap[0x66]		= SDLK_LMETA;
   3.121 +		keymap[0x67]		= SDLK_RMETA;
   3.122 +		keymap[0x68]		= SDLK_MENU;
   3.123 +		keymap[0x69]		= SDLK_EURO;
   3.124 +		keymap[0x6a]		= SDLK_KP_EQUALS;
   3.125 +		keymap[0x6b]		= SDLK_POWER;
   3.126  }
   3.127  
   3.128  }; /* Extern C */
   3.129 +
   3.130 +void SDL_BWin::DispatchMessage(BMessage *msg, BHandler *target)
   3.131 +{
   3.132 +	switch (msg->what) {
   3.133 +		case B_MOUSE_MOVED:
   3.134 +		{
   3.135 +			SDL_VideoDevice *view = current_video;
   3.136 +			BPoint where;
   3.137 +			int32 transit;
   3.138 +			if (msg->FindPoint("where", &where) == B_OK && msg->FindInt32("be:transit", &transit) == B_OK) {
   3.139 +
   3.140 +//BeSman: I need another method for cursor catching !!!
   3.141 +if(view->input_grab != SDL_GRAB_OFF)
   3.142 +{			
   3.143 +			BPoint center;
   3.144 +			center.x = (SDL_VideoSurface->w/2);
   3.145 +			center.y = (SDL_VideoSurface->h/2);
   3.146 +			BPoint delta = where - center;
   3.147 +if(delta.x > center.x)
   3.148 +SDL_WarpMouse((int)center.x*2,(int)where.y);
   3.149 +
   3.150 +if(delta.x < -center.x)
   3.151 +SDL_WarpMouse(0,(int)where.y);
   3.152 +
   3.153 +if(delta.y > center.y)
   3.154 +SDL_WarpMouse((int)where.x,(int)center.y*2);
   3.155 +
   3.156 +if(delta.y < -center.y)
   3.157 +SDL_WarpMouse((int)where.x,0);
   3.158 +
   3.159 +
   3.160 +if((delta.x-1 < -center.x)&&(delta.y-1 < -center.y))
   3.161 +SDL_WarpMouse(1,1);
   3.162 +
   3.163 +if((delta.x-1 < -center.x)&&(delta.y+1 > center.y))
   3.164 +SDL_WarpMouse(1,(int)center.y*2-1);
   3.165 +
   3.166 +if((delta.x+1 > center.x)&&(delta.y-1 < -center.y))
   3.167 +SDL_WarpMouse((int)center.x*2-1,1);
   3.168 +
   3.169 +if((delta.x+1 > center.x)&&(delta.y+1 > center.y))
   3.170 +SDL_WarpMouse((int)center.x*2-1,(int)center.y*2-1);				
   3.171 +
   3.172 +}
   3.173 +				if (transit == B_EXITED_VIEW) {
   3.174 +					if ( SDL_GetAppState() & SDL_APPMOUSEFOCUS ) {
   3.175 +						SDL_PrivateAppActive(0, SDL_APPMOUSEFOCUS);
   3.176 +				//		be_app->SetCursor(B_HAND_CURSOR);
   3.177 +					}
   3.178 +				} else {
   3.179 +		
   3.180 +					int x, y;
   3.181 +					if ( ! (SDL_GetAppState() & SDL_APPMOUSEFOCUS) ) {
   3.182 +						SDL_PrivateAppActive(1, SDL_APPMOUSEFOCUS);
   3.183 +						SDL_SetCursor(NULL);
   3.184 +					}
   3.185 +					x = (int)where.x;
   3.186 +					y = (int)where.y;
   3.187 +
   3.188 +					if ( mouse_relative ) {
   3.189 +						BPoint center;
   3.190 +						center.x = (SDL_VideoSurface->w/2);
   3.191 +						center.y = (SDL_VideoSurface->h/2);
   3.192 +						x -= (int)center.x;
   3.193 +						y -= (int)center.y;
   3.194 +						if ( x || y ) {
   3.195 +							ConvertToScreen(&center);
   3.196 +							set_mouse_position((int)center.x, (int)center.y);
   3.197 +							SDL_PrivateMouseMotion(0, 1, x, y);
   3.198 +						}
   3.199 +					} else {
   3.200 +						SDL_PrivateMouseMotion(0, 0, x, y);
   3.201 +					}
   3.202 +				}
   3.203 +			}
   3.204 +			break;
   3.205 +		}
   3.206 +
   3.207 +		case B_MOUSE_DOWN:
   3.208 +		{
   3.209 +			/*	it looks like mouse down is send only for first clicked
   3.210 +				button, each next is not send while last one is holded */
   3.211 +			int32 buttons;
   3.212 +			int sdl_buttons = 0;
   3.213 +			if (msg->FindInt32("buttons", &buttons) == B_OK) {
   3.214 +				/* Add any mouse button events */
   3.215 +				if (buttons & B_PRIMARY_MOUSE_BUTTON) {
   3.216 +					sdl_buttons |= SDL_BUTTON_LEFT;
   3.217 +				}
   3.218 +				if (buttons & B_SECONDARY_MOUSE_BUTTON) {
   3.219 +					sdl_buttons |= SDL_BUTTON_RIGHT;
   3.220 +				}
   3.221 +				if (buttons & B_TERTIARY_MOUSE_BUTTON) {
   3.222 +					sdl_buttons |= SDL_BUTTON_MIDDLE;
   3.223 +				}
   3.224 +				SDL_PrivateMouseButton(SDL_PRESSED, sdl_buttons, 0, 0);
   3.225 +
   3.226 +				last_buttons = buttons;
   3.227 +			}
   3.228 +			break;
   3.229 +		}
   3.230 +
   3.231 +		case B_MOUSE_UP:
   3.232 +		{
   3.233 +			/*	mouse up doesn't give which button was released,
   3.234 +				only state of buttons (after release, so it's always = 0),
   3.235 +				which is not what we need ;]
   3.236 +				So we need to store button in mouse down, and restore
   3.237 +				in mouse up :(
   3.238 +				mouse up is (similarly to mouse down) send only for
   3.239 +				first button down (ie. it's no send if we click another button
   3.240 +				without releasing previous one first) - but that's probably
   3.241 +				because of how drivers are written?, not BeOS itself. */
   3.242 +			int32 buttons;
   3.243 +			int sdl_buttons = 0;
   3.244 +			if (msg->FindInt32("buttons", &buttons) == B_OK) {
   3.245 +				/* Add any mouse button events */
   3.246 +				if ((buttons ^ B_PRIMARY_MOUSE_BUTTON) & last_buttons) {
   3.247 +					sdl_buttons |= SDL_BUTTON_LEFT;
   3.248 +				}
   3.249 +				if ((buttons ^ B_SECONDARY_MOUSE_BUTTON) & last_buttons) {
   3.250 +					sdl_buttons |= SDL_BUTTON_RIGHT;
   3.251 +				}
   3.252 +				if ((buttons ^ B_TERTIARY_MOUSE_BUTTON) & last_buttons) {
   3.253 +					sdl_buttons |= SDL_BUTTON_MIDDLE;
   3.254 +				}
   3.255 +				SDL_PrivateMouseButton(SDL_RELEASED, sdl_buttons, 0, 0);
   3.256 +
   3.257 +				last_buttons = buttons;
   3.258 +			}
   3.259 +			break;
   3.260 +		}
   3.261 +
   3.262 +		case B_MOUSE_WHEEL_CHANGED:
   3.263 +		{
   3.264 +			float x, y;
   3.265 +			x = y = 0;
   3.266 +			if (msg->FindFloat("be:wheel_delta_x", &x) == B_OK && msg->FindFloat("be:wheel_delta_y", &y) == B_OK) {
   3.267 +				if (x < 0 || y < 0) {
   3.268 +					SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELDOWN, 0, 0);
   3.269 +					SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELDOWN, 0, 0);
   3.270 +				} else if (x > 0 || y > 0) {
   3.271 +					SDL_PrivateMouseButton(SDL_PRESSED, SDL_BUTTON_WHEELUP, 0, 0);
   3.272 +					SDL_PrivateMouseButton(SDL_RELEASED, SDL_BUTTON_WHEELUP, 0, 0);
   3.273 +				}
   3.274 +			}
   3.275 +			break;
   3.276 +		}
   3.277 +
   3.278 +		case B_KEY_DOWN:
   3.279 +		case B_UNMAPPED_KEY_DOWN: /* modifier keys are unmapped */
   3.280 +		{
   3.281 +			int32 key;
   3.282 +			int32 modifiers;
   3.283 +			int32 key_repeat;
   3.284 +			/* Workaround for SDL message queue being filled too fast because of BeOS own key-repeat mechanism */
   3.285 +			if (msg->FindInt32("be:key_repeat", &key_repeat) == B_OK && key_repeat > 0)
   3.286 +				break;
   3.287 +
   3.288 +			if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   3.289 +				SDL_keysym keysym;
   3.290 +				keysym.scancode = key;
   3.291 +				if (key < 128) {
   3.292 +					keysym.sym = keymap[key];
   3.293 +				} else {
   3.294 +					keysym.sym = SDLK_UNKNOWN;
   3.295 +				}
   3.296 +				/*	FIX THIS?
   3.297 +					it seems SDL_PrivateKeyboard() changes mod value
   3.298 +					anyway, and doesn't care about what we setup here */
   3.299 +				keysym.mod = KMOD_NONE;
   3.300 +				keysym.unicode = 0;
   3.301 +				if (SDL_TranslateUNICODE) {
   3.302 +					const char *bytes;
   3.303 +					if (msg->FindString("bytes", &bytes) == B_OK) {
   3.304 +						/*	FIX THIS?
   3.305 +							this cares only about first "letter",
   3.306 +							so if someone maps some key to print
   3.307 +							"BeOS rulez!" only "B" will be used. */
   3.308 +						keysym.unicode = Translate2Unicode(bytes);
   3.309 +					}
   3.310 +				}
   3.311 +				SDL_PrivateKeyboard(SDL_PRESSED, &keysym);
   3.312 +			}
   3.313 +			break;
   3.314 +		}
   3.315 +
   3.316 +		case B_KEY_UP:
   3.317 +		case B_UNMAPPED_KEY_UP: /* modifier keys are unmapped */
   3.318 +		{
   3.319 +			int32 key;
   3.320 +			int32 modifiers;
   3.321 +			if (msg->FindInt32("key", &key) == B_OK && msg->FindInt32("modifiers", &modifiers) == B_OK) {
   3.322 +				SDL_keysym keysym;
   3.323 +				keysym.scancode = key;
   3.324 +				if (key < 128) {
   3.325 +					keysym.sym = keymap[key];
   3.326 +				} else {
   3.327 +					keysym.sym = SDLK_UNKNOWN;
   3.328 +				}
   3.329 +				keysym.mod = KMOD_NONE; /* FIX THIS? */
   3.330 +				keysym.unicode = 0;
   3.331 +				if (SDL_TranslateUNICODE) {
   3.332 +					const char *bytes;
   3.333 +					if (msg->FindString("bytes", &bytes) == B_OK) {
   3.334 +						keysym.unicode = Translate2Unicode(bytes);
   3.335 +					}
   3.336 +				}
   3.337 +				SDL_PrivateKeyboard(SDL_RELEASED, &keysym);
   3.338 +			}
   3.339 +			break;
   3.340 +		}
   3.341 +
   3.342 +		default:
   3.343 +			/* move it after switch{} so it's always handled
   3.344 +				that way we keep BeOS feautures like:
   3.345 +				- CTRL+Q to close window (and other shortcuts)
   3.346 +				- PrintScreen to make screenshot into /boot/home
   3.347 +				- etc.. */
   3.348 +			//BDirectWindow::DispatchMessage(msg, target);
   3.349 +			break;
   3.350 +	}
   3.351 +	BDirectWindow::DispatchMessage(msg, target);
   3.352 +}
     4.1 --- a/src/video/bwindow/SDL_sysmouse.cc	Sun Sep 24 01:27:40 2006 +0000
     4.2 +++ b/src/video/bwindow/SDL_sysmouse.cc	Sun Sep 24 15:31:42 2006 +0000
     4.3 @@ -27,7 +27,7 @@
     4.4  #include "SDL_BWin.h"
     4.5  
     4.6  extern "C" {
     4.7 -
     4.8 +#include "SDL_cursor_c.h"
     4.9  #include "SDL_sysmouse_c.h"
    4.10  
    4.11  /* Convert bits to padded bytes */
    4.12 @@ -128,11 +128,26 @@
    4.13  /* Implementation by Christian Bauer <cbauer@student.physik.uni-mainz.de> */
    4.14  void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y)
    4.15  {
    4.16 +	if (_this->screen && (_this->screen->flags & SDL_FULLSCREEN) ) {		
    4.17 +		SDL_PrivateMouseMotion(0, 0, x, y);
    4.18 +	} else {
    4.19  	BPoint pt(x, y);
    4.20  	SDL_Win->Lock();
    4.21  	SDL_Win->ConvertToScreen(&pt);
    4.22  	SDL_Win->Unlock();
    4.23  	set_mouse_position((int32)pt.x, (int32)pt.y);
    4.24 +	}
    4.25 +}
    4.26 +/* Check to see if we need to enter or leave mouse relative mode */
    4.27 +void BE_CheckMouseMode(_THIS)
    4.28 +{
    4.29 +        /* If the mouse is hidden and input is grabbed, we use relative mode */
    4.30 +        if ( !(SDL_cursorstate & CURSOR_VISIBLE) &&
    4.31 +             (_this->input_grab != SDL_GRAB_OFF) ) {
    4.32 +                mouse_relative = 1;
    4.33 +        } else {
    4.34 +                mouse_relative = 0;
    4.35 +        }
    4.36  }
    4.37  
    4.38  }; /* Extern C */
     5.1 --- a/src/video/bwindow/SDL_sysmouse_c.h	Sun Sep 24 01:27:40 2006 +0000
     5.2 +++ b/src/video/bwindow/SDL_sysmouse_c.h	Sun Sep 24 15:31:42 2006 +0000
     5.3 @@ -29,4 +29,5 @@
     5.4  		Uint8 *data, Uint8 *mask, int w, int h, int hot_x, int hot_y);
     5.5  extern int BE_ShowWMCursor(_THIS, WMcursor *cursor);
     5.6  extern void BE_WarpWMCursor(_THIS, Uint16 x, Uint16 y);
     5.7 +extern void BE_CheckMouseMode(_THIS);
     5.8  
     6.1 --- a/src/video/bwindow/SDL_sysvideo.cc	Sun Sep 24 01:27:40 2006 +0000
     6.2 +++ b/src/video/bwindow/SDL_sysvideo.cc	Sun Sep 24 15:31:42 2006 +0000
     6.3 @@ -135,7 +135,7 @@
     6.4  	device->SetCaption = BE_SetWMCaption;
     6.5  	device->SetIcon = NULL;
     6.6  	device->IconifyWindow = BE_IconifyWindow;
     6.7 -	device->GrabInput = NULL;
     6.8 +	device->GrabInput = BE_GrabInput;
     6.9  	device->GetWMInfo = BE_GetWMInfo;
    6.10  	/* Cursor manager functions */
    6.11  	device->FreeWMCursor = BE_FreeWMCursor;
    6.12 @@ -143,7 +143,7 @@
    6.13  	device->ShowWMCursor = BE_ShowWMCursor;
    6.14  	device->WarpWMCursor = BE_WarpWMCursor;
    6.15  	device->MoveWMCursor = NULL;
    6.16 -	device->CheckMouseMode = NULL;
    6.17 +	device->CheckMouseMode = BE_CheckMouseMode;
    6.18  	/* Event manager functions */
    6.19  	device->InitOSKeymap = BE_InitOSKeymap;
    6.20  	device->PumpEvents = BE_PumpEvents;
    6.21 @@ -365,8 +365,11 @@
    6.22  	if ( ! modes[i] || (modes[i]->w < width) || (modes[i]->h < width) ) {
    6.23  		--i;	/* We went too far */
    6.24  	}
    6.25 -	width = modes[i]->w;
    6.26 -	height = modes[i]->h;      
    6.27 +
    6.28 +/*  BeSman::We dont want to use a Desktop resolution */
    6.29 +//	width = modes[i]->w;
    6.30 +//	height = modes[i]->h;      
    6.31 +
    6.32  	bscreen.GetModeList(&dmodes, &nmodes);
    6.33  	for ( i = 0; i < nmodes; ++i ) {
    6.34  		if ( (bpp == ColorSpaceToBitsPerPixel(dmodes[i].space)) &&
    6.35 @@ -433,7 +436,7 @@
    6.36  	}
    6.37  
    6.38  	if ( SDL_Win->Lock() ) {
    6.39 -		int xoff, yoff;
    6.40 +		int cx, cy;
    6.41  		if ( SDL_Win->Shown() ) {
    6.42  			needs_unlock = 1;
    6.43  			SDL_Win->Hide();
    6.44 @@ -449,19 +452,12 @@
    6.45  		/* Calculate offsets - used either to center window
    6.46  		 * (windowed mode) or to set drawing offsets (fullscreen mode)
    6.47  		 */
    6.48 -		xoff = (bounds.IntegerWidth() - width)/2;
    6.49 -		yoff = (bounds.IntegerHeight() - height)/2;
    6.50 -		if ( fullscreen ) {
    6.51 -			/* Set offset for drawing */
    6.52 -			SDL_Win->SetXYOffset(xoff, yoff);
    6.53 -		} else {
    6.54 -			/* Center window and reset the drawing offset */
    6.55 -			SDL_Win->SetXYOffset(0, 0);
    6.56 -		}
    6.57 +		cx = (bounds.IntegerWidth() - width)/2;
    6.58 +		cy = (bounds.IntegerHeight() - height)/2;
    6.59 +
    6.60  		if ( ! needs_unlock || was_fullscreen ) {
    6.61  			/* Center the window the first time */
    6.62 -			SDL_Win->MoveTo(xoff > 0 ? (float)xoff : 0.0f,
    6.63 -					yoff > 0 ? (float)yoff : 0.0f);
    6.64 +			SDL_Win->MoveTo(cx, cy);
    6.65  		}
    6.66  		SDL_Win->Show();
    6.67  		
     7.1 --- a/src/video/bwindow/SDL_syswm.cc	Sun Sep 24 01:27:40 2006 +0000
     7.2 +++ b/src/video/bwindow/SDL_syswm.cc	Sun Sep 24 15:31:42 2006 +0000
     7.3 @@ -24,9 +24,9 @@
     7.4  #include "SDL_BWin.h"
     7.5  
     7.6  extern "C" {
     7.7 -
     7.8  #include "SDL_syswm_c.h"
     7.9  #include "SDL_error.h"
    7.10 +#include "../SDL_cursor_c.h"
    7.11  
    7.12  void BE_SetWMCaption(_THIS, const char *title, const char *icon)
    7.13  {
    7.14 @@ -38,6 +38,42 @@
    7.15  	SDL_Win->Minimize(true);
    7.16  }
    7.17  
    7.18 +SDL_GrabMode BE_GrabInput(_THIS, SDL_GrabMode mode)
    7.19 +{
    7.20 +	if ( mode == SDL_GRAB_OFF ) {
    7.21 +//		be_app->ShowCursor();
    7.22 +		if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) {
    7.23 +		/*	BeSman: Jan 2, 2006
    7.24 +			must be leaving relative mode, move mouse from
    7.25 +			center of window to where it belongs ... */
    7.26 +			BPoint pt;
    7.27 +			int x, y;
    7.28 +			SDL_GetMouseState(&x,&y);
    7.29 +			pt.x = x;
    7.30 +			pt.y = y;
    7.31 +			SDL_Win->Lock();
    7.32 +			SDL_Win->ConvertToScreen(&pt);
    7.33 +			SDL_Win->Unlock();
    7.34 +			set_mouse_position((int)pt.x, (int)pt.y);
    7.35 +		}
    7.36 +	} else {
    7.37 +//		be_app->HideCursor();
    7.38 +		if ( !(SDL_cursorstate & CURSOR_VISIBLE) ) {
    7.39 +		/*	BeSman: Jan 2, 2006
    7.40 +			must be entering relative mode, get ready by
    7.41 +			moving mouse to	center of window ... */
    7.42 +			BPoint pt;
    7.43 +			pt.x = (SDL_VideoSurface->w/2);
    7.44 +			pt.y = (SDL_VideoSurface->h/2);
    7.45 +			SDL_Win->Lock();
    7.46 +			SDL_Win->ConvertToScreen(&pt);
    7.47 +			SDL_Win->Unlock();
    7.48 +			set_mouse_position((int)pt.x, (int)pt.y);
    7.49 +		}
    7.50 +	}
    7.51 +	return(mode);
    7.52 +}
    7.53 +
    7.54  int BE_GetWMInfo(_THIS, SDL_SysWMinfo *info)
    7.55  {
    7.56      if (info->version.major <= SDL_MAJOR_VERSION)
     8.1 --- a/src/video/bwindow/SDL_syswm_c.h	Sun Sep 24 01:27:40 2006 +0000
     8.2 +++ b/src/video/bwindow/SDL_syswm_c.h	Sun Sep 24 15:31:42 2006 +0000
     8.3 @@ -29,3 +29,4 @@
     8.4  extern void BE_SetWMCaption(_THIS, const char *title, const char *icon);
     8.5  extern int BE_IconifyWindow(_THIS);
     8.6  extern int BE_GetWMInfo(_THIS, SDL_SysWMinfo *info);
     8.7 +extern SDL_GrabMode BE_GrabInput(_THIS, SDL_GrabMode mode);
     8.8 \ No newline at end of file