[FancyZones] Update OnThreadExecutor usage

This commit is contained in:
Jeremy Sinclair
2025-12-15 22:44:33 -05:00
parent 37f90d8c1f
commit dd76564a47
4 changed files with 15 additions and 10 deletions

View File

@@ -136,7 +136,7 @@ bool EditorParameters::Save(const WorkAreaConfiguration& configuration, OnThread
dpiUnawareThread.submit(OnThreadExecutor::task_t{
[&]() {
combinedWorkArea = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFOEX::rcWork>();
} }).wait();
} }).get();
RECT combinedMonitorArea = FancyZonesUtils::GetAllMonitorsCombinedRect<&MONITORINFOEX::rcMonitor>();
// use dpi-unaware values
@@ -198,7 +198,7 @@ bool EditorParameters::Save(const WorkAreaConfiguration& configuration, OnThread
{
return;
}
} }).wait();
} }).get();
float width = static_cast<float>(monitorInfo.rcMonitor.right - monitorInfo.rcMonitor.left);
float height = static_cast<float>(monitorInfo.rcMonitor.bottom - monitorInfo.rcMonitor.top);

View File

@@ -259,7 +259,7 @@ FancyZones::Run() noexcept
SetThreadDpiAwarenessContext(DPI_AWARENESS_CONTEXT_UNAWARE);
SetThreadDpiHostingBehavior(DPI_HOSTING_BEHAVIOR_MIXED);
} })
.wait();
.get();
m_toggleEditorEventWaiter = EventWaiter(CommonSharedConstants::FANCY_ZONES_EDITOR_TOGGLE_EVENT, [&](int err) {
if (err == ERROR_SUCCESS)
@@ -463,7 +463,7 @@ void FancyZones::WindowCreated(HWND window) noexcept
if (!isMoved)
{
FancyZonesWindowProperties::StampMovedOnOpeningProperty(window);
m_dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&] { MonitorUtils::OpenWindowOnActiveMonitor(window, active); } }).wait();
m_dpiUnawareThread.submit(OnThreadExecutor::task_t{ [&] { MonitorUtils::OpenWindowOnActiveMonitor(window, active); } }).get();
}
}
}

View File

@@ -9,13 +9,17 @@ OnThreadExecutor::OnThreadExecutor() :
{
}
std::future<void> OnThreadExecutor::submit(task_t task)
winrt::Windows::Foundation::IAsyncAction OnThreadExecutor::submit(task_t task)
{
auto future = task.get_future();
std::lock_guard lock{ _task_mutex };
_task_queue.emplace(std::move(task));
_task_cv.notify_one();
return future;
{
std::lock_guard lock{ _task_mutex };
_task_queue.emplace(std::move(task));
_task_cv.notify_one();
}
co_await winrt::resume_background();
future.wait();
}
void OnThreadExecutor::cancel()

View File

@@ -5,6 +5,7 @@
#include <functional>
#include <queue>
#include <atomic>
#include <winrt/Windows.Foundation.h>
// OnThreadExecutor allows its caller to off-load some work to a persistently running background thread.
// This might come in handy if you use the API which sets thread-wide global state and the state needs
@@ -17,7 +18,7 @@ public:
OnThreadExecutor();
~OnThreadExecutor();
std::future<void> submit(task_t task);
winrt::Windows::Foundation::IAsyncAction submit(task_t task);
void cancel();
private: