From 6adeafdec3cc5f5d44e2ac8eeb370d9eaf9be7d6 Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Wed, 18 Feb 2015 21:23:47 +0100 Subject: [PATCH] Test if cairo-xcb is usable during startup Create a pixmap of size 1x1 and a cairo-xcb surface for this pixmap. If the surface ends up in an error state, awesome will refuse to start. This turns a "awesome is unusable and prints lots of errors on X11 servers where the root window has a depth of 8bpp and no one knows where exactly the problem is" into "awesome refuses to start on such X11 servers and prints an error that helps Uli to say immediately what the problem is". Signed-off-by: Uli Schlachter --- awesome.c | 3 +++ draw.c | 16 ++++++++++++++++ draw.h | 2 ++ 3 files changed, 21 insertions(+) diff --git a/awesome.c b/awesome.c index 625aadd8f..0d8cb6a53 100644 --- a/awesome.c +++ b/awesome.c @@ -437,6 +437,9 @@ main(int argc, char **argv) if (xcb_cursor_context_new(globalconf.connection, globalconf.screen, &globalconf.cursor_ctx) < 0) fatal("Failed to initialize xcb-cursor"); + /* Did we get some usable data from the above X11 setup? */ + draw_test_cairo_xcb(); + /* initialize dbus */ a_dbus_init(); diff --git a/draw.c b/draw.c index 7e5d762d1..8dd361ac8 100644 --- a/draw.c +++ b/draw.c @@ -21,6 +21,7 @@ #include "config.h" #include "draw.h" +#include "globalconf.h" #include #include @@ -299,4 +300,19 @@ uint8_t draw_visual_depth(const xcb_screen_t *s, xcb_visualid_t vis) fatal("Could not find a visual's depth"); } +void draw_test_cairo_xcb(void) +{ + xcb_pixmap_t pixmap = xcb_generate_id(globalconf.connection); + xcb_create_pixmap(globalconf.connection, globalconf.default_depth, pixmap, + globalconf.screen->root, 1, 1); + cairo_surface_t *surface = cairo_xcb_surface_create(globalconf.connection, + pixmap, globalconf.visual, 1, 1); + if(cairo_surface_status(surface) != CAIRO_STATUS_SUCCESS) + fatal("Could not set up display: got cairo surface with status %s", + cairo_status_to_string(cairo_surface_status(surface))); + cairo_surface_finish(surface); + cairo_surface_destroy(surface); + xcb_free_pixmap(globalconf.connection, pixmap); +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 diff --git a/draw.h b/draw.h index 1bbf1cc7a..c38fb6eed 100644 --- a/draw.h +++ b/draw.h @@ -75,5 +75,7 @@ xcb_visualtype_t *draw_default_visual(const xcb_screen_t *s); xcb_visualtype_t *draw_argb_visual(const xcb_screen_t *s); uint8_t draw_visual_depth(const xcb_screen_t *s, xcb_visualid_t vis); +void draw_test_cairo_xcb(void); + #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80