[gtk/wip/carlosg/startup-notification-fixes: 1/2] gtkapplication: Stash DESKTOP_STARTUP_ID on a constructor
- From: Carlos Garnacho <carlosg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/wip/carlosg/startup-notification-fixes: 1/2] gtkapplication: Stash DESKTOP_STARTUP_ID on a constructor
- Date: Mon, 18 Mar 2019 11:31:42 +0000 (UTC)
commit 224a53d97b53da9cc9d08e1675ae860d7e49f8b6
Author: Carlos Garnacho <carlosg gnome org>
Date: Sun Mar 17 16:04:51 2019 +0100
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
gtk/gtkapplication.c | 29 +++++++++++++++++++++++------
1 file changed, 23 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkapplication.c b/gtk/gtkapplication.c
index 5d26f07088..d0f32a8638 100644
--- a/gtk/gtkapplication.c
+++ b/gtk/gtkapplication.c
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]