diff options
author | Mathias Gumz <akira at fluxbox dot org> | 2013-05-23 07:18:37 (GMT) |
---|---|---|
committer | Mathias Gumz <akira at fluxbox dot org> | 2013-05-23 07:18:37 (GMT) |
commit | 2da808667301d27110497e036b8cbdec6f65023d (patch) | |
tree | cd499cf5e37b0d0c7586326abe1ff956684e32e8 | |
parent | 9b0cedf9618f382c8691d3243668771e065732b2 (diff) | |
download | fluxbox-2da808667301d27110497e036b8cbdec6f65023d.zip fluxbox-2da808667301d27110497e036b8cbdec6f65023d.tar.bz2 |
Use shared code, minor code simplification
-rw-r--r-- | src/RectangleUtil.hh | 21 | ||||
-rw-r--r-- | src/Window.cc | 12 |
2 files changed, 19 insertions, 14 deletions
diff --git a/src/RectangleUtil.hh b/src/RectangleUtil.hh index 9725e63..dfb0082 100644 --- a/src/RectangleUtil.hh +++ b/src/RectangleUtil.hh | |||
@@ -3,6 +3,14 @@ | |||
3 | 3 | ||
4 | namespace RectangleUtil { | 4 | namespace RectangleUtil { |
5 | 5 | ||
6 | inline bool insideRectangle(int x, int y, int width, int height, int px, int py) { | ||
7 | |||
8 | return | ||
9 | px >= x && | ||
10 | px < (x + width) && | ||
11 | py >= y && | ||
12 | py < (y + height); | ||
13 | } | ||
6 | 14 | ||
7 | /* | 15 | /* |
8 | * Determines if a point is inside a rectangle-like objects border. | 16 | * Determines if a point is inside a rectangle-like objects border. |
@@ -10,18 +18,17 @@ namespace RectangleUtil { | |||
10 | * height. | 18 | * height. |
11 | * @param x | 19 | * @param x |
12 | * @param y | 20 | * @param y |
13 | * @param border_width The size of the border. | 21 | * @param border The size of the border. |
14 | * @returns true if point is inside the rectangle-like object. | 22 | * @returns true if point is inside the rectangle-like object. |
15 | */ | 23 | */ |
24 | |||
16 | template <typename RectangleLike> | 25 | template <typename RectangleLike> |
17 | bool insideBorder(const RectangleLike& rect, | 26 | bool insideBorder(const RectangleLike& rect, |
18 | int x, int y, | 27 | int x, int y, |
19 | int border_width) { | 28 | int border) { |
20 | return | 29 | const int w = static_cast<int>(rect.width()) - border; |
21 | x >= rect.x() + border_width && | 30 | const int h = static_cast<int>(rect.height()) - border; |
22 | x < rect.x() + (int)rect.width() + border_width && | 31 | return insideRectangle(rect.x() + border, rect.y() + border, w, h, x, y); |
23 | y >= rect.y() + border_width && | ||
24 | y < rect.y() + (int)rect.height() + border_width; | ||
25 | } | 32 | } |
26 | 33 | ||
27 | 34 | ||
diff --git a/src/Window.cc b/src/Window.cc index 1c9c795..9416978 100644 --- a/src/Window.cc +++ b/src/Window.cc | |||
@@ -223,11 +223,8 @@ bool isWindowVisibleOnSomeHeadOrScreen(FluxboxWindow const& w) { | |||
223 | 223 | ||
224 | if (w.screen().hasXinerama()) { // xinerama available => use head info | 224 | if (w.screen().hasXinerama()) { // xinerama available => use head info |
225 | return (0 != w.screen().getHead(real_x, real_y)); // if visible on some head | 225 | return (0 != w.screen().getHead(real_x, real_y)); // if visible on some head |
226 | } else { // no xinerama available => use screen info | ||
227 | return (real_x >= 0 && real_y >= 0 && | ||
228 | real_x <= (signed) w.screen().width() && | ||
229 | real_y <= (signed) w.screen().height()); // if visible on the screen | ||
230 | } | 226 | } |
227 | return RectangleUtil::insideRectangle(0, 0, w.screen().width(), w.screen().height(), real_x, real_y); | ||
231 | } | 228 | } |
232 | 229 | ||
233 | class SetClientCmd:public FbTk::Command<void> { | 230 | class SetClientCmd:public FbTk::Command<void> { |
@@ -464,14 +461,15 @@ void FluxboxWindow::init() { | |||
464 | 461 | ||
465 | setWindowType(m_client->getWindowType()); | 462 | setWindowType(m_client->getWindowType()); |
466 | 463 | ||
464 | bool is_visible = isWindowVisibleOnSomeHeadOrScreen(*this); | ||
465 | |||
467 | if (fluxbox.isStartup()) | 466 | if (fluxbox.isStartup()) |
468 | m_placed = true; | 467 | m_placed = true; |
469 | else if (m_client->isTransient() || | 468 | else if (m_client->isTransient() || |
470 | m_client->normal_hint_flags & (PPosition|USPosition)) { | 469 | m_client->normal_hint_flags & (PPosition|USPosition)) { |
471 | if (isWindowVisibleOnSomeHeadOrScreen(*this)) | 470 | m_placed = is_visible; |
472 | m_placed = true; | ||
473 | } else { | 471 | } else { |
474 | if (!isWindowVisibleOnSomeHeadOrScreen(*this)) { | 472 | if (!is_visible) { |
475 | int cur = screen().getHead(fbWindow()); | 473 | int cur = screen().getHead(fbWindow()); |
476 | move(screen().getHeadX(cur), screen().getHeadY(cur)); | 474 | move(screen().getHeadX(cur), screen().getHeadY(cur)); |
477 | m_placed = false; // allow placement strategy to fix position | 475 | m_placed = false; // allow placement strategy to fix position |