]>
Dogcows Code - chaz/openbox/blob - src/util.cc
83b076771d0a4dd6b1a7811a9cffc58c8bb07793
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
4 # include "../config.h"
5 #endif // HAVE_CONFIG_H
16 #ifdef TIME_WITH_SYS_TIME
17 # include <sys/time.h>
19 #else // !TIME_WITH_SYS_TIME
20 # ifdef HAVE_SYS_TIME_H
21 # include <sys/time.h>
22 # else // !HAVE_SYS_TIME_H
24 # endif // HAVE_SYS_TIME_H
25 #endif // TIME_WITH_SYS_TIME
28 #endif // HAVE_UNISTD_H
29 #if defined(HAVE_PROCESS_H) && defined(__EMX__)
31 #endif // HAVE_PROCESS_H __EMX__
43 void Rect::setX(int x
) {
49 void Rect::setY(int y
)
56 void Rect::setPos(int x
, int y
) {
64 void Rect::setWidth(unsigned int w
) {
69 void Rect::setHeight(unsigned int h
) {
74 void Rect::setSize(unsigned int w
, unsigned int h
) {
80 void Rect::setRect(int x
, int y
, unsigned int w
, unsigned int h
) {
81 *this = Rect(x
, y
, w
, h
);
85 void Rect::setCoords(int l
, int t
, int r
, int b
) {
93 Rect
Rect::operator|(const Rect
&a
) const {
96 b
._x1
= std::min(_x1
, a
._x1
);
97 b
._y1
= std::min(_y1
, a
._y1
);
98 b
._x2
= std::max(_x2
, a
._x2
);
99 b
._y2
= std::max(_y2
, a
._y2
);
105 Rect
Rect::operator&(const Rect
&a
) const {
108 b
._x1
= std::max(_x1
, a
._x1
);
109 b
._y1
= std::max(_y1
, a
._y1
);
110 b
._x2
= std::min(_x2
, a
._x2
);
111 b
._y2
= std::min(_y2
, a
._y2
);
117 bool Rect::intersects(const Rect
&a
) const {
118 return std::max(_x1
, a
._x1
) <= std::min(_x2
, a
._x2
) &&
119 std::max(_y1
, a
._y1
) <= std::min(_y2
, a
._y2
);
123 bool Rect::contains(int x
, int y
) const {
124 return x
>= _x1
&& x
<= _x2
&&
125 y
>= _y1
&& y
<= _y2
;
129 bool Rect::contains(const Rect
& a
) const {
130 return a
._x1
>= _x1
&& a
._x2
<= _x2
&&
131 a
._y1
>= _y1
&& a
._y2
<= _y2
;
135 string
expandTilde(const string
& s
) {
136 if (s
[0] != '~') return s
;
138 const char* const home
= getenv("HOME");
139 if (home
== NULL
) return s
;
141 return string(home
+ s
.substr(s
.find('/')));
145 void bexec(const string
& command
, const string
& displaystring
) {
149 int ret
= putenv(const_cast<char *>(displaystring
.c_str()));
151 ret
= execl("/bin/sh", "/bin/sh", "-c", command
.c_str(), NULL
);
155 spawnlp(P_NOWAIT
, "cmd.exe", "cmd.exe", "/c", command
.c_str(), NULL
);
160 #ifndef HAVE_BASENAME
161 string
basename (const string
& path
) {
162 string::size_type slash
= path
.rfind('/');
163 if (slash
== string::npos
)
165 return path
.substr(slash
+1);
167 #endif // HAVE_BASENAME
170 string
textPropertyToString(Display
*display
, XTextProperty
& text_prop
) {
173 if (text_prop
.value
&& text_prop
.nitems
> 0) {
174 if (text_prop
.encoding
== XA_STRING
) {
175 ret
= (char *) text_prop
.value
;
177 text_prop
.nitems
= strlen((char *) text_prop
.value
);
181 if (XmbTextPropertyToTextList(display
, &text_prop
,
182 &list
, &num
) == Success
&&
185 XFreeStringList(list
);
194 timeval
normalizeTimeval(const timeval
&tm
) {
197 while (ret
.tv_usec
< 0) {
198 if (ret
.tv_sec
> 0) {
200 ret
.tv_usec
+= 1000000;
206 if (ret
.tv_usec
>= 1000000) {
207 ret
.tv_sec
+= ret
.tv_usec
/ 1000000;
208 ret
.tv_usec
%= 1000000;
211 if (ret
.tv_sec
< 0) ret
.tv_sec
= 0;
217 string
itostring(unsigned long i
) {
222 for (; i
> 0; i
/= 10)
223 tmp
.insert(tmp
.begin(), "0123456789"[i%10
]);
228 string
itostring(long i
) {
229 std::string tmp
= itostring( (unsigned long) std::abs(i
));
231 tmp
.insert(tmp
.begin(), '-');
This page took 0.045476 seconds and 4 git commands to generate.