summaryrefslogtreecommitdiffhomepage
path: root/compat/check-visible.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2017-07-28 16:23:55 +0200
committerStanislaw Halik <sthalik@misaki.pl>2017-07-28 16:23:55 +0200
commit7a60015ba99125b493d1cb85afc072bcebb97681 (patch)
treec161b23b42e46cac98093f8cb0940fe35c42e0a1 /compat/check-visible.cpp
parent720026a79cd6aa33c4180f2241425cdd8829b36b (diff)
gui: don't update the main window if it's hidden
Diffstat (limited to 'compat/check-visible.cpp')
-rw-r--r--compat/check-visible.cpp67
1 files changed, 67 insertions, 0 deletions
diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp
new file mode 100644
index 00000000..6030ad92
--- /dev/null
+++ b/compat/check-visible.cpp
@@ -0,0 +1,67 @@
+#include "check-visible.hpp"
+
+#if defined _WIN32
+
+#include "timer.hpp"
+
+#include <QMutexLocker>
+
+#include <windows.h>
+
+static constexpr int visible_timeout = 5000;
+
+static Timer timer;
+static QMutex mtx;
+static bool visible = true;
+
+never_inline OTR_COMPAT_EXPORT
+void set_is_visible(const QWidget& w, bool force)
+{
+ QMutexLocker l(&mtx);
+
+ if (!force && timer.elapsed_ms() < visible_timeout)
+ return;
+
+ timer.start();
+
+ const HWND id = (HWND) w.winId();
+ const QPoint pt = w.mapToGlobal({ 0, 0 });
+
+ const int W = w.width(), H = w.height();
+
+ const QPoint points[] =
+ {
+ 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)
+ if (!!(visible = WindowFromPoint({ pt.x(), pt.y() }) == id))
+ break;
+}
+
+never_inline OTR_COMPAT_EXPORT
+bool check_is_visible()
+{
+ QMutexLocker l(&mtx);
+
+ return visible;
+}
+
+#else
+
+always_inline OTR_COMPAT_EXPORT
+void set_is_visible(const QWidget&)
+{
+}
+
+always_inline OTR_COMPAT_EXPORT
+bool check_is_visible()
+{
+ return true;
+}
+
+#endif