summaryrefslogtreecommitdiff
path: root/src/helpers
diff options
context:
space:
mode:
authorVaxry <43317083+vaxerski@users.noreply.github.com>2025-09-18 22:10:30 +0200
committerGitHub <noreply@github.com>2025-09-18 22:10:30 +0200
commit4fc95d646dbbe71744fb4e02ca0e995b652bffe5 (patch)
treed2cfad68788de39712289d3e5aab54ebb20ef22e /src/helpers
parent91f592a87509436dc6f6ea7b3d6705ed7c5af046 (diff)
renderer: asynchronously load background tex (#11749)
Bumps required hyprgraphics to 0.1.6 --------- Co-authored-by: Mihai Fufezan <mihai@fufexan.net>
Diffstat (limited to 'src/helpers')
-rw-r--r--src/helpers/MainLoopExecutor.cpp47
-rw-r--r--src/helpers/MainLoopExecutor.hpp31
-rw-r--r--src/helpers/Monitor.cpp2
-rw-r--r--src/helpers/Monitor.hpp3
-rw-r--r--src/helpers/memory/Memory.hpp3
5 files changed, 86 insertions, 0 deletions
diff --git a/src/helpers/MainLoopExecutor.cpp b/src/helpers/MainLoopExecutor.cpp
new file mode 100644
index 00000000..19c49563
--- /dev/null
+++ b/src/helpers/MainLoopExecutor.cpp
@@ -0,0 +1,47 @@
+#include "MainLoopExecutor.hpp"
+#include "../managers/eventLoop/EventLoopManager.hpp"
+#include "../macros.hpp"
+
+static int onDataRead(int fd, uint32_t mask, void* data) {
+ ((CMainLoopExecutor*)data)->onFired();
+ return 0;
+}
+
+CMainLoopExecutor::CMainLoopExecutor(std::function<void()>&& callback) : m_fn(std::move(callback)) {
+
+ int fds[2];
+ pipe(fds);
+
+ RASSERT(fds[0] != 0, "CMainLoopExecutor: failed to open a pipe");
+ RASSERT(fds[1] != 0, "CMainLoopExecutor: failed to open a pipe");
+
+ m_event = wl_event_loop_add_fd(g_pEventLoopManager->m_wayland.loop, fds[0], WL_EVENT_READABLE, ::onDataRead, this);
+
+ m_readFd = Hyprutils::OS::CFileDescriptor(fds[0]);
+ m_writeFd = Hyprutils::OS::CFileDescriptor(fds[1]);
+}
+
+CMainLoopExecutor::~CMainLoopExecutor() {
+ if (m_event) // FIXME: potential race in case of a weird destroy on a worker thread
+ wl_event_source_remove(m_event);
+}
+
+void CMainLoopExecutor::signal() {
+ const char* amogus = "h";
+ write(m_writeFd.get(), amogus, 1);
+}
+
+void CMainLoopExecutor::onFired() {
+ if (!m_fn)
+ return;
+
+ m_fn();
+ m_fn = nullptr;
+
+ // we need to remove the event here because we're on the main thread
+ wl_event_source_remove(m_event);
+ m_event = nullptr;
+
+ m_readFd.reset();
+ m_writeFd.reset();
+}
diff --git a/src/helpers/MainLoopExecutor.hpp b/src/helpers/MainLoopExecutor.hpp
new file mode 100644
index 00000000..b33148f0
--- /dev/null
+++ b/src/helpers/MainLoopExecutor.hpp
@@ -0,0 +1,31 @@
+#pragma once
+
+#include <functional>
+#include <hyprutils/os/FileDescriptor.hpp>
+#include <wayland-server-core.h>
+
+class CMainLoopExecutor {
+ public:
+ /*
+ MainLoopExecutor
+
+ Executes a function on the main thread once the writeFd() has some data written to it,
+ then destroys itself.
+
+ Needs to be kept owned, otherwise will die and kill the fds.
+ */
+
+ CMainLoopExecutor(std::function<void()>&& callback);
+ ~CMainLoopExecutor();
+
+ // Call from your worker thread: signals to the main thread. Destroy afterwards.
+ void signal();
+
+ // do not call
+ void onFired();
+
+ private:
+ Hyprutils::OS::CFileDescriptor m_readFd, m_writeFd;
+ wl_event_source* m_event = nullptr;
+ std::function<void()> m_fn;
+};
diff --git a/src/helpers/Monitor.cpp b/src/helpers/Monitor.cpp
index 4a9f93ff..1c08faff 100644
--- a/src/helpers/Monitor.cpp
+++ b/src/helpers/Monitor.cpp
@@ -55,6 +55,8 @@ CMonitor::CMonitor(SP<Aquamarine::IOutput> output_) : m_state(this), m_output(ou
m_cursorZoom->setUpdateCallback([this](auto) { g_pHyprRenderer->damageMonitor(m_self.lock()); });
g_pAnimationManager->createAnimation(0.F, m_zoomAnimProgress, g_pConfigManager->getAnimationPropertyConfig("monitorAdded"), AVARDAMAGE_NONE);
m_zoomAnimProgress->setUpdateCallback([this](auto) { g_pHyprRenderer->damageMonitor(m_self.lock()); });
+ g_pAnimationManager->createAnimation(0.F, m_backgroundOpacity, g_pConfigManager->getAnimationPropertyConfig("monitorAdded"), AVARDAMAGE_NONE);
+ m_backgroundOpacity->setUpdateCallback([this](auto) { g_pHyprRenderer->damageMonitor(m_self.lock()); });
g_pAnimationManager->createAnimation(0.F, m_dpmsBlackOpacity, g_pConfigManager->getAnimationPropertyConfig("fadeDpms"), AVARDAMAGE_NONE);
m_dpmsBlackOpacity->setUpdateCallback([this](auto) { g_pHyprRenderer->damageMonitor(m_self.lock()); });
}
diff --git a/src/helpers/Monitor.hpp b/src/helpers/Monitor.hpp
index 542207b6..d628ac58 100644
--- a/src/helpers/Monitor.hpp
+++ b/src/helpers/Monitor.hpp
@@ -188,6 +188,9 @@ class CMonitor {
PHLANIMVAR<float> m_cursorZoom;
+ // for fading in the wallpaper because it doesn't happen instantly (it's loaded async)
+ PHLANIMVAR<float> m_backgroundOpacity;
+
// for initial zoom anim
PHLANIMVAR<float> m_zoomAnimProgress;
CTimer m_newMonitorAnimTimer;
diff --git a/src/helpers/memory/Memory.hpp b/src/helpers/memory/Memory.hpp
index 7d9d18b1..66ba2c1f 100644
--- a/src/helpers/memory/Memory.hpp
+++ b/src/helpers/memory/Memory.hpp
@@ -1,6 +1,7 @@
#pragma once
#include <hyprutils/memory/WeakPtr.hpp>
+#include <hyprutils/memory/Atomic.hpp>
using namespace Hyprutils::Memory;
@@ -10,3 +11,5 @@ template <typename T>
using WP = Hyprutils::Memory::CWeakPointer<T>;
template <typename T>
using UP = Hyprutils::Memory::CUniquePointer<T>;
+template <typename T>
+using ASP = Hyprutils::Memory::CAtomicSharedPointer<T>;