screen: store default visual

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2009-07-10 16:26:49 +02:00
parent 9cd29814f0
commit 16376a9f7c
4 changed files with 33 additions and 39 deletions

48
draw.c
View File

@ -1,7 +1,7 @@
/* /*
* draw.c - draw functions * draw.c - draw functions
* *
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info> * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
* *
* This program is free software; you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -30,6 +30,7 @@
#include <math.h> #include <math.h>
#include "structs.h" #include "structs.h"
#include "screen.h"
#include "common/tokenize.h" #include "common/tokenize.h"
#include "common/xutil.h" #include "common/xutil.h"
@ -88,24 +89,6 @@ draw_iso2utf8(const char *iso, size_t len, char **dest, ssize_t *dlen)
return true; 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. /** Create a new Pango font.
* \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]). * \param fontname Pango fontname (e.g. [FAMILY-LIST] [STYLE-OPTIONS] [SIZE]).
* \return A new font. * \return A new font.
@ -119,16 +102,11 @@ draw_font_new(const char *fontname)
PangoLayout *layout; PangoLayout *layout;
font_t *font = p_new(font_t, 1); 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 /* Create a dummy cairo surface, cairo context and pango layout in
* order to get font informations */ * order to get font informations */
surface = cairo_xcb_surface_create(globalconf.connection, surface = cairo_xcb_surface_create(globalconf.connection,
globalconf.default_screen, globalconf.default_screen,
visual, globalconf.screens.tab[0].visual,
s->width_in_pixels, s->width_in_pixels,
s->height_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, int width, int height, xcb_pixmap_t px,
const xcolor_t *fg, const xcolor_t *bg) 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->phys_screen = phys_screen;
d->width = width; d->width = width;
d->height = height; d->height = height;
d->visual = draw_screen_default_visual(s);
d->pixmap = px; 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->cr = cairo_create(d->surface);
d->layout = pango_cairo_create_layout(d->cr); d->layout = pango_cairo_create_layout(d->cr);
d->fg = *fg; d->fg = *fg;
@ -627,9 +604,11 @@ draw_rotate(draw_context_t *ctx,
cairo_t *cr; cairo_t *cr;
surface = cairo_xcb_surface_create(globalconf.connection, dest, 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, 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); cr = cairo_create (surface);
cairo_translate(cr, tx, ty); cairo_translate(cr, tx, ty);
@ -660,14 +639,9 @@ draw_text_extents(draw_text_context_t *data)
if(data->len <= 0) if(data->len <= 0)
return geom; return geom;
xcb_visualtype_t *visual = draw_screen_default_visual(s);
if(!visual)
fatal("no visual found");
surface = cairo_xcb_surface_create(globalconf.connection, surface = cairo_xcb_surface_create(globalconf.connection,
globalconf.default_screen, globalconf.default_screen,
visual, globalconf.screens.tab[0].visual,
s->width_in_pixels, s->width_in_pixels,
s->height_in_pixels); s->height_in_pixels);

1
draw.h
View File

@ -91,7 +91,6 @@ typedef struct
typedef struct typedef struct
{ {
xcb_pixmap_t pixmap; xcb_pixmap_t pixmap;
xcb_visualtype_t *visual;
uint16_t width; uint16_t width;
uint16_t height; uint16_t height;
int phys_screen; int phys_screen;

View File

@ -1,7 +1,7 @@
/* /*
* screen.c - screen management * screen.c - screen management
* *
* Copyright © 2007-2008 Julien Danjou <julien@danjou.info> * Copyright © 2007-2009 Julien Danjou <julien@danjou.info>
* *
* This program is free software; you can redistribute it and/or modify * 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 * 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; 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. /** Get screens informations and fill global configuration.
*/ */
void void
@ -99,6 +114,9 @@ screen_scan(void)
} }
p_delete(&xsq); 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 else
/* One screen only / Zaphod mode */ /* One screen only / Zaphod mode */
@ -113,6 +131,7 @@ screen_scan(void)
s.geometry.y = 0; s.geometry.y = 0;
s.geometry.width = xcb_screen->width_in_pixels; s.geometry.width = xcb_screen->width_in_pixels;
s.geometry.height = xcb_screen->height_in_pixels; s.geometry.height = xcb_screen->height_in_pixels;
s.visual = screen_default_visual(xcb_screen);
screen_array_append(&globalconf.screens, s); screen_array_append(&globalconf.screens, s);
} }

View File

@ -45,6 +45,8 @@ struct a_screen
client_t *client_focus; client_t *client_focus;
/** The monitor of startup notifications */ /** The monitor of startup notifications */
SnMonitorContext *snmonitor; SnMonitorContext *snmonitor;
/** The default visual, used to draw */
xcb_visualtype_t *visual;
}; };
ARRAY_FUNCS(screen_t, screen, DO_NOTHING) ARRAY_FUNCS(screen_t, screen, DO_NOTHING)