From 9a11ce772cacea29e31a399059e25f93c14f6dcc Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Fri, 28 Dec 2018 02:07:50 +0100 Subject: compat/check-visible: really fix this time --- compat/check-visible.cpp | 47 ++++++++++++++++++++++++++++------------------- 1 file changed, 28 insertions(+), 19 deletions(-) diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index 9afdbb76..4cdb1b46 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -3,12 +3,14 @@ #if defined _WIN32 #include "timer.hpp" +#include "math.hpp" #include +#include #include -constexpr int visible_timeout = 5000; +constexpr int visible_timeout = 1000; constexpr int invisible_timeout = 250; static Timer timer; @@ -23,27 +25,34 @@ void set_is_visible(const QWidget& w, bool force) return; timer.start(); + HWND hwnd = (HWND)w.winId(); - HWND id = (HWND) w.winId(); - const QPoint pt = w.mapToGlobal({ 0, 0 }); - const QPoint pt2 = w.mapToGlobal({ w.width(), w.height() }); - - const int W = pt2.x(), H = pt2.y(); - - const QPoint points[] = + if (RECT r; GetWindowRect(hwnd, &r)) { - pt, - pt + QPoint(W - 1, 0), - pt + QPoint(0, H - 1), - pt + QPoint(W - 1, H - 1), - pt + QPoint(W / 2, H / 2), - }; - - for (const QPoint& pt : points) + const int x = r.left+1, y = r.top+1; + const int w = r.right - x - 1, h = r.bottom - y - 1; + + const POINT xs[] { + { x + w, y }, + { x, y + h }, + { x + w, h + y }, + { x, y }, + { x + w/2, y + h/2 }, + }; + + visible = false; + + for (const POINT& pt : xs) + if (WindowFromPoint(pt) == hwnd) + { + visible = true; + break; + } + } + else { - visible = WindowFromPoint({ pt.x(), pt.y() }) == id; - if (visible) - break; + eval_once(qDebug() << "check-visible: GetWindowRect failed"); + visible = true; } } -- cgit v1.2.3