Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register
authorSam Lantinga <slouken@libsdl.org>
Thu, 14 Nov 2013 22:26:49 -0800
changeset 7990a05a48e493c0
parent 7989 c13adfce24a9
child 7992 6558e2b68c03
Fixed bug 2240 - On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register

philhassey

On OS/X after calling SDL_SetWindowBordered right mouse clicks no longer register.

Steps to Reproduce:

1. Open a windowed window on OS/X. (With the border on.)

2. e.button.button will give values 1,2,3 depending on which mouse button I click.

3. Call SDL_SetWindowBordered to disable the border.

4. e.button.button will only give values 1,2. 3 (right mouse button) stops coming through.

Expected result:

I expect all mouse buttons to register.
src/video/cocoa/SDL_cocoawindow.m
     1.1 --- a/src/video/cocoa/SDL_cocoawindow.m	Thu Nov 14 21:39:54 2013 -0800
     1.2 +++ b/src/video/cocoa/SDL_cocoawindow.m	Thu Nov 14 22:26:49 2013 -0800
     1.3 @@ -88,6 +88,31 @@
     1.4      return style;
     1.5  }
     1.6  
     1.7 +static SDL_bool
     1.8 +SetWindowStyle(SDL_Window * window, unsigned int style)
     1.9 +{
    1.10 +    SDL_WindowData *data = (SDL_WindowData *) window->driverdata;
    1.11 +    NSWindow *nswindow = data->nswindow;
    1.12 +
    1.13 +    if (![nswindow respondsToSelector: @selector(setStyleMask:)]) {
    1.14 +        return SDL_FALSE;
    1.15 +    }
    1.16 +
    1.17 +    /* The view responder chain gets messed with during setStyleMask */
    1.18 +    if ([[nswindow contentView] nextResponder] == data->listener) {
    1.19 +        [[nswindow contentView] setNextResponder:nil];
    1.20 +    }
    1.21 +
    1.22 +    [nswindow performSelector: @selector(setStyleMask:) withObject: (id)(uintptr_t)style];
    1.23 +
    1.24 +    /* The view responder chain gets messed with during setStyleMask */
    1.25 +    if ([[nswindow contentView] nextResponder] != data->listener) {
    1.26 +        [[nswindow contentView] setNextResponder:data->listener];
    1.27 +    }
    1.28 +
    1.29 +    return SDL_TRUE;
    1.30 +}
    1.31 +
    1.32  
    1.33  @implementation Cocoa_WindowListener
    1.34  
    1.35 @@ -422,10 +447,9 @@
    1.36  - (void)windowWillEnterFullScreen:(NSNotification *)aNotification
    1.37  {
    1.38      SDL_Window *window = _data->window;
    1.39 -    NSWindow *nswindow = _data->nswindow;
    1.40  
    1.41      window->flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.42 -    [nswindow setStyleMask:(NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask)];
    1.43 +    SetWindowStyle(window, (NSTitledWindowMask|NSClosableWindowMask|NSMiniaturizableWindowMask|NSResizableWindowMask));
    1.44  
    1.45      isFullscreenSpace = YES;
    1.46      inFullscreenTransition = YES;
    1.47 @@ -454,10 +478,9 @@
    1.48  - (void)windowWillExitFullScreen:(NSNotification *)aNotification
    1.49  {
    1.50      SDL_Window *window = _data->window;
    1.51 -    NSWindow *nswindow = _data->nswindow;
    1.52  
    1.53      window->flags &= ~SDL_WINDOW_FULLSCREEN_DESKTOP;
    1.54 -    [nswindow setStyleMask:GetWindowStyle(window)];
    1.55 +    SetWindowStyle(window, GetWindowStyle(window));
    1.56  
    1.57      isFullscreenSpace = NO;
    1.58      inFullscreenTransition = YES;
    1.59 @@ -1173,9 +1196,7 @@
    1.60  Cocoa_SetWindowBordered(_THIS, SDL_Window * window, SDL_bool bordered)
    1.61  {
    1.62      NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    1.63 -    NSWindow *nswindow = ((SDL_WindowData *) window->driverdata)->nswindow;
    1.64 -    if ([nswindow respondsToSelector:@selector(setStyleMask:)]) {
    1.65 -        [nswindow setStyleMask:GetWindowStyle(window)];
    1.66 +    if (SetWindowStyle(window, GetWindowStyle(window))) {
    1.67          if (bordered) {
    1.68              Cocoa_SetWindowTitle(_this, window);  /* this got blanked out. */
    1.69          }