@@ -707,10 +707,7 @@ static void Cocoa_UpdateClipCursor(SDL_Window *window)
707
707
static void Cocoa_SetKeyboardFocus (SDL_Window *window, bool set_active_focus)
708
708
{
709
709
SDL_Window *toplevel = GetParentToplevelWindow (window);
710
- SDL_CocoaWindowData *toplevel_data;
711
-
712
- toplevel_data = (__bridge SDL_CocoaWindowData *)toplevel->internal ;
713
- toplevel_data.keyboard_focus = window;
710
+ toplevel->keyboard_focus = window;
714
711
715
712
if (set_active_focus && !window->is_hiding && !window->is_destroying ) {
716
713
SDL_SetKeyboardFocus (window);
@@ -1252,7 +1249,7 @@ - (void)windowDidBecomeKey:(NSNotification *)aNotification
1252
1249
1253
1250
// We're going to get keyboard events, since we're key.
1254
1251
// This needs to be done before restoring the relative mouse mode.
1255
- Cocoa_SetKeyboardFocus (_data. keyboard_focus ? _data. keyboard_focus : window, true );
1252
+ Cocoa_SetKeyboardFocus (window-> keyboard_focus ? window-> keyboard_focus : window, true );
1256
1253
1257
1254
// If we just gained focus we need the updated mouse position
1258
1255
if (!(window->flags & SDL_WINDOW_MOUSE_RELATIVE_MODE)) {
@@ -2244,7 +2241,9 @@ then immediately ordering out (removing) the window does work. */
2244
2241
[nswindow setIgnoresMouseEvents: YES ];
2245
2242
[nswindow setAcceptsMouseMovedEvents: NO ];
2246
2243
} else if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_HIDDEN)) {
2247
- Cocoa_SetKeyboardFocus (window, window->parent == SDL_GetKeyboardFocus ());
2244
+ if (!(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
2245
+ Cocoa_SetKeyboardFocus (window, true );
2246
+ }
2248
2247
Cocoa_UpdateMouseFocus ();
2249
2248
}
2250
2249
}
@@ -2334,7 +2333,7 @@ bool Cocoa_CreateWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_Properti
2334
2333
rect.origin .y -= screenRect.origin .y ;
2335
2334
2336
2335
// Constrain the popup
2337
- if (SDL_WINDOW_IS_POPUP (window)) {
2336
+ if (SDL_WINDOW_IS_POPUP (window) && window-> constrain_popup ) {
2338
2337
if (rect.origin .x + rect.size .width > screenRect.origin .x + screenRect.size .width ) {
2339
2338
rect.origin .x -= (rect.origin .x + rect.size .width ) - (screenRect.origin .x + screenRect.size .width );
2340
2339
}
@@ -2490,7 +2489,7 @@ bool Cocoa_SetWindowPosition(SDL_VideoDevice *_this, SDL_Window *window)
2490
2489
ConvertNSRect (&rect);
2491
2490
2492
2491
// Position and constrain the popup
2493
- if (SDL_WINDOW_IS_POPUP (window)) {
2492
+ if (SDL_WINDOW_IS_POPUP (window) && window-> constrain_popup ) {
2494
2493
NSRect screenRect = [ScreenForRect (&rect) frame ];
2495
2494
2496
2495
if (rect.origin .x + rect.size .width > screenRect.origin .x + screenRect.size .width ) {
@@ -2631,7 +2630,9 @@ void Cocoa_ShowWindow(SDL_VideoDevice *_this, SDL_Window *window)
2631
2630
}
2632
2631
}
2633
2632
} else if (window->flags & SDL_WINDOW_POPUP_MENU) {
2634
- Cocoa_SetKeyboardFocus (window, window->parent == SDL_GetKeyboardFocus ());
2633
+ if (!(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
2634
+ Cocoa_SetKeyboardFocus (window, true );
2635
+ }
2635
2636
Cocoa_UpdateMouseFocus ();
2636
2637
}
2637
2638
}
@@ -2665,20 +2666,9 @@ void Cocoa_HideWindow(SDL_VideoDevice *_this, SDL_Window *window)
2665
2666
Cocoa_SetWindowModal (_this, window, false );
2666
2667
2667
2668
// Transfer keyboard focus back to the parent when closing a popup menu
2668
- if (window->flags & SDL_WINDOW_POPUP_MENU) {
2669
- SDL_Window *new_focus = window->parent ;
2670
- bool set_focus = window == SDL_GetKeyboardFocus ();
2671
-
2672
- // Find the highest level window, up to the toplevel parent, that isn't being hidden or destroyed.
2673
- while (SDL_WINDOW_IS_POPUP (new_focus) && (new_focus->is_hiding || new_focus->is_destroying )) {
2674
- new_focus = new_focus->parent ;
2675
-
2676
- // If some window in the chain currently had focus, set it to the new lowest-level window.
2677
- if (!set_focus) {
2678
- set_focus = new_focus == SDL_GetKeyboardFocus ();
2679
- }
2680
- }
2681
-
2669
+ if ((window->flags & SDL_WINDOW_POPUP_MENU) && !(window->flags & SDL_WINDOW_NOT_FOCUSABLE)) {
2670
+ SDL_Window *new_focus;
2671
+ const bool set_focus = SDL_ShouldRelinquishPopupFocus (window, &new_focus);
2682
2672
Cocoa_SetKeyboardFocus (new_focus, set_focus);
2683
2673
Cocoa_UpdateMouseFocus ();
2684
2674
} else if (window->parent && waskey) {
@@ -3105,20 +3095,19 @@ void Cocoa_DestroyWindow(SDL_VideoDevice *_this, SDL_Window *window)
3105
3095
3106
3096
#endif // SDL_VIDEO_OPENGL
3107
3097
SDL_Window *topmost = GetParentToplevelWindow (window);
3108
- SDL_CocoaWindowData *topmost_data = (__bridge SDL_CocoaWindowData *)topmost->internal ;
3109
3098
3110
3099
/* Reset the input focus of the root window if this window is still set as keyboard focus.
3111
3100
* SDL_DestroyWindow will have already taken care of reassigning focus if this is the SDL
3112
3101
* keyboard focus, this ensures that an inactive window with this window set as input focus
3113
3102
* does not try to reference it the next time it gains focus.
3114
3103
*/
3115
- if (topmost_data. keyboard_focus == window) {
3104
+ if (topmost-> keyboard_focus == window) {
3116
3105
SDL_Window *new_focus = window;
3117
3106
while (SDL_WINDOW_IS_POPUP (new_focus) && (new_focus->is_hiding || new_focus->is_destroying )) {
3118
3107
new_focus = new_focus->parent ;
3119
3108
}
3120
3109
3121
- topmost_data. keyboard_focus = new_focus;
3110
+ topmost-> keyboard_focus = new_focus;
3122
3111
}
3123
3112
3124
3113
if ([data.listener isInFullscreenSpace ]) {
@@ -3283,6 +3272,20 @@ bool Cocoa_FlashWindow(SDL_VideoDevice *_this, SDL_Window *window, SDL_FlashOper
3283
3272
3284
3273
bool Cocoa_SetWindowFocusable (SDL_VideoDevice *_this, SDL_Window *window, bool focusable)
3285
3274
{
3275
+ if (window->flags & SDL_WINDOW_POPUP_MENU) {
3276
+ if (!(window->flags & SDL_WINDOW_HIDDEN)) {
3277
+ if (!focusable && (window->flags & SDL_WINDOW_INPUT_FOCUS)) {
3278
+ SDL_Window *new_focus;
3279
+ const bool set_focus = SDL_ShouldRelinquishPopupFocus (window, &new_focus);
3280
+ Cocoa_SetKeyboardFocus (new_focus, set_focus);
3281
+ } else if (focusable) {
3282
+ if (SDL_ShouldFocusPopup (window)) {
3283
+ Cocoa_SetKeyboardFocus (window, true );
3284
+ }
3285
+ }
3286
+ }
3287
+ }
3288
+
3286
3289
return true ; // just succeed, the real work is done elsewhere.
3287
3290
}
3288
3291
0 commit comments