diff --git a/cmake/PanoPainterSources.cmake b/cmake/PanoPainterSources.cmake index c3c7dbc1..91bbc230 100644 --- a/cmake/PanoPainterSources.cmake +++ b/cmake/PanoPainterSources.cmake @@ -237,6 +237,8 @@ set(PP_WINDOWS_PLATFORM_SOURCES src/platform_windows/windows_bootstrap_helpers.cpp src/platform_windows/windows_lifecycle_shell.cpp src/platform_windows/windows_lifecycle_shell.h + src/platform_windows/windows_main_window_session.cpp + src/platform_windows/windows_main_window_session.h src/platform_windows/windows_platform_services.cpp src/platform_windows/windows_platform_services.h src/platform_windows/windows_runtime_shell.cpp diff --git a/docs/modernization/roadmap.md b/docs/modernization/roadmap.md index f3c9a59a..0e36c5e6 100644 --- a/docs/modernization/roadmap.md +++ b/docs/modernization/roadmap.md @@ -70,6 +70,12 @@ What is already real: - `pp_app_core` Latest slice: +- `src/platform_windows/windows_main_window_session.*` now owns the retained + Win32 main-window session fields (`HWND`, title buffer, sandbox flag) + instead of leaving them inside `windows_runtime_shell.cpp`. +- `src/platform_windows/windows_runtime_shell.cpp` now keeps Windows runtime + ownership focused on `App` and tablet lifetime rather than also owning + main-window session metadata. - `src/platform_legacy/legacy_platform_services.*` now owns Android storage paths through explicit `create_platform_services(...)` configuration instead of reading them from a shared legacy singleton. diff --git a/docs/modernization/tasks.md b/docs/modernization/tasks.md index 52f39eea..aa6c1251 100644 --- a/docs/modernization/tasks.md +++ b/docs/modernization/tasks.md @@ -78,6 +78,10 @@ Completed, blocked, and superseded task history moved to the queue is now ordered by code movement instead. Current slice: +- `src/platform_windows/windows_main_window_session.*` now owns the retained + Win32 main-window session fields. +- `src/platform_windows/windows_runtime_shell.cpp` no longer carries the + retained `HWND` / title-buffer / sandbox pocket. - `src/platform_legacy/legacy_platform_services.*` now takes Android storage paths through explicit `create_platform_services(...)` config instead of the legacy singleton state. diff --git a/src/platform_windows/windows_bootstrap_helpers.cpp b/src/platform_windows/windows_bootstrap_helpers.cpp index 092f9cc9..bf5854e8 100644 --- a/src/platform_windows/windows_bootstrap_helpers.cpp +++ b/src/platform_windows/windows_bootstrap_helpers.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "platform_windows/windows_bootstrap_helpers.h" +#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_runtime_shell.h" #include "platform_windows/windows_window_shell.h" @@ -176,7 +177,7 @@ void setup_exception_handler(const App& app) GetFullPathNameA(path.c_str(), MAX_PATH, abspath, NULL); static char message[4096]; snprintf(message, sizeof(message), "File recovered in: %s", abspath); - MessageBoxA(main_window_handle(), message, "File Recovery", MB_OK | MB_ICONWARNING); + MessageBoxA(retained_main_window_handle_ref(), message, "File Recovery", MB_OK | MB_ICONWARNING); } LogRemote::I.file_close(); }, reinterpret_cast(&app)); @@ -338,7 +339,7 @@ int read_WMI_info() if (get_int(clsObj, L"CodeIntegrityPolicyEnforcementStatus") > 0) { LOG("SANDBOX DETECTED"); - set_main_window_sandboxed(true); + set_retained_main_window_sandboxed(true); } SAFEARRAY *psaNames = NULL; diff --git a/src/platform_windows/windows_lifecycle_shell.cpp b/src/platform_windows/windows_lifecycle_shell.cpp index bf274053..48fb37f4 100644 --- a/src/platform_windows/windows_lifecycle_shell.cpp +++ b/src/platform_windows/windows_lifecycle_shell.cpp @@ -4,6 +4,7 @@ #include "app.h" #include "legacy_preference_storage.h" +#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_runtime_shell.h" #include "platform_windows/windows_stylus_input.h" diff --git a/src/platform_windows/windows_main_window_session.cpp b/src/platform_windows/windows_main_window_session.cpp new file mode 100644 index 00000000..89e5c436 --- /dev/null +++ b/src/platform_windows/windows_main_window_session.cpp @@ -0,0 +1,47 @@ +#include "pch.h" + +#include "platform_windows/windows_main_window_session.h" + +namespace pp::platform::windows { +namespace { + +struct RetainedMainWindowSessionState final { + HWND handle{}; + wchar_t title[512]{}; + bool sandboxed = false; +}; + +[[nodiscard]] RetainedMainWindowSessionState& retained_main_window_session_state() noexcept +{ + static RetainedMainWindowSessionState state; + return state; +} + +} + +HWND& retained_main_window_handle_ref() noexcept +{ + return retained_main_window_session_state().handle; +} + +wchar_t* retained_main_window_title_buffer() noexcept +{ + return retained_main_window_session_state().title; +} + +const wchar_t* retained_main_window_title() noexcept +{ + return retained_main_window_session_state().title; +} + +bool retained_main_window_sandboxed() noexcept +{ + return retained_main_window_session_state().sandboxed; +} + +void set_retained_main_window_sandboxed(bool sandboxed) noexcept +{ + retained_main_window_session_state().sandboxed = sandboxed; +} + +} diff --git a/src/platform_windows/windows_main_window_session.h b/src/platform_windows/windows_main_window_session.h new file mode 100644 index 00000000..1fae17a5 --- /dev/null +++ b/src/platform_windows/windows_main_window_session.h @@ -0,0 +1,13 @@ +#pragma once + +#include + +namespace pp::platform::windows { + +[[nodiscard]] HWND& retained_main_window_handle_ref() noexcept; +[[nodiscard]] wchar_t* retained_main_window_title_buffer() noexcept; +[[nodiscard]] const wchar_t* retained_main_window_title() noexcept; +[[nodiscard]] bool retained_main_window_sandboxed() noexcept; +void set_retained_main_window_sandboxed(bool sandboxed) noexcept; + +} diff --git a/src/platform_windows/windows_platform_services.cpp b/src/platform_windows/windows_platform_services.cpp index 409258b5..36a15651 100644 --- a/src/platform_windows/windows_platform_services.cpp +++ b/src/platform_windows/windows_platform_services.cpp @@ -1,6 +1,7 @@ #include "pch.h" #include "platform_windows/windows_bootstrap_helpers.h" #include "platform_windows/windows_lifecycle_shell.h" +#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_platform_services.h" #include "platform_windows/windows_runtime_shell.h" #include "keymap.h" @@ -40,12 +41,12 @@ HWND pp_windows_main_window_handle(); HWND pp_windows_main_window_handle() { - return pp::platform::windows::main_window_handle(); + return pp::platform::windows::retained_main_window_handle_ref(); } void destroy_window() { - pp::platform::windows::enqueue_main_thread_task(std::packaged_task([hWnd = pp::platform::windows::main_window_handle()] { + pp::platform::windows::enqueue_main_thread_task(std::packaged_task([hWnd = pp::platform::windows::retained_main_window_handle_ref()] { pp::platform::windows::request_window_close(hWnd); })); } @@ -78,8 +79,8 @@ void win32_update_stylus(float dt) void win32_update_fps(int frames) { pp::platform::windows::enqueue_main_thread_task(std::packaged_task([ - hWnd = pp::platform::windows::main_window_handle(), - window_title = pp::platform::windows::main_window_title(), + hWnd = pp::platform::windows::retained_main_window_handle_ref(), + window_title = pp::platform::windows::retained_main_window_title(), vr = &pp::platform::windows::platform_vr_state(), frames] { pp::platform::windows::update_window_fps(hWnd, window_title, *vr, frames); @@ -90,7 +91,7 @@ bool win32_vr_start() { return pp::platform::windows::start_window_vr( pp::platform::windows::platform_vr_state(), - pp::platform::windows::main_window_sandboxed()); + pp::platform::windows::retained_main_window_sandboxed()); } void win32_vr_stop() @@ -100,7 +101,7 @@ void win32_vr_stop() void win32_save_window_state() { - pp::platform::windows::save_window_preferences(pp::platform::windows::main_window_handle()); + pp::platform::windows::save_window_preferences(pp::platform::windows::retained_main_window_handle_ref()); } namespace pp::platform::windows { diff --git a/src/platform_windows/windows_runtime_shell.cpp b/src/platform_windows/windows_runtime_shell.cpp index 76b34908..9d3e50b1 100644 --- a/src/platform_windows/windows_runtime_shell.cpp +++ b/src/platform_windows/windows_runtime_shell.cpp @@ -6,6 +6,7 @@ #include "log.h" #include "platform_windows/windows_bootstrap_helpers.h" #include "platform_windows/windows_lifecycle_shell.h" +#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_platform_services.h" #include "platform_windows/windows_stylus_input.h" #include "platform_windows/windows_window_shell.h" @@ -16,23 +17,11 @@ namespace pp::platform::windows { namespace { -struct RetainedMainWindowSessionState final { - HWND handle{}; - wchar_t title[512]{}; - bool sandboxed = false; -}; - struct RetainedWindowsRuntimeState final { std::unique_ptr owned_app; WacomTablet tablet; }; -[[nodiscard]] RetainedMainWindowSessionState& retained_main_window_session_state() -{ - static RetainedMainWindowSessionState state; - return state; -} - [[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state() { static RetainedWindowsRuntimeState state; @@ -149,30 +138,9 @@ WacomTablet* bound_wacom_tablet() noexcept return &retained_runtime_state().tablet; } -HWND main_window_handle() noexcept -{ - return retained_main_window_session_state().handle; -} - -const wchar_t* main_window_title() noexcept -{ - return retained_main_window_session_state().title; -} - -bool main_window_sandboxed() noexcept -{ - return retained_main_window_session_state().sandboxed; -} - -void set_main_window_sandboxed(bool sandboxed) noexcept -{ - retained_main_window_session_state().sandboxed = sandboxed; -} - int run_main_application(int argc, char** argv) { const auto instance = GetModuleHandle(NULL); - auto& main_window_state = retained_main_window_session_state(); auto& runtime_state = retained_runtime_state(); runtime_state.owned_app = std::make_unique(); @@ -203,9 +171,9 @@ int run_main_application(int argc, char** argv) auto context = pp::platform::windows::OpenGlWindowContext {}; switch (pp::platform::windows::initialize_main_window_and_gl( startup, - main_window_state.handle, + retained_main_window_handle_ref(), instance, - main_window_state.title, + retained_main_window_title_buffer(), context)) { case pp::platform::windows::MainStartupResult::Ok: @@ -245,25 +213,24 @@ int run_main_application(int argc, char** argv) void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, HINSTANCE instance, SplashScreen& splash) { - auto& main_window_state = retained_main_window_session_state(); auto* app = bound_app(); - register_touch_window(main_window_state.handle); + register_touch_window(retained_main_window_handle_ref()); wglMakeCurrent(NULL, NULL); initialize_runtime_threads(); install_debug_gl_callbacks(); - initialize_wintab(main_window_state.handle, main_window_state.sandboxed); - set_main_window_icon(main_window_state.handle); + initialize_wintab(retained_main_window_handle_ref(), retained_main_window_sandboxed()); + set_main_window_icon(retained_main_window_handle_ref()); app->ui_sync(); - restore_window_placement(main_window_state.handle, startup.show_command); + restore_window_placement(retained_main_window_handle_ref(), startup.show_command); if (start_in_vr) app->vr_start(); LOG("show main window"); - SetForegroundWindow(main_window_state.handle); + SetForegroundWindow(retained_main_window_handle_ref()); splash.dismiss(); diff --git a/src/platform_windows/windows_runtime_shell.h b/src/platform_windows/windows_runtime_shell.h index fb113c05..551d4062 100644 --- a/src/platform_windows/windows_runtime_shell.h +++ b/src/platform_windows/windows_runtime_shell.h @@ -14,9 +14,5 @@ void bind_app(App* app) noexcept; [[nodiscard]] App* bound_app() noexcept; void release_bound_app() noexcept; [[nodiscard]] WacomTablet* bound_wacom_tablet() noexcept; -[[nodiscard]] HWND main_window_handle() noexcept; -[[nodiscard]] const wchar_t* main_window_title() noexcept; -[[nodiscard]] bool main_window_sandboxed() noexcept; -void set_main_window_sandboxed(bool sandboxed) noexcept; } diff --git a/src/platform_windows/windows_window_shell.cpp b/src/platform_windows/windows_window_shell.cpp index 068b1081..c245536c 100644 --- a/src/platform_windows/windows_window_shell.cpp +++ b/src/platform_windows/windows_window_shell.cpp @@ -4,6 +4,7 @@ #include "app.h" #include "platform_windows/windows_lifecycle_shell.h" +#include "platform_windows/windows_main_window_session.h" #include "platform_windows/windows_platform_services.h" #include "platform_windows/windows_runtime_shell.h" #include "platform_windows/windows_stylus_input.h"