Procházet zdrojové kódy

dialog: Cocoa backend should reactivate the app after the modal dialog.

Otherwise the window won't have focus until you click on it again. Calling
makeKeyAndOrderFront isn't enough to fix it, either.

This trick comes from a similar problem we solve in our
applicationDidFinishLaunching implementation: activate (give app focus to) the
system Dock, as something that definitely exists that isn't us and is harmless
to activate, and then activate us right afterwards. This unconfuses whatever
is getting confused inside Cocoa.

Fixes #12684.
Ryan C. Gordon před 7 měsíci
rodič
revize
57346f2ba8
1 změnil soubory, kde provedl 12 přidání a 0 odebrání
  1. 12 0
      src/dialog/cocoa/SDL_cocoadialog.m

+ 12 - 0
src/dialog/cocoa/SDL_cocoadialog.m

@@ -47,6 +47,15 @@ static void AddFileExtensionType(NSMutableArray *types, const char *pattern_ptr)
     }
 }
 
+static void ReactivateAfterDialog(void)
+{
+    for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
+        [i activateWithOptions:0];
+        break;
+    }
+    [NSApp activateIgnoringOtherApps:YES];
+}
+
 void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props)
 {
     SDL_Window* window = SDL_GetPointerProperty(props, SDL_PROP_FILE_DIALOG_WINDOW_POINTER, NULL);
@@ -176,6 +185,8 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
                 const char *files[1] = { NULL };
                 callback(userdata, files, -1);
             }
+
+            ReactivateAfterDialog();
         }];
     } else {
         if ([dialog runModal] == NSModalResponseOK) {
@@ -195,6 +206,7 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
             const char *files[1] = { NULL };
             callback(userdata, files, -1);
         }
+        ReactivateAfterDialog();
     }
 }