summaryrefslogtreecommitdiffhomepage
path: root/compat/check-visible.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2018-12-29 13:27:21 +0100
committerStanislaw Halik <sthalik@misaki.pl>2019-01-16 07:48:18 +0100
commite9bbb68829e972df2e458aa5beec0568d4737f02 (patch)
treeb305103d53214dcddb76c1f26738d334972b17d3 /compat/check-visible.cpp
parenta1a9a091093c9fb711a1665de9f4d46ae5c5ab67 (diff)
compat/spinlock: implement and use it
Diffstat (limited to 'compat/check-visible.cpp')
-rw-r--r--compat/check-visible.cpp37
1 files changed, 19 insertions, 18 deletions
diff --git a/compat/check-visible.cpp b/compat/check-visible.cpp
index 4cdb1b46..d7f24177 100644
--- a/compat/check-visible.cpp
+++ b/compat/check-visible.cpp
@@ -1,31 +1,33 @@
#include "check-visible.hpp"
-#if defined _WIN32
-
+#include "macros.hpp"
#include "timer.hpp"
-#include "math.hpp"
+#include "spinlock.hpp"
-#include <QMutex>
+#include <QWidget>
#include <QDebug>
-#include <windows.h>
-
constexpr int visible_timeout = 1000;
constexpr int invisible_timeout = 250;
static Timer timer;
-static QMutex mtx;
+static std::atomic_flag lock = ATOMIC_FLAG_INIT;
static bool visible = true;
+#if defined _WIN32
+
+#include <windows.h>
+
void set_is_visible(const QWidget& w, bool force)
{
- QMutexLocker l(&mtx);
+ spinlock_guard l(lock);
+
+ HWND hwnd = (HWND)w.winId();
if (!force && timer.elapsed_ms() < (visible ? visible_timeout : invisible_timeout))
return;
timer.start();
- HWND hwnd = (HWND)w.winId();
if (RECT r; GetWindowRect(hwnd, &r))
{
@@ -56,22 +58,21 @@ void set_is_visible(const QWidget& w, bool force)
}
}
-bool check_is_visible()
-{
- QMutexLocker l(&mtx);
-
- return visible;
-}
-
#else
void set_is_visible(const QWidget&, bool)
{
}
-bool check_is_visible()
+void check_is_visible(bool)
{
- return true;
}
#endif
+
+bool check_is_visible()
+{
+ spinlock_guard l(lock);
+ return visible;
+}
+