]> icculus.org git repositories - mikachu/openbox.git/blob - src/Util.hh
backing out all changes to make mouse button mapping's configurable
[mikachu/openbox.git] / 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
32 class Rect {
33 public:
34   inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
35   inline Rect(int __x, int __y, unsigned int __w, unsigned int __h)
36     : _x1(__x), _y1(__y), _x2(__w + __x - 1), _y2(__h + __y - 1) { }
37   inline explicit Rect(const XRectangle& xrect)
38     : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
39       _y2(xrect.height + xrect.y - 1) { }
40
41   inline int left(void) const { return _x1; }
42   inline int top(void) const { return _y1; }
43   inline int right(void) const { return _x2; }
44   inline int bottom(void) const { return _y2; }
45
46   inline int x(void) const { return _x1; }
47   inline int y(void) const { return _y1; }
48   void setX(int __x);
49   void setY(int __y);
50   void setPos(int __x, int __y);
51
52   inline unsigned int width(void) const { return _x2 - _x1 + 1; }
53   inline unsigned int height(void) const { return _y2 - _y1 + 1; }
54   void setWidth(unsigned int __w);
55   void setHeight(unsigned int __h);
56   void setSize(unsigned int __w, unsigned int __h);
57
58   void setRect(int __x, int __y, unsigned int __w, unsigned int __h);
59
60   void setCoords(int __l, int __t, int __r, int __b);
61
62   inline bool operator==(const Rect &a)
63   { return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; }
64   inline bool operator!=(const Rect &a) { return ! operator==(a); }
65
66   Rect operator|(const Rect &a) const;
67   Rect operator&(const Rect &a) const;
68   inline Rect &operator|=(const Rect &a) { *this = *this | a; return *this; }
69   inline Rect &operator&=(const Rect &a) { *this = *this & a; return *this; }
70
71   inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
72
73   bool intersects(const Rect &a) const;
74
75 private:
76   int _x1, _y1, _x2, _y2;
77 };
78
79 /* XXX: this needs autoconf help */
80 const unsigned int BSENTINEL = 65535;
81
82 std::string expandTilde(const std::string& s);
83
84 void bexec(const std::string& command, const std::string& displaystring);
85
86 #ifndef   HAVE_BASENAME
87 std::string basename(const std::string& path);
88 #endif
89
90 std::string textPropertyToString(Display *display, XTextProperty& text_prop);
91
92 struct timeval; // forward declare to avoid the header
93 timeval normalizeTimeval(const timeval &tm);
94
95 struct PointerAssassin {
96   template<typename T>
97   inline void operator()(const T ptr) const {
98     delete ptr;
99   }
100 };
101
102 std::string itostring(unsigned long i);
103 std::string itostring(long i);
104 inline std::string itostring(unsigned int i) {
105   return itostring((unsigned long) i);
106 }
107 inline std::string itostring(int i) {
108   return itostring((long) i);
109 }
110
111 #endif