summaryrefslogtreecommitdiffhomepage
path: root/opentrack/is-window-visible.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'opentrack/is-window-visible.hpp')
-rw-r--r--opentrack/is-window-visible.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/opentrack/is-window-visible.hpp b/opentrack/is-window-visible.hpp
new file mode 100644
index 00000000..300e541a
--- /dev/null
+++ b/opentrack/is-window-visible.hpp
@@ -0,0 +1,26 @@
+#ifdef _WIN32
+
+#include <windows.h>
+#include <QWidget>
+#include <QRect>
+#include <QDebug>
+
+template<typename=void>
+bool is_window_visible(const QWidget* widget)
+{
+ const QWidget* window = widget->window();
+
+ if (!window)
+ return true;
+
+ const QPoint p = widget->mapToGlobal(widget->pos());
+ const QSize s = widget->size();
+ POINT pt = { p.x() + s.width()/2, p.y() + s.height()/2 };
+
+ return WindowFromPoint(pt) == (HWND) widget->winId();
+}
+
+#else
+template<typename=void>
+bool is_window_visible(const QWidget* widget) { return true; }
+#endif