gtk: Change the private export handle api

Make unexport_handle take the handle, which will
let us deal with multiple exports in the future.

Update all callers to store their handle, and
pass it to unexport_handle.
This commit is contained in:
Matthias Clasen
2023-05-14 17:14:43 -04:00
parent 38f610f85e
commit 4c69192837
6 changed files with 31 additions and 10 deletions

View File

@@ -31,6 +31,7 @@ G_GNUC_BEGIN_IGNORE_DEPRECATIONS
typedef struct {
GtkWindow *parent;
char *handle;
GAppLaunchContext *context;
char *uri;
GTask *task;
@@ -39,9 +40,10 @@ typedef struct {
static void
gtk_show_uri_data_free (GtkShowUriData *data)
{
if (data->parent)
gtk_window_unexport_handle (data->parent);
if (data->parent && data->handle)
gtk_window_unexport_handle (data->parent, data->handle);
g_clear_object (&data->parent);
g_free (data->handle);
g_clear_object (&data->context);
g_free (data->uri);
g_clear_object (&data->task);
@@ -72,7 +74,10 @@ window_handle_exported (GtkWindow *window,
GtkShowUriData *data = user_data;
if (handle)
g_app_launch_context_setenv (data->context, "PARENT_WINDOW_ID", handle);
{
g_app_launch_context_setenv (data->context, "PARENT_WINDOW_ID", handle);
data->handle = g_strdup (handle);
}
g_app_info_launch_default_for_uri_async (data->uri,
data->context,

View File

@@ -52,6 +52,7 @@ typedef struct {
const char *method_name;
char *exported_handle;
GtkWindow *exported_window;
PortalErrorHandler error_handler;
} FilechooserPortalData;
@@ -79,7 +80,11 @@ filechooser_portal_data_clear (FilechooserPortalData *data)
if (data->exported_window)
{
gtk_window_unexport_handle (data->exported_window);
if (data->exported_handle)
{
gtk_window_unexport_handle (data->exported_window, data->exported_handle);
g_clear_pointer (&data->exported_handle, g_free);
}
g_clear_object (&data->exported_window);
}
@@ -460,6 +465,7 @@ window_handle_exported (GtkWindow *window,
gtk_grab_add (GTK_WIDGET (data->grab_widget));
}
data->exported_handle = g_strdup (handle_str);
show_portal_file_chooser (self, handle_str);
}

View File

@@ -108,6 +108,7 @@ enum {
typedef struct {
GtkWindow *parent;
char *parent_handle;
GFile *file;
char *uri;
gboolean open_folder;
@@ -128,8 +129,9 @@ open_uri_data_free (OpenUriData *data)
g_clear_object (&data->connection);
if (data->cancel_handler)
g_signal_handler_disconnect (data->cancellable, data->cancel_handler);
if (data->parent)
gtk_window_unexport_handle (data->parent);
if (data->parent && data->parent_handle)
gtk_window_unexport_handle (data->parent, data->parent_handle);
g_free (data->parent_handle);
g_clear_object (&data->parent);
g_clear_object (&data->file);
g_free (data->uri);
@@ -426,6 +428,8 @@ window_handle_exported (GtkWindow *window,
GAppLaunchContext *context;
char *activation_token = NULL;
data->parent_handle = g_strdup (handle);
if (window)
display = gtk_widget_get_display (GTK_WIDGET (window));
else

View File

@@ -48,6 +48,7 @@ typedef struct {
GtkPrintOperationResult result;
GtkPrintOperationPrintFunc print_cb;
GtkWindow *parent;
char *handle;
GMainLoop *loop;
guint32 token;
GDestroyNotify destroy;
@@ -62,8 +63,9 @@ portal_data_free (gpointer data)
{
PortalData *portal = data;
if (portal->parent)
gtk_window_unexport_handle (portal->parent);
if (portal->parent && portal->handle)
gtk_window_unexport_handle (portal->parent, portal->handle);
g_free (portal->handle);
g_object_unref (portal->op);
g_object_unref (portal->proxy);
if (portal->loop)
@@ -547,6 +549,8 @@ window_handle_exported (GtkWindow *window,
{
PortalData *portal = user_data;
portal->handle = g_strdup (handle_str);
g_dbus_proxy_call (portal->proxy,
"PreparePrint",
g_variant_new ("(ss@a{sv}@a{sv}@a{sv})",

View File

@@ -6336,7 +6336,8 @@ gtk_window_export_handle (GtkWindow *window,
}
void
gtk_window_unexport_handle (GtkWindow *window)
gtk_window_unexport_handle (GtkWindow *window,
const char *handle)
{
GtkWindowPrivate *priv = gtk_window_get_instance_private (window);

View File

@@ -79,7 +79,8 @@ typedef void (*GtkWindowHandleExported) (GtkWindow *window,
gboolean gtk_window_export_handle (GtkWindow *window,
GtkWindowHandleExported callback,
gpointer user_data);
void gtk_window_unexport_handle (GtkWindow *window);
void gtk_window_unexport_handle (GtkWindow *window,
const char *handle);
GtkWidget * gtk_window_lookup_pointer_focus_widget (GtkWindow *window,
GdkDevice *device,