diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index cbedafacbf6f480eb9940c73ae611dd8deb9363a..a736776bd2de74571d182b8bac657d4d63b50956 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -26,6 +26,13 @@ #include #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 +#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() */ diff --git a/plug-ins/script-fu/libscriptfu/script-fu-dialog.c b/plug-ins/script-fu/libscriptfu/script-fu-dialog.c index 6b5e4cfc1d2569685038a9ac31ae8ef28f018096..dee19979665fa6808109913b9d1b8ebc6e1a8b1a 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-dialog.c +++ b/plug-ins/script-fu/libscriptfu/script-fu-dialog.c @@ -22,6 +22,10 @@ #include +#ifdef GDK_WINDOWING_QUARTZ +#import +#endif + #include "script-fu-types.h" /* SFScript */ #include "script-fu-script.h" /* get_title */ #include "script-fu-command.h" @@ -212,6 +216,21 @@ sf_dialog_run (GimpProcedure *procedure, gimp_procedure_dialog_fill_list (dialog, NULL); } +#ifdef GDK_WINDOWING_QUARTZ + /* Make the Dock icon appear. + * The dialog does not stay in front, so user needs Dock menu item "Show." + */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + + /* 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 @@ -252,6 +271,11 @@ script_fu_dialog_run_image_proc ( else result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL); +#ifdef GDK_WINDOWING_QUARTZ + /* Make dock icon go away. */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +#endif + return result; } @@ -277,6 +301,11 @@ script_fu_dialog_run_regular_proc (GimpProcedure *procedure, else result = gimp_procedure_new_return_values (procedure, GIMP_PDB_CANCEL, NULL); +#ifdef GDK_WINDOWING_QUARTZ + /* Make dock icon go away. */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +#endif + return result; } diff --git a/plug-ins/script-fu/libscriptfu/script-fu-interface.c b/plug-ins/script-fu/libscriptfu/script-fu-interface.c index 485ed175cf88454caf141f3e31e1ad5565168aae..1faed5622a4895dcefc25ae5171db6958044c37e 100644 --- a/plug-ins/script-fu/libscriptfu/script-fu-interface.c +++ b/plug-ins/script-fu/libscriptfu/script-fu-interface.c @@ -517,6 +517,12 @@ script_fu_interface_dialog (SFScript *script, gtk_widget_show (dialog); gtk_main (); + /* The script ran, or was canceled, and called gtk_main_quit */ + +#ifdef GDK_WINDOWING_QUARTZ + /* Make dock icon go away. */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyAccessory]; +#endif #ifdef G_OS_WIN32 if (! GetForegroundWindow ()) @@ -1004,9 +1010,9 @@ script_fu_activate_main_dialog (void) { /* Ensure the main dialog of the script-fu extension process is not obscured. */ #ifdef GDK_WINDOWING_QUARTZ - /* In Objective-C, get instance of NSApplication - * and send it a "activateIgnoringOtherApps" message, i.e. bring to front. - */ + /* Make Dock icon appear. */ + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + /* Bring to front. */ [NSApp activateIgnoringOtherApps: YES]; #else /* empty function, optimized out. */ diff --git a/plug-ins/script-fu/script-fu.c b/plug-ins/script-fu/script-fu.c index 6d3372cc0e1910e9549f2e22b21cc425f0f88a75..ff685618a21600d6b4dae6b2d98983ff94608ce9 100644 --- a/plug-ins/script-fu/script-fu.c +++ b/plug-ins/script-fu/script-fu.c @@ -202,16 +202,24 @@ script_fu_run (GimpProcedure *procedure, if (strcmp (name, "extension-script-fu") == 0) { - /* - * The main script-fu extension. + /* Simultaneously poll both reads of commands from gimp app, and GUI events. + * extension-script-fu periodically has GUI: dialogs for sequential commands. */ /* Acknowledge that the extension is properly initialized */ gimp_procedure_persistent_ready (procedure); - /* Go into an endless loop */ - while (TRUE) - gimp_plug_in_persistent_process (plug_in, 0); + /* Hang async read from gimp app. */ + gimp_plug_in_persistent_enable (plug_in); + + /* Process both async reads of commands and GUI events. */ + g_main_loop_run (g_main_loop_new (NULL, FALSE)); + + /* The loop does not return because no command or event calls gimp_quit. + * Gimp app does not orderly shutdown extension-script-fu. + * When orderly, need to free the GMainLoop. + */ + g_assert_not_reached (); } else if (strcmp (name, "plug-in-script-fu-text-console") == 0) {