From 4f0dbdabb0460c6eb9c43e88367dc7539613606d Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Sun, 8 Jun 2008 10:08:44 +0200 Subject: [PATCH] [xutil] Move cursor creation to xutil Signed-off-by: Julien Danjou --- awesome.c | 42 +++++++++--------------------------------- common/xutil.c | 28 ++++++++++++++++++++++++++-- common/xutil.h | 1 + 3 files changed, 36 insertions(+), 35 deletions(-) diff --git a/awesome.c b/awesome.c index 2648a9624..050d172a9 100644 --- a/awesome.c +++ b/awesome.c @@ -164,30 +164,6 @@ scan() p_delete(&root_wins); } -/** Equivalent to 'XCreateFontCursor()', error are handled by the - * default current error handler - * \param cursor_font type of cursor to use - * \return allocated cursor font - */ -static xcb_cursor_t -create_font_cursor(unsigned int cursor_font) -{ - xcb_font_t font; - xcb_cursor_t cursor; - - /* Get the font for the cursor*/ - font = xcb_generate_id(globalconf.connection); - xcb_open_font(globalconf.connection, font, strlen("cursor"), "cursor"); - - cursor = xcb_generate_id(globalconf.connection); - xcb_create_glyph_cursor (globalconf.connection, cursor, font, font, - cursor_font, cursor_font + 1, - 0, 0, 0, - 65535, 65535, 65535); - - return cursor; -} - /** Startup Error handler to check if another window manager * is already running. * \param data Additional optional parameters data @@ -387,15 +363,15 @@ main(int argc, char **argv) eprint("failed to load/parse configuration file %s", confpath); /* init cursors */ - globalconf.cursor[CurNormal] = create_font_cursor(CURSOR_LEFT_PTR); - globalconf.cursor[CurResize] = create_font_cursor(CURSOR_SIZING); - globalconf.cursor[CurResizeH] = create_font_cursor(CURSOR_DOUBLE_ARROW_HORIZ); - globalconf.cursor[CurResizeV] = create_font_cursor(CURSOR_DOUBLE_ARROW_VERT); - globalconf.cursor[CurMove] = create_font_cursor(CURSOR_FLEUR); - globalconf.cursor[CurTopRight] = create_font_cursor(CURSOR_TOP_RIGHT_CORNER); - globalconf.cursor[CurTopLeft] = create_font_cursor(CURSOR_TOP_LEFT_CORNER); - globalconf.cursor[CurBotRight] = create_font_cursor(CURSOR_BOTTOM_RIGHT_CORNER); - globalconf.cursor[CurBotLeft] = create_font_cursor(CURSOR_BOTTOM_LEFT_CORNER); + globalconf.cursor[CurNormal] = xutil_cursor_new(globalconf.connection, CURSOR_LEFT_PTR); + globalconf.cursor[CurResize] = xutil_cursor_new(globalconf.connection, CURSOR_SIZING); + globalconf.cursor[CurResizeH] = xutil_cursor_new(globalconf.connection, CURSOR_DOUBLE_ARROW_HORIZ); + globalconf.cursor[CurResizeV] = xutil_cursor_new(globalconf.connection, CURSOR_DOUBLE_ARROW_VERT); + globalconf.cursor[CurMove] = xutil_cursor_new(globalconf.connection, CURSOR_FLEUR); + globalconf.cursor[CurTopRight] = xutil_cursor_new(globalconf.connection, CURSOR_TOP_RIGHT_CORNER); + globalconf.cursor[CurTopLeft] = xutil_cursor_new(globalconf.connection, CURSOR_TOP_LEFT_CORNER); + globalconf.cursor[CurBotRight] = xutil_cursor_new(globalconf.connection, CURSOR_BOTTOM_RIGHT_CORNER); + globalconf.cursor[CurBotLeft] = xutil_cursor_new(globalconf.connection, CURSOR_BOTTOM_LEFT_CORNER); /* select for events */ const uint32_t change_win_vals[] = diff --git a/common/xutil.c b/common/xutil.c index 42aea0d1d..8215347b9 100644 --- a/common/xutil.c +++ b/common/xutil.c @@ -209,12 +209,12 @@ xutil_intern_atom_reply(xcb_connection_t *c, xutil_atom_cache_t **atoms, xutil_atom_cache_t *atom_cache, *atom_next; /* If the atom is present in the cache, just returns the - * atom... */ + * atom... */ if(atom_req.cache_hit) return atom_req.cache->atom; /* Get the reply from InternAtom request */ - if((atom_rep = xcb_intern_atom_reply(c, atom_req.cookie, NULL)) == NULL) + if(!(atom_rep = xcb_intern_atom_reply(c, atom_req.cookie, NULL))) return 0; /* Create a new atom cache entry */ @@ -583,4 +583,28 @@ xutil_button_fromint(int button) return 0; } +/** Equivalent to 'XCreateFontCursor()', error are handled by the + * default current error handler. + * \param cursor_font Type of cursor to use. + * \return Allocated cursor font. + */ +xcb_cursor_t +xutil_cursor_new(xcb_connection_t *conn, unsigned int cursor_font) +{ + xcb_font_t font; + xcb_cursor_t cursor; + + /* Get the font for the cursor*/ + font = xcb_generate_id(conn); + xcb_open_font(conn, font, a_strlen("cursor"), "cursor"); + + cursor = xcb_generate_id(conn); + xcb_create_glyph_cursor(conn, cursor, font, font, + cursor_font, cursor_font + 1, + 0, 0, 0, + 65535, 65535, 65535); + + return cursor; +} + // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80 diff --git a/common/xutil.h b/common/xutil.h index d1e863067..fd6ca35ac 100644 --- a/common/xutil.h +++ b/common/xutil.h @@ -158,6 +158,7 @@ xutil_error_t *xutil_get_error(const xcb_generic_error_t *); void xutil_delete_error(xutil_error_t *); xcb_keysym_t xutil_keymask_fromstr(const char *); unsigned int xutil_button_fromint(int); +xcb_cursor_t xutil_cursor_new(xcb_connection_t *, unsigned int); #endif // vim: filetype=c:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80