From e0fb83ab83d8847d8f70b358f3401768c889bf16 Mon Sep 17 00:00:00 2001 From: Egbert Eich Date: Tue, 24 May 2011 18:41:05 +0200 Subject: [PATCH] Allow disabling of individual extensions. Allow the user to specify thru environment variables XLIB_SKIP_EXT_ which extensions will not be seen by xcb_get_extension_data(). Signed-off-by: Egbert Eich --- src/xcb_ext.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) diff --git a/src/xcb_ext.c b/src/xcb_ext.c index 831f283..5a1e75e 100644 --- a/src/xcb_ext.c +++ b/src/xcb_ext.c @@ -59,6 +59,28 @@ static lazyreply *get_index(xcb_connection_t *c, int idx) return c->ext.extensions + idx - 1; } +static int check_ext_override(char *name) +{ +#define PREFIX "XLIB_SKIP_EXT_" +#define PREFLEN (sizeof(PREFIX)) + + if (name) { + char var[256 + PREFLEN]; + int i; + + strcpy(var, PREFIX); + for (i = 0; name[i] && (i < 255); i++) + var[i + PREFLEN - 1] = (name[i] == '-') ? '_' : name[i]; + var[i + PREFLEN - 1] = '\0'; + + if (getenv(var)) + return 1; + } +#undef PREFIX +#undef PREFLEN + return 0; +} + static lazyreply *get_lazyreply(xcb_connection_t *c, xcb_extension_t *ext) { static pthread_mutex_t global_lock = PTHREAD_MUTEX_INITIALIZER; @@ -74,9 +96,22 @@ static lazyreply *get_lazyreply(xcb_connection_t *c, xcb_extension_t *ext) data = get_index(c, ext->global_id); if(data && data->tag == LAZY_NONE) { - /* cache miss: query the server */ - data->tag = LAZY_COOKIE; - data->value.cookie = xcb_query_extension(c, strlen(ext->name), ext->name); + /* cache miss */ + if (!check_ext_override(ext->name)) { + /* query the server */ + data->tag = LAZY_COOKIE; + data->value.cookie = xcb_query_extension(c, strlen(ext->name), ext->name); + } else { + /* synth a reply */ + xcb_query_extension_reply_t *reply; + data->tag = LAZY_FORCED; + reply = malloc(sizeof (xcb_query_extension_reply_t)); + if (reply) { + reply->response_type = 1; + reply->present = 0; + } + data->value.reply = reply; + } } return data; } -- 1.8.1.4