2004-08-30 02:36:30 +08:00
|
|
|
/* LIBGIMP - The GIMP Library
|
|
|
|
* Copyright (C) 1995-1997 Peter Mattis and Spencer Kimball
|
|
|
|
*
|
|
|
|
* gimpprogress.c
|
|
|
|
*
|
2009-01-18 06:28:01 +08:00
|
|
|
* This library is free software: you can redistribute it and/or
|
2004-08-30 02:36:30 +08:00
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
2009-01-18 06:28:01 +08:00
|
|
|
* version 3 of the License, or (at your option) any later version.
|
2004-08-30 02:36:30 +08:00
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Library General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
2009-01-18 06:28:01 +08:00
|
|
|
* License along with this library. If not, see
|
2018-07-12 05:27:07 +08:00
|
|
|
* <https://www.gnu.org/licenses/>.
|
2004-08-30 02:36:30 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
2013-10-15 07:58:39 +08:00
|
|
|
#include <gio/gio.h>
|
2005-09-10 02:07:31 +08:00
|
|
|
|
2012-05-03 06:54:21 +08:00
|
|
|
#include "libgimpbase/gimpbase.h"
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
#include "gimpprogress.h"
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
#include "gimp.h"
|
|
|
|
|
|
|
|
|
2007-05-22 22:04:35 +08:00
|
|
|
typedef struct
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2005-09-10 02:07:31 +08:00
|
|
|
gchar *progress_callback;
|
|
|
|
GimpProgressVtable vtable;
|
|
|
|
gpointer data;
|
2019-08-04 23:51:59 +08:00
|
|
|
GDestroyNotify data_destroy;
|
2007-05-22 22:04:35 +08:00
|
|
|
} GimpProgressData;
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* local function prototypes */
|
|
|
|
|
2023-06-17 00:27:11 +08:00
|
|
|
static void gimp_progress_data_free (GimpProgressData *data);
|
2007-05-22 22:04:35 +08:00
|
|
|
|
2023-06-17 00:27:11 +08:00
|
|
|
static GimpValueArray * gimp_temp_progress_run (GimpProcedure *procedure,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* private variables */
|
|
|
|
|
2007-05-04 18:19:50 +08:00
|
|
|
static gdouble gimp_progress_current = 0.0;
|
|
|
|
static const gdouble gimp_progress_step = (1.0 / 256.0);
|
2021-02-16 04:54:06 +08:00
|
|
|
static const gint64 gimp_progress_delay = 50000; /* 50 millisecond */
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
|
|
|
|
/* public functions */
|
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
/**
|
|
|
|
* gimp_progress_install_vtable:
|
2019-08-11 21:35:55 +08:00
|
|
|
* @vtable: a pointer to a @GimpProgressVtable.
|
|
|
|
* @user_data: a pointer that is passed as user_data to all vtable
|
|
|
|
* functions.
|
|
|
|
* @user_data_destroy: (nullable): destroy function for @user_data, or %NULL.
|
2005-09-10 02:07:31 +08:00
|
|
|
*
|
2019-08-03 06:10:14 +08:00
|
|
|
* Returns: the name of the temporary procedure that's been installed
|
2005-09-10 02:07:31 +08:00
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-10 02:07:31 +08:00
|
|
|
**/
|
|
|
|
const gchar *
|
|
|
|
gimp_progress_install_vtable (const GimpProgressVtable *vtable,
|
2019-08-04 23:51:59 +08:00
|
|
|
gpointer user_data,
|
|
|
|
GDestroyNotify user_data_destroy)
|
2004-08-30 02:36:30 +08:00
|
|
|
{
|
2019-08-04 23:51:59 +08:00
|
|
|
GimpPlugIn *plug_in;
|
2019-08-15 01:03:48 +08:00
|
|
|
GimpProcedure *procedure;
|
2019-08-04 23:51:59 +08:00
|
|
|
gchar *progress_callback;
|
|
|
|
GimpProgressData *progress_data;
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2005-09-10 02:07:31 +08:00
|
|
|
g_return_val_if_fail (vtable != NULL, NULL);
|
|
|
|
g_return_val_if_fail (vtable->start != NULL, NULL);
|
|
|
|
g_return_val_if_fail (vtable->end != NULL, NULL);
|
|
|
|
g_return_val_if_fail (vtable->set_text != NULL, NULL);
|
|
|
|
g_return_val_if_fail (vtable->set_value != NULL, NULL);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
plug_in = gimp_get_plug_in ();
|
|
|
|
|
2019-08-15 01:03:48 +08:00
|
|
|
progress_callback = gimp_pdb_temp_procedure_name (gimp_get_pdb ());
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
progress_data = g_slice_new0 (GimpProgressData);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
app, libgimp*, pdb, plug-ins: reimplement generic inter-process transient window.
Having windows ID as guint32 is a mistake. Different systems have
different protocols. In Wayland in particular, Windows handles are
exchanged as strings. What this commit does is the following:
In core:
- get_window_id() virtual function in core GimpProgress is changed to
return a GBytes, as a generic "data" to represent a window differently
on different systems.
- All implementations of get_window_id() in various classes implementing
this interface are updated accordingly:
* GimpSubProgress
* GimpDisplay returns the handle of its shell.
* GimpDisplayShell now creates its window handle at construction with
libgimpwidget's gimp_widget_set_native_handle() and simply return
this handle every time it's requested.
* GimpFileDialog also creates its window handle at construction with
gimp_widget_set_native_handle().
- gimp_window_set_transient_for() in core is changed to take a
GimpProgress as argument (instead of a guint32 ID), requests and
process the ID itself, according to the running platform. In
particular, the following were improved:
* Unlike old code, it will work even if the window is not visible yet.
In such a case, the function simply adds a signal handler to set
transient at mapping. It makes it easier to use it at construction
in a reliable way.
* It now works for Wayland too, additionally to X11.
- GimpPdbProgress now exchanges a GBytes too with the command
GIMP_PROGRESS_COMMAND_GET_WINDOW.
- display_get_window_id() in gimp-gui.h also returns a GBytes now.
PDB/libgimp:
- gimp_display_get_window_handle() and gimp_progress_get_window_handle()
now return a GBytes to represent a window handle in an opaque way
(depending on the running platform).
In libgimp:
- GimpProgress's get_window() virtual function changed to return a
GBytes and renamed get_window_handle().
- In particular GimpProgressBar is the only implementation of
get_window_handle(). It creates its handle at object construction with
libgimpwidget's gimp_widget_set_native_handle() and the virtual
method's implementation simply returns the GBytes.
In libgimpUi:
- gimp_ui_get_display_window() and gimp_ui_get_progress_window() were
removed. We should not assume anymore that it is possible to create a
GdkWindow to be used. For instance this is not possible with Wayland
which has its own way to set a window transient with a string handle.
- gimp_window_set_transient_for_display() and
gimp_window_set_transient() now use an internal implementation similar
to core gimp_window_set_transient_for(), with the same improvements
(works even at construction when the window is not visible yet + works
for Wayland too).
In libgimpwidgets:
- New gimp_widget_set_native_handle() is a helper function used both in
core and libgimp* libraries for widgets which we want to be usable as
possible parents. It takes care of getting the relevant window handle
(depending on the running platform) and stores it in a given pointer,
either immediately or after a callback once the widget is mapped. So
it can be used at construction. Also it sets a handle for X11 or
Wayland.
In plug-ins:
- Screenshot uses the new gimp_progress_get_window_handle() directly now
in its X11 code path and creates out of it a GdkWindows itself with
gdk_x11_window_foreign_new_for_display().
Our inter-process transient implementation only worked for X11, and with
this commit, it works for Wayland too.
There is code for Windows but it is currently disabled as it apparently
hangs (there is a comment in-code which links to this old report:
https://bugzilla.gnome.org/show_bug.cgi?id=359538). NikcDC tested
yesterday with re-enabling the code and said they experienced a freeze.
;-(
Finally there is no infrastructure yet to make this work on macOS and
apparently there is no implementation of window handle in GDK for macOS
that I could find. I'm not sure if macOS doesn't have this concept of
setting transient on another processus's window or GDK is simply lacking
the implementation.
2023-08-14 20:23:06 +08:00
|
|
|
progress_data->progress_callback = progress_callback;
|
|
|
|
progress_data->vtable.start = vtable->start;
|
|
|
|
progress_data->vtable.end = vtable->end;
|
|
|
|
progress_data->vtable.set_text = vtable->set_text;
|
|
|
|
progress_data->vtable.set_value = vtable->set_value;
|
|
|
|
progress_data->vtable.pulse = vtable->pulse;
|
|
|
|
progress_data->vtable.get_window_handle = vtable->get_window_handle;
|
|
|
|
progress_data->data = user_data;
|
|
|
|
progress_data->data_destroy = user_data_destroy;
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2023-06-17 00:34:53 +08:00
|
|
|
procedure = gimp_procedure_new (plug_in,
|
|
|
|
progress_callback,
|
|
|
|
GIMP_PDB_PROC_TYPE_TEMPORARY,
|
|
|
|
gimp_temp_progress_run,
|
|
|
|
progress_data,
|
|
|
|
(GDestroyNotify)
|
|
|
|
gimp_progress_data_free);
|
2019-08-15 01:03:48 +08:00
|
|
|
|
2019-08-19 16:02:07 +08:00
|
|
|
GIMP_PROC_ARG_ENUM (procedure, "command",
|
|
|
|
"Command",
|
|
|
|
"The progress command",
|
|
|
|
GIMP_TYPE_PROGRESS_COMMAND,
|
|
|
|
GIMP_PROGRESS_COMMAND_START,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_STRING (procedure, "text",
|
|
|
|
"Text",
|
|
|
|
"The progress text",
|
|
|
|
NULL,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_ARG_DOUBLE (procedure, "value",
|
2020-11-14 08:40:17 +08:00
|
|
|
"Value",
|
2019-08-19 16:02:07 +08:00
|
|
|
"The progress value",
|
|
|
|
0.0, 1.0, 0.0,
|
|
|
|
G_PARAM_READWRITE);
|
|
|
|
|
|
|
|
GIMP_PROC_VAL_DOUBLE (procedure, "value",
|
2020-11-14 08:40:17 +08:00
|
|
|
"Value",
|
2019-08-19 16:02:07 +08:00
|
|
|
"The progress value",
|
|
|
|
0.0, 1.0, 0.0,
|
|
|
|
G_PARAM_READWRITE);
|
2019-08-04 23:51:59 +08:00
|
|
|
|
2019-08-15 01:03:48 +08:00
|
|
|
gimp_plug_in_add_temp_procedure (plug_in, procedure);
|
|
|
|
g_object_unref (procedure);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
if (_gimp_progress_install (progress_callback))
|
|
|
|
{
|
|
|
|
/* Allow callbacks to be watched */
|
2019-08-15 01:03:48 +08:00
|
|
|
gimp_plug_in_extension_enable (plug_in);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
return progress_callback;
|
|
|
|
}
|
|
|
|
|
2019-08-15 01:03:48 +08:00
|
|
|
gimp_plug_in_remove_temp_procedure (plug_in, progress_callback);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2004-08-31 03:19:02 +08:00
|
|
|
/**
|
|
|
|
* gimp_progress_uninstall:
|
|
|
|
* @progress_callback: the name of the temporary procedure to uninstall
|
|
|
|
*
|
|
|
|
* Uninstalls a temporary progress procedure that was installed using
|
|
|
|
* gimp_progress_install().
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.2
|
2004-08-31 03:19:02 +08:00
|
|
|
**/
|
2019-08-04 23:51:59 +08:00
|
|
|
void
|
2004-08-30 02:36:30 +08:00
|
|
|
gimp_progress_uninstall (const gchar *progress_callback)
|
|
|
|
{
|
2019-08-04 23:51:59 +08:00
|
|
|
GimpPlugIn *plug_in = gimp_get_plug_in ();
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
g_return_if_fail (progress_callback != NULL);
|
2004-08-30 02:36:30 +08:00
|
|
|
|
2019-08-15 01:03:48 +08:00
|
|
|
gimp_plug_in_remove_temp_procedure (plug_in, progress_callback);
|
2004-08-30 02:36:30 +08:00
|
|
|
}
|
|
|
|
|
2006-02-20 15:35:42 +08:00
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_progress_init:
|
|
|
|
* @message: Message to use in the progress dialog.
|
|
|
|
*
|
|
|
|
* Initializes the progress bar for the current plug-in.
|
|
|
|
*
|
|
|
|
* Initializes the progress bar for the current plug-in. It is only
|
|
|
|
* valid to call this procedure from a plug-in.
|
|
|
|
*
|
|
|
|
* Returns: TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gimp_progress_init (const gchar *message)
|
|
|
|
{
|
2019-08-14 04:54:37 +08:00
|
|
|
GimpDisplay *display = gimp_default_display ();
|
|
|
|
gboolean success;
|
|
|
|
|
2006-02-20 15:35:42 +08:00
|
|
|
gimp_progress_current = 0.0;
|
|
|
|
|
2019-08-14 04:54:37 +08:00
|
|
|
success = _gimp_progress_init (message, display);
|
|
|
|
|
|
|
|
return success;
|
2006-02-20 15:35:42 +08:00
|
|
|
}
|
|
|
|
|
2005-02-13 08:11:24 +08:00
|
|
|
/**
|
2005-09-30 02:34:08 +08:00
|
|
|
* gimp_progress_init_printf:
|
|
|
|
* @format: a standard printf() format string
|
2011-11-26 04:39:55 +08:00
|
|
|
* @...: arguments for @format
|
2005-09-30 02:34:08 +08:00
|
|
|
*
|
|
|
|
* Initializes the progress bar for the current plug-in.
|
|
|
|
*
|
|
|
|
* Initializes the progress bar for the current plug-in. It is only
|
|
|
|
* valid to call this procedure from a plug-in.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-09-30 02:34:08 +08:00
|
|
|
**/
|
|
|
|
gboolean
|
|
|
|
gimp_progress_init_printf (const gchar *format,
|
|
|
|
...)
|
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
gboolean retval;
|
|
|
|
va_list args;
|
|
|
|
|
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
text = g_strdup_vprintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
|
|
|
retval = gimp_progress_init (text);
|
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* gimp_progress_set_text_printf:
|
2005-02-13 08:11:24 +08:00
|
|
|
* @format: a standard printf() format string
|
2011-11-26 04:39:55 +08:00
|
|
|
* @...: arguments for @format
|
2005-02-13 08:11:24 +08:00
|
|
|
*
|
|
|
|
* Changes the text in the progress bar for the current plug-in.
|
|
|
|
*
|
2012-11-11 22:50:25 +08:00
|
|
|
* This function changes the text in the progress bar for the current
|
|
|
|
* plug-in. Unlike gimp_progress_init() it does not change the
|
2005-02-13 08:11:24 +08:00
|
|
|
* displayed value.
|
|
|
|
*
|
|
|
|
* Returns: %TRUE on success.
|
|
|
|
*
|
2015-06-01 03:18:09 +08:00
|
|
|
* Since: 2.4
|
2005-02-13 08:11:24 +08:00
|
|
|
**/
|
2005-02-13 09:43:07 +08:00
|
|
|
gboolean
|
2005-09-30 02:34:08 +08:00
|
|
|
gimp_progress_set_text_printf (const gchar *format,
|
|
|
|
...)
|
2005-02-13 08:11:24 +08:00
|
|
|
{
|
|
|
|
gchar *text;
|
|
|
|
gboolean retval;
|
|
|
|
va_list args;
|
|
|
|
|
2005-02-13 21:28:48 +08:00
|
|
|
g_return_val_if_fail (format != NULL, FALSE);
|
2005-02-13 08:11:24 +08:00
|
|
|
|
|
|
|
va_start (args, format);
|
|
|
|
text = g_strdup_vprintf (format, args);
|
|
|
|
va_end (args);
|
|
|
|
|
2005-09-30 02:34:08 +08:00
|
|
|
retval = gimp_progress_set_text (text);
|
2005-02-13 08:11:24 +08:00
|
|
|
|
|
|
|
g_free (text);
|
|
|
|
|
|
|
|
return retval;
|
|
|
|
}
|
|
|
|
|
2006-02-20 15:35:42 +08:00
|
|
|
/**
|
|
|
|
* gimp_progress_update:
|
2021-02-16 04:54:06 +08:00
|
|
|
* @percentage: Percentage of progress completed (in the range from 0.0
|
|
|
|
* to 1.0).
|
2006-02-20 15:35:42 +08:00
|
|
|
*
|
|
|
|
* Updates the progress bar for the current plug-in.
|
|
|
|
*
|
2021-02-16 04:54:06 +08:00
|
|
|
* The library will handle over-updating by possibly dropping silently
|
|
|
|
* some updates when they happen too close next to each other (either
|
|
|
|
* time-wise or step-wise).
|
|
|
|
* The caller does not have to take care of this aspect of progression
|
|
|
|
* and can focus on computing relevant progression steps.
|
|
|
|
*
|
2006-02-20 15:35:42 +08:00
|
|
|
* Returns: TRUE on success.
|
|
|
|
*/
|
|
|
|
gboolean
|
|
|
|
gimp_progress_update (gdouble percentage)
|
|
|
|
{
|
2021-02-16 04:54:06 +08:00
|
|
|
static gint64 last_update = 0;
|
|
|
|
gboolean changed;
|
2006-02-20 15:35:42 +08:00
|
|
|
|
|
|
|
if (percentage <= 0.0)
|
|
|
|
{
|
|
|
|
changed = (gimp_progress_current != 0.0);
|
|
|
|
percentage = 0.0;
|
|
|
|
}
|
|
|
|
else if (percentage >= 1.0)
|
|
|
|
{
|
|
|
|
changed = (gimp_progress_current != 1.0);
|
|
|
|
percentage = 1.0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-02-16 04:54:06 +08:00
|
|
|
if (last_update == 0 ||
|
|
|
|
g_get_monotonic_time () - last_update >= gimp_progress_delay)
|
2007-05-04 18:19:50 +08:00
|
|
|
{
|
2021-02-16 04:54:06 +08:00
|
|
|
/* If the progression step is too small, better not show it. */
|
|
|
|
changed =
|
|
|
|
(fabs (gimp_progress_current - percentage) > gimp_progress_step);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Too many changes in a short time interval. */
|
|
|
|
changed = FALSE;
|
2007-05-04 18:19:50 +08:00
|
|
|
}
|
2006-02-20 15:35:42 +08:00
|
|
|
}
|
|
|
|
|
2021-02-16 04:54:06 +08:00
|
|
|
/* Suppress the update if the change was only marginal or progression
|
|
|
|
* update happens too often. This is not an error, it is just
|
|
|
|
* unneeded to overload the GUI with constant updates.
|
|
|
|
*/
|
2006-02-20 15:35:42 +08:00
|
|
|
if (! changed)
|
|
|
|
return TRUE;
|
|
|
|
|
|
|
|
gimp_progress_current = percentage;
|
2021-02-16 04:54:06 +08:00
|
|
|
last_update = g_get_monotonic_time ();
|
2006-02-20 15:35:42 +08:00
|
|
|
|
|
|
|
return _gimp_progress_update (gimp_progress_current);
|
|
|
|
}
|
|
|
|
|
2004-08-30 02:36:30 +08:00
|
|
|
|
|
|
|
/* private functions */
|
|
|
|
|
2007-05-22 22:04:35 +08:00
|
|
|
static void
|
|
|
|
gimp_progress_data_free (GimpProgressData *data)
|
|
|
|
{
|
2019-08-04 23:51:59 +08:00
|
|
|
_gimp_progress_uninstall (data->progress_callback);
|
|
|
|
|
|
|
|
g_free (data->progress_callback);
|
|
|
|
|
|
|
|
if (data->data_destroy)
|
|
|
|
data->data_destroy (data->data);
|
|
|
|
|
2007-05-22 22:04:35 +08:00
|
|
|
g_slice_free (GimpProgressData, data);
|
|
|
|
}
|
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
static GimpValueArray *
|
2023-06-17 00:27:11 +08:00
|
|
|
gimp_temp_progress_run (GimpProcedure *procedure,
|
|
|
|
GimpProcedureConfig *config,
|
|
|
|
gpointer run_data)
|
2019-08-04 23:51:59 +08:00
|
|
|
{
|
|
|
|
GimpProgressData *progress_data = run_data;
|
|
|
|
GimpProgressCommand command;
|
2023-06-17 00:27:11 +08:00
|
|
|
gchar *text;
|
2019-08-04 23:51:59 +08:00
|
|
|
gdouble value;
|
|
|
|
|
2023-06-17 00:27:11 +08:00
|
|
|
g_object_get (config,
|
|
|
|
"command", &command,
|
|
|
|
"text", &text,
|
|
|
|
"value", &value,
|
|
|
|
NULL);
|
2019-08-04 23:51:59 +08:00
|
|
|
|
|
|
|
switch (command)
|
|
|
|
{
|
|
|
|
case GIMP_PROGRESS_COMMAND_START:
|
|
|
|
progress_data->vtable.start (text, value != 0.0,
|
|
|
|
progress_data->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PROGRESS_COMMAND_END:
|
|
|
|
progress_data->vtable.end (progress_data->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PROGRESS_COMMAND_SET_TEXT:
|
|
|
|
progress_data->vtable.set_text (text, progress_data->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PROGRESS_COMMAND_SET_VALUE:
|
|
|
|
progress_data->vtable.set_value (value, progress_data->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PROGRESS_COMMAND_PULSE:
|
|
|
|
if (progress_data->vtable.pulse)
|
|
|
|
progress_data->vtable.pulse (progress_data->data);
|
|
|
|
else
|
|
|
|
progress_data->vtable.set_value (-1, progress_data->data);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GIMP_PROGRESS_COMMAND_GET_WINDOW:
|
|
|
|
{
|
|
|
|
GimpValueArray *return_vals;
|
app, libgimp*, pdb, plug-ins: reimplement generic inter-process transient window.
Having windows ID as guint32 is a mistake. Different systems have
different protocols. In Wayland in particular, Windows handles are
exchanged as strings. What this commit does is the following:
In core:
- get_window_id() virtual function in core GimpProgress is changed to
return a GBytes, as a generic "data" to represent a window differently
on different systems.
- All implementations of get_window_id() in various classes implementing
this interface are updated accordingly:
* GimpSubProgress
* GimpDisplay returns the handle of its shell.
* GimpDisplayShell now creates its window handle at construction with
libgimpwidget's gimp_widget_set_native_handle() and simply return
this handle every time it's requested.
* GimpFileDialog also creates its window handle at construction with
gimp_widget_set_native_handle().
- gimp_window_set_transient_for() in core is changed to take a
GimpProgress as argument (instead of a guint32 ID), requests and
process the ID itself, according to the running platform. In
particular, the following were improved:
* Unlike old code, it will work even if the window is not visible yet.
In such a case, the function simply adds a signal handler to set
transient at mapping. It makes it easier to use it at construction
in a reliable way.
* It now works for Wayland too, additionally to X11.
- GimpPdbProgress now exchanges a GBytes too with the command
GIMP_PROGRESS_COMMAND_GET_WINDOW.
- display_get_window_id() in gimp-gui.h also returns a GBytes now.
PDB/libgimp:
- gimp_display_get_window_handle() and gimp_progress_get_window_handle()
now return a GBytes to represent a window handle in an opaque way
(depending on the running platform).
In libgimp:
- GimpProgress's get_window() virtual function changed to return a
GBytes and renamed get_window_handle().
- In particular GimpProgressBar is the only implementation of
get_window_handle(). It creates its handle at object construction with
libgimpwidget's gimp_widget_set_native_handle() and the virtual
method's implementation simply returns the GBytes.
In libgimpUi:
- gimp_ui_get_display_window() and gimp_ui_get_progress_window() were
removed. We should not assume anymore that it is possible to create a
GdkWindow to be used. For instance this is not possible with Wayland
which has its own way to set a window transient with a string handle.
- gimp_window_set_transient_for_display() and
gimp_window_set_transient() now use an internal implementation similar
to core gimp_window_set_transient_for(), with the same improvements
(works even at construction when the window is not visible yet + works
for Wayland too).
In libgimpwidgets:
- New gimp_widget_set_native_handle() is a helper function used both in
core and libgimp* libraries for widgets which we want to be usable as
possible parents. It takes care of getting the relevant window handle
(depending on the running platform) and stores it in a given pointer,
either immediately or after a callback once the widget is mapped. So
it can be used at construction. Also it sets a handle for X11 or
Wayland.
In plug-ins:
- Screenshot uses the new gimp_progress_get_window_handle() directly now
in its X11 code path and creates out of it a GdkWindows itself with
gdk_x11_window_foreign_new_for_display().
Our inter-process transient implementation only worked for X11, and with
this commit, it works for Wayland too.
There is code for Windows but it is currently disabled as it apparently
hangs (there is a comment in-code which links to this old report:
https://bugzilla.gnome.org/show_bug.cgi?id=359538). NikcDC tested
yesterday with re-enabling the code and said they experienced a freeze.
;-(
Finally there is no infrastructure yet to make this work on macOS and
apparently there is no implementation of window handle in GDK for macOS
that I could find. I'm not sure if macOS doesn't have this concept of
setting transient on another processus's window or GDK is simply lacking
the implementation.
2023-08-14 20:23:06 +08:00
|
|
|
GBytes *window_handle = NULL;
|
2019-08-04 23:51:59 +08:00
|
|
|
|
app, libgimp*, pdb, plug-ins: reimplement generic inter-process transient window.
Having windows ID as guint32 is a mistake. Different systems have
different protocols. In Wayland in particular, Windows handles are
exchanged as strings. What this commit does is the following:
In core:
- get_window_id() virtual function in core GimpProgress is changed to
return a GBytes, as a generic "data" to represent a window differently
on different systems.
- All implementations of get_window_id() in various classes implementing
this interface are updated accordingly:
* GimpSubProgress
* GimpDisplay returns the handle of its shell.
* GimpDisplayShell now creates its window handle at construction with
libgimpwidget's gimp_widget_set_native_handle() and simply return
this handle every time it's requested.
* GimpFileDialog also creates its window handle at construction with
gimp_widget_set_native_handle().
- gimp_window_set_transient_for() in core is changed to take a
GimpProgress as argument (instead of a guint32 ID), requests and
process the ID itself, according to the running platform. In
particular, the following were improved:
* Unlike old code, it will work even if the window is not visible yet.
In such a case, the function simply adds a signal handler to set
transient at mapping. It makes it easier to use it at construction
in a reliable way.
* It now works for Wayland too, additionally to X11.
- GimpPdbProgress now exchanges a GBytes too with the command
GIMP_PROGRESS_COMMAND_GET_WINDOW.
- display_get_window_id() in gimp-gui.h also returns a GBytes now.
PDB/libgimp:
- gimp_display_get_window_handle() and gimp_progress_get_window_handle()
now return a GBytes to represent a window handle in an opaque way
(depending on the running platform).
In libgimp:
- GimpProgress's get_window() virtual function changed to return a
GBytes and renamed get_window_handle().
- In particular GimpProgressBar is the only implementation of
get_window_handle(). It creates its handle at object construction with
libgimpwidget's gimp_widget_set_native_handle() and the virtual
method's implementation simply returns the GBytes.
In libgimpUi:
- gimp_ui_get_display_window() and gimp_ui_get_progress_window() were
removed. We should not assume anymore that it is possible to create a
GdkWindow to be used. For instance this is not possible with Wayland
which has its own way to set a window transient with a string handle.
- gimp_window_set_transient_for_display() and
gimp_window_set_transient() now use an internal implementation similar
to core gimp_window_set_transient_for(), with the same improvements
(works even at construction when the window is not visible yet + works
for Wayland too).
In libgimpwidgets:
- New gimp_widget_set_native_handle() is a helper function used both in
core and libgimp* libraries for widgets which we want to be usable as
possible parents. It takes care of getting the relevant window handle
(depending on the running platform) and stores it in a given pointer,
either immediately or after a callback once the widget is mapped. So
it can be used at construction. Also it sets a handle for X11 or
Wayland.
In plug-ins:
- Screenshot uses the new gimp_progress_get_window_handle() directly now
in its X11 code path and creates out of it a GdkWindows itself with
gdk_x11_window_foreign_new_for_display().
Our inter-process transient implementation only worked for X11, and with
this commit, it works for Wayland too.
There is code for Windows but it is currently disabled as it apparently
hangs (there is a comment in-code which links to this old report:
https://bugzilla.gnome.org/show_bug.cgi?id=359538). NikcDC tested
yesterday with re-enabling the code and said they experienced a freeze.
;-(
Finally there is no infrastructure yet to make this work on macOS and
apparently there is no implementation of window handle in GDK for macOS
that I could find. I'm not sure if macOS doesn't have this concept of
setting transient on another processus's window or GDK is simply lacking
the implementation.
2023-08-14 20:23:06 +08:00
|
|
|
if (progress_data->vtable.get_window_handle)
|
|
|
|
window_handle = progress_data->vtable.get_window_handle (progress_data->data);
|
2019-08-04 23:51:59 +08:00
|
|
|
|
|
|
|
return_vals = gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_SUCCESS,
|
|
|
|
NULL);
|
app, libgimp*, pdb, plug-ins: reimplement generic inter-process transient window.
Having windows ID as guint32 is a mistake. Different systems have
different protocols. In Wayland in particular, Windows handles are
exchanged as strings. What this commit does is the following:
In core:
- get_window_id() virtual function in core GimpProgress is changed to
return a GBytes, as a generic "data" to represent a window differently
on different systems.
- All implementations of get_window_id() in various classes implementing
this interface are updated accordingly:
* GimpSubProgress
* GimpDisplay returns the handle of its shell.
* GimpDisplayShell now creates its window handle at construction with
libgimpwidget's gimp_widget_set_native_handle() and simply return
this handle every time it's requested.
* GimpFileDialog also creates its window handle at construction with
gimp_widget_set_native_handle().
- gimp_window_set_transient_for() in core is changed to take a
GimpProgress as argument (instead of a guint32 ID), requests and
process the ID itself, according to the running platform. In
particular, the following were improved:
* Unlike old code, it will work even if the window is not visible yet.
In such a case, the function simply adds a signal handler to set
transient at mapping. It makes it easier to use it at construction
in a reliable way.
* It now works for Wayland too, additionally to X11.
- GimpPdbProgress now exchanges a GBytes too with the command
GIMP_PROGRESS_COMMAND_GET_WINDOW.
- display_get_window_id() in gimp-gui.h also returns a GBytes now.
PDB/libgimp:
- gimp_display_get_window_handle() and gimp_progress_get_window_handle()
now return a GBytes to represent a window handle in an opaque way
(depending on the running platform).
In libgimp:
- GimpProgress's get_window() virtual function changed to return a
GBytes and renamed get_window_handle().
- In particular GimpProgressBar is the only implementation of
get_window_handle(). It creates its handle at object construction with
libgimpwidget's gimp_widget_set_native_handle() and the virtual
method's implementation simply returns the GBytes.
In libgimpUi:
- gimp_ui_get_display_window() and gimp_ui_get_progress_window() were
removed. We should not assume anymore that it is possible to create a
GdkWindow to be used. For instance this is not possible with Wayland
which has its own way to set a window transient with a string handle.
- gimp_window_set_transient_for_display() and
gimp_window_set_transient() now use an internal implementation similar
to core gimp_window_set_transient_for(), with the same improvements
(works even at construction when the window is not visible yet + works
for Wayland too).
In libgimpwidgets:
- New gimp_widget_set_native_handle() is a helper function used both in
core and libgimp* libraries for widgets which we want to be usable as
possible parents. It takes care of getting the relevant window handle
(depending on the running platform) and stores it in a given pointer,
either immediately or after a callback once the widget is mapped. So
it can be used at construction. Also it sets a handle for X11 or
Wayland.
In plug-ins:
- Screenshot uses the new gimp_progress_get_window_handle() directly now
in its X11 code path and creates out of it a GdkWindows itself with
gdk_x11_window_foreign_new_for_display().
Our inter-process transient implementation only worked for X11, and with
this commit, it works for Wayland too.
There is code for Windows but it is currently disabled as it apparently
hangs (there is a comment in-code which links to this old report:
https://bugzilla.gnome.org/show_bug.cgi?id=359538). NikcDC tested
yesterday with re-enabling the code and said they experienced a freeze.
;-(
Finally there is no infrastructure yet to make this work on macOS and
apparently there is no implementation of window handle in GDK for macOS
that I could find. I'm not sure if macOS doesn't have this concept of
setting transient on another processus's window or GDK is simply lacking
the implementation.
2023-08-14 20:23:06 +08:00
|
|
|
GIMP_VALUES_SET_BYTES (return_vals, 1, window_handle);
|
|
|
|
g_bytes_unref (window_handle);
|
2023-06-17 00:27:11 +08:00
|
|
|
g_free (text);
|
2019-08-04 23:51:59 +08:00
|
|
|
|
|
|
|
return return_vals;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
2023-06-17 00:27:11 +08:00
|
|
|
g_free (text);
|
2019-08-04 23:51:59 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure,
|
|
|
|
GIMP_PDB_CALLING_ERROR,
|
|
|
|
NULL);
|
|
|
|
}
|
|
|
|
|
2023-06-17 00:27:11 +08:00
|
|
|
g_free (text);
|
|
|
|
|
2019-08-04 23:51:59 +08:00
|
|
|
return gimp_procedure_new_return_values (procedure, GIMP_PDB_SUCCESS, NULL);
|
|
|
|
}
|