From 366b1727bb2faa82f65c7d0a99142a9c195eb416 Mon Sep 17 00:00:00 2001 From: "J?rgen P. Tjern?" Date: Wed, 29 Jan 2014 18:37:23 -0800 Subject: [PATCH] Mac: [NSApp keyWindow] is not valid in windowDidBecomeKey: This fixes weird behavior on Mac where our first responder reverts to the window itself, rather than the SDLTranslatorResponder, after the window has lost focus once. This causes Escape to call cancelOperation: on the NSWindow, which by default removes our fullscreen-ness. When someone has turned off SDL_TEXTINPUT we should probably set another initial responder that handles the Escape behavior, so that SDL_TEXTINPUT doesn't change fullscreen behavior (and possibly other behavior) like it does now. --- src/video/cocoa/SDL_cocoakeyboard.m | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/video/cocoa/SDL_cocoakeyboard.m b/src/video/cocoa/SDL_cocoakeyboard.m index 406de234e..6f8a6efd8 100644 --- a/src/video/cocoa/SDL_cocoakeyboard.m +++ b/src/video/cocoa/SDL_cocoakeyboard.m @@ -506,7 +506,12 @@ Cocoa_StartTextInput(_THIS) { SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSView *parentView = [[NSApp keyWindow] contentView]; + SDL_Window *window = SDL_GetKeyboardFocus(); + NSWindow *nswindow = nil; + if (window) + nswindow = ((SDL_WindowData*)window->driverdata)->nswindow; + + NSView *parentView = [nswindow contentView]; /* We only keep one field editor per process, since only the front most * window can receive text input events, so it make no sense to keep more @@ -523,7 +528,7 @@ Cocoa_StartTextInput(_THIS) /* DEBUG_IME(@"add fieldEdit to window contentView"); */ [data->fieldEdit removeFromSuperview]; [parentView addSubview: data->fieldEdit]; - [[NSApp keyWindow] makeFirstResponder: data->fieldEdit]; + [nswindow makeFirstResponder: data->fieldEdit]; } [pool release];