]>
Dogcows Code - chaz/openbox/blob - 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)
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:
13 // The above copyright notice and this permission notice shall be included in
14 // all copies or substantial portions of the Software.
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.
24 #ifndef _BLACKBOX_UTIL_HH
25 #define _BLACKBOX_UTIL_HH
28 #include <X11/Xutil.h>
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) { }
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
; }
47 inline int x(void) const { return _x1
; }
48 inline int y(void) const { return _y1
; }
51 void setPos(int __x
, int __y
);
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
);
59 void setRect(int __x
, int __y
, unsigned int __w
, unsigned int __h
);
61 void setCoords(int __l
, int __t
, int __r
, int __b
);
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
); }
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; }
72 inline bool valid(void) const { return _x2
> _x1
&& _y2
> _y1
; }
74 bool intersects(const Rect
&a
) const;
75 bool contains(int __x
, int __y
) const;
76 bool contains(const Rect
&a
) const;
79 int _x1
, _y1
, _x2
, _y2
;
82 typedef std::vector
<Rect
> RectList
;
85 unsigned int top
, bottom
, left
, right
;
87 Strut(void): top(0), bottom(0), left(0), right(0) {}
90 /* XXX: this needs autoconf help */
91 const unsigned int BSENTINEL
= 65535;
93 std::string
expandTilde(const std::string
& s
);
95 void bexec(const std::string
& command
, const std::string
& displaystring
);
98 std::string
basename(const std::string
& path
);
101 std::string
textPropertyToString(Display
*display
, XTextProperty
& text_prop
);
103 struct timeval
; // forward declare to avoid the header
104 timeval
normalizeTimeval(const timeval
&tm
);
106 struct PointerAssassin
{
108 inline void operator()(const T ptr
) const {
113 std::string
itostring(unsigned long i
);
114 std::string
itostring(long i
);
115 inline std::string
itostring(unsigned int i
)
116 { return itostring((unsigned long) i
); }
117 inline std::string
itostring(int i
)
118 { return itostring((long) i
); }
This page took 0.036761 seconds and 4 git commands to generate.