2 This file is part of PulseAudio.
4 Copyright 2004-2006 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 published
8 by the Free Software Foundation; either version 2.1 of the License,
9 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 General Public License for more details.
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-1307
30 #include <pulsecore/macro.h>
32 #include <xcb/xproto.h>
34 #define PA_XCB_FORMAT 8
36 static xcb_screen_t
*screen_of_display(xcb_connection_t
*xcb
, int screen
) {
38 xcb_screen_iterator_t iter
;
40 if ((s
= xcb_get_setup(xcb
))) {
41 iter
= xcb_setup_roots_iterator(s
);
42 for (; iter
.rem
; --screen
, xcb_screen_next(&iter
))
49 void pa_x11_set_prop(xcb_connection_t
*xcb
, int screen
, const char *name
, const char *data
) {
51 xcb_intern_atom_reply_t
*reply
;
57 if ((xs
= screen_of_display(xcb
, screen
))) {
58 reply
= xcb_intern_atom_reply(xcb
,
59 xcb_intern_atom(xcb
, 0, strlen(name
), name
),
63 xcb_change_property(xcb
, XCB_PROP_MODE_REPLACE
, xs
->root
, reply
->atom
,
64 XCB_ATOM_STRING
, PA_XCB_FORMAT
,
65 (int) strlen(data
), (const void*) data
);
72 void pa_x11_del_prop(xcb_connection_t
*xcb
, int screen
, const char *name
) {
74 xcb_intern_atom_reply_t
*reply
;
79 if ((xs
= screen_of_display(xcb
, screen
))) {
80 reply
= xcb_intern_atom_reply(xcb
,
81 xcb_intern_atom(xcb
, 0, strlen(name
), name
),
85 xcb_delete_property(xcb
, xs
->root
, reply
->atom
);
91 char* pa_x11_get_prop(xcb_connection_t
*xcb
, int screen
, const char *name
, char *p
, size_t l
) {
94 xcb_get_property_cookie_t req
;
95 xcb_get_property_reply_t
* prop
= NULL
;
97 xcb_intern_atom_reply_t
*reply
;
104 xs
= screen_of_display(xcb
, screen
);
106 * Also try and get the settings from the first screen.
107 * This allows for e.g. a Media Center to run on screen 1 (e.g. HDMI) and have
108 * different defaults (e.g. prefer the HDMI sink) than the primary screen 0
109 * which uses the Internal Audio sink.
111 if (!xs
&& 0 != screen
)
112 xs
= screen_of_display(xcb
, 0);
115 reply
= xcb_intern_atom_reply(xcb
,
116 xcb_intern_atom(xcb
, 0, strlen(name
), name
),
122 req
= xcb_get_property(xcb
, 0, xs
->root
, reply
->atom
, XCB_ATOM_STRING
, 0, (uint32_t)(l
-1));
124 prop
= xcb_get_property_reply(xcb
, req
, NULL
);
129 if (PA_XCB_FORMAT
!= prop
->format
)
132 len
= xcb_get_property_value_length(prop
);
133 if (len
< 1 || len
>= (int)l
)
136 memcpy(p
, xcb_get_property_value(prop
), len
);