# HG changeset patch # User Sam Lantinga # Date 1278395315 25200 # Node ID 82d661ea0d5aba9ee1522de7270139dbcb8349f8 # Parent 9322f7db860332dbdeac3e349e75314c20458155# Parent 92e65e3041c23bc616644cc49945068902d9b3ab Merged changes from default diff -r 92e65e3041c2 -r 82d661ea0d5a src/events/SDL_mouse.c --- a/src/events/SDL_mouse.c Mon Jul 05 18:18:25 2010 -0700 +++ b/src/events/SDL_mouse.c Mon Jul 05 22:48:35 2010 -0700 @@ -112,7 +112,7 @@ } int -SDL_SendMouseMotion(int relative, int x, int y) +SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y) { SDL_Mouse *mouse = &SDL_mouse; int posted; @@ -120,6 +120,10 @@ int yrel; int x_max = 0, y_max = 0; + if (window) { + SDL_SetMouseFocus(window); + } + /* the relative motion is calculated regarding the system cursor last position */ if (relative) { xrel = x; @@ -194,12 +198,16 @@ } int -SDL_SendMouseButton(Uint8 state, Uint8 button) +SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button) { SDL_Mouse *mouse = &SDL_mouse; int posted; Uint32 type; + if (window) { + SDL_SetMouseFocus(window); + } + /* Figure out which event to perform */ switch (state) { case SDL_PRESSED: @@ -239,11 +247,15 @@ } int -SDL_SendMouseWheel(int x, int y) +SDL_SendMouseWheel(SDL_Window * window, int x, int y) { SDL_Mouse *mouse = &SDL_mouse; int posted; + if (window) { + SDL_SetMouseFocus(window); + } + if (!x && !y) { return 0; } @@ -304,8 +316,7 @@ if (mouse->WarpMouse) { mouse->WarpMouse(mouse, window, x, y); } else { - SDL_SetMouseFocus(window); - SDL_SendMouseMotion(0, x, y); + SDL_SendMouseMotion(window, 0, x, y); } } diff -r 92e65e3041c2 -r 82d661ea0d5a src/events/SDL_mouse_c.h --- a/src/events/SDL_mouse_c.h Mon Jul 05 18:18:25 2010 -0700 +++ b/src/events/SDL_mouse_c.h Mon Jul 05 22:48:35 2010 -0700 @@ -40,13 +40,13 @@ extern void SDL_SetMouseFocus(SDL_Window * window); /* Send a mouse motion event */ -extern int SDL_SendMouseMotion(int relative, int x, int y); +extern int SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y); /* Send a mouse button event */ -extern int SDL_SendMouseButton(Uint8 state, Uint8 button); +extern int SDL_SendMouseButton(SDL_Window * window, Uint8 state, Uint8 button); /* Send a mouse wheel event */ -extern int SDL_SendMouseWheel(int x, int y); +extern int SDL_SendMouseWheel(SDL_Window * window, int x, int y); /* Shutdown the mouse subsystem */ extern void SDL_MouseQuit(void); diff -r 92e65e3041c2 -r 82d661ea0d5a src/video/cocoa/SDL_cocoamouse.m --- a/src/video/cocoa/SDL_cocoamouse.m Mon Jul 05 18:18:25 2010 -0700 +++ b/src/video/cocoa/SDL_cocoamouse.m Mon Jul 05 22:48:35 2010 -0700 @@ -52,6 +52,7 @@ int i; NSPoint point = { 0, 0 }; SDL_Window *window; + SDL_Window *focus = SDL_GetMouseFocus(); /* See if there are any fullscreen windows that might handle this event */ window = NULL; @@ -66,19 +67,18 @@ point = [NSEvent mouseLocation]; point.x = point.x - bounds.x; point.y = CGDisplayPixelsHigh(kCGDirectMainDisplay) - point.y - bounds.y; - if ((point.x >= 0 && point.x < candidate->w) || + if ((point.x >= 0 && point.x < candidate->w) && (point.y >= 0 && point.y < candidate->h)) { /* This is it! */ window = candidate; break; + } else if (candidate == focus) { + SDL_SetMouseFocus(NULL); } } } - /* Set the focus appropriately */ - SDL_SetMouseFocus(window); - - if (window) { + if (!window) { return; } @@ -86,18 +86,18 @@ case NSLeftMouseDown: case NSOtherMouseDown: case NSRightMouseDown: - SDL_SendMouseButton(SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); + SDL_SendMouseButton(window, SDL_PRESSED, ConvertMouseButtonToSDL([event buttonNumber])); break; case NSLeftMouseUp: case NSOtherMouseUp: case NSRightMouseUp: - SDL_SendMouseButton(SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); + SDL_SendMouseButton(window, SDL_RELEASED, ConvertMouseButtonToSDL([event buttonNumber])); break; case NSLeftMouseDragged: case NSRightMouseDragged: case NSOtherMouseDragged: /* usually middle mouse dragged */ case NSMouseMoved: - SDL_SendMouseMotion(0, (int)point.x, (int)point.y); + SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y); break; default: /* just to avoid compiler warnings */ break; diff -r 92e65e3041c2 -r 82d661ea0d5a src/video/cocoa/SDL_cocoawindow.m --- a/src/video/cocoa/SDL_cocoawindow.m Mon Jul 05 18:18:25 2010 -0700 +++ b/src/video/cocoa/SDL_cocoawindow.m Mon Jul 05 22:48:35 2010 -0700 @@ -171,7 +171,7 @@ button = [theEvent buttonNumber]; break; } - SDL_SendMouseButton(SDL_PRESSED, button); + SDL_SendMouseButton(_data->window, SDL_PRESSED, button); } - (void)rightMouseDown:(NSEvent *)theEvent @@ -202,7 +202,7 @@ button = [theEvent buttonNumber]; break; } - SDL_SendMouseButton(SDL_RELEASED, button); + SDL_SendMouseButton(_data->window, SDL_RELEASED, button); } - (void)rightMouseUp:(NSEvent *)theEvent @@ -228,8 +228,7 @@ SDL_SetMouseFocus(NULL); } } else { - SDL_SetMouseFocus(_data->window); - SDL_SendMouseMotion(0, (int)point.x, (int)point.y); + SDL_SendMouseMotion(window, 0, (int)point.x, (int)point.y); } } @@ -250,7 +249,20 @@ - (void)scrollWheel:(NSEvent *)theEvent { - SDL_SendMouseWheel((int)([theEvent deltaX]+0.9f), (int)([theEvent deltaY]+0.9f)); + float x = [theEvent deltaX]; + float y = [theEvent deltaY]; + + if (x > 0) { + x += 0.9f; + } else if (x < 0) { + x -= 0.9f; + } + if (y > 0) { + y += 0.9f; + } else if (y < 0) { + y -= 0.9f; + } + SDL_SendMouseWheel(_data->window, (int)x, (int)y); } @end diff -r 92e65e3041c2 -r 82d661ea0d5a src/video/win32/SDL_win32events.c --- a/src/video/win32/SDL_win32events.c Mon Jul 05 18:18:25 2010 -0700 +++ b/src/video/win32/SDL_win32events.c Mon Jul 05 22:48:35 2010 -0700 @@ -177,18 +177,15 @@ break; case WM_MOUSEMOVE: - SDL_SetMouseFocus(data->window); - SDL_SendMouseMotion(0, LOWORD(lParam), HIWORD(lParam)); + SDL_SendMouseMotion(data->window, 0, LOWORD(lParam), HIWORD(lParam)); break; case WM_LBUTTONDOWN: - SDL_SetMouseFocus(data->window); - SDL_SendMouseButton(SDL_PRESSED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(data->window, SDL_PRESSED, SDL_BUTTON_LEFT); break; case WM_LBUTTONUP: - SDL_SetMouseFocus(data->window); - SDL_SendMouseButton(SDL_RELEASED, SDL_BUTTON_LEFT); + SDL_SendMouseButton(data->window, SDL_RELEASED, SDL_BUTTON_LEFT); break; case WM_MOUSELEAVE: diff -r 92e65e3041c2 -r 82d661ea0d5a src/video/x11/SDL_x11events.c --- a/src/video/x11/SDL_x11events.c Mon Jul 05 18:18:25 2010 -0700 +++ b/src/video/x11/SDL_x11events.c Mon Jul 05 22:48:35 2010 -0700 @@ -272,17 +272,17 @@ #ifdef DEBUG_MOTION printf("X11 motion: %d,%d\n", xevent.xmotion.x, xevent.xmotion.y); #endif - SDL_SendMouseMotion(0, xevent.xmotion.x, xevent.xmotion.y); + SDL_SendMouseMotion(data->window, 0, xevent.xmotion.x, xevent.xmotion.y); } break; case ButtonPress:{ - SDL_SendMouseButton(SDL_PRESSED, xevent.xbutton.button); + SDL_SendMouseButton(data->window, SDL_PRESSED, xevent.xbutton.button); } break; case ButtonRelease:{ - SDL_SendMouseButton(SDL_RELEASED, xevent.xbutton.button); + SDL_SendMouseButton(data->window, SDL_RELEASED, xevent.xbutton.button); } break; diff -r 92e65e3041c2 -r 82d661ea0d5a test/Makefile.in --- a/test/Makefile.in Mon Jul 05 18:18:25 2010 -0700 +++ b/test/Makefile.in Mon Jul 05 22:48:35 2010 -0700 @@ -7,7 +7,7 @@ CFLAGS = @CFLAGS@ LIBS = @LIBS@ -TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmmousetablet$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) +TARGETS = checkkeys$(EXE) graywin$(EXE) loopwave$(EXE) testalpha$(EXE) testatomic$(EXE) testaudioinfo$(EXE) testbitmap$(EXE) testblitspeed$(EXE) testcursor$(EXE) testdraw2$(EXE) testdyngles$(EXE) testdyngl$(EXE) testerror$(EXE) testfile$(EXE) testfill$(EXE) testgamma$(EXE) testgl2$(EXE) testgles$(EXE) testgl$(EXE) testhaptic$(EXE) testhread$(EXE) testiconv$(EXE) testime$(EXE) testintersections$(EXE) testjoystick$(EXE) testkeys$(EXE) testloadso$(EXE) testlock$(EXE) testmultiaudio$(EXE) testoverlay2$(EXE) testoverlay$(EXE) testpalette$(EXE) testplatform$(EXE) testpower$(EXE) testresample$(EXE) testsem$(EXE) testsprite2$(EXE) testsprite$(EXE) testspriteminimal$(EXE) testtimer$(EXE) testver$(EXE) testvidinfo$(EXE) testwin$(EXE) testwm2$(EXE) testwm$(EXE) threadwin$(EXE) torturethread$(EXE) all: Makefile $(TARGETS) @@ -149,9 +149,6 @@ testhaptic$(EXE): $(srcdir)/testhaptic.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) -testmmousetablet$(EXE): $(srcdir)/testmmousetablet.c - $(CC) -o $@ $? $(CFLAGS) $(LIBS) - testatomic$(EXE): $(srcdir)/testatomic.c $(CC) -o $@ $? $(CFLAGS) $(LIBS) diff -r 92e65e3041c2 -r 82d661ea0d5a test/common.c --- a/test/common.c Mon Jul 05 18:18:25 2010 -0700 +++ b/test/common.c Mon Jul 05 22:48:35 2010 -0700 @@ -6,7 +6,7 @@ #include "common.h" #define VIDEO_USAGE \ -"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display %d] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" +"[--video driver] [--renderer driver] [--info all|video|modes|render|event] [--display N] [--fullscreen | --windows N] [--title title] [--center | --position X,Y] [--geometry WxH] [--depth N] [--refresh R] [--vsync] [--noframe] [--resize] [--minimize] [--maximize] [--grab] [--double] [--triple]" #define AUDIO_USAGE \ "[--rate N] [--format U8|S8|U16|U16LE|U16BE|S16|S16LE|S16BE] [--channels N] [--samples N]" diff -r 92e65e3041c2 -r 82d661ea0d5a test/testmmousetablet.c --- a/test/testmmousetablet.c Mon Jul 05 18:18:25 2010 -0700 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,67 +0,0 @@ -#include -#include "SDL.h" - -SDL_Surface *screen; -int quit = 0; - -int -main(int argc, char *argv[]) -{ - SDL_Event event; - int mice; - int i; - printf("Initing...\n"); - if (SDL_Init(0) != 0) { - return 1; - } - if (SDL_InitSubSystem(SDL_INIT_VIDEO) != 0) { - return 1; - } else { - screen = SDL_SetVideoMode(640, 480, 32, SDL_DOUBLEBUF); - } - mice = SDL_GetNumMice(); - printf("%d pointing devices found\n", mice); - for (i = 0; i < mice; ++i) { - printf("device index: %d name:%s\n", i, SDL_GetMouseName(i)); - } - while (quit != 1) { - if (SDL_PollEvent(&event) == 0) { - } else { - switch (event.type) { - case SDL_MOUSEMOTION: - printf - ("Device id: %d x: %d y: %d relx: %d rely: %d pressure: %d\n \ - pressure_max: %d pressure_min: %d current cursor:%d\n", - event.motion.which, event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, - event.motion.pressure, event.motion.pressure_max, event.motion.pressure_min, - event.motion.cursor); - break; - case SDL_PROXIMITYIN: - printf("proximity in id: %d x: %d y: %d\n", - (int) event.proximity.which, event.proximity.x, - event.proximity.y); - break; - case SDL_PROXIMITYOUT: - printf("proximity out id: %d x: %d y: %d\n", - (int) event.proximity.which, event.proximity.x, - event.proximity.y); - break; - case SDL_MOUSEBUTTONDOWN: - printf("mouse button down id: %d button:%d\n", - event.button.which, event.button.button); - break; - case SDL_MOUSEBUTTONUP: - printf("mouse button up id: %d button: %d\n", - event.button.which, event.button.button); - break; - case SDL_QUIT: - printf("Quitting\n"); - SDL_QuitSubSystem(SDL_INIT_VIDEO); - SDL_Quit(); - quit = 1; - break; - } - } - } - return 0; -}