From f73e9c19f7fd4f7aaecd06a283b125078d8ad884 Mon Sep 17 00:00:00 2001 From: Colin Guthrie Date: Sat, 18 Sep 2010 11:12:56 +0100 Subject: [PATCH] x11: Use the default screen for X11 properties. This commit restores the functionality originally included in 65e807 by Leszek Koltunski. --- src/modules/x11/module-x11-publish.c | 37 ++++++++++++++---------- src/pulse/client-conf-x11.c | 12 ++++---- src/pulsecore/x11prop.c | 53 +++++++++++++++++++++++----------- src/pulsecore/x11prop.h | 6 ++-- src/utils/pax11publish.c | 56 ++++++++++++++++++------------------ 5 files changed, 95 insertions(+), 69 deletions(-) diff --git a/src/modules/x11/module-x11-publish.c b/src/modules/x11/module-x11-publish.c index e811bdf..6544e07 100644 --- a/src/modules/x11/module-x11-publish.c +++ b/src/modules/x11/module-x11-publish.c @@ -84,6 +84,8 @@ struct userdata { static void publish_servers(struct userdata *u, pa_strlist *l) { + int screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper)); + if (l) { char *s; @@ -91,20 +93,22 @@ static void publish_servers(struct userdata *u, pa_strlist *l) { s = pa_strlist_tostring(l); pa_strlist_reverse(l); - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SERVER", s); + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SERVER", s); pa_xfree(s); } else - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SERVER"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SERVER"); } static pa_hook_result_t servers_changed_cb(void *hook_data, void *call_data, void *slot_data) { pa_strlist *servers = call_data; struct userdata *u = slot_data; char t[256]; + int screen; pa_assert(u); - if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) { + screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper)); + if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) { pa_log_warn("PulseAudio information vanished from X11!"); return PA_HOOK_OK; } @@ -138,6 +142,7 @@ int pa__init(pa_module*m) { char *mid, *sid; char hx[PA_NATIVE_COOKIE_LENGTH*2+1]; const char *t; + int screen; pa_assert(m); @@ -163,26 +168,27 @@ int pa__init(pa_module*m) { if (!(u->x11_wrapper = pa_x11_wrapper_get(m->core, pa_modargs_get_value(ma, "display", NULL)))) goto fail; + screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper)); mid = pa_machine_id(); u->id = pa_sprintf_malloc("%lu@%s/%lu", (unsigned long) getuid(), mid, (unsigned long) getpid()); pa_xfree(mid); - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_ID", u->id); + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", u->id); if ((sid = pa_session_id())) { - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SESSION_ID", sid); + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SESSION_ID", sid); pa_xfree(sid); } publish_servers(u, pa_native_protocol_servers(u->protocol)); if ((t = pa_modargs_get_value(ma, "source", NULL))) - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SOURCE", t); + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SOURCE", t); if ((t = pa_modargs_get_value(ma, "sink", NULL))) - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SINK", t); + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SINK", t); - pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_COOKIE", + pa_x11_set_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_COOKIE", pa_hexstr(pa_auth_cookie_read(u->auth_cookie, PA_NATIVE_COOKIE_LENGTH), PA_NATIVE_COOKIE_LENGTH, hx, sizeof(hx))); u->x11_client = pa_x11_client_new(u->x11_wrapper, NULL, x11_kill_cb, u); @@ -213,17 +219,18 @@ void pa__done(pa_module*m) { if (u->x11_wrapper) { char t[256]; + int screen = DefaultScreen(pa_x11_wrapper_get_display(u->x11_wrapper)); /* Yes, here is a race condition */ - if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) + if (!pa_x11_get_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID", t, sizeof(t)) || strcmp(t, u->id)) pa_log_warn("PulseAudio information vanished from X11!"); else { - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_ID"); - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SERVER"); - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SINK"); - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SOURCE"); - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_COOKIE"); - pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), "PULSE_SESSION_ID"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_ID"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SERVER"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SINK"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SOURCE"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_COOKIE"); + pa_x11_del_prop(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper), screen, "PULSE_SESSION_ID"); xcb_flush(pa_x11_wrapper_get_xcb_connection(u->x11_wrapper)); } diff --git a/src/pulse/client-conf-x11.c b/src/pulse/client-conf-x11.c index 0348a2f..76b1b7b 100644 --- a/src/pulse/client-conf-x11.c +++ b/src/pulse/client-conf-x11.c @@ -39,7 +39,7 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) { xcb_connection_t *xcb = NULL; - int ret = -1; + int ret = -1, screen = 0; char t[1024]; pa_assert(c); @@ -60,13 +60,13 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) { goto finish; } - if (pa_x11_get_prop(xcb, "PULSE_SERVER", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t))) { pa_bool_t disable_autospawn = TRUE; pa_xfree(c->default_server); c->default_server = pa_xstrdup(t); - if (pa_x11_get_prop(xcb, "PULSE_SESSION_ID", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "PULSE_SESSION_ID", t, sizeof(t))) { char *id; if ((id = pa_session_id())) { @@ -80,17 +80,17 @@ int pa_client_conf_from_x11(pa_client_conf *c, const char *dname) { c->autospawn = FALSE; } - if (pa_x11_get_prop(xcb, "PULSE_SINK", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t))) { pa_xfree(c->default_sink); c->default_sink = pa_xstrdup(t); } - if (pa_x11_get_prop(xcb, "PULSE_SOURCE", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t))) { pa_xfree(c->default_source); c->default_source = pa_xstrdup(t); } - if (pa_x11_get_prop(xcb, "PULSE_COOKIE", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t))) { uint8_t cookie[PA_NATIVE_COOKIE_LENGTH]; if (pa_parsehex(t, cookie, sizeof(cookie)) != sizeof(cookie)) { diff --git a/src/pulsecore/x11prop.c b/src/pulsecore/x11prop.c index 4f2fec0..4cb21da 100644 --- a/src/pulsecore/x11prop.c +++ b/src/pulsecore/x11prop.c @@ -34,55 +34,74 @@ #define PA_XCB_FORMAT 8 -void pa_x11_set_prop(xcb_connection_t *xcb, const char *name, const char *data) { - xcb_screen_t *screen; +static xcb_screen_t *screen_of_display(xcb_connection_t *xcb, int screen) +{ const xcb_setup_t *s; + xcb_screen_iterator_t iter; + + if ((s = xcb_get_setup(xcb))) { + iter = xcb_setup_roots_iterator(s); + for (; iter.rem; --screen, xcb_screen_next(&iter)) + if (0 == screen) + return iter.data; + } + return NULL; +} + +void pa_x11_set_prop(xcb_connection_t *xcb, int screen, const char *name, const char *data) { + xcb_screen_t *xs; xcb_atom_t a; pa_assert(xcb); pa_assert(name); pa_assert(data); - if ((s = xcb_get_setup(xcb))) { + if ((xs = screen_of_display(xcb, screen))) { a = xcb_atom_get(xcb, name); - screen = xcb_setup_roots_iterator(s).data; - xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, screen->root, a, STRING, PA_XCB_FORMAT, (int) strlen(data), (const void*) data); + xcb_change_property(xcb, XCB_PROP_MODE_REPLACE, xs->root, a, STRING, PA_XCB_FORMAT, (int) strlen(data), (const void*) data); } } -void pa_x11_del_prop(xcb_connection_t *xcb, const char *name) { - xcb_screen_t *screen; - const xcb_setup_t *s; +void pa_x11_del_prop(xcb_connection_t *xcb, int screen, const char *name) { + xcb_screen_t *xs; xcb_atom_t a; pa_assert(xcb); pa_assert(name); - if ((s = xcb_get_setup(xcb))) { + if ((xs = screen_of_display(xcb, screen))) { a = xcb_atom_get(xcb, name); - screen = xcb_setup_roots_iterator(s).data; - xcb_delete_property(xcb, screen->root, a); + xcb_delete_property(xcb, xs->root, a); } } -char* pa_x11_get_prop(xcb_connection_t *xcb, const char *name, char *p, size_t l) { +char* pa_x11_get_prop(xcb_connection_t *xcb, int screen, const char *name, char *p, size_t l) { char *ret = NULL; int len; xcb_get_property_cookie_t req; xcb_get_property_reply_t* prop = NULL; - xcb_screen_t *screen; - const xcb_setup_t *s; + xcb_screen_t *xs; xcb_atom_t a; pa_assert(xcb); pa_assert(name); pa_assert(p); - if ((s = xcb_get_setup(xcb))) { + + xs = screen_of_display(xcb, screen); + /* + * Also try and get the settings from the first screen. + * This allows for e.g. a Media Center to run on screen 1 (e.g. HDMI) and have + * different defaults (e.g. prefer the HDMI sink) than the primary screen 0 + * which uses the Internal Audio sink. + */ + if (!xs && 0 != screen) + xs = screen_of_display(xcb, 0); + + if (xs) { a = xcb_atom_get(xcb, name); - screen = xcb_setup_roots_iterator(s).data; - req = xcb_get_property(xcb, 0, screen->root, a, STRING, 0, (uint32_t)(l-1)); + req = xcb_get_property(xcb, 0, xs->root, a, STRING, 0, (uint32_t)(l-1)); prop = xcb_get_property_reply(xcb, req, NULL); if (!prop) diff --git a/src/pulsecore/x11prop.h b/src/pulsecore/x11prop.h index 7492261..5a12114 100644 --- a/src/pulsecore/x11prop.h +++ b/src/pulsecore/x11prop.h @@ -27,8 +27,8 @@ #include -void pa_x11_set_prop(xcb_connection_t *xcb, const char *name, const char *data); -void pa_x11_del_prop(xcb_connection_t *xcb, const char *name); -char* pa_x11_get_prop(xcb_connection_t *xcb, const char *name, char *p, size_t l); +void pa_x11_set_prop(xcb_connection_t *xcb, int screen, const char *name, const char *data); +void pa_x11_del_prop(xcb_connection_t *xcb, int screen, const char *name); +char* pa_x11_get_prop(xcb_connection_t *xcb, int screen, const char *name, char *p, size_t l); #endif diff --git a/src/utils/pax11publish.c b/src/utils/pax11publish.c index 62b798c..e155888 100644 --- a/src/utils/pax11publish.c +++ b/src/utils/pax11publish.c @@ -44,7 +44,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; + int c, ret = 1, screen = 0; xcb_connection_t *xcb = NULL; enum { DUMP, EXPORT, IMPORT, REMOVE } mode = DUMP; @@ -95,7 +95,7 @@ int main(int argc, char *argv[]) { } } - if (!(xcb = xcb_connect(dname, NULL))) { + if (!(xcb = xcb_connect(dname, &screen))) { pa_log(_("xcb_connect() failed")); goto finish; } @@ -108,13 +108,13 @@ int main(int argc, char *argv[]) { switch (mode) { case DUMP: { char t[1024]; - if (pa_x11_get_prop(xcb, "PULSE_SERVER", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t))) printf(_("Server: %s\n"), t); - if (pa_x11_get_prop(xcb, "PULSE_SOURCE", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t))) printf(_("Source: %s\n"), t); - if (pa_x11_get_prop(xcb, "PULSE_SINK", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t))) printf(_("Sink: %s\n"), t); - if (pa_x11_get_prop(xcb, "PULSE_COOKIE", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_COOKIE", t, sizeof(t))) printf(_("Cookie: %s\n"), t); break; @@ -122,14 +122,14 @@ int main(int argc, char *argv[]) { case IMPORT: { char t[1024]; - if (pa_x11_get_prop(xcb, "PULSE_SERVER", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SERVER", t, sizeof(t))) printf("PULSE_SERVER='%s'\nexport PULSE_SERVER\n", t); - if (pa_x11_get_prop(xcb, "PULSE_SOURCE", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SOURCE", t, sizeof(t))) printf("PULSE_SOURCE='%s'\nexport PULSE_SOURCE\n", t); - if (pa_x11_get_prop(xcb, "PULSE_SINK", t, sizeof(t))) + if (pa_x11_get_prop(xcb, screen, "PULSE_SINK", t, sizeof(t))) printf("PULSE_SINK='%s'\nexport PULSE_SINK\n", t); - if (pa_x11_get_prop(xcb, "PULSE_COOKIE", t, sizeof(t))) { + if (pa_x11_get_prop(xcb, screen, "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)) { @@ -162,16 +162,16 @@ int main(int argc, char *argv[]) { goto finish; } - 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"); + pa_x11_del_prop(xcb, screen, "PULSE_SERVER"); + pa_x11_del_prop(xcb, screen, "PULSE_SINK"); + pa_x11_del_prop(xcb, screen, "PULSE_SOURCE"); + pa_x11_del_prop(xcb, screen, "PULSE_ID"); + pa_x11_del_prop(xcb, screen, "PULSE_COOKIE"); if (server) - pa_x11_set_prop(xcb, "PULSE_SERVER", server); + pa_x11_set_prop(xcb, screen, "PULSE_SERVER", server); else if (conf->default_server) - pa_x11_set_prop(xcb, "PULSE_SERVER", conf->default_server); + pa_x11_set_prop(xcb, screen, "PULSE_SERVER", conf->default_server); else { char hn[256]; if (!pa_get_fqdn(hn, sizeof(hn))) { @@ -179,18 +179,18 @@ int main(int argc, char *argv[]) { goto finish; } - pa_x11_set_prop(xcb, "PULSE_SERVER", hn); + pa_x11_set_prop(xcb, screen, "PULSE_SERVER", hn); } if (sink) - pa_x11_set_prop(xcb, "PULSE_SINK", sink); + pa_x11_set_prop(xcb, screen, "PULSE_SINK", sink); else if (conf->default_sink) - pa_x11_set_prop(xcb, "PULSE_SINK", conf->default_sink); + pa_x11_set_prop(xcb, screen, "PULSE_SINK", conf->default_sink); if (source) - pa_x11_set_prop(xcb, "PULSE_SOURCE", source); + pa_x11_set_prop(xcb, screen, "PULSE_SOURCE", source); if (conf->default_source) - pa_x11_set_prop(xcb, "PULSE_SOURCE", conf->default_source); + pa_x11_set_prop(xcb, screen, "PULSE_SOURCE", conf->default_source); pa_client_conf_free(conf); @@ -199,16 +199,16 @@ int main(int argc, char *argv[]) { goto finish; } - pa_x11_set_prop(xcb, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx))); + pa_x11_set_prop(xcb, screen, "PULSE_COOKIE", pa_hexstr(cookie, sizeof(cookie), hx, sizeof(hx))); break; } case REMOVE: - 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"); + pa_x11_del_prop(xcb, screen, "PULSE_SERVER"); + pa_x11_del_prop(xcb, screen, "PULSE_SINK"); + pa_x11_del_prop(xcb, screen, "PULSE_SOURCE"); + pa_x11_del_prop(xcb, screen, "PULSE_ID"); + pa_x11_del_prop(xcb, screen, "PULSE_COOKIE"); break; default: -- 2.7.4