diff options
Diffstat (limited to 'opentrack/is-window-visible.hpp')
-rw-r--r-- | opentrack/is-window-visible.hpp | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/opentrack/is-window-visible.hpp b/opentrack/is-window-visible.hpp index 300e541a..fa6aeb53 100644 --- a/opentrack/is-window-visible.hpp +++ b/opentrack/is-window-visible.hpp @@ -4,6 +4,8 @@ #include <QWidget> #include <QRect> #include <QDebug> +#include <QPoint> +#include <initializer_list> template<typename=void> bool is_window_visible(const QWidget* widget) @@ -13,11 +15,22 @@ bool is_window_visible(const QWidget* widget) if (!window) return true; - const QPoint p = widget->mapToGlobal(widget->pos()); + const QPoint p = widget->mapToGlobal(QPoint(0, 0)); const QSize s = widget->size(); - POINT pt = { p.x() + s.width()/2, p.y() + s.height()/2 }; - return WindowFromPoint(pt) == (HWND) widget->winId(); + const std::initializer_list<POINT> points = + { + { p.x(), p.y() }, + { p.x() + s.width(), p.y() }, + { p.x() + s.width(), p.y() + s.height() }, + { p.x(), p.y() + s.height() }, + { p.x() + s.width()/2, p.y() + s.height()/2 }, + }; + + for (const POINT& pt : points) + if (WindowFromPoint(pt) == (HWND) widget->winId()) + return true; + return false; } #else |