From 9f519ec0fcb7cd0dec61a4c31d246800f9a73cb3 Mon Sep 17 00:00:00 2001 From: Henrik Kinnunen Date: Sun, 14 Sep 2008 20:06:28 +0200 Subject: some minor code cleaning. --- src/FbWinFrame.cc | 7 +++++++ src/FbWinFrame.hh | 3 +++ src/RectangleUtil.hh | 30 +++++++++++++++++++++++++++++ src/Window.cc | 54 +++++++++++++++++++++------------------------------- 4 files changed, 62 insertions(+), 32 deletions(-) create mode 100644 src/RectangleUtil.hh diff --git a/src/FbWinFrame.cc b/src/FbWinFrame.cc index 5b91218..fc35ae1 100644 --- a/src/FbWinFrame.cc +++ b/src/FbWinFrame.cc @@ -1717,3 +1717,10 @@ void FbWinFrame::displaySize(unsigned int width, unsigned int height) const { width, height - titlebarHeight() - handleHeight()); m_screen.showGeometry(i, j); } + +bool FbWinFrame::insideTitlebar(Window win) const { + return + gripLeft().window() != win && + gripRight().window() != win && + window().window() != win; +} diff --git a/src/FbWinFrame.hh b/src/FbWinFrame.hh index fcbe11e..ff9c19e 100644 --- a/src/FbWinFrame.hh +++ b/src/FbWinFrame.hh @@ -236,6 +236,9 @@ public: const FbTk::Subject &frameExtentSig() const { return m_frame_extent_sig; } FbTk::Subject &frameExtentSig() { return m_frame_extent_sig; } + /// @returns true if the window is inside titlebar, + /// assuming window is an event window that was generated for this frame. + bool insideTitlebar(Window win) const; //@} diff --git a/src/RectangleUtil.hh b/src/RectangleUtil.hh new file mode 100644 index 0000000..88c3a33 --- /dev/null +++ b/src/RectangleUtil.hh @@ -0,0 +1,30 @@ +#ifndef RECTANGLEUTIL_HH +#define RECTANGLEUTIL_HH + +namespace RectangleUtil { + + +/* + * Determines if a point is inside a rectangle-like objects border. + * @param rect A rectangle-like object that has accessors for x, y, width, and + * height. + * @param x + * @param y + * @param border_width 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; +} + +} // namespace RectangleUtil + + +#endif // RECTANGLEUTIL_HH diff --git a/src/Window.cc b/src/Window.cc index 16334c6..5d50fcf 100644 --- a/src/Window.cc +++ b/src/Window.cc @@ -41,6 +41,7 @@ #include "FocusControl.hh" #include "IconButton.hh" #include "ScreenPlacement.hh" +#include "RectangleUtil.hh" #include "FbTk/StringUtil.hh" #include "FbTk/Compose.hh" @@ -2362,10 +2363,9 @@ void FluxboxWindow::buttonPressEvent(XButtonEvent &be) { m_last_button_x = be.x_root; m_last_button_y = be.y_root; - bool onTitlebar = frame().gripLeft().window() != be.window && - frame().gripRight().window() != be.window && - frame().handle().window() != be.window && - frame().window() != be.window; + bool onTitlebar = + frame().insideTitlebar( be.window ) && + frame().handle().window() != be.window; if (onTitlebar && be.button == 1) raise(); @@ -2422,41 +2422,31 @@ void FluxboxWindow::motionNotifyEvent(XMotionEvent &me) { me.window = frame().window().window(); } - bool inside_titlebar = frame().gripLeft().window() != me.window && - frame().gripRight().window() != me.window && - frame().window() != me.window; + bool inside_titlebar = frame().insideTitlebar( me.window ); if (Fluxbox::instance()->getIgnoreBorder() && m_attaching_tab == 0 && !(isMoving() || isResizing())) { + + using RectangleUtil::insideBorder; + int borderw = frame().window().borderWidth(); //!! TODO(tabs): the below test ought to be in FbWinFrame // if mouse is currently on the window border, ignore it - if ((me.x_root < (frame().x() + borderw) || - me.y_root < (frame().y() + borderw) || - me.x_root >= (frame().x() + (int)frame().width() + borderw) || - me.y_root >= (frame().y() + (int)frame().height() + borderw)) - && (!frame().externalTabMode() || - (me.x_root < (frame().tabcontainer().x() + borderw) || - me.y_root < (frame().tabcontainer().y() + borderw) || - me.x_root >= (frame().tabcontainer().x() + - (int)frame().tabcontainer().width() + borderw) || - me.y_root >= (frame().tabcontainer().y() + - (int)frame().tabcontainer().height() + borderw))) - // or if mouse was on border when it was last clicked - || (m_last_button_x < (frame().x() + borderw) || - m_last_button_y < (frame().y() + borderw) || - m_last_button_x >= (frame().x() + - (int)frame().width() + borderw) || - m_last_button_y >= (frame().y() + - (int)frame().height() + borderw)) - && (!frame().externalTabMode() || - (m_last_button_x < (frame().tabcontainer().x() + borderw) || - m_last_button_y < (frame().tabcontainer().y() + borderw) || - m_last_button_x >= (frame().tabcontainer().x() + - (int)frame().tabcontainer().width() + borderw) || - m_last_button_y >= (frame().tabcontainer().y() + - (int)frame().tabcontainer().height() + borderw)))) + if ( ! insideBorder(frame(), + me.x_root, me.y_root, borderw) && + ( !frame().externalTabMode() || + ! insideBorder(frame().tabcontainer(), + me.x_root, me.y_root, borderw) ) + + || // or if mouse was on border when it was last clicked + + ! insideBorder(frame(), + m_last_button_x, m_last_button_y, borderw) && + ( ! frame().externalTabMode() || + ! insideBorder(frame().tabcontainer(), + m_last_button_x, m_last_button_y, borderw ) ) ) { return; + } } if (moving || ((me.state & Button1Mask) && functions.move && -- cgit v0.11.2