From: Phil Sutter Date: Sun, 22 Nov 2009 13:55:22 +0000 (+0100) Subject: move get_x11_color() to colours.c X-Git-Url: http://vcs.maemo.org/git/?a=commitdiff_plain;h=346b4cfbc1ab7b9ee519634b50282946b2e95fd2;p=monky move get_x11_color() to colours.c --- diff --git a/src/colours.c b/src/colours.c index b50337d..61810c9 100644 --- a/src/colours.c +++ b/src/colours.c @@ -163,3 +163,28 @@ unsigned long *do_gradient(int width, unsigned long first_colour, unsigned long return colours; } +long get_x11_color(const char *name) +{ + XColor color; + + color.pixel = 0; + if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) { + /* lets check if it's a hex colour with the # missing in front + * if yes, then do something about it */ + char newname[DEFAULT_TEXT_BUFFER_SIZE]; + + newname[0] = '#'; + strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1); + /* now lets try again */ + if (!XParseColor(display, DefaultColormap(display, screen), &newname[0], + &color)) { + NORM_ERR("can't parse X color '%s'", name); + return 0xFF00FF; + } + } + if (!XAllocColor(display, DefaultColormap(display, screen), &color)) { + NORM_ERR("can't allocate X color '%s'", name); + } + + return (long) color.pixel; +} diff --git a/src/colours.h b/src/colours.h index f73e17d..203a888 100644 --- a/src/colours.h +++ b/src/colours.h @@ -32,4 +32,6 @@ unsigned int adjust_colours(unsigned int); unsigned long *do_gradient(int, unsigned long, unsigned long); +long get_x11_color(const char *); + #endif /* _COLOURS_H */ diff --git a/src/x11.c b/src/x11.c index 80c02b3..36cc4e8 100644 --- a/src/x11.c +++ b/src/x11.c @@ -524,32 +524,6 @@ static Window find_subwindow(Window win, int w, int h) return win; } -long get_x11_color(const char *name) -{ - XColor color; - - color.pixel = 0; - if (!XParseColor(display, DefaultColormap(display, screen), name, &color)) { - /* lets check if it's a hex colour with the # missing in front - * if yes, then do something about it */ - char newname[DEFAULT_TEXT_BUFFER_SIZE]; - - newname[0] = '#'; - strncpy(&newname[1], name, DEFAULT_TEXT_BUFFER_SIZE - 1); - /* now lets try again */ - if (!XParseColor(display, DefaultColormap(display, screen), &newname[0], - &color)) { - NORM_ERR("can't parse X color '%s'", name); - return 0xFF00FF; - } - } - if (!XAllocColor(display, DefaultColormap(display, screen), &color)) { - NORM_ERR("can't allocate X color '%s'", name); - } - - return (long) color.pixel; -} - void create_gc(void) { XGCValues values; diff --git a/src/x11.h b/src/x11.h index e339f0c..a4b2a2a 100644 --- a/src/x11.h +++ b/src/x11.h @@ -91,7 +91,6 @@ void init_window(int use_own_window, int width, int height, int set_trans, void destroy_window(void); void create_gc(void); void set_transparent_background(Window win); -long get_x11_color(const char *); void get_x11_desktop_info(Display *display, Atom atom); void set_struts(int);