From cca637135b121ddbce782d3afabaecf6ff06d4ad Mon Sep 17 00:00:00 2001 From: Jehan Date: Sat, 8 Jun 2024 21:46:19 +0200 Subject: [PATCH] app, libgimp, pdb, plug-ins: fix failure to set plug-in as transient. While setting a plug-in as transient usually worked, it was failing in cases the plug-in's progress bar was not initialized (i.e. if progress_init() was not called before setting the dialog transient). This commit stores the calling display, core side too (libgimp side, the plug-in already had the calling display ID information), and we use this when a GimpProgress has not been created yet. --- app/pdb/progress-cmds.c | 4 ++-- app/plug-in/gimpplugin-progress.c | 2 ++ app/plug-in/gimpplugin.c | 8 +++++++- app/plug-in/gimpplugin.h | 4 +++- app/plug-in/gimppluginmanager-call.c | 12 ++++++------ libgimp/gimpprogress_pdb.c | 6 ++++-- pdb/groups/progress.pdb | 3 ++- plug-ins/common/file-ps.c | 7 ------- 8 files changed, 26 insertions(+), 20 deletions(-) diff --git a/app/pdb/progress-cmds.c b/app/pdb/progress-cmds.c index be9497e4db..72aaa1cd3c 100644 --- a/app/pdb/progress-cmds.c +++ b/app/pdb/progress-cmds.c @@ -414,8 +414,8 @@ register_progress_procs (GimpPDB *pdb) gimp_object_set_static_name (GIMP_OBJECT (procedure), "gimp-progress-get-window-handle"); gimp_procedure_set_static_help (procedure, - "Returns the native handle of the toplevel window this plug-in's progress is displayed in.", - "This function returns the native handle allowing to identify the toplevel window this plug-in's progress is displayed in.\n" + "Returns the native handle of the toplevel window this plug-in's progress is or would be displayed in.", + "This function returns the native handle allowing to identify the toplevel window this plug-in's progress is displayed in. It should still work even if the progress bar has not been initialized yet, unless the plug-in wasn't called from a GUI.\n" "This handle can be of various types (integer, string, etc.) depending on the platform you are running on which is why it returns a GBytes. There are usually no reasons to call this directly.", NULL); gimp_procedure_set_static_attribution (procedure, diff --git a/app/plug-in/gimpplugin-progress.c b/app/plug-in/gimpplugin-progress.c index a384987d7f..4381b6c0c6 100644 --- a/app/plug-in/gimpplugin-progress.c +++ b/app/plug-in/gimpplugin-progress.c @@ -244,6 +244,8 @@ gimp_plug_in_progress_get_window_id (GimpPlugIn *plug_in) if (proc_frame->progress) return gimp_progress_get_window_id (proc_frame->progress); + else if (plug_in->display) + return gimp_get_display_window_id (plug_in->manager->gimp, plug_in->display); return 0; } diff --git a/app/plug-in/gimpplugin.c b/app/plug-in/gimpplugin.c index 2dc813342b..7d02359052 100644 --- a/app/plug-in/gimpplugin.c +++ b/app/plug-in/gimpplugin.c @@ -75,6 +75,7 @@ #include "plug-in-types.h" #include "core/gimp.h" +#include "core/gimpdisplay.h" #include "core/gimp-spawn.h" #include "core/gimpprogress.h" @@ -142,6 +143,7 @@ gimp_plug_in_init (GimpPlugIn *plug_in) { plug_in->manager = NULL; plug_in->file = NULL; + plug_in->display = NULL; plug_in->call_mode = GIMP_PLUG_IN_CALL_NONE; plug_in->open = FALSE; @@ -171,6 +173,7 @@ gimp_plug_in_finalize (GObject *object) GimpPlugIn *plug_in = GIMP_PLUG_IN (object); g_clear_object (&plug_in->file); + g_clear_weak_pointer (&plug_in->display); gimp_plug_in_proc_frame_dispose (&plug_in->main_proc_frame, plug_in); @@ -396,7 +399,8 @@ gimp_plug_in_new (GimpPlugInManager *manager, GimpContext *context, GimpProgress *progress, GimpPlugInProcedure *procedure, - GFile *file) + GFile *file, + GimpDisplay *display) { GimpPlugIn *plug_in; @@ -406,6 +410,7 @@ gimp_plug_in_new (GimpPlugInManager *manager, g_return_val_if_fail (procedure == NULL || GIMP_IS_PLUG_IN_PROCEDURE (procedure), NULL); g_return_val_if_fail (file == NULL || G_IS_FILE (file), NULL); + g_return_val_if_fail (display == NULL || GIMP_IS_DISPLAY (display), NULL); g_return_val_if_fail ((procedure != NULL || file != NULL) && ! (procedure != NULL && file != NULL), NULL); @@ -419,6 +424,7 @@ gimp_plug_in_new (GimpPlugInManager *manager, plug_in->manager = manager; plug_in->file = g_object_ref (file); + g_set_weak_pointer (&plug_in->display, display); gimp_plug_in_proc_frame_init (&plug_in->main_proc_frame, context, progress, procedure); diff --git a/app/plug-in/gimpplugin.h b/app/plug-in/gimpplugin.h index 400be77056..de1f222494 100644 --- a/app/plug-in/gimpplugin.h +++ b/app/plug-in/gimpplugin.h @@ -44,6 +44,7 @@ struct _GimpPlugIn GimpPlugInManager *manager; GFile *file; /* Plug-in's full path name */ + GimpDisplay *display; /* The display this plug-in was called from. */ GimpPlugInCallMode call_mode; /* QUERY, INIT or RUN */ guint open : 1; /* Is the plug-in open? */ guint hup : 1; /* Did we receive a G_IO_HUP */ @@ -82,7 +83,8 @@ GimpPlugIn * gimp_plug_in_new (GimpPlugInManager *manager, GimpContext *context, GimpProgress *progress, GimpPlugInProcedure *procedure, - GFile *file); + GFile *file, + GimpDisplay *display); gboolean gimp_plug_in_open (GimpPlugIn *plug_in, GimpPlugInCallMode call_mode, diff --git a/app/plug-in/gimppluginmanager-call.c b/app/plug-in/gimppluginmanager-call.c index def62a335c..7579371f47 100644 --- a/app/plug-in/gimppluginmanager-call.c +++ b/app/plug-in/gimppluginmanager-call.c @@ -78,7 +78,7 @@ gimp_plug_in_manager_call_query (GimpPlugInManager *manager, g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def)); plug_in = gimp_plug_in_new (manager, context, NULL, - NULL, plug_in_def->file); + NULL, plug_in_def->file, NULL); if (plug_in) { @@ -118,7 +118,7 @@ gimp_plug_in_manager_call_init (GimpPlugInManager *manager, g_return_if_fail (GIMP_IS_PLUG_IN_DEF (plug_in_def)); plug_in = gimp_plug_in_new (manager, context, NULL, - NULL, plug_in_def->file); + NULL, plug_in_def->file, NULL); if (plug_in) { @@ -165,7 +165,10 @@ gimp_plug_in_manager_call_run (GimpPlugInManager *manager, g_return_val_if_fail (args != NULL, NULL); g_return_val_if_fail (display == NULL || GIMP_IS_DISPLAY (display), NULL); - plug_in = gimp_plug_in_new (manager, context, progress, procedure, NULL); + if (! display) + display = gimp_context_get_display (context); + + plug_in = gimp_plug_in_new (manager, context, progress, procedure, NULL, display); if (plug_in) { @@ -199,9 +202,6 @@ gimp_plug_in_manager_call_run (GimpPlugInManager *manager, return return_vals; } - if (! display) - display = gimp_context_get_display (context); - display_id = display ? gimp_display_get_id (display) : -1; icon_theme_dir = gimp_get_icon_theme_dir (manager->gimp); diff --git a/libgimp/gimpprogress_pdb.c b/libgimp/gimpprogress_pdb.c index 72bb35ac1c..906cdc2bc8 100644 --- a/libgimp/gimpprogress_pdb.c +++ b/libgimp/gimpprogress_pdb.c @@ -220,10 +220,12 @@ gimp_progress_end (void) * gimp_progress_get_window_handle: * * Returns the native handle of the toplevel window this plug-in's - * progress is displayed in. + * progress is or would be displayed in. * * This function returns the native handle allowing to identify the - * toplevel window this plug-in's progress is displayed in. + * toplevel window this plug-in's progress is displayed in. It should + * still work even if the progress bar has not been initialized yet, + * unless the plug-in wasn't called from a GUI. * This handle can be of various types (integer, string, etc.) * depending on the platform you are running on which is why it returns * a GBytes. There are usually no reasons to call this directly. diff --git a/pdb/groups/progress.pdb b/pdb/groups/progress.pdb index 93c9000352..f274e45921 100644 --- a/pdb/groups/progress.pdb +++ b/pdb/groups/progress.pdb @@ -180,10 +180,11 @@ CODE } sub progress_get_window_handle { - $blurb = 'Returns the native handle of the toplevel window this plug-in\'s progress is displayed in.'; + $blurb = 'Returns the native handle of the toplevel window this plug-in\'s progress is or would be displayed in.'; $help = <<'HELP'; This function returns the native handle allowing to identify the toplevel window this plug-in's progress is displayed in. +It should still work even if the progress bar has not been initialized yet, unless the plug-in wasn't called from a GUI. This handle can be of various types (integer, string, etc.) depending on the platform you are running on which is why it returns a GBytes. There are usually no reasons to call this directly. diff --git a/plug-ins/common/file-ps.c b/plug-ins/common/file-ps.c index 39e22c63e3..f22e8b6d8f 100644 --- a/plug-ins/common/file-ps.c +++ b/plug-ins/common/file-ps.c @@ -3790,13 +3790,6 @@ load_dialog (GFile *file, GIMP_PROCEDURE_CONFIG (config), &extracted_data, NULL); - gimp_dialog_set_alternative_button_order (GTK_DIALOG (dialog), - GTK_RESPONSE_OK, - GTK_RESPONSE_CANCEL, - -1); - - gimp_window_set_transient (GTK_WINDOW (dialog)); - if (page_count > 1) { selector = gimp_page_selector_new ();