summaryrefslogtreecommitdiffhomepage
path: root/api/is-window-visible.cpp
blob: fc25bb7d682995a6b2b0224f48dbe493814e104f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include "is-window-visible.hpp"
#include <QPoint>

#ifdef _WIN32

#include <windows.h>

OPENTRACK_API_EXPORT bool is_window_visible(const QWidget* widget)
{
    const QPoint p = widget->mapToGlobal(QPoint(0, 0));
    const QSize s = widget->size();

    const 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
OPENTRACK_API_EXPORT bool is_window_visible(const QWidget* widget)
{
    return true;
}
#endif