From d091350a69198ef0a00ca89b5ebb504de639f893 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Wed, 16 Jan 2019 07:45:07 +0100 Subject: compat/check-visible: fix off-by-one The case `x+1 + w-1` and similar are wrong. --- compat/check-visible.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index 1212ab90..f786ca14 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -38,15 +38,15 @@ void set_is_visible(const QWidget& w, bool force) if (RECT r; GetWindowRect(hwnd, &r)) { - const int x = r.left+1, y = r.top+1; - const int w = r.right - x - 1, h = r.bottom - y - 1; + const int x = r.left, y = r.top; + const int w = r.right - x, h = r.bottom - y; const POINT xs[] { - { x + w, y }, - { x, y + h }, - { x + w, h + y }, - { x, y }, - { x + w/2, y + h/2 }, + { x + w - 1, y + 1 }, + { x + 1, y + h - 1 }, + { x + w - 1, y + h - 1 }, + { x + 1, y + 1 }, + { x + w/2, y + h/2 }, }; visible = false; @@ -54,6 +54,7 @@ void set_is_visible(const QWidget& w, bool force) for (const POINT& pt : xs) if (WindowFromPoint(pt) == hwnd) { + visible = true; break; } @@ -69,7 +70,7 @@ void set_is_visible(const QWidget& w, bool force) void set_is_visible(const QWidget& w, bool) { - spinlock_guard l(lock); + QMutexLocker l(&lock); visible = !(w.isHidden() || w.windowState() & Qt::WindowMinimized); } -- cgit v1.2.3