diff --git a/draw.c b/draw.c index 686bcfeb6..e9486d4ba 100644 --- a/draw.c +++ b/draw.c @@ -1,7 +1,7 @@ /* * draw.c - draw functions * - * Copyright © 2007-2008 Julien Danjou + * Copyright © 2007-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,6 +30,7 @@ #include #include "structs.h" +#include "screen.h" #include "common/tokenize.h" #include "common/xutil.h" @@ -88,24 +89,6 @@ draw_iso2utf8(const char *iso, size_t len, char **dest, ssize_t *dlen) return true; } -static xcb_visualtype_t * -draw_screen_default_visual(xcb_screen_t *s) -{ - if(!s) - return NULL; - - xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s); - - if(depth_iter.data) - for(; depth_iter.rem; xcb_depth_next (&depth_iter)) - for(xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator (depth_iter.data); - visual_iter.rem; xcb_visualtype_next (&visual_iter)) - if(s->root_visual == visual_iter.data->visual_id) - return visual_iter.data; - - return NULL; -} - /** Create a new Pango font. * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]). * \return A new font. @@ -119,16 +102,11 @@ draw_font_new(const char *fontname) PangoLayout *layout; font_t *font = p_new(font_t, 1); - xcb_visualtype_t *visual = draw_screen_default_visual(s); - - if(!visual) - fatal("cannot get visual"); - /* Create a dummy cairo surface, cairo context and pango layout in * order to get font informations */ surface = cairo_xcb_surface_create(globalconf.connection, globalconf.default_screen, - visual, + globalconf.screens.tab[0].visual, s->width_in_pixels, s->height_in_pixels); @@ -203,14 +181,13 @@ draw_context_init(draw_context_t *d, int phys_screen, int width, int height, xcb_pixmap_t px, const xcolor_t *fg, const xcolor_t *bg) { - xcb_screen_t *s = xutil_screen_get(globalconf.connection, phys_screen); - d->phys_screen = phys_screen; d->width = width; d->height = height; - d->visual = draw_screen_default_visual(s); d->pixmap = px; - d->surface = cairo_xcb_surface_create(globalconf.connection, px, d->visual, width, height); + d->surface = cairo_xcb_surface_create(globalconf.connection, + px, globalconf.screens.tab[phys_screen].visual, + width, height); d->cr = cairo_create(d->surface); d->layout = pango_cairo_create_layout(d->cr); d->fg = *fg; @@ -627,9 +604,11 @@ draw_rotate(draw_context_t *ctx, cairo_t *cr; surface = cairo_xcb_surface_create(globalconf.connection, dest, - ctx->visual, dest_w, dest_h); + globalconf.screens.tab[ctx->phys_screen].visual, + dest_w, dest_h); source = cairo_xcb_surface_create(globalconf.connection, src, - ctx->visual, src_w, src_h); + globalconf.screens.tab[ctx->phys_screen].visual, + src_w, src_h); cr = cairo_create (surface); cairo_translate(cr, tx, ty); @@ -660,14 +639,9 @@ draw_text_extents(draw_text_context_t *data) if(data->len <= 0) return geom; - xcb_visualtype_t *visual = draw_screen_default_visual(s); - - if(!visual) - fatal("no visual found"); - surface = cairo_xcb_surface_create(globalconf.connection, globalconf.default_screen, - visual, + globalconf.screens.tab[0].visual, s->width_in_pixels, s->height_in_pixels); diff --git a/draw.h b/draw.h index 5f7c84bb8..48671cd4f 100644 --- a/draw.h +++ b/draw.h @@ -91,7 +91,6 @@ typedef struct typedef struct { xcb_pixmap_t pixmap; - xcb_visualtype_t *visual; uint16_t width; uint16_t height; int phys_screen; diff --git a/screen.c b/screen.c index fa62c8a73..4cdc33b3b 100644 --- a/screen.c +++ b/screen.c @@ -1,7 +1,7 @@ /* * screen.c - screen management * - * Copyright © 2007-2008 Julien Danjou + * Copyright © 2007-2009 Julien Danjou * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -45,6 +45,21 @@ screen_xsitoarea(xcb_xinerama_screen_info_t si) return a; } +static xcb_visualtype_t * +screen_default_visual(xcb_screen_t *s) +{ + xcb_depth_iterator_t depth_iter = xcb_screen_allowed_depths_iterator(s); + + if(depth_iter.data) + for(; depth_iter.rem; xcb_depth_next (&depth_iter)) + for(xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data); + visual_iter.rem; xcb_visualtype_next (&visual_iter)) + if(s->root_visual == visual_iter.data->visual_id) + return visual_iter.data; + + return NULL; +} + /** Get screens informations and fill global configuration. */ void @@ -99,6 +114,9 @@ screen_scan(void) } p_delete(&xsq); + + xcb_screen_t *s = xutil_screen_get(globalconf.connection, globalconf.default_screen); + globalconf.screens.tab[0].visual = screen_default_visual(s); } else /* One screen only / Zaphod mode */ @@ -113,6 +131,7 @@ screen_scan(void) s.geometry.y = 0; s.geometry.width = xcb_screen->width_in_pixels; s.geometry.height = xcb_screen->height_in_pixels; + s.visual = screen_default_visual(xcb_screen); screen_array_append(&globalconf.screens, s); } diff --git a/screen.h b/screen.h index 8d173ea83..0308f69c0 100644 --- a/screen.h +++ b/screen.h @@ -45,6 +45,8 @@ struct a_screen client_t *client_focus; /** The monitor of startup notifications */ SnMonitorContext *snmonitor; + /** The default visual, used to draw */ + xcb_visualtype_t *visual; }; ARRAY_FUNCS(screen_t, screen, DO_NOTHING)