Skip to content

Instantly share code, notes, and snippets.

@jorgenpt
Created March 1, 2013 19:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jorgenpt/5067271 to your computer and use it in GitHub Desktop.
Save jorgenpt/5067271 to your computer and use it in GitHub Desktop.
SDL2: Fix for missing movement updates when losing focus.
--- /tmp/tmp.4049.39 2013-03-01 11:53:56.199276885 -0800
+++ src/events/SDL_mouse.c 2013-03-01 11:52:47.390674778 -0800
@@ -33,6 +33,8 @@
/* The mouse state */
static SDL_Mouse SDL_mouse;
+static int
+SDL_PrivateSendMouseMotion(SDL_Window * window, int relative, int x, int y);
/* Public functions */
int
@@ -154,8 +156,9 @@
#endif
if (window == mouse->focus) {
#ifdef DEBUG_MOUSE
- printf("Mouse left window, synthesizing focus lost event\n");
+ printf("Mouse left window, synthesizing move & focus lost event\n");
#endif
+ SDL_PrivateSendMouseMotion(window, 0, x, y);
SDL_SetMouseFocus(NULL);
}
return SDL_FALSE;
@@ -176,18 +179,25 @@
int
SDL_SendMouseMotion(SDL_Window * window, int relative, int x, int y)
{
- SDL_Mouse *mouse = SDL_GetMouse();
- int posted;
- int xrel;
- int yrel;
- int x_max = 0, y_max = 0;
-
if (window && !relative) {
+ SDL_Mouse *mouse = SDL_GetMouse();
if (!SDL_UpdateMouseFocus(window, x, y, mouse->buttonstate)) {
return 0;
}
}
+ return SDL_PrivateSendMouseMotion(window, relative, x, y);
+}
+
+static int
+SDL_PrivateSendMouseMotion(SDL_Window * window, int relative, int x, int y)
+{
+ SDL_Mouse *mouse = SDL_GetMouse();
+ int posted;
+ int xrel;
+ int yrel;
+ int x_max = 0, y_max = 0;
+
/* relative motion is calculated regarding the system cursor last position */
if (relative) {
xrel = x;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment