]> Dogcows Code - chaz/openbox/blob - src/Util.hh
d70eabc8e7807687116ef94f8055a63129092735
[chaz/openbox] / src / Util.hh
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2 // Util.cc for Blackbox - an X11 Window manager
3 // Copyright (c) 2002 Sean 'Shaleh' Perry <shaleh@debian.org>
4 // Copyright (c) 1997 - 2000 Brad Hughes (bhughes@tcac.net)
5 //
6 // Permission is hereby granted, free of charge, to any person obtaining a
7 // copy of this software and associated documentation files (the "Software"),
8 // to deal in the Software without restriction, including without limitation
9 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 // and/or sell copies of the Software, and to permit persons to whom the
11 // Software is furnished to do so, subject to the following conditions:
12 //
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
15 //
16 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
22 // DEALINGS IN THE SOFTWARE.
23
24 #ifndef _BLACKBOX_UTIL_HH
25 #define _BLACKBOX_UTIL_HH
26
27 #include <X11/Xlib.h>
28 #include <X11/Xutil.h>
29
30 #include <string>
31 #include <list>
32
33 class Rect {
34 public:
35 inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
36 inline Rect(int __x, int __y, unsigned int __w, unsigned int __h)
37 : _x1(__x), _y1(__y), _x2(__w + __x - 1), _y2(__h + __y - 1) { }
38 inline explicit Rect(const XRectangle& xrect)
39 : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
40 _y2(xrect.height + xrect.y - 1) { }
41
42 inline int left(void) const { return _x1; }
43 inline int top(void) const { return _y1; }
44 inline int right(void) const { return _x2; }
45 inline int bottom(void) const { return _y2; }
46
47 inline int x(void) const { return _x1; }
48 inline int y(void) const { return _y1; }
49 void setX(int __x);
50 void setY(int __y);
51 void setPos(int __x, int __y);
52
53 inline unsigned int width(void) const { return _x2 - _x1 + 1; }
54 inline unsigned int height(void) const { return _y2 - _y1 + 1; }
55 void setWidth(unsigned int __w);
56 void setHeight(unsigned int __h);
57 void setSize(unsigned int __w, unsigned int __h);
58
59 void setRect(int __x, int __y, unsigned int __w, unsigned int __h);
60
61 void setCoords(int __l, int __t, int __r, int __b);
62
63 inline bool operator==(const Rect &a)
64 { return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; }
65 inline bool operator!=(const Rect &a) { return ! operator==(a); }
66
67 Rect operator|(const Rect &a) const;
68 Rect operator&(const Rect &a) const;
69 inline Rect &operator|=(const Rect &a) { *this = *this | a; return *this; }
70 inline Rect &operator&=(const Rect &a) { *this = *this & a; return *this; }
71
72 inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
73
74 bool intersects(const Rect &a) const;
75
76 private:
77 int _x1, _y1, _x2, _y2;
78 };
79
80 typedef std::list<Rect> RectList;
81
82 struct Strut {
83 unsigned int top, bottom, left, right;
84
85 Strut(void): top(0), bottom(0), left(0), right(0) {}
86 };
87
88 /* XXX: this needs autoconf help */
89 const unsigned int BSENTINEL = 65535;
90
91 std::string expandTilde(const std::string& s);
92
93 void bexec(const std::string& command, const std::string& displaystring);
94
95 #ifndef HAVE_BASENAME
96 std::string basename(const std::string& path);
97 #endif
98
99 std::string textPropertyToString(Display *display, XTextProperty& text_prop);
100
101 struct timeval; // forward declare to avoid the header
102 timeval normalizeTimeval(const timeval &tm);
103
104 struct PointerAssassin {
105 template<typename T>
106 inline void operator()(const T ptr) const {
107 delete ptr;
108 }
109 };
110
111 std::string itostring(unsigned long i);
112 std::string itostring(long i);
113 inline std::string itostring(unsigned int i)
114 { return itostring((unsigned long) i); }
115 inline std::string itostring(int i)
116 { return itostring((long) i); }
117
118 #endif
This page took 0.037897 seconds and 4 git commands to generate.