Kelsidavis-WoWee/src/main.cpp
Kelsi cb01821d89 Add Windows build support via MSYS2 and fix platform-specific code
Guard X11 display crash handler with __linux__, add Windows GlobalMemoryStatusEx
path in memory_monitor, guard warden cache paths with APPDATA on Windows, and
make pkg-config optional in CMakeLists with a find_library fallback. Add Windows
x86-64 CI job using MSYS2 MINGW64 to the build workflow.
2026-02-18 17:38:08 -08:00

70 lines
1.9 KiB
C++

#include "core/application.hpp"
#include "core/logger.hpp"
#include <exception>
#include <csignal>
#include <SDL2/SDL.h>
#ifdef __linux__
#include <X11/Xlib.h>
// Keep a persistent X11 connection for emergency mouse release in signal handlers.
// XOpenDisplay inside a signal handler is unreliable, so we open it once at startup.
static Display* g_emergencyDisplay = nullptr;
static void releaseMouseGrab() {
if (g_emergencyDisplay) {
XUngrabPointer(g_emergencyDisplay, CurrentTime);
XUngrabKeyboard(g_emergencyDisplay, CurrentTime);
XFlush(g_emergencyDisplay);
}
}
#else
static void releaseMouseGrab() {}
#endif
static void crashHandler(int sig) {
releaseMouseGrab();
std::signal(sig, SIG_DFL);
std::raise(sig);
}
int main([[maybe_unused]] int argc, [[maybe_unused]] char* argv[]) {
#ifdef __linux__
g_emergencyDisplay = XOpenDisplay(nullptr);
#endif
std::signal(SIGSEGV, crashHandler);
std::signal(SIGABRT, crashHandler);
std::signal(SIGFPE, crashHandler);
std::signal(SIGTERM, crashHandler);
std::signal(SIGINT, crashHandler);
try {
wowee::core::Logger::getInstance().setLogLevel(wowee::core::LogLevel::INFO);
LOG_INFO("=== Wowee Native Client ===");
LOG_INFO("Starting application...");
wowee::core::Application app;
if (!app.initialize()) {
LOG_FATAL("Failed to initialize application");
return 1;
}
app.run();
app.shutdown();
LOG_INFO("Application exited successfully");
#ifdef __linux__
if (g_emergencyDisplay) { XCloseDisplay(g_emergencyDisplay); g_emergencyDisplay = nullptr; }
#endif
return 0;
}
catch (const std::exception& e) {
releaseMouseGrab();
LOG_FATAL("Unhandled exception: ", e.what());
return 1;
}
catch (...) {
releaseMouseGrab();
LOG_FATAL("Unknown exception occurred");
return 1;
}
}