Branch data Line data Source code
1 : : /***
2 : : This file is part of PulseAudio.
3 : :
4 : : Copyright 2004-2006 Lennart Poettering
5 : :
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 published
8 : : by the Free Software Foundation; either version 2.1 of the License,
9 : : or (at your option) any later version.
10 : :
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 : : General Public License for more details.
15 : :
16 : : You should have received a copy of the GNU Lesser General Public License
17 : : along with PulseAudio; if not, write to the Free Software
18 : : Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-13071
19 : : USA.
20 : : ***/
21 : :
22 : : #ifdef HAVE_CONFIG_H
23 : : #include <config.h>
24 : : #endif
25 : :
26 : : #include <string.h>
27 : :
28 : : #include <xcb/xcb.h>
29 : :
30 : : #include <pulse/xmalloc.h>
31 : :
32 : : #include <pulsecore/i18n.h>
33 : : #include <pulsecore/x11prop.h>
34 : : #include <pulsecore/log.h>
35 : : #include <pulsecore/core-util.h>
36 : : #include <pulsecore/macro.h>
37 : :
38 : : #include "client-conf-x11.h"
39 : :
40 : 0 : int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
41 : 0 : xcb_connection_t *xcb = NULL;
42 : 0 : int ret = -1, screen = 0;
43 : : char t[1024];
44 : :
45 [ # # ]: 0 : pa_assert(c);
46 : :
47 [ # # ][ # # ]: 0 : if (!dname && !(dname = getenv("DISPLAY")))
48 : : goto finish;
49 : :
50 [ # # ]: 0 : if (*dname == 0)
51 : : goto finish;
52 : :
53 [ # # ]: 0 : if (!(xcb = xcb_connect(dname, NULL))) {
54 : 0 : pa_log(_("xcb_connect() failed"));
55 : 0 : goto finish;
56 : : }
57 : :
58 [ # # ]: 0 : if (xcb_connection_has_error(xcb)) {
59 : 0 : pa_log(_("xcb_connection_has_error() returned true"));
60 : 0 : goto finish;
61 : : }
62 : :
63 [ # # ]: 0 : if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t))) {
64 : 0 : pa_bool_t disable_autospawn = TRUE;
65 : :
66 : 0 : pa_xfree(c->default_server);
67 : 0 : c->default_server = pa_xstrdup(t);
68 : :
69 [ # # ]: 0 : if (pa_x11_get_prop(xcb, screen, "PULSE_SESSION_ID", t, sizeof(t))) {
70 : : char *id;
71 : :
72 [ # # ]: 0 : if ((id = pa_session_id())) {
73 [ # # ]: 0 : if (pa_streq(t, id))
74 : 0 : disable_autospawn = FALSE;
75 : 0 : pa_xfree(id);
76 : : }
77 : : }
78 : :
79 [ # # ]: 0 : if (disable_autospawn)
80 : 0 : c->autospawn = FALSE;
81 : : }
82 : :
83 [ # # ]: 0 : if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t))) {
84 : 0 : pa_xfree(c->default_sink);
85 : 0 : c->default_sink = pa_xstrdup(t);
86 : : }
87 : :
88 [ # # ]: 0 : if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t))) {
89 : 0 : pa_xfree(c->default_source);
90 : 0 : c->default_source = pa_xstrdup(t);
91 : : }
92 : :
93 [ # # ]: 0 : if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t))) {
94 : : uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
95 : :
96 [ # # ]: 0 : if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
97 : 0 : pa_log(_("Failed to parse cookie data"));
98 : 0 : goto finish;
99 : : }
100 : :
101 : : pa_assert(sizeof(cookie) == sizeof(c->cookie));
102 : 0 : memcpy(c->cookie, cookie, sizeof(cookie));
103 : :
104 : 0 : c->cookie_valid = TRUE;
105 : :
106 : 0 : pa_xfree(c->cookie_file);
107 : 0 : c->cookie_file = NULL;
108 : : }
109 : :
110 : : ret = 0;
111 : :
112 : : finish:
113 [ # # ]: 0 : if (xcb)
114 : 0 : xcb_disconnect(xcb);
115 : :
116 : 0 : return ret;
117 : :
118 : : }
|