From 9fef3dd07c01a1fd78c3c1c8286ce54049958dda Mon Sep 17 00:00:00 2001 From: Uli Schlachter Date: Sun, 29 Jul 2012 15:21:02 +0200 Subject: [PATCH] Move some helper functions to draw.h Signed-off-by: Uli Schlachter --- awesome.c | 51 +++------------------------------------------------ draw.c | 42 ++++++++++++++++++++++++++++++++++++++++++ draw.h | 4 ++++ 3 files changed, 49 insertions(+), 48 deletions(-) diff --git a/awesome.c b/awesome.c index d0f498d9..a04f27d3 100644 --- a/awesome.c +++ b/awesome.c @@ -152,51 +152,6 @@ scan(xcb_query_tree_cookie_t tree_c) 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 a_refresh_cb(EV_P_ ev_prepare *w, int revents) { @@ -419,12 +374,12 @@ main(int argc, char **argv) fatal("cannot open display"); 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) - globalconf.visual = a_argb_visual(globalconf.screen); + globalconf.visual = draw_argb_visual(globalconf.screen); if(!globalconf.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; if(globalconf.default_depth != globalconf.screen->root_depth) { diff --git a/draw.c b/draw.c index 7f0bfa1d..06ddf505 100644 --- a/draw.c +++ b/draw.c @@ -222,4 +222,46 @@ draw_load_image(lua_State *L, const char *path) 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 diff --git a/draw.h b/draw.h index bc772035..e2766c1d 100644 --- a/draw.h +++ b/draw.h @@ -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_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 // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80