diff options
Diffstat (limited to 'src/pulsecore/proplist-util.c')
-rw-r--r-- | src/pulsecore/proplist-util.c | 103 |
1 files changed, 83 insertions, 20 deletions
diff --git a/src/pulsecore/proplist-util.c b/src/pulsecore/proplist-util.c index 8a447cf7..bdae0e65 100644 --- a/src/pulsecore/proplist-util.c +++ b/src/pulsecore/proplist-util.c @@ -34,6 +34,7 @@ extern char **environ; #endif +#include <pulse/gccmacro.h> #include <pulse/proplist.h> #include <pulse/utf8.h> #include <pulse/xmalloc.h> @@ -41,8 +42,64 @@ extern char **environ; #include <pulsecore/core-util.h> +#if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF) +#include <glib.h> +static G_CONST_RETURN gchar* _g_get_application_name(void) PA_GCC_WEAKREF(g_get_application_name); +#endif + +#if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF) +#include <gtk/gtk.h> +#include <gdk/gdkx.h> +static G_CONST_RETURN gchar* _gtk_window_get_default_icon_name(void) PA_GCC_WEAKREF(gtk_window_get_default_icon_name); +static Display *_gdk_display PA_GCC_WEAKREF(gdk_display); +#endif + #include "proplist-util.h" +static void add_glib_properties(pa_proplist *p) { + +#if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF) + + if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) + if (_g_get_application_name) { + const gchar *t; + + /* We ignore the tiny race condition here. */ + + if ((t = _g_get_application_name())) + pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, t); + } + +#endif +} + +static void add_gtk_properties(pa_proplist *p) { + +#if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF) + + if (!pa_proplist_contains(p, PA_PROP_APPLICATION_ICON_NAME)) + if (_gtk_window_get_default_icon_name) { + const gchar *t; + + /* We ignore the tiny race condition here. */ + + if ((t = _gtk_window_get_default_icon_name())) + pa_proplist_sets(p, PA_PROP_APPLICATION_ICON_NAME, t); + } + + if (!pa_proplist_contains(p, PA_PROP_WINDOW_X11_DISPLAY)) + if (&_gdk_display && _gdk_display) { + const char *t; + + /* We ignore the tiny race condition here. */ + + if ((t = DisplayString(_gdk_display))) + pa_proplist_sets(p, PA_PROP_WINDOW_X11_DISPLAY, t); + } + +#endif +} + void pa_init_proplist(pa_proplist *p) { char **e; const char *pp; @@ -58,18 +115,27 @@ void pa_init_proplist(pa_proplist *p) { for (e = environ; *e; e++) { if (pa_startswith(*e, "PULSE_PROP_")) { - size_t kl = strcspn(*e+11, "="); + size_t kl, skip; char *k; + pa_bool_t override; - if ((*e)[11+kl] != '=') - continue; + if (pa_startswith(*e, "PULSE_PROP_OVERRIDE_")) { + skip = 20; + override = TRUE; + } else { + skip = 11; + override = FALSE; + } - if (!pa_utf8_valid(*e+11+kl+1)) + kl = strcspn(*e+skip, "="); + + if ((*e)[skip+kl] != '=') continue; - k = pa_xstrndup(*e+11, kl); + k = pa_xstrndup(*e+skip, kl); - pa_proplist_sets(p, k, *e+11+kl+1); + if (override || !pa_proplist_contains(p, k)) + pa_proplist_sets(p, k, *e+skip+kl+1); pa_xfree(k); } } @@ -79,6 +145,15 @@ void pa_init_proplist(pa_proplist *p) { pa_proplist *t; if ((t = pa_proplist_from_string(pp))) { + pa_proplist_update(p, PA_UPDATE_MERGE, t); + pa_proplist_free(t); + } + } + + if ((pp = getenv("PULSE_PROP_OVERRIDE"))) { + pa_proplist *t; + + if ((t = pa_proplist_from_string(pp))) { pa_proplist_update(p, PA_UPDATE_REPLACE, t); pa_proplist_free(t); } @@ -117,20 +192,8 @@ void pa_init_proplist(pa_proplist *p) { } } -#ifdef RTLD_NOLOAD - if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) { - void *dl; - - if ((dl = dlopen("libglib-2.0", RTLD_NOLOAD))) { - const char *(*_g_get_application_name)(void); - - if ((*(void**) &_g_get_application_name = dlsym(dl, "g_get_application_name"))) - pa_proplist_sets(p, PA_PROP_APPLICATION_NAME, _g_get_application_name()); - - dlclose(dl); - } - } -#endif + add_glib_properties(p); + add_gtk_properties(p); if (!pa_proplist_contains(p, PA_PROP_APPLICATION_NAME)) { const char *t; |