2 This file is part of PulseAudio.
4 Copyright 2008 Lennart Poettering
6 PulseAudio is free software; you can redistribute it and/or modify
7 it under the terms of the GNU Lesser General Public License as
8 published by the Free Software Foundation; either version 2.1 of the
9 License, or (at your option) any later version.
11 PulseAudio is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with PulseAudio; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
31 #include <crt_externs.h>
32 #define environ (*_NSGetEnviron())
33 #elif !HAVE_DECL_ENVIRON
34 extern char **environ
;
37 #include <pulse/gccmacro.h>
38 #include <pulse/proplist.h>
39 #include <pulse/utf8.h>
40 #include <pulse/xmalloc.h>
41 #include <pulse/util.h>
43 #include <pulsecore/core-util.h>
45 #if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF)
47 static G_CONST_RETURN gchar
* _g_get_application_name(void) PA_GCC_WEAKREF(g_get_application_name
);
50 #if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF)
53 static G_CONST_RETURN gchar
* _gtk_window_get_default_icon_name(void) PA_GCC_WEAKREF(gtk_window_get_default_icon_name
);
54 static Display
*_gdk_display
PA_GCC_WEAKREF(gdk_display
);
57 #include "proplist-util.h"
59 static void add_glib_properties(pa_proplist
*p
) {
61 #if defined(HAVE_GLIB) && defined(PA_GCC_WEAKREF)
63 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_NAME
))
64 if (_g_get_application_name
) {
67 /* We ignore the tiny race condition here. */
69 if ((t
= _g_get_application_name()))
70 pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, t
);
76 static void add_gtk_properties(pa_proplist
*p
) {
78 #if defined(HAVE_GTK) && defined(PA_GCC_WEAKREF)
80 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_ICON_NAME
))
81 if (_gtk_window_get_default_icon_name
) {
84 /* We ignore the tiny race condition here. */
86 if ((t
= _gtk_window_get_default_icon_name()))
87 pa_proplist_sets(p
, PA_PROP_APPLICATION_ICON_NAME
, t
);
90 if (!pa_proplist_contains(p
, PA_PROP_WINDOW_X11_DISPLAY
))
91 if (&_gdk_display
&& _gdk_display
) {
94 /* We ignore the tiny race condition here. */
96 if ((t
= DisplayString(_gdk_display
)))
97 pa_proplist_sets(p
, PA_PROP_WINDOW_X11_DISPLAY
, t
);
103 void pa_init_proplist(pa_proplist
*p
) {
111 /* Some applications seem to reset environ to NULL for various
112 * reasons, hence we need to check for this explicitly. See
115 for (e
= environ
; *e
; e
++) {
117 if (pa_startswith(*e
, "PULSE_PROP_")) {
122 if (pa_startswith(*e
, "PULSE_PROP_OVERRIDE_")) {
130 kl
= strcspn(*e
+skip
, "=");
132 if ((*e
)[skip
+kl
] != '=')
135 k
= pa_xstrndup(*e
+skip
, kl
);
137 if (override
|| !pa_proplist_contains(p
, k
))
138 pa_proplist_sets(p
, k
, *e
+skip
+kl
+1);
144 if ((pp
= getenv("PULSE_PROP"))) {
147 if ((t
= pa_proplist_from_string(pp
))) {
148 pa_proplist_update(p
, PA_UPDATE_MERGE
, t
);
153 if ((pp
= getenv("PULSE_PROP_OVERRIDE"))) {
156 if ((t
= pa_proplist_from_string(pp
))) {
157 pa_proplist_update(p
, PA_UPDATE_REPLACE
, t
);
162 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_ID
)) {
164 pa_snprintf(t
, sizeof(t
), "%lu", (unsigned long) getpid());
165 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_ID
, t
);
168 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_USER
)) {
170 if (pa_get_user_name(t
, sizeof(t
))) {
171 char *c
= pa_utf8_filter(t
);
172 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_USER
, c
);
177 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_HOST
)) {
179 if (pa_get_host_name(t
, sizeof(t
))) {
180 char *c
= pa_utf8_filter(t
);
181 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_HOST
, c
);
186 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_BINARY
)) {
188 if (pa_get_binary_name(t
, sizeof(t
))) {
189 char *c
= pa_utf8_filter(t
);
190 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_BINARY
, c
);
195 add_glib_properties(p
);
196 add_gtk_properties(p
);
198 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_NAME
)) {
201 if ((t
= pa_proplist_gets(p
, PA_PROP_APPLICATION_PROCESS_BINARY
)))
202 pa_proplist_sets(p
, PA_PROP_APPLICATION_NAME
, t
);
205 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_LANGUAGE
)) {
208 if ((l
= setlocale(LC_MESSAGES
, NULL
)))
209 pa_proplist_sets(p
, PA_PROP_APPLICATION_LANGUAGE
, l
);
212 if (!pa_proplist_contains(p
, PA_PROP_WINDOW_X11_DISPLAY
)) {
215 if ((t
= getenv("DISPLAY"))) {
216 char *c
= pa_utf8_filter(t
);
217 pa_proplist_sets(p
, PA_PROP_WINDOW_X11_DISPLAY
, c
);
222 if (!pa_proplist_contains(p
, PA_PROP_APPLICATION_PROCESS_MACHINE_ID
)) {
225 if ((m
= pa_machine_id())) {
226 pa_proplist_sets(p
, PA_PROP_APPLICATION_PROCESS_MACHINE_ID
, m
);