all repos — fluxbox @ ab26593cddf2fc0004da8048e28216792ed433ef

custom fork of the fluxbox windowmanager

added static validColorString function, returns true if the color string is in valid color format
fluxgen fluxgen
commit

ab26593cddf2fc0004da8048e28216792ed433ef

parent

e85b2f3f5b091bac8101bc90ba04e575b845758e

2 files changed, 17 insertions(+), 5 deletions(-)

jump to
M src/FbTk/Color.ccsrc/FbTk/Color.cc

@@ -31,11 +31,9 @@ #include <iostream>

using namespace std; namespace { -unsigned char maxValue(unsigned short colval) { - if (colval == 65535) - return 0xFF; - return static_cast<unsigned char>(colval/0xFF); +inline unsigned char maxValue(unsigned short colval) { + return colval == 65535 ? 0xFF : static_cast<unsigned char>(colval/0xFF); } };

@@ -106,6 +104,17 @@

return true; } +bool Color::validColorString(const char *color_string, int screen) { + XColor color; + Display *disp = App::instance()->display(); + Colormap colm = DefaultColormap(disp, screen); + // trim white space + string color_string_tmp = color_string; + StringUtil::removeFirstWhitespace(color_string_tmp); + StringUtil::removeTrailingWhitespace(color_string_tmp); + + return XParseColor(disp, colm, color_string_tmp.c_str(), &color) != 0; +} Color &Color::operator = (const Color &col_copy) { // check for aliasing
M src/FbTk/Color.hhsrc/FbTk/Color.hh

@@ -54,7 +54,10 @@ inline unsigned short red() const { return m_red; }

inline unsigned short green() const { return m_green; } inline unsigned short blue() const { return m_blue; } inline unsigned long pixel() const { return m_pixel; } - + + /// @return true if the color name in color_string is resolved, else false + static bool validColorString(const char *color_string, int screen); + private: void free(); void copy(const Color &col);