diff options
Diffstat (limited to 'compat/check-visible.cpp')
-rw-r--r-- | compat/check-visible.cpp | 92 |
1 files changed, 57 insertions, 35 deletions
diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp index 96dba60f..f786ca14 100644 --- a/compat/check-visible.cpp +++ b/compat/check-visible.cpp @@ -1,67 +1,89 @@ #include "check-visible.hpp" +#include <QMutex> +#include <QWidget> +#include <QDebug> + +static QMutex lock; +static bool visible = true; + #if defined _WIN32 #include "timer.hpp" +#include "macros.hpp" -#include <QMutex> - -#include <windows.h> +static Timer timer; -constexpr int visible_timeout = 5000; +constexpr int visible_timeout = 1000; constexpr int invisible_timeout = 250; -static Timer timer; -static QMutex mtx; -static bool visible = true; +#include <windows.h> void set_is_visible(const QWidget& w, bool force) { - QMutexLocker l(&mtx); + QMutexLocker l(&lock); - if (!force && timer.elapsed_ms() < (visible ? visible_timeout : invisible_timeout)) + if (w.isHidden() || w.windowState() & Qt::WindowMinimized) + { + visible = false; return; + } - timer.start(); + HWND hwnd = (HWND)w.winId(); - const HWND id = (HWND) w.winId(); - const QPoint pt = w.mapToGlobal({ 0, 0 }); + if (!force && timer.elapsed_ms() < (visible ? visible_timeout : invisible_timeout)) + return; - const int W = w.width(), H = w.height(); + timer.start(); - 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, y = r.top; + const int w = r.right - x, h = r.bottom - y; + + const POINT xs[] { + { 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; + + 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; } } -bool check_is_visible() -{ - QMutexLocker l(&mtx); - - return visible; -} - #else -void set_is_visible(const QWidget&, bool) +void set_is_visible(const QWidget& w, bool) { + QMutexLocker l(&lock); + visible = !(w.isHidden() || w.windowState() & Qt::WindowMinimized); } +#endif + bool check_is_visible() { - return true; + QMutexLocker l(&lock); + return visible; } -#endif +void force_is_visible(bool value) +{ + QMutexLocker l(&lock); + visible = value; +} |