From 72f7a1b07d393e6cfdbac1ecb168a703919fd03e Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 21 Jul 2016 14:30:09 +0200 Subject: api/is-window-visible: check for more window positions Having the window center invisible making the feed not refresh is confusing. Also check for all the corners. --- opentrack/is-window-visible.hpp | 19 ++++++++++++++++--- 1 file 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 #include #include +#include +#include template 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 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 -- cgit v1.2.3