gtkapplication: Stash DESKTOP_STARTUP_ID on a constructor

It might be too late to do it at GtkApplication::add_platform_data time,
since the envvar may be consumed earlier on if gdk_display_open() happened
to be called before (eg. through gtk_get_option_group(TRUE)).

Stash the envvar in a constructor function, so its ensured to happen before
it can get consumed.

Closes: https://gitlab.gnome.org/GNOME/gtk/issues/1754
This commit is contained in:
Carlos Garnacho 2019-03-17 16:04:51 +01:00
parent 967c5f7f7f
commit 224a53d97b

View File

@ -28,6 +28,8 @@
#include <unistd.h>
#endif
#include "gdk/gdkconstructor.h"
#include "gtkapplicationprivate.h"
#include "gtkclipboardprivate.h"
#include "gtkmarshalers.h"
@ -166,6 +168,21 @@ struct _GtkApplicationPrivate
G_DEFINE_TYPE_WITH_PRIVATE (GtkApplication, gtk_application, G_TYPE_APPLICATION)
#ifdef G_HAS_CONSTRUCTORS
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_desktop_startup_id)
#endif
G_DEFINE_CONSTRUCTOR(stash_desktop_startup_id)
#endif
static const char *desktop_startup_id = NULL;
static void
stash_desktop_startup_id (void)
{
desktop_startup_id = g_getenv ("DESKTOP_STARTUP_ID");
}
static gboolean
gtk_application_focus_in_event_cb (GtkWindow *window,
GdkEventFocus *event,
@ -338,8 +355,6 @@ static void
gtk_application_add_platform_data (GApplication *application,
GVariantBuilder *builder)
{
const gchar *startup_id;
/* This is slightly evil.
*
* We don't have an impl here because we're remote so we can't figure
@ -347,11 +362,9 @@ gtk_application_add_platform_data (GApplication *application,
*
* So we do all the things... which currently is just one thing.
*/
startup_id = getenv ("DESKTOP_STARTUP_ID");
if (startup_id && g_utf8_validate (startup_id, -1, NULL))
if (desktop_startup_id && g_utf8_validate (desktop_startup_id, -1, NULL))
g_variant_builder_add (builder, "{sv}", "desktop-startup-id",
g_variant_new_string (startup_id));
g_variant_new_string (desktop_startup_id));
}
static void
@ -380,6 +393,10 @@ gtk_application_init (GtkApplication *application)
application->priv->muxer = gtk_action_muxer_new ();
application->priv->accels = gtk_application_accels_new ();
#ifndef G_HAS_CONSTRUCTORS
stash_desktop_startup_id ();
#endif
}
static void