X-Git-Url: https://git.dogcows.com/gitweb?a=blobdiff_plain;f=src%2FUtil.cc;h=9013544788da08a20014d22f75326a5093596784;hb=5b8ec886237aff9ede99feb66721f8ac7a44d2ed;hp=0300e52bb0ee279e66f3f0611bb3749ff49bc5c0;hpb=8794d357e67abddf9fda9db77b235e294d0ec590;p=chaz%2Fopenbox diff --git a/src/Util.cc b/src/Util.cc index 0300e52b..90135447 100644 --- a/src/Util.cc +++ b/src/Util.cc @@ -26,6 +26,8 @@ #endif // HAVE_CONFIG_H extern "C" { +#include + #ifdef HAVE_STRING_H #include #endif @@ -48,9 +50,9 @@ extern "C" { #if defined(HAVE_PROCESS_H) && defined(__EMX__) # include #endif // HAVE_PROCESS_H __EMX__ -} -#include +#include +} #include @@ -59,53 +61,53 @@ extern "C" { using std::string; -void Rect::setX(int __x) { - _x2 += __x - _x1; - _x1 = __x; +void Rect::setX(int x) { + _x2 += x - _x1; + _x1 = x; } -void Rect::setY(int __y) +void Rect::setY(int y) { - _y2 += __y - _y1; - _y1 = __y; + _y2 += y - _y1; + _y1 = y; } -void Rect::setPos(int __x, int __y) { - _x2 += __x - _x1; - _x1 = __x; - _y2 += __y - _y1; - _y1 = __y; +void Rect::setPos(int x, int y) { + _x2 += x - _x1; + _x1 = x; + _y2 += y - _y1; + _y1 = y; } -void Rect::setWidth(unsigned int __w) { - _x2 = __w + _x1 - 1; +void Rect::setWidth(unsigned int w) { + _x2 = w + _x1 - 1; } -void Rect::setHeight(unsigned int __h) { - _y2 = __h + _y1 - 1; +void Rect::setHeight(unsigned int h) { + _y2 = h + _y1 - 1; } -void Rect::setSize(unsigned int __w, unsigned int __h) { - _x2 = __w + _x1 - 1; - _y2 = __h + _y1 - 1; +void Rect::setSize(unsigned int w, unsigned int h) { + _x2 = w + _x1 - 1; + _y2 = h + _y1 - 1; } -void Rect::setRect(int __x, int __y, unsigned int __w, unsigned int __h) { - *this = Rect(__x, __y, __w, __h); +void Rect::setRect(int x, int y, unsigned int w, unsigned int h) { + *this = Rect(x, y, w, h); } -void Rect::setCoords(int __l, int __t, int __r, int __b) { - _x1 = __l; - _y1 = __t; - _x2 = __r; - _y2 = __b; +void Rect::setCoords(int l, int t, int r, int b) { + _x1 = l; + _y1 = t; + _x2 = r; + _y2 = b; } @@ -139,6 +141,18 @@ bool Rect::intersects(const Rect &a) const { } +bool Rect::contains(int x, int y) const { + return x >= _x1 && x <= _x2 && + y >= _y1 && y <= _y2; +} + + +bool Rect::contains(const Rect& a) const { + return a._x1 >= _x1 && a._x2 <= _x2 && + a._y1 >= _y1 && a._y2 <= _y2; +} + + string expandTilde(const string& s) { if (s[0] != '~') return s; @@ -155,13 +169,11 @@ void bexec(const string& command, const string& displaystring) { setsid(); int ret = putenv(const_cast(displaystring.c_str())); assert(ret != -1); - string cmd = "exec "; - cmd += command; - execl("/bin/sh", "/bin/sh", "-c", cmd.c_str(), NULL); - exit(0); + ret = execl("/bin/sh", "/bin/sh", "-c", command.c_str(), NULL); + exit(ret); } #else // __EMX__ - spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", command, NULL); + spawnlp(P_NOWAIT, "cmd.exe", "cmd.exe", "/c", command.c_str(), NULL); #endif // !__EMX__ } @@ -180,8 +192,9 @@ string textPropertyToString(Display *display, XTextProperty& text_prop) { string ret; if (text_prop.value && text_prop.nitems > 0) { - ret = (char *) text_prop.value; - if (text_prop.encoding != XA_STRING) { + if (text_prop.encoding == XA_STRING) { + ret = (char *) text_prop.value; + } else { text_prop.nitems = strlen((char *) text_prop.value); char **list; @@ -220,3 +233,22 @@ timeval normalizeTimeval(const timeval &tm) { return ret; } + + +string itostring(unsigned long i) { + if (i == 0) + return string("0"); + + string tmp; + for (; i > 0; i /= 10) + tmp.insert(tmp.begin(), "0123456789"[i%10]); + return tmp; +} + + +string itostring(long i) { + std::string tmp = itostring( (unsigned long) std::abs(i)); + if (i < 0) + tmp.insert(tmp.begin(), '-'); + return tmp; +}