Extract Win32 runtime state storage

This commit is contained in:
2026-06-17 11:34:14 +02:00
parent ba94785eda
commit 0cf6a6ea4f
6 changed files with 66 additions and 17 deletions

View File

@@ -8,6 +8,7 @@
#include "platform_windows/windows_lifecycle_state.h"
#include "platform_windows/windows_main_window_session.h"
#include "platform_windows/windows_platform_services.h"
#include "platform_windows/windows_runtime_state.h"
#include "platform_windows/windows_stylus_input.h"
#include "platform_windows/windows_window_shell.h"
#include "wacom.h"
@@ -17,17 +18,6 @@ namespace pp::platform::windows {
namespace {
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
WacomTablet tablet;
};
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state()
{
static RetainedWindowsRuntimeState state;
return state;
}
void register_touch_window(HWND hWnd)
{
// link: https://docs.microsoft.com/en-us/windows/desktop/api/winuser/nf-winuser-registertouchwindow
@@ -110,7 +100,7 @@ void run_main_message_loop()
void shutdown_main_window_runtime(const MainWindowStartupState& startup, HINSTANCE hInst)
{
retained_runtime_state().tablet.terminate();
retained_wacom_tablet().terminate();
UnregisterClass(startup.window_class.lpszClassName, hInst);
LogRemote::I.stop();
}
@@ -130,21 +120,21 @@ App* bound_app() noexcept
void release_bound_app() noexcept
{
bind_app(nullptr);
retained_runtime_state().owned_app.reset();
retained_owned_app().reset();
}
WacomTablet* bound_wacom_tablet() noexcept
{
return &retained_runtime_state().tablet;
return &retained_wacom_tablet();
}
int run_main_application(int argc, char** argv)
{
const auto instance = GetModuleHandle(NULL);
auto& runtime_state = retained_runtime_state();
runtime_state.owned_app = std::make_unique<App>();
auto* app = runtime_state.owned_app.get();
auto& owned_app = retained_owned_app();
owned_app = std::make_unique<App>();
auto* app = owned_app.get();
bind_app(app);
app->set_platform_services(&pp::platform::windows::platform_services());
app->initLog();

View File

@@ -0,0 +1,34 @@
#include "pch.h"
#include "platform_windows/windows_runtime_state.h"
#include "app.h"
#include "wacom.h"
namespace pp::platform::windows {
namespace {
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
WacomTablet tablet;
};
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() noexcept
{
static RetainedWindowsRuntimeState state;
return state;
}
}
std::unique_ptr<App>& retained_owned_app() noexcept
{
return retained_runtime_state().owned_app;
}
WacomTablet& retained_wacom_tablet() noexcept
{
return retained_runtime_state().tablet;
}
}

View File

@@ -0,0 +1,13 @@
#pragma once
#include <memory>
class App;
class WacomTablet;
namespace pp::platform::windows {
[[nodiscard]] std::unique_ptr<App>& retained_owned_app() noexcept;
[[nodiscard]] WacomTablet& retained_wacom_tablet() noexcept;
}