]> code.delx.au - pulseaudio/blob - src/polyp/client-conf-x11.c
83d0bd2e4f65ba8c54061d1ad128183dd4674f30
[pulseaudio] / src / polyp / client-conf-x11.c
1 /* $Id$ */
2
3 /***
4 This file is part of polypaudio.
5
6 polypaudio 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 of the License,
9 or (at your option) any later version.
10
11 polypaudio 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 polypaudio; 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 #include <assert.h>
28
29 #include <X11/Xlib.h>
30 #include <X11/Xatom.h>
31
32 #include "client-conf-x11.h"
33 #include <polypcore/x11prop.h>
34 #include <polypcore/log.h>
35 #include <polypcore/xmalloc.h>
36 #include <polypcore/util.h>
37
38 int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) {
39 Display *d = NULL;
40 int ret = -1;
41 char t[1024];
42
43 if (!dname && !getenv("DISPLAY"))
44 goto finish;
45
46 if (!(d = XOpenDisplay(dname))) {
47 pa_log(__FILE__": XOpenDisplay() failed\n");
48 goto finish;
49 }
50
51 if (pa_x11_get_prop(d, "POLYP_SERVER", t, sizeof(t))) {
52 pa_xfree(c->default_server);
53 c->default_server = pa_xstrdup(t);
54 }
55
56 if (pa_x11_get_prop(d, "POLYP_SINK", t, sizeof(t))) {
57 pa_xfree(c->default_sink);
58 c->default_sink = pa_xstrdup(t);
59 }
60
61 if (pa_x11_get_prop(d, "POLYP_SOURCE", t, sizeof(t))) {
62 pa_xfree(c->default_source);
63 c->default_source = pa_xstrdup(t);
64 }
65
66 if (pa_x11_get_prop(d, "POLYP_COOKIE", t, sizeof(t))) {
67 uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
68
69 if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) {
70 pa_log(__FILE__": failed to parse cookie data\n");
71 goto finish;
72 }
73
74 assert(sizeof(cookie) == sizeof(c->cookie));
75 memcpy(c->cookie, cookie, sizeof(cookie));
76
77 c->cookie_valid = 1;
78
79 pa_xfree(c->cookie_file);
80 c->cookie_file = NULL;
81 }
82
83 ret = 0;
84
85 finish:
86 if (d)
87 XCloseDisplay(d);
88
89 return ret;
90
91 }