x11: Partially convert to XCB.

This commit mostly converts the X11 handling to XCB. There are still
some uses of XLib to deal with the X11 session handling modules, however all
client-side code should now be free of XLib and thus this should fix Bug #799

Note that this removes the screen-based changes by Leszek Koltunski
in 65e80, however this will be restored in due course.
This commit is contained in:
Colin Guthrie 2010-05-29 19:33:54 +01:00
parent 2ecd764662
commit 38778117f8
8 changed files with 109 additions and 98 deletions

View file

@ -29,8 +29,7 @@
#include <assert.h>
#include <locale.h>
#include <X11/Xlib.h>
#include <X11/Xatom.h>
#include <xcb/xcb.h>
#include <pulse/util.h>
#include <pulse/i18n.h>
@ -46,7 +45,7 @@
int main(int argc, char *argv[]) {
const char *dname = NULL, *sink = NULL, *source = NULL, *server = NULL, *cookie_file = PA_NATIVE_COOKIE_FILE;
int c, ret = 1;
Display *d = NULL;
xcb_connection_t *xcb = NULL;
enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP;
setlocale(LC_ALL, "");
@ -96,21 +95,21 @@ int main(int argc, char *argv[]) {
}
}
if (!(d = XOpenDisplay(dname))) {
pa_log(_("XOpenDisplay() failed"));
if (!(xcb = xcb_connect(dname, NULL))) {
pa_log(_("xcb_connect() failed"));
goto finish;
}
switch (mode) {
case DUMP: {
char t[1024];
if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SERVER", t, sizeof(t)))
printf(_("Server: %s\n"), t);
if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SOURCE", t, sizeof(t)))
printf(_("Source: %s\n"), t);
if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SINK", t, sizeof(t)))
printf(_("Sink: %s\n"), t);
if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_COOKIE", t, sizeof(t)))
printf(_("Cookie: %s\n"), t);
break;
@ -118,14 +117,14 @@ int main(int argc, char *argv[]) {
case IMPORT: {
char t[1024];
if (pa_x11_get_prop(d, "PULSE_SERVER", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SERVER", t, sizeof(t)))
printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t);
if (pa_x11_get_prop(d, "PULSE_SOURCE", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SOURCE", t, sizeof(t)))
printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t);
if (pa_x11_get_prop(d, "PULSE_SINK", t, sizeof(t)))
if (pa_x11_get_prop(xcb, "PULSE_SINK", t, sizeof(t)))
printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t);
if (pa_x11_get_prop(d, "PULSE_COOKIE", t, sizeof(t))) {
if (pa_x11_get_prop(xcb, "PULSE_COOKIE", t, sizeof(t))) {
uint8_t cookie[PA_NATIVE_COOKIE_LENGTH];
size_t l;
if ((l = pa_parsehex(t, cookie, sizeof(cookie))) != sizeof(cookie)) {
@ -158,16 +157,16 @@ int main(int argc, char *argv[]) {
goto finish;
}
pa_x11_del_prop(d, "PULSE_SERVER");
pa_x11_del_prop(d, "PULSE_SINK");
pa_x11_del_prop(d, "PULSE_SOURCE");
pa_x11_del_prop(d, "PULSE_ID");
pa_x11_del_prop(d, "PULSE_COOKIE");
pa_x11_del_prop(xcb, "PULSE_SERVER");
pa_x11_del_prop(xcb, "PULSE_SINK");
pa_x11_del_prop(xcb, "PULSE_SOURCE");
pa_x11_del_prop(xcb, "PULSE_ID");
pa_x11_del_prop(xcb, "PULSE_COOKIE");
if (server)
pa_x11_set_prop(d, "PULSE_SERVER", server);
pa_x11_set_prop(xcb, "PULSE_SERVER", server);
else if (conf->default_server)
pa_x11_set_prop(d, "PULSE_SERVER", conf->default_server);
pa_x11_set_prop(xcb, "PULSE_SERVER", conf->default_server);
else {
char hn[256];
if (!pa_get_fqdn(hn, sizeof(hn))) {
@ -175,18 +174,18 @@ int main(int argc, char *argv[]) {
goto finish;
}
pa_x11_set_prop(d, "PULSE_SERVER", hn);
pa_x11_set_prop(xcb, "PULSE_SERVER", hn);
}
if (sink)
pa_x11_set_prop(d, "PULSE_SINK", sink);
pa_x11_set_prop(xcb, "PULSE_SINK", sink);
else if (conf->default_sink)
pa_x11_set_prop(d, "PULSE_SINK", conf->default_sink);
pa_x11_set_prop(xcb, "PULSE_SINK", conf->default_sink);
if (source)
pa_x11_set_prop(d, "PULSE_SOURCE", source);
pa_x11_set_prop(xcb, "PULSE_SOURCE", source);
if (conf->default_source)
pa_x11_set_prop(d, "PULSE_SOURCE", conf->default_source);
pa_x11_set_prop(xcb, "PULSE_SOURCE", conf->default_source);
pa_client_conf_free(conf);
@ -195,16 +194,16 @@ int main(int argc, char *argv[]) {
goto finish;
}
pa_x11_set_prop(d, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
pa_x11_set_prop(xcb, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx)));
break;
}
case REMOVE:
pa_x11_del_prop(d, "PULSE_SERVER");
pa_x11_del_prop(d, "PULSE_SINK");
pa_x11_del_prop(d, "PULSE_SOURCE");
pa_x11_del_prop(d, "PULSE_ID");
pa_x11_del_prop(d, "PULSE_COOKIE");
pa_x11_del_prop(xcb, "PULSE_SERVER");
pa_x11_del_prop(xcb, "PULSE_SINK");
pa_x11_del_prop(xcb, "PULSE_SOURCE");
pa_x11_del_prop(xcb, "PULSE_ID");
pa_x11_del_prop(xcb, "PULSE_COOKIE");
break;
default:
@ -216,9 +215,9 @@ int main(int argc, char *argv[]) {
finish:
if (d) {
XSync(d, False);
XCloseDisplay(d);
if (xcb) {
xcb_flush(xcb);
xcb_disconnect(xcb);
}
return ret;