From d613381a46c281d6f96c5b6079b625e85d450ab4 Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Thu, 21 Jul 2016 20:06:22 +0200 Subject: api/is-window-visible: move from header --- opentrack/is-window-visible.cpp | 33 +++++++++++++++++++++++++++++++++ opentrack/is-window-visible.hpp | 38 +++----------------------------------- 2 files changed, 36 insertions(+), 35 deletions(-) create mode 100644 opentrack/is-window-visible.cpp diff --git a/opentrack/is-window-visible.cpp b/opentrack/is-window-visible.cpp new file mode 100644 index 00000000..fc25bb7d --- /dev/null +++ b/opentrack/is-window-visible.cpp @@ -0,0 +1,33 @@ +#include "is-window-visible.hpp" +#include + +#ifdef _WIN32 + +#include + +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 diff --git a/opentrack/is-window-visible.hpp b/opentrack/is-window-visible.hpp index fa6aeb53..18c9251a 100644 --- a/opentrack/is-window-visible.hpp +++ b/opentrack/is-window-visible.hpp @@ -1,39 +1,7 @@ -#ifdef _WIN32 +#pragma once -#include #include -#include -#include -#include -#include +#include "export.hpp" -template -bool is_window_visible(const QWidget* widget) -{ - const QWidget* window = widget->window(); +OPENTRACK_API_EXPORT bool is_window_visible(const QWidget* widget); - if (!window) - return true; - - const QPoint p = widget->mapToGlobal(QPoint(0, 0)); - const QSize s = widget->size(); - - const std::initializer_list 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 -template -bool is_window_visible(const QWidget* widget) { return true; } -#endif -- cgit v1.2.3