]> icculus.org git repositories - dana/openbox.git/blob - src/util.hh
add gettext
[dana/openbox.git] / src / util.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 #ifndef _BLACKBOX_UTIL_HH
3 #define _BLACKBOX_UTIL_HH
4
5 #include <X11/Xlib.h>
6 #include <X11/Xutil.h>
7
8 #include <string>
9 #include <vector>
10
11 class Rect {
12 public:
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) { }
19
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; }
24
25   inline int x(void) const { return _x1; }
26   inline int y(void) const { return _y1; }
27   void setX(int __x);
28   void setY(int __y);
29   void setPos(int __x, int __y);
30
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);
36
37   void setRect(int __x, int __y, unsigned int __w, unsigned int __h);
38
39   void setCoords(int __l, int __t, int __r, int __b);
40
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); }
44
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; }
49
50   inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
51
52   bool intersects(const Rect &a) const;
53   bool contains(int __x, int __y) const;
54   bool contains(const Rect &a) const;
55
56 private:
57   int _x1, _y1, _x2, _y2;
58 };
59
60 typedef std::vector<Rect> RectList;
61
62 struct Strut {
63   unsigned int top, bottom, left, right;
64
65   Strut(void): top(0), bottom(0), left(0), right(0) {}
66 };
67
68 /* XXX: this needs autoconf help */
69 const unsigned int BSENTINEL = 65535;
70
71 std::string expandTilde(const std::string& s);
72
73 void bexec(const std::string& command, const std::string& displaystring);
74
75 #ifndef   HAVE_BASENAME
76 std::string basename(const std::string& path);
77 #endif
78
79 std::string textPropertyToString(Display *display, XTextProperty& text_prop);
80
81 struct timeval; // forward declare to avoid the header
82 timeval normalizeTimeval(const timeval &tm);
83
84 struct PointerAssassin {
85   template<typename T>
86   inline void operator()(const T ptr) const {
87     delete ptr;
88   }
89 };
90
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); }
97   
98 #endif