SDL 2.0 patches

Hi there SDL folks,

I’ve recently updated my first attempt at a game engine to use SDL 1.3/2.0. I was very happy to see the new relative mouse mode available on OS X and can’t wait till it’s supported on other window managers. Unfortunately I noticed a few problems with it, luckily I have attached patches to fix these problems :slight_smile:

The first is simply fixing a crash when disabling relative mouse mode without the mouse being over an SDL window, since the cursor was not being controlled by SDL we don’t need to bother warping it around.

The second moves some of the low level cursor control from the window manager to the mouse manager. I’m not entirely certain this is correct, but I believe when the cursor is outside an SDL window it should be rendered with the default look, while saving what look it had for when the window is re-entered.

The reason behind this change was the cursor was not being hidden/unhidden when relative mode was enabled/disabled with the mouse outside any SDL window.

The third change saves the current x, y co-ordinates when relative mode is entered and then restores them when relative mode is disabled. I’m pretty sure this was the intended behavior of the warp.–
Wim Looman
@Wim_Looman


HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328263728 -46800

Node ID 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Parent 07e08cb5869602f5771ff5a61f4ef5b76e8a4cba

Fix null reference exception.

Occurred when using relative mouse mode without a focused window.

diff -r 07e08cb58696 -r 43d4e29a5dfc src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Sat Jan 28 14:53:23 2012 -0500
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
@@ -323,7 +323,7 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled) {
  • if (!enabled && mouse->focus) {
    /* Restore the expected mouse position */
    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    }

HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328266431 -46800

Node ID 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Parent 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Change SDL_SetCursor to set the cursor back to the default cursor when the
window is unfocused.

diff -r 43d4e29a5dfc -r 2688fd67db68 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
@@ -465,7 +465,11 @@
}
mouse->cur_cursor = cursor;
} else {

  •    cursor = mouse->cur_cursor;
    
  •    if (mouse->focus) {
    
  •        cursor = mouse->cur_cursor;
    
  •    } else {
    
  •        cursor = mouse->def_cursor;
    
  •    }
    

    }

    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoamouse.m
    — a/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:53:51 2012 +1300
    @@ -92,15 +92,13 @@
    {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  • if (SDL_GetMouseFocus()) {
  •    if (cursor) {
    
  •        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  • if (cursor) {
  •    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  •        [nscursor set];
    
  •        [NSCursor unhide];
    
  •    } else {
    
  •        [NSCursor hide];
    
  •    }
    
  •    [nscursor set];
    
  •    [NSCursor unhide];
    
  • } else {

  •    [NSCursor hide];
    

    }

    [pool release];
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoawindow.m
    — a/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:53:51 2012 +1300
    @@ -313,9 +313,7 @@
    CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
    } else {
    SDL_SetMouseFocus(NULL);

  •        [[NSCursor arrowCursor] set];
    
  •        [NSCursor unhide];
    
  •        SDL_SetCursor(NULL);
      }
    
    }
    }

HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328267601 -46800

Node ID 0d5148d1e578c2a9eb35f3afe2b541d1e48c90e5

Parent 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Make mouse relative mode save the original co-ordinates to restore them
properly.

diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse.c Sat Feb 04 00:13:21 2012 +1300
@@ -323,9 +323,13 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled && mouse->focus) {
  • if (enabled) {
  •    /* Save the expected mouse position */
    
  •    mouse->original_x = mouse->x;
    
  •    mouse->original_y = mouse->y;
    
  • } else if (mouse->focus) {
    /* Restore the expected mouse position */
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
    

    }

    /* Flush pending mouse motion /
    diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse_c.h
    — a/src/events/SDL_mouse_c.h Fri Feb 03 23:53:51 2012 +1300
    +++ b/src/events/SDL_mouse_c.h Sat Feb 04 00:13:21 2012 +1300
    @@ -60,6 +60,8 @@
    int last_x, last_y; /
    the last reported x and y coordinates */
    Uint8 buttonstate;
    SDL_bool relative_mode;

  • /* the x and y coordinates when relative mode was activated */

  • int original_x, original_y;

SDL_Cursor *cursors;
SDL_Cursor *def_cursor;

Thanks for the patches, but they’re inline in the e-mail and do not apply.
Can you enter a bug in bugzilla for them?
http://bugzilla.libsdl.org

Thanks!On Tue, Feb 7, 2012 at 4:07 PM, Wim Looman wrote:

Hi there SDL folks,

I’ve recently updated my first attempt at a game engine to use SDL
1.3/2.0. I was very happy to see the new relative mouse mode available on
OS X and can’t wait till it’s supported on other window managers.
Unfortunately I noticed a few problems with it, luckily I have attached
patches to fix these problems :slight_smile:

The first is simply fixing a crash when disabling relative mouse mode
without the mouse being over an SDL window, since the cursor was not being
controlled by SDL we don’t need to bother warping it around.

The second moves some of the low level cursor control from the window
manager to the mouse manager. I’m not entirely certain this is correct,
but I believe when the cursor is outside an SDL window it should be
rendered with the default look, while saving what look it had for when the
window is re-entered.

The reason behind this change was the cursor was not being hidden/unhidden
when relative mode was enabled/disabled with the mouse outside any SDL
window.

The third change saves the current x, y co-ordinates when relative mode is
entered and then restores them when relative mode is disabled. I’m pretty
sure this was the intended behavior of the warp.


Wim Looman
ghostunderscore at gmail.com


HG changeset patch

User Wim Looman

Date 1328263728 -46800

Node ID 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Parent 07e08cb5869602f5771ff5a61f4ef5b76e8a4cba

Fix null reference exception.

Occurred when using relative mouse mode without a focused window.

diff -r 07e08cb58696 -r 43d4e29a5dfc src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Sat Jan 28 14:53:23 2012 -0500
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
@@ -323,7 +323,7 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled) {
  • if (!enabled && mouse->focus) {
    /* Restore the expected mouse position */
    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    }

HG changeset patch

User Wim Looman

Date 1328266431 -46800

Node ID 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Parent 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Change SDL_SetCursor to set the cursor back to the default cursor when the
window is unfocused.

diff -r 43d4e29a5dfc -r 2688fd67db68 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
@@ -465,7 +465,11 @@
}
mouse->cur_cursor = cursor;
} else {

  •    cursor = mouse->cur_cursor;
    
  •    if (mouse->focus) {
    
  •        cursor = mouse->cur_cursor;
    
  •    } else {
    
  •        cursor = mouse->def_cursor;
    
  •    }
    

    }

    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoamouse.m
    — a/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:53:51 2012 +1300
    @@ -92,15 +92,13 @@
    {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  • if (SDL_GetMouseFocus()) {
  •    if (cursor) {
    
  •        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  • if (cursor) {
  •    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  •        [nscursor set];
    
  •        [NSCursor unhide];
    
  •    } else {
    
  •        [NSCursor hide];
    
  •    }
    
  •    [nscursor set];
    
  •    [NSCursor unhide];
    
  • } else {

  •    [NSCursor hide];
    

    }

    [pool release];
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoawindow.m
    — a/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:53:51 2012 +1300
    @@ -313,9 +313,7 @@
    CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
    } else {
    SDL_SetMouseFocus(NULL);

  •        [[NSCursor arrowCursor] set];
    
  •        [NSCursor unhide];
    
  •        SDL_SetCursor(NULL);
     }
    
    }
    }

HG changeset patch

User Wim Looman

Date 1328267601 -46800

Node ID 0d5148d1e578c2a9eb35f3afe2b541d1e48c90e5

Parent 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Make mouse relative mode save the original co-ordinates to restore them
properly.

diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse.c Sat Feb 04 00:13:21 2012 +1300
@@ -323,9 +323,13 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled && mouse->focus) {
  • if (enabled) {
  •    /* Save the expected mouse position */
    
  •    mouse->original_x = mouse->x;
    
  •    mouse->original_y = mouse->y;
    
  • } else if (mouse->focus) {
    /* Restore the expected mouse position */
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->original_x,
    

mouse->original_y);
}

/* Flush pending mouse motion /
diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse_c.h
— a/src/events/SDL_mouse_c.h Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse_c.h Sat Feb 04 00:13:21 2012 +1300
@@ -60,6 +60,8 @@
int last_x, last_y; /
the last reported x and y coordinates */
Uint8 buttonstate;
SDL_bool relative_mode;

  • /* the x and y coordinates when relative mode was activated */
  • int original_x, original_y;

SDL_Cursor *cursors;
SDL_Cursor *def_cursor;


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org

I’d like to second these patches, I’ve been compiling a new list of problems I’ve had with 2.0 on OS X and the crashing with the relative mouse movement is the big one. I’ll also put out that the “SDL 1.2 Mac shortcut key passthrough” one is also important as things like cmd-q are now caught by the system and produce a “beep” because my program doesn’t have a proper quit action.

[>] Brian

Bug created (http://bugzilla.libsdl.org/show_bug.cgi?id=1414). As I said in there, if there’s a better way to create the patches than hg export let me know and I can recreate them, not that used to using mercurial yet.–
Wim Looman
@Wim_Looman

On 8/02/2012, at 12:55 PM, Sam Lantinga wrote:

Thanks for the patches, but they’re inline in the e-mail and do not apply. Can you enter a bug in bugzilla for them?
http://bugzilla.libsdl.org

Thanks!

On Tue, Feb 7, 2012 at 4:07 PM, Wim Looman <@Wim_Looman> wrote:
Hi there SDL folks,

I’ve recently updated my first attempt at a game engine to use SDL 1.3/2.0. I was very happy to see the new relative mouse mode available on OS X and can’t wait till it’s supported on other window managers. Unfortunately I noticed a few problems with it, luckily I have attached patches to fix these problems :slight_smile:

The first is simply fixing a crash when disabling relative mouse mode without the mouse being over an SDL window, since the cursor was not being controlled by SDL we don’t need to bother warping it around.

The second moves some of the low level cursor control from the window manager to the mouse manager. I’m not entirely certain this is correct, but I believe when the cursor is outside an SDL window it should be rendered with the default look, while saving what look it had for when the window is re-entered.

The reason behind this change was the cursor was not being hidden/unhidden when relative mode was enabled/disabled with the mouse outside any SDL window.

The third change saves the current x, y co-ordinates when relative mode is entered and then restores them when relative mode is disabled. I’m pretty sure this was the intended behavior of the warp.


Wim Looman
@Wim_Looman


HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328263728 -46800

Node ID 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Parent 07e08cb5869602f5771ff5a61f4ef5b76e8a4cba

Fix null reference exception.

Occurred when using relative mouse mode without a focused window.

diff -r 07e08cb58696 -r 43d4e29a5dfc src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Sat Jan 28 14:53:23 2012 -0500
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
@@ -323,7 +323,7 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled) {
  • if (!enabled && mouse->focus) {
    /* Restore the expected mouse position */
    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    }

HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328266431 -46800

Node ID 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Parent 43d4e29a5dfc8f3343127578047d38183b1c1a4c

Change SDL_SetCursor to set the cursor back to the default cursor when the
window is unfocused.

diff -r 43d4e29a5dfc -r 2688fd67db68 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:08:48 2012 +1300
+++ b/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
@@ -465,7 +465,11 @@
}
mouse->cur_cursor = cursor;
} else {

  •    cursor = mouse->cur_cursor;
    
  •    if (mouse->focus) {
    
  •        cursor = mouse->cur_cursor;
    
  •    } else {
    
  •        cursor = mouse->def_cursor;
    
  •    }
    

    }

    if (cursor && mouse->cursor_shown && !mouse->relative_mode) {
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoamouse.m
    — a/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoamouse.m Fri Feb 03 23:53:51 2012 +1300
    @@ -92,15 +92,13 @@
    {
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];

  • if (SDL_GetMouseFocus()) {
  •    if (cursor) {
    
  •        NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  • if (cursor) {
  •    NSCursor *nscursor = (NSCursor *)cursor->driverdata;
    
  •        [nscursor set];
    
  •        [NSCursor unhide];
    
  •    } else {
    
  •        [NSCursor hide];
    
  •    }
    
  •    [nscursor set];
    
  •    [NSCursor unhide];
    
  • } else {

  •    [NSCursor hide];
    

    }

    [pool release];
    diff -r 43d4e29a5dfc -r 2688fd67db68 src/video/cocoa/SDL_cocoawindow.m
    — a/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:08:48 2012 +1300
    +++ b/src/video/cocoa/SDL_cocoawindow.m Fri Feb 03 23:53:51 2012 +1300
    @@ -313,9 +313,7 @@
    CGDisplayMoveCursorToPoint(kCGDirectMainDisplay, cgpoint);
    } else {
    SDL_SetMouseFocus(NULL);

  •        [[NSCursor arrowCursor] set];
    
  •        [NSCursor unhide];
    
  •        SDL_SetCursor(NULL);
     }
    
    }
    }

HG changeset patch

User Wim Looman <@Wim_Looman>

Date 1328267601 -46800

Node ID 0d5148d1e578c2a9eb35f3afe2b541d1e48c90e5

Parent 2688fd67db682b8f907c71b8e0516a46fa9a7f14

Make mouse relative mode save the original co-ordinates to restore them
properly.

diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse.c
— a/src/events/SDL_mouse.c Fri Feb 03 23:53:51 2012 +1300
+++ b/src/events/SDL_mouse.c Sat Feb 04 00:13:21 2012 +1300
@@ -323,9 +323,13 @@
/* Set the relative mode */
mouse->relative_mode = enabled;

  • if (!enabled && mouse->focus) {
  • if (enabled) {
  •    /* Save the expected mouse position */
    
  •    mouse->original_x = mouse->x;
    
  •    mouse->original_y = mouse->y;
    
  • } else if (mouse->focus) {
    /* Restore the expected mouse position */
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->x, mouse->y);
    
  •    SDL_WarpMouseInWindow(mouse->focus, mouse->original_x, mouse->original_y);
    

    }

    /* Flush pending mouse motion /
    diff -r 2688fd67db68 -r 0d5148d1e578 src/events/SDL_mouse_c.h
    — a/src/events/SDL_mouse_c.h Fri Feb 03 23:53:51 2012 +1300
    +++ b/src/events/SDL_mouse_c.h Sat Feb 04 00:13:21 2012 +1300
    @@ -60,6 +60,8 @@
    int last_x, last_y; /
    the last reported x and y coordinates */
    Uint8 buttonstate;
    SDL_bool relative_mode;

  • /* the x and y coordinates when relative mode was activated */

  • int original_x, original_y;

SDL_Cursor *cursors;
SDL_Cursor *def_cursor;


SDL mailing list
SDL at lists.libsdl.org
http://lists.libsdl.org/listinfo.cgi/sdl-libsdl.org