mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-26 13:41:07 +00:00
display: Avoid unsetting the DESKTOP_STARTUP_ID variable too late
Similar to what has been done recently for DESKTOP_AUTOSTART_ID [1], we need to get rid of this call to g_unsetenv() in the displays' backends for X11 and Wayland, so that it's guarantee to happen any thread is created, while still being accessible when needed. Let's stash the value of this environment variable when loading the GDK library, and provide a private method so that it can be retrieved from the displays' backend when implementing gdk_display_make_default(). [1] https://gitlab.gnome.org/GNOME/gtk/commit/22269902 Closes: https://gitlab.gnome.org/GNOME/gtk/issues/979
This commit is contained in:
parent
33b8f087a3
commit
ef3427575f
@ -40,4 +40,6 @@ void gdk_display_set_cursor_theme (GdkDisplay *display,
|
||||
const char *theme,
|
||||
int size);
|
||||
|
||||
const gchar * gdk_get_startup_notification_id (void);
|
||||
|
||||
#endif /* __GDK__PRIVATE_H__ */
|
||||
|
50
gdk/gdk.c
50
gdk/gdk.c
@ -154,6 +154,36 @@ static const GDebugKey gdk_debug_keys[] = {
|
||||
};
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef G_HAS_CONSTRUCTORS
|
||||
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_desktop_startup_notification_id)
|
||||
#endif
|
||||
G_DEFINE_CONSTRUCTOR(stash_desktop_startup_notification_id)
|
||||
#endif
|
||||
|
||||
static gchar *startup_notification_id = NULL;
|
||||
|
||||
static void
|
||||
stash_desktop_startup_notification_id (void)
|
||||
{
|
||||
const char *desktop_startup_id;
|
||||
|
||||
desktop_startup_id = g_getenv ("DESKTOP_STARTUP_ID");
|
||||
if (desktop_startup_id && *desktop_startup_id != '\0')
|
||||
{
|
||||
if (!g_utf8_validate (desktop_startup_id, -1, NULL))
|
||||
g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
|
||||
else
|
||||
startup_notification_id = g_strdup (desktop_startup_id ? desktop_startup_id : "");
|
||||
}
|
||||
|
||||
/* Clear the environment variable so it won't be inherited by
|
||||
* child processes and confuse things.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_STARTUP_ID");
|
||||
}
|
||||
|
||||
static gpointer
|
||||
register_resources (gpointer dummy G_GNUC_UNUSED)
|
||||
{
|
||||
@ -186,6 +216,10 @@ gdk_pre_parse (void)
|
||||
G_N_ELEMENTS (gdk_debug_keys));
|
||||
}
|
||||
#endif /* G_ENABLE_DEBUG */
|
||||
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
stash_desktop_startup_notification_id ();
|
||||
#endif
|
||||
}
|
||||
|
||||
/*< private >
|
||||
@ -216,6 +250,22 @@ gdk_display_open_default (void)
|
||||
return display;
|
||||
}
|
||||
|
||||
/*< private >
|
||||
*
|
||||
* gdk_get_startup_notification_id
|
||||
*
|
||||
* Returns the original value of the DESKTOP_STARTUP_ID environment
|
||||
* variable if it was defined and valid, or %NULL otherwise.
|
||||
*
|
||||
* Returns: (nullable) (transfer none): the original value of the
|
||||
* DESKTOP_STARTUP_ID environment variable, or %NULL.
|
||||
*/
|
||||
const gchar *
|
||||
gdk_get_startup_notification_id (void)
|
||||
{
|
||||
return startup_notification_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* SECTION:threads
|
||||
* @Short_description: Functions for using GDK in multi-threaded programs
|
||||
|
@ -54,6 +54,8 @@
|
||||
|
||||
#include "wm-button-layout-translation.h"
|
||||
|
||||
#include "gdk/gdk-private.h"
|
||||
|
||||
/**
|
||||
* SECTION:wayland_interaction
|
||||
* @Short_description: Wayland backend-specific functions
|
||||
@ -817,19 +819,9 @@ gdk_wayland_display_make_default (GdkDisplay *display)
|
||||
g_free (display_wayland->startup_notification_id);
|
||||
display_wayland->startup_notification_id = NULL;
|
||||
|
||||
startup_id = g_getenv ("DESKTOP_STARTUP_ID");
|
||||
if (startup_id && *startup_id != '\0')
|
||||
{
|
||||
if (!g_utf8_validate (startup_id, -1, NULL))
|
||||
g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
|
||||
else
|
||||
display_wayland->startup_notification_id = g_strdup (startup_id);
|
||||
|
||||
/* Clear the environment variable so it won't be inherited by
|
||||
* child processes and confuse things.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_STARTUP_ID");
|
||||
}
|
||||
startup_id = gdk_get_startup_notification_id ();
|
||||
if (startup_id)
|
||||
display_wayland->startup_notification_id = g_strdup (startup_id);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -2153,19 +2153,9 @@ gdk_x11_display_make_default (GdkDisplay *display)
|
||||
g_free (display_x11->startup_notification_id);
|
||||
display_x11->startup_notification_id = NULL;
|
||||
|
||||
startup_id = g_getenv ("DESKTOP_STARTUP_ID");
|
||||
if (startup_id && *startup_id != '\0')
|
||||
{
|
||||
if (!g_utf8_validate (startup_id, -1, NULL))
|
||||
g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
|
||||
else
|
||||
gdk_x11_display_set_startup_notification_id (display, startup_id);
|
||||
|
||||
/* Clear the environment variable so it won't be inherited by
|
||||
* child processes and confuse things.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_STARTUP_ID");
|
||||
}
|
||||
startup_id = gdk_get_startup_notification_id ();
|
||||
if (startup_id)
|
||||
gdk_x11_display_set_startup_notification_id (display, startup_id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user