Merge branch 'startup-id-private' into 'gtk-3-24'
Centralize DESKTOP_STARTUP/AUTOSTART_ID handling See merge request GNOME/gtk!659
This commit is contained in:
commit
a6eb593370
@ -17,6 +17,8 @@ gdk__private__ (void)
|
||||
gdk_display_set_rendering_mode,
|
||||
gdk_display_get_debug_updates,
|
||||
gdk_display_set_debug_updates,
|
||||
gdk_get_desktop_startup_id,
|
||||
gdk_get_desktop_autostart_id,
|
||||
};
|
||||
|
||||
return &table;
|
||||
|
@ -31,6 +31,9 @@ gboolean gdk_display_get_debug_updates (GdkDisplay *display);
|
||||
void gdk_display_set_debug_updates (GdkDisplay *display,
|
||||
gboolean debug_updates);
|
||||
|
||||
const gchar * gdk_get_desktop_startup_id (void);
|
||||
const gchar * gdk_get_desktop_autostart_id (void);
|
||||
|
||||
typedef struct {
|
||||
/* add all private functions here, initialize them in gdk-private.c */
|
||||
gboolean (* gdk_device_grab_info) (GdkDisplay *display,
|
||||
@ -56,6 +59,9 @@ typedef struct {
|
||||
gboolean (* gdk_display_get_debug_updates) (GdkDisplay *display);
|
||||
void (* gdk_display_set_debug_updates) (GdkDisplay *display,
|
||||
gboolean debug_updates);
|
||||
|
||||
const gchar * (* gdk_get_desktop_startup_id) (void);
|
||||
const gchar * (* gdk_get_desktop_autostart_id) (void);
|
||||
} GdkPrivateVTable;
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
80
gdk/gdk.c
80
gdk/gdk.c
@ -38,6 +38,8 @@
|
||||
#include "gdkkeysyms.h"
|
||||
#endif
|
||||
|
||||
#include "gdkconstructor.h"
|
||||
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
@ -1132,3 +1134,81 @@ gdk_unichar_direction (gunichar ch)
|
||||
else
|
||||
return PANGO_DIRECTION_LTR;
|
||||
}
|
||||
|
||||
#ifdef G_HAS_CONSTRUCTORS
|
||||
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_startup_id)
|
||||
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_autostart_id)
|
||||
#endif
|
||||
G_DEFINE_CONSTRUCTOR(stash_startup_id)
|
||||
G_DEFINE_CONSTRUCTOR(stash_autostart_id)
|
||||
#endif
|
||||
|
||||
static char *desktop_startup_id = NULL;
|
||||
static char *desktop_autostart_id = NULL;
|
||||
|
||||
static void
|
||||
stash_startup_id (void)
|
||||
{
|
||||
const char *startup_id = g_getenv ("DESKTOP_STARTUP_ID");
|
||||
|
||||
if (startup_id == NULL || startup_id[0] == '\0')
|
||||
return;
|
||||
|
||||
if (!g_utf8_validate (startup_id, -1, NULL))
|
||||
{
|
||||
g_warning ("DESKTOP_STARTUP_ID contains invalid UTF-8");
|
||||
return;
|
||||
}
|
||||
|
||||
desktop_startup_id = g_strdup (startup_id);
|
||||
}
|
||||
|
||||
static void
|
||||
stash_autostart_id (void)
|
||||
{
|
||||
const char *autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
|
||||
desktop_autostart_id = g_strdup (autostart_id ? autostart_id : "");
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gdk_get_desktop_startup_id (void)
|
||||
{
|
||||
static gsize init = 0;
|
||||
|
||||
if (g_once_init_enter (&init))
|
||||
{
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
stash_startup_id ();
|
||||
#endif
|
||||
/* Clear the environment variable so it won't be inherited by
|
||||
* child processes and confuse things.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_STARTUP_ID");
|
||||
|
||||
g_once_init_leave (&init, 1);
|
||||
}
|
||||
|
||||
return desktop_startup_id;
|
||||
}
|
||||
|
||||
const gchar *
|
||||
gdk_get_desktop_autostart_id (void)
|
||||
{
|
||||
static gsize init = 0;
|
||||
|
||||
if (g_once_init_enter (&init))
|
||||
{
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
stash_autostart_id ();
|
||||
#endif
|
||||
/* Clear the environment variable so it won't be inherited by
|
||||
* child processes and confuse things.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_AUTOSTART_ID");
|
||||
|
||||
g_once_init_leave (&init, 1);
|
||||
}
|
||||
|
||||
return desktop_autostart_id;
|
||||
}
|
||||
|
@ -42,6 +42,7 @@
|
||||
#include "gdkprivate-wayland.h"
|
||||
#include "gdkglcontext-wayland.h"
|
||||
#include "gdkwaylandmonitor.h"
|
||||
#include "gdk-private.h"
|
||||
#include "pointer-gestures-unstable-v1-client-protocol.h"
|
||||
#include "tablet-unstable-v2-client-protocol.h"
|
||||
#include "xdg-shell-unstable-v6-client-protocol.h"
|
||||
@ -805,19 +806,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_desktop_startup_id ();
|
||||
if (startup_id)
|
||||
display_wayland->startup_notification_id = g_strdup (startup_id);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
|
@ -2229,19 +2229,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_desktop_startup_id ();
|
||||
if (startup_id)
|
||||
gdk_x11_display_set_startup_notification_id (display, startup_id);
|
||||
}
|
||||
|
||||
static void
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include "gtksettings.h"
|
||||
#include "gtkprivate.h"
|
||||
|
||||
#include "gdk/gdkconstructor.h"
|
||||
#include "gdk/gdk-private.h"
|
||||
|
||||
G_DEFINE_TYPE (GtkApplicationImplDBus, gtk_application_impl_dbus, GTK_TYPE_APPLICATION_IMPL)
|
||||
|
||||
@ -155,29 +155,6 @@ gtk_application_get_proxy_if_service_present (GDBusConnection *connection,
|
||||
return proxy;
|
||||
}
|
||||
|
||||
#ifdef G_HAS_CONSTRUCTORS
|
||||
#ifdef G_DEFINE_CONSTRUCTOR_NEEDS_PRAGMA
|
||||
#pragma G_DEFINE_CONSTRUCTOR_PRAGMA_ARGS(stash_desktop_autostart_id)
|
||||
#endif
|
||||
G_DEFINE_CONSTRUCTOR(stash_desktop_autostart_id)
|
||||
#endif
|
||||
|
||||
static char *client_id = NULL;
|
||||
|
||||
static void
|
||||
stash_desktop_autostart_id (void)
|
||||
{
|
||||
const char *desktop_autostart_id;
|
||||
|
||||
desktop_autostart_id = g_getenv ("DESKTOP_AUTOSTART_ID");
|
||||
client_id = g_strdup (desktop_autostart_id ? desktop_autostart_id : "");
|
||||
|
||||
/* Unset DESKTOP_AUTOSTART_ID in order to avoid child processes to
|
||||
* use the same client id.
|
||||
*/
|
||||
g_unsetenv ("DESKTOP_AUTOSTART_ID");
|
||||
}
|
||||
|
||||
static void
|
||||
screensaver_signal_session (GDBusProxy *proxy,
|
||||
const char *sender_name,
|
||||
@ -280,10 +257,7 @@ gtk_application_impl_dbus_startup (GtkApplicationImpl *impl,
|
||||
gboolean same_bus;
|
||||
const char *bus_name;
|
||||
const char *client_interface;
|
||||
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
stash_desktop_autostart_id ();
|
||||
#endif
|
||||
const char *client_id = GDK_PRIVATE_CALL (gdk_get_desktop_autostart_id) ();
|
||||
|
||||
dbus->session = g_application_get_dbus_connection (G_APPLICATION (impl->application));
|
||||
|
||||
|
@ -28,7 +28,7 @@
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include "gdk/gdkconstructor.h"
|
||||
#include "gdk/gdk-private.h"
|
||||
|
||||
#include "gtkapplicationprivate.h"
|
||||
#include "gtkclipboardprivate.h"
|
||||
@ -169,21 +169,6 @@ 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,
|
||||
@ -363,7 +348,9 @@ gtk_application_add_platform_data (GApplication *application,
|
||||
*
|
||||
* So we do all the things... which currently is just one thing.
|
||||
*/
|
||||
if (desktop_startup_id && g_utf8_validate (desktop_startup_id, -1, NULL))
|
||||
const gchar *desktop_startup_id =
|
||||
GDK_PRIVATE_CALL (gdk_get_desktop_startup_id) ();
|
||||
if (desktop_startup_id)
|
||||
g_variant_builder_add (builder, "{sv}", "desktop-startup-id",
|
||||
g_variant_new_string (desktop_startup_id));
|
||||
}
|
||||
@ -395,9 +382,8 @@ gtk_application_init (GtkApplication *application)
|
||||
|
||||
application->priv->accels = gtk_application_accels_new ();
|
||||
|
||||
#ifndef G_HAS_CONSTRUCTORS
|
||||
stash_desktop_startup_id ();
|
||||
#endif
|
||||
/* getenv now at the latest */
|
||||
GDK_PRIVATE_CALL (gdk_get_desktop_startup_id) ();
|
||||
}
|
||||
|
||||
static void
|
||||
|
Loading…
Reference in New Issue
Block a user