]> code.delx.au - pulseaudio/blob - src/pulse/client-conf-x11.c
merge glitch-free branch back into trunk
[pulseaudio] / src / pulse / client-conf-x11.c
1 /* $Id$ */
2
3 /***
4 This file is part of PulseAudio.
5
6 Copyright 2004-2006 Lennart Poettering
7
8 PulseAudio is free software; you can redistribute it and/or modify
9 it under the terms of the GNU Lesser General Public License as published
10 by the Free Software Foundation; either version 2 of the License,
11 or (at your option) any later version.
12
13 PulseAudio is distributed in the hope that it will be useful, but
14 WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 General Public License for more details.
17
18 You should have received a copy of the GNU Lesser General Public License
19 along with PulseAudio; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-13071
21 USA.
22 ***/
23
24 #ifdef HAVE_CONFIG_H
25 #include <config.h>
26 #endif
27
28 #include <string.h>
29
30 #include <X11/Xlib.h>
31 #include <X11/Xatom.h>
32
33 #include <pulse/xmalloc.h>
34
35 #include <pulsecore/x11prop.h>
36 #include <pulsecore/log.h>
37 #include <pulsecore/core-util.h>
38 #include <pulsecore/macro.h>
39
40 #include "client-conf-x11.h"
41
42 int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
43 Display *d = NULL;
44 int ret = -1;
45 char t[1024];
46
47 pa_assert(c);
48
49 if (!dname && !(dname = getenv("DISPLAY")))
50 goto finish;
51
52 if (*dname == 0)
53 goto finish;
54
55 if (!(d = XOpenDisplay(dname))) {
56 pa_log("XOpenDisplay() failed");
57 goto finish;
58 }
59
60 if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t))) {
61 pa_xfree(c->default_server);
62 c->default_server = pa_xstrdup(t);
63 }
64
65 if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t))) {
66 pa_xfree(c->default_sink);
67 c->default_sink = pa_xstrdup(t);
68 }
69
70 if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t))) {
71 pa_xfree(c->default_source);
72 c->default_source = pa_xstrdup(t);
73 }
74
75 if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t))) {
76 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
77
78 if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
79 pa_log("failed to parse cookie data");
80 goto finish;
81 }
82
83 pa_assert(sizeof(cookie) == sizeof(c->cookie));
84 memcpy(c->cookie, cookie, sizeof(cookie));
85
86 c->cookie_valid = TRUE;
87
88 pa_xfree(c->cookie_file);
89 c->cookie_file = NULL;
90 }
91
92 ret = 0;
93
94 finish:
95 if (d)
96 XCloseDisplay(d);
97
98 return ret;
99
100 }