|
@@ -707,10 +707,7 @@ static SDL_Window *GetParentToplevelWindow(SDL_Window *window)
|
|
static void Cocoa_SetKeyboardFocus(SDL_Window *window, bool set_active_focus)
|
|
static void Cocoa_SetKeyboardFocus(SDL_Window *window, bool set_active_focus)
|
|
{
|
|
{
|
|
SDL_Window *toplevel = GetParentToplevelWindow(window);
|
|
SDL_Window *toplevel = GetParentToplevelWindow(window);
|
|
- SDL_CocoaWindowData *toplevel_data;
|
|
|
|
-
|
|
|
|
- toplevel_data = (__bridge SDL_CocoaWindowData *)toplevel->internal;
|
|
|
|
- toplevel_data.keyboard_focus = window;
|
|
|
|
|
|
+ toplevel->keyboard_focus = window;
|
|
|
|
|
|
if (set_active_focus && !window->is_hiding && !window->is_destroying) {
|
|
if (set_active_focus && !window->is_hiding && !window->is_destroying) {
|
|
SDL_SetKeyboardFocus(window);
|
|
SDL_SetKeyboardFocus(window);
|
|
@@ -1252,7 +1249,7 @@ static NSCursor *Cocoa_GetDesiredCursor(void)
|
|
|
|
|
|
// We're going to get keyboard events, since we're key.
|
|
// We're going to get keyboard events, since we're key.
|
|
// This needs to be done before restoring the relative mouse mode.
|
|
// This needs to be done before restoring the relative mouse mode.
|
|
- Cocoa_SetKeyboardFocus(_data.keyboard_focus ? _data.keyboard_focus : window, true);
|
|
|
|
|
|
+ Cocoa_SetKeyboardFocus(window->keyboard_focus ? window->keyboard_focus : window, true);
|
|
|
|
|
|
// If we just gained focus we need the updated mouse position
|
|
// If we just gained focus we need the updated mouse position
|
|
if (!(window->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE)) {
|
|
if (!(window->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE)) {
|
|
@@ -2261,7 +2258,9 @@ static bool SetupWindowData(SDL_VideoDevice *_this, SDL_Window *window, NSWindow
|
|
[nswindow setIgnoresMouseEvents:YES];
|
|
[nswindow setIgnoresMouseEvents:YES];
|
|
[nswindow setAcceptsMouseMovedEvents:NO];
|
|
[nswindow setAcceptsMouseMovedEvents:NO];
|
|
} else if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_HIDDEN)) {
|
|
} else if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_HIDDEN)) {
|
|
- Cocoa_SetKeyboardFocus(window, window->parent == SDL_GetKeyboardFocus());
|
|
|
|
|
|
+ if (!(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
|
|
|
|
+ Cocoa_SetKeyboardFocus(window, true);
|
|
|
|
+ }
|
|
Cocoa_UpdateMouseFocus();
|
|
Cocoa_UpdateMouseFocus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2351,7 +2350,7 @@ bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
|
|
rect.origin.y -= screenRect.origin.y;
|
|
rect.origin.y -= screenRect.origin.y;
|
|
|
|
|
|
// Constrain the popup
|
|
// Constrain the popup
|
|
- if (SDL_WINDOW_IS_POPUP(window)) {
|
|
|
|
|
|
+ if (SDL_WINDOW_IS_POPUP(window) && window->constrain_popup) {
|
|
if (rect.origin.x + rect.size.width > screenRect.origin.x + screenRect.size.width) {
|
|
if (rect.origin.x + rect.size.width > screenRect.origin.x + screenRect.size.width) {
|
|
rect.origin.x -= (rect.origin.x + rect.size.width) - (screenRect.origin.x + screenRect.size.width);
|
|
rect.origin.x -= (rect.origin.x + rect.size.width) - (screenRect.origin.x + screenRect.size.width);
|
|
}
|
|
}
|
|
@@ -2507,7 +2506,7 @@ bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
|
|
ConvertNSRect(&rect);
|
|
ConvertNSRect(&rect);
|
|
|
|
|
|
// Position and constrain the popup
|
|
// Position and constrain the popup
|
|
- if (SDL_WINDOW_IS_POPUP(window)) {
|
|
|
|
|
|
+ if (SDL_WINDOW_IS_POPUP(window) && window->constrain_popup) {
|
|
NSRect screenRect = [ScreenForRect(&rect) frame];
|
|
NSRect screenRect = [ScreenForRect(&rect) frame];
|
|
|
|
|
|
if (rect.origin.x + rect.size.width > screenRect.origin.x + screenRect.size.width) {
|
|
if (rect.origin.x + rect.size.width > screenRect.origin.x + screenRect.size.width) {
|
|
@@ -2648,7 +2647,9 @@ void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} else if (window->flags & SDL_WINDOW_POPUP_MENU) {
|
|
} else if (window->flags & SDL_WINDOW_POPUP_MENU) {
|
|
- Cocoa_SetKeyboardFocus(window, window->parent == SDL_GetKeyboardFocus());
|
|
|
|
|
|
+ if (!(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
|
|
|
|
+ Cocoa_SetKeyboardFocus(window, true);
|
|
|
|
+ }
|
|
Cocoa_UpdateMouseFocus();
|
|
Cocoa_UpdateMouseFocus();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -2682,20 +2683,9 @@ void Cocoa_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
|
Cocoa_SetWindowModal(_this, window, false);
|
|
Cocoa_SetWindowModal(_this, window, false);
|
|
|
|
|
|
// Transfer keyboard focus back to the parent when closing a popup menu
|
|
// Transfer keyboard focus back to the parent when closing a popup menu
|
|
- if (window->flags & SDL_WINDOW_POPUP_MENU) {
|
|
|
|
- SDL_Window *new_focus = window->parent;
|
|
|
|
- bool set_focus = window == SDL_GetKeyboardFocus();
|
|
|
|
-
|
|
|
|
- // Find the highest level window, up to the toplevel parent, that isn't being hidden or destroyed.
|
|
|
|
- while (SDL_WINDOW_IS_POPUP(new_focus) && (new_focus->is_hiding || new_focus->is_destroying)) {
|
|
|
|
- new_focus = new_focus->parent;
|
|
|
|
-
|
|
|
|
- // If some window in the chain currently had focus, set it to the new lowest-level window.
|
|
|
|
- if (!set_focus) {
|
|
|
|
- set_focus = new_focus == SDL_GetKeyboardFocus();
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
|
|
+ if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
|
|
|
|
+ SDL_Window *new_focus;
|
|
|
|
+ const bool set_focus = SDL_ShouldRelinquishPopupFocus(window, &new_focus);
|
|
Cocoa_SetKeyboardFocus(new_focus, set_focus);
|
|
Cocoa_SetKeyboardFocus(new_focus, set_focus);
|
|
Cocoa_UpdateMouseFocus();
|
|
Cocoa_UpdateMouseFocus();
|
|
} else if (window->parent && waskey) {
|
|
} else if (window->parent && waskey) {
|
|
@@ -3122,20 +3112,19 @@ void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
|
|
|
|
|
|
#endif // SDL_VIDEO_OPENGL
|
|
#endif // SDL_VIDEO_OPENGL
|
|
SDL_Window *topmost = GetParentToplevelWindow(window);
|
|
SDL_Window *topmost = GetParentToplevelWindow(window);
|
|
- SDL_CocoaWindowData *topmost_data = (__bridge SDL_CocoaWindowData *)topmost->internal;
|
|
|
|
|
|
|
|
/* Reset the input focus of the root window if this window is still set as keyboard focus.
|
|
/* Reset the input focus of the root window if this window is still set as keyboard focus.
|
|
* SDL_DestroyWindow will have already taken care of reassigning focus if this is the SDL
|
|
* SDL_DestroyWindow will have already taken care of reassigning focus if this is the SDL
|
|
* keyboard focus, this ensures that an inactive window with this window set as input focus
|
|
* keyboard focus, this ensures that an inactive window with this window set as input focus
|
|
* does not try to reference it the next time it gains focus.
|
|
* does not try to reference it the next time it gains focus.
|
|
*/
|
|
*/
|
|
- if (topmost_data.keyboard_focus == window) {
|
|
|
|
|
|
+ if (topmost->keyboard_focus == window) {
|
|
SDL_Window *new_focus = window;
|
|
SDL_Window *new_focus = window;
|
|
while (SDL_WINDOW_IS_POPUP(new_focus) && (new_focus->is_hiding || new_focus->is_destroying)) {
|
|
while (SDL_WINDOW_IS_POPUP(new_focus) && (new_focus->is_hiding || new_focus->is_destroying)) {
|
|
new_focus = new_focus->parent;
|
|
new_focus = new_focus->parent;
|
|
}
|
|
}
|
|
|
|
|
|
- topmost_data.keyboard_focus = new_focus;
|
|
|
|
|
|
+ topmost->keyboard_focus = new_focus;
|
|
}
|
|
}
|
|
|
|
|
|
if ([data.listener isInFullscreenSpace]) {
|
|
if ([data.listener isInFullscreenSpace]) {
|
|
@@ -3300,6 +3289,20 @@ bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOper
|
|
|
|
|
|
bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
|
|
bool Cocoa_SetWindowFocusable(SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
|
|
{
|
|
{
|
|
|
|
+ if (window->flags & SDL_WINDOW_POPUP_MENU) {
|
|
|
|
+ if (!(window->flags & SDL_WINDOW_HIDDEN)) {
|
|
|
|
+ if (!focusable && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
|
|
|
|
+ SDL_Window *new_focus;
|
|
|
|
+ const bool set_focus = SDL_ShouldRelinquishPopupFocus(window, &new_focus);
|
|
|
|
+ Cocoa_SetKeyboardFocus(new_focus, set_focus);
|
|
|
|
+ } else if (focusable) {
|
|
|
|
+ if (SDL_ShouldFocusPopup(window)) {
|
|
|
|
+ Cocoa_SetKeyboardFocus(window, true);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
return true; // just succeed, the real work is done elsewhere.
|
|
return true; // just succeed, the real work is done elsewhere.
|
|
}
|
|
}
|
|
|
|
|