]> code.delx.au - pulseaudio/blobdiff - src/pulsecore/proplist-util.c
cpu: check for CMOV flag before using this intsruction in assembly
[pulseaudio] / src / pulsecore / proplist-util.c
index ae8e08023d9cc47df08e8c760b6e523c1dc082c7..23864bcbf151dfdf2d13d59fa7c89b1b71b3bef7 100644 (file)
@@ -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,65 @@ 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)
+#pragma GCC diagnostic ignored "-Wstrict-prototypes"
+#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;
@@ -77,8 +135,9 @@ void pa_init_proplist(pa_proplist *p) {
 
                 k = pa_xstrndup(*e+skip, kl);
 
-                if (override || !pa_proplist_contains(p, k))
-                    pa_proplist_sets(p, k, *e+skip+kl+1);
+                if (!pa_streq(k, "OVERRIDE"))
+                    if (override || !pa_proplist_contains(p, k))
+                        pa_proplist_sets(p, k, *e+skip+kl+1);
                 pa_xfree(k);
             }
         }
@@ -109,46 +168,36 @@ void pa_init_proplist(pa_proplist *p) {
     }
 
     if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_USER)) {
-        char t[64];
-        if (pa_get_user_name(t, sizeof(t))) {
-            char *c = pa_utf8_filter(t);
-            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, c);
-            pa_xfree(c);
+        char *u;
+
+        if ((u = pa_get_user_name_malloc())) {
+            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_USER, u);
+            pa_xfree(u);
         }
     }
 
     if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_HOST)) {
-        char t[64];
-        if (pa_get_host_name(t, sizeof(t))) {
-            char *c = pa_utf8_filter(t);
-            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, c);
-            pa_xfree(c);
+        char *h;
+
+        if ((h = pa_get_host_name_malloc())) {
+            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_HOST, h);
+            pa_xfree(h);
         }
     }
 
     if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_BINARY)) {
-        char t[PATH_MAX];
-        if (pa_get_binary_name(t, sizeof(t))) {
+        char *t;
+
+        if ((t = pa_get_binary_name_malloc())) {
             char *c = pa_utf8_filter(t);
             pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_BINARY, c);
+            pa_xfree(t);
             pa_xfree(c);
         }
     }
 
-#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;
@@ -182,4 +231,13 @@ void pa_init_proplist(pa_proplist *p) {
             pa_xfree(m);
         }
     }
+
+    if (!pa_proplist_contains(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID)) {
+        char *s;
+
+        if ((s = pa_session_id())) {
+            pa_proplist_sets(p, PA_PROP_APPLICATION_PROCESS_SESSION_ID, s);
+            pa_xfree(s);
+        }
+    }
 }