From 2da808667301d27110497e036b8cbdec6f65023d Mon Sep 17 00:00:00 2001 From: Mathias Gumz Date: Thu, 23 May 2013 09:18:37 +0200 Subject: Use shared code, minor code simplification --- src/RectangleUtil.hh | 21 ++++++++++++++------- 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 @@ namespace RectangleUtil { +inline bool insideRectangle(int x, int y, int width, int height, int px, int py) { + + return + px >= x && + px < (x + width) && + py >= y && + py < (y + height); +} /* * Determines if a point is inside a rectangle-like objects border. @@ -10,18 +18,17 @@ namespace RectangleUtil { * height. * @param x * @param y - * @param border_width The size of the border. + * @param border The size of the border. * @returns true if point is inside the rectangle-like object. */ + template bool insideBorder(const RectangleLike& rect, int x, int y, - int border_width) { - return - x >= rect.x() + border_width && - x < rect.x() + (int)rect.width() + border_width && - y >= rect.y() + border_width && - y < rect.y() + (int)rect.height() + border_width; + int border) { + const int w = static_cast(rect.width()) - border; + const int h = static_cast(rect.height()) - border; + return insideRectangle(rect.x() + border, rect.y() + border, w, h, x, y); } 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) { if (w.screen().hasXinerama()) { // xinerama available => use head info return (0 != w.screen().getHead(real_x, real_y)); // if visible on some head - } else { // no xinerama available => use screen info - return (real_x >= 0 && real_y >= 0 && - real_x <= (signed) w.screen().width() && - real_y <= (signed) w.screen().height()); // if visible on the screen } + return RectangleUtil::insideRectangle(0, 0, w.screen().width(), w.screen().height(), real_x, real_y); } class SetClientCmd:public FbTk::Command { @@ -464,14 +461,15 @@ void FluxboxWindow::init() { setWindowType(m_client->getWindowType()); + bool is_visible = isWindowVisibleOnSomeHeadOrScreen(*this); + if (fluxbox.isStartup()) m_placed = true; else if (m_client->isTransient() || m_client->normal_hint_flags & (PPosition|USPosition)) { - if (isWindowVisibleOnSomeHeadOrScreen(*this)) - m_placed = true; + m_placed = is_visible; } else { - if (!isWindowVisibleOnSomeHeadOrScreen(*this)) { + if (!is_visible) { int cur = screen().getHead(fbWindow()); move(screen().getHeadX(cur), screen().getHeadY(cur)); m_placed = false; // allow placement strategy to fix position -- cgit v0.11.2