Bind non-Windows platform services explicitly

This commit is contained in:
2026-06-17 10:02:58 +02:00
parent ea1845d924
commit f98e4f4889
11 changed files with 123 additions and 40 deletions

View File

@@ -16,12 +16,25 @@ namespace pp::platform::windows {
namespace {
struct RetainedMainWindowSessionState final {
HINSTANCE instance{};
HWND handle{};
wchar_t title[512]{};
bool sandboxed = false;
};
struct RetainedWindowsRuntimeState final {
std::unique_ptr<App> owned_app;
App* app = nullptr;
WacomTablet tablet;
};
[[nodiscard]] RetainedMainWindowSessionState& retained_main_window_session_state()
{
static RetainedMainWindowSessionState state;
return state;
}
[[nodiscard]] RetainedWindowsRuntimeState& retained_runtime_state()
{
static RetainedWindowsRuntimeState state;
@@ -142,28 +155,28 @@ WacomTablet* bound_wacom_tablet() noexcept
HWND main_window_handle() noexcept
{
return retained_state().hWnd;
return retained_main_window_session_state().handle;
}
const wchar_t* main_window_title() noexcept
{
return retained_state().window_title;
return retained_main_window_session_state().title;
}
bool main_window_sandboxed() noexcept
{
return retained_state().sandboxed;
return retained_main_window_session_state().sandboxed;
}
void set_main_window_sandboxed(bool sandboxed) noexcept
{
retained_state().sandboxed = sandboxed;
retained_main_window_session_state().sandboxed = sandboxed;
}
int run_main_application(int argc, char** argv)
{
auto& state = retained_state();
state.hInst = GetModuleHandle(NULL);
auto& main_window_state = retained_main_window_session_state();
main_window_state.instance = GetModuleHandle(NULL);
auto& runtime_state = retained_runtime_state();
runtime_state.owned_app = std::make_unique<App>();
@@ -180,7 +193,7 @@ int run_main_application(int argc, char** argv)
pp::platform::windows::ensure_runtime_data_directory();
pp::platform::windows::SplashScreen splash(state.hInst);
pp::platform::windows::SplashScreen splash(main_window_state.instance);
pp::platform::windows::initialize_retained_input_state();
@@ -192,7 +205,12 @@ int run_main_application(int argc, char** argv)
auto startup = pp::platform::windows::initialize_main_window_startup_state(*app);
auto context = pp::platform::windows::OpenGlWindowContext {};
switch (pp::platform::windows::initialize_main_window_and_gl(startup, state.hWnd, state.hInst, state.window_title, context))
switch (pp::platform::windows::initialize_main_window_and_gl(
startup,
main_window_state.handle,
main_window_state.instance,
main_window_state.title,
context))
{
case pp::platform::windows::MainStartupResult::Ok:
break;
@@ -231,30 +249,30 @@ int run_main_application(int argc, char** argv)
void run_main_window_runtime(const MainWindowStartupState& startup, bool start_in_vr, SplashScreen& splash)
{
auto& state = retained_state();
auto& main_window_state = retained_main_window_session_state();
auto* app = bound_app();
register_touch_window(state.hWnd);
register_touch_window(main_window_state.handle);
wglMakeCurrent(NULL, NULL);
initialize_runtime_threads();
install_debug_gl_callbacks();
initialize_wintab(state.hWnd, state.sandboxed);
set_main_window_icon(state.hWnd);
initialize_wintab(main_window_state.handle, main_window_state.sandboxed);
set_main_window_icon(main_window_state.handle);
app->ui_sync();
restore_window_placement(state.hWnd, startup.show_command);
restore_window_placement(main_window_state.handle, startup.show_command);
if (start_in_vr)
app->vr_start();
LOG("show main window");
SetForegroundWindow(state.hWnd);
SetForegroundWindow(main_window_state.handle);
splash.dismiss();
run_main_message_loop();
shutdown_main_window_runtime(startup, state.hInst);
shutdown_main_window_runtime(startup, main_window_state.instance);
}
}

View File

@@ -8,12 +8,8 @@
struct RetainedState
{
HINSTANCE hInst{};
HWND hWnd{};
bool keys[256]{};
std::map<kKey, int> vkey_map;
wchar_t window_title[512]{};
bool sandboxed = false;
pp::platform::windows::VrShellState vr;
};