1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef _BLACKBOX_UTIL_HH
3 #define _BLACKBOX_UTIL_HH
13 inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
14 inline Rect(int __x, int __y, unsigned int __w, unsigned int __h)
15 : _x1(__x), _y1(__y), _x2(__w + __x - 1), _y2(__h + __y - 1) { }
16 inline explicit Rect(const XRectangle& xrect)
17 : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
18 _y2(xrect.height + xrect.y - 1) { }
20 inline int left(void) const { return _x1; }
21 inline int top(void) const { return _y1; }
22 inline int right(void) const { return _x2; }
23 inline int bottom(void) const { return _y2; }
25 inline int x(void) const { return _x1; }
26 inline int y(void) const { return _y1; }
29 void setPos(int __x, int __y);
31 inline unsigned int width(void) const { return _x2 - _x1 + 1; }
32 inline unsigned int height(void) const { return _y2 - _y1 + 1; }
33 void setWidth(unsigned int __w);
34 void setHeight(unsigned int __h);
35 void setSize(unsigned int __w, unsigned int __h);
37 void setRect(int __x, int __y, unsigned int __w, unsigned int __h);
39 void setCoords(int __l, int __t, int __r, int __b);
41 inline bool operator==(const Rect &a)
42 { return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; }
43 inline bool operator!=(const Rect &a) { return ! operator==(a); }
45 Rect operator|(const Rect &a) const;
46 Rect operator&(const Rect &a) const;
47 inline Rect &operator|=(const Rect &a) { *this = *this | a; return *this; }
48 inline Rect &operator&=(const Rect &a) { *this = *this & a; return *this; }
50 inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
52 bool intersects(const Rect &a) const;
53 bool contains(int __x, int __y) const;
54 bool contains(const Rect &a) const;
57 int _x1, _y1, _x2, _y2;
60 typedef std::vector<Rect> RectList;
63 unsigned int top, bottom, left, right;
65 Strut(void): top(0), bottom(0), left(0), right(0) {}
68 /* XXX: this needs autoconf help */
69 const unsigned int BSENTINEL = 65535;
71 std::string expandTilde(const std::string& s);
73 void bexec(const std::string& command, const std::string& displaystring);
76 std::string basename(const std::string& path);
79 std::string textPropertyToString(Display *display, XTextProperty& text_prop);
81 struct timeval; // forward declare to avoid the header
82 timeval normalizeTimeval(const timeval &tm);
84 struct PointerAssassin {
86 inline void operator()(const T ptr) const {
91 std::string itostring(unsigned long i);
92 std::string itostring(long i);
93 inline std::string itostring(unsigned int i)
94 { return itostring((unsigned long) i); }
95 inline std::string itostring(int i)
96 { return itostring((long) i); }