Skip to content

Commit 57346f2

Browse files
committed
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.
1 parent caf269c commit 57346f2

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/dialog/cocoa/SDL_cocoadialog.m

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ static void AddFileExtensionType(NSMutableArray *types, const char *pattern_ptr)
4747
}
4848
}
4949

50+
static void ReactivateAfterDialog(void)
51+
{
52+
for (NSRunningApplication *i in [NSRunningApplication runningApplicationsWithBundleIdentifier:@"com.apple.dock"]) {
53+
[i activateWithOptions:0];
54+
break;
55+
}
56+
[NSApp activateIgnoringOtherApps:YES];
57+
}
58+
5059
void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFileCallback callback, void *userdata, SDL_PropertiesID props)
5160
{
5261
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
176185
const char *files[1] = { NULL };
177186
callback(userdata, files, -1);
178187
}
188+
189+
ReactivateAfterDialog();
179190
}];
180191
} else {
181192
if ([dialog runModal] == NSModalResponseOK) {
@@ -195,6 +206,7 @@ void SDL_SYS_ShowFileDialogWithProperties(SDL_FileDialogType type, SDL_DialogFil
195206
const char *files[1] = { NULL };
196207
callback(userdata, files, -1);
197208
}
209+
ReactivateAfterDialog();
198210
}
199211
}
200212

0 commit comments

Comments
 (0)