Move some helper functions to draw.h

Signed-off-by: Uli Schlachter <psychon@znc.in>
This commit is contained in:
Uli Schlachter 2012-07-29 15:21:02 +02:00
parent 05a8ef2ed9
commit 9fef3dd07c
3 changed files with 49 additions and 48 deletions

View File

@ -152,51 +152,6 @@ scan(xcb_query_tree_cookie_t tree_c)
p_delete(&tree_r); p_delete(&tree_r);
} }
static xcb_visualtype_t *
a_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;
}
static xcb_visualtype_t *
a_argb_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))
if(depth_iter.data->depth == 32)
for(xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
visual_iter.rem; xcb_visualtype_next (&visual_iter))
return visual_iter.data;
return NULL;
}
static uint8_t
a_visual_depth(xcb_screen_t *s, xcb_visualid_t vis)
{
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(vis == visual_iter.data->visual_id)
return depth_iter.data->depth;
fatal("Could not find a visual's depth");
}
static void static void
a_refresh_cb(EV_P_ ev_prepare *w, int revents) a_refresh_cb(EV_P_ ev_prepare *w, int revents)
{ {
@ -419,12 +374,12 @@ main(int argc, char **argv)
fatal("cannot open display"); fatal("cannot open display");
globalconf.screen = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen); globalconf.screen = xcb_aux_get_screen(globalconf.connection, globalconf.default_screen);
globalconf.default_visual = a_default_visual(globalconf.screen); globalconf.default_visual = draw_default_visual(globalconf.screen);
if(!no_argb) if(!no_argb)
globalconf.visual = a_argb_visual(globalconf.screen); globalconf.visual = draw_argb_visual(globalconf.screen);
if(!globalconf.visual) if(!globalconf.visual)
globalconf.visual = globalconf.default_visual; globalconf.visual = globalconf.default_visual;
globalconf.default_depth = a_visual_depth(globalconf.screen, globalconf.visual->visual_id); globalconf.default_depth = draw_visual_depth(globalconf.screen, globalconf.visual->visual_id);
globalconf.default_cmap = globalconf.screen->default_colormap; globalconf.default_cmap = globalconf.screen->default_colormap;
if(globalconf.default_depth != globalconf.screen->root_depth) if(globalconf.default_depth != globalconf.screen->root_depth)
{ {

42
draw.c
View File

@ -222,4 +222,46 @@ draw_load_image(lua_State *L, const char *path)
return ret; return ret;
} }
xcb_visualtype_t *draw_default_visual(const 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;
}
xcb_visualtype_t *draw_argb_visual(const 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))
if(depth_iter.data->depth == 32)
for(xcb_visualtype_iterator_t visual_iter = xcb_depth_visuals_iterator(depth_iter.data);
visual_iter.rem; xcb_visualtype_next (&visual_iter))
return visual_iter.data;
return NULL;
}
uint8_t draw_visual_depth(const xcb_screen_t *s, xcb_visualid_t vis)
{
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(vis == visual_iter.data->visual_id)
return depth_iter.data->depth;
fatal("Could not find a visual's depth");
}
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80

4
draw.h
View File

@ -69,5 +69,9 @@ cairo_surface_t *draw_surface_from_data(int width, int height, uint32_t *data);
cairo_surface_t *draw_dup_image_surface(cairo_surface_t *surface); cairo_surface_t *draw_dup_image_surface(cairo_surface_t *surface);
cairo_surface_t *draw_load_image(lua_State *L, const char *path); cairo_surface_t *draw_load_image(lua_State *L, const char *path);
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);
#endif #endif
// vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80