ScriptFu: fix #12150, activate apps (extension-script-fu and gimp) properly on MacOS

The gimp app and extension-script-fu (long-running)
are separate processes and "apps."
An app can be "active": in front and receiving GUI events.

As reported, on MacOS, when an extension-script-fu plugin yields,
the gimp app did not become active.
Also, on the second invocation of a plugin served by extension-script-fu,
the dialog could be hidden or require an extra click
because extension-script-fu was not active.
(Independently interpreted plugins did become active,
because it was a new process and gimpui_init activates on MacOS.)

On MacOS:
1. after the first dialog shown by extension-script-fu,
ensure subsequent calls to plugin make extension-script-fu active.
2. After a plugin yields, plugin manager ensure the Gimp app is active.

Note that this is done whenever a TEMPORARY procedure returns.
Most are calls to extension-script-fu plugins.
But some are also callbacks from Resource choosers running in the gimp app.
When they return, the gimp app remains active, and user must first click in
the plugin dialog to continue working.
Especially when the user clicks OK in a Resource Chooser, closing the chooser,
it would be nice if the plugin dialog became active.
That requires more, FUTURE development.

Special to MacOS: on Linux, "transient for foreign window" ensures this,
but that doesn't work on MacOS.

The fix is somewhat brute force and as simple as possible.
There is a more cooperative API for app activation on MacOS.
An app yields, and apps request, not force, self or other app be activated.
The fix does not use the cooperative API.
To do so would require a platform abstraction layer, in GIMP or Gtk.

The fix also sprinkles the code with #ifdefs.
That could be hidden if there were a platform abstraction layer PAL
The layer would be the greatest common denominator across platforms.
PAL methods would always be called in GIMP code,
but not do anything when the effect was accomplished another way.
For example "gimp_platform_request_app_active"
would request the app was active,
but do nothing on Linux where that is ensured by "transient for."
This commit is contained in:
lloyd konneker 2024-12-03 09:58:00 -05:00 committed by Lukas Oberhuber
parent 5ae61a890d
commit 078e283f4b
2 changed files with 33 additions and 0 deletions

View File

@ -26,6 +26,13 @@
#include <windows.h>
#endif
#ifdef __APPLE__
/* Not include gtk/gtk.h and depend on gtk just for GDK_WINDOWING_QUARTZ macro.
* __APPLE__ suffices, we only build for MacOS (vs iOS) and Quartz (vs X11)
*/
#import <Cocoa/Cocoa.h>
#endif
#include "libgimpbase/gimpbase.h"
#include "libgimpbase/gimpprotocol.h"
#include "libgimpbase/gimpwire.h"
@ -385,6 +392,18 @@ gimp_plug_in_manager_call_run_temp (GimpPlugInManager *manager,
gimp_plug_in_main_loop (plug_in);
#ifdef __APPLE__
/* The plugin temporary procedure returned, from separate, active process.
* Ensure gimp app active.
* Usually extension-script-fu was active, except when the temporary procedure
* was say a callback from a Resource chooser dialog.
* In that case, when the chooser is closing, it would be better
* to activate the plugin, avoiding an extra click by the user.
* We can't do that here, unless we use the more cooperative API of MacOS.
*/
[NSApp activateIgnoringOtherApps:YES];
#endif
/* main_loop is quit and proc_frame is popped in
* gimp_plug_in_handle_temp_proc_return()
*/

View File

@ -22,6 +22,10 @@
#include <libgimp/gimpui.h>
#ifdef GDK_WINDOWING_QUARTZ
#import <Cocoa/Cocoa.h>
#endif
#include "script-fu-types.h" /* SFScript */
#include "script-fu-script.h" /* get_title */
#include "script-fu-command.h"
@ -212,6 +216,16 @@ sf_dialog_run (GimpProcedure *procedure,
gimp_procedure_dialog_fill_list (dialog, NULL);
}
#ifdef GDK_WINDOWING_QUARTZ
/* The user chose a plugin from gimp app, now ensure this process is active.
* The gimp app was active, but now the plugin should be active.
* This is also called in gimpui_init(), but that is not sufficient
* for second calls of plugins served by long-running extension-script-fu.
* The user can still raise other gimp windows, hiding the dialog.
*/
[NSApp activateIgnoringOtherApps:YES];
#endif
not_canceled = gimp_procedure_dialog_run (dialog);
#if DEBUG_CONFIG_PROPERTIES