diff --git a/include/aurora/aurora.h b/include/aurora/aurora.h index 1cc9877..1bd6af9 100644 --- a/include/aurora/aurora.h +++ b/include/aurora/aurora.h @@ -31,6 +31,11 @@ typedef enum { LOG_FATAL, } AuroraLogLevel; +typedef struct { + int32_t x; + int32_t y; +} AuroraWindowPos; + typedef struct { uint32_t width; uint32_t height; @@ -52,6 +57,8 @@ typedef struct { uint32_t msaa; uint16_t maxTextureAnisotropy; bool startFullscreen; + int32_t windowPosX; + int32_t windowPosY; uint32_t windowWidth; uint32_t windowHeight; void* iconRGBA8; diff --git a/include/aurora/event.h b/include/aurora/event.h index 0cb7146..3af13f0 100644 --- a/include/aurora/event.h +++ b/include/aurora/event.h @@ -17,6 +17,7 @@ typedef enum { AURORA_NONE, AURORA_EXIT, AURORA_SDL_EVENT, + AURORA_WINDOW_MOVED, AURORA_WINDOW_RESIZED, AURORA_CONTROLLER_ADDED, AURORA_CONTROLLER_REMOVED, @@ -28,6 +29,7 @@ struct AuroraEvent { AuroraEventType type; union { SDL_Event sdl; + AuroraWindowPos windowPos; AuroraWindowSize windowSize; int32_t controller; }; diff --git a/lib/window.cpp b/lib/window.cpp index 1292742..1f1a7d8 100644 --- a/lib/window.cpp +++ b/lib/window.cpp @@ -59,6 +59,13 @@ const AuroraEvent* poll_events() { }); break; } + case SDL_WINDOWEVENT_MOVED: { + g_events.push_back(AuroraEvent{ + .type = AURORA_WINDOW_MOVED, + .windowPos = {.x = event.window.data1, .y = event.window.data2}, + }); + break; + } case SDL_WINDOWEVENT_SIZE_CHANGED: { resize_swapchain(false); g_events.push_back(AuroraEvent{ @@ -154,8 +161,16 @@ bool create_window(AuroraBackend backend) { width = 1280; height = 960; } + + int32_t x = g_config.windowPosX; + int32_t y = g_config.windowPosY; + if (x < 0 || y < 0) { + x = SDL_WINDOWPOS_UNDEFINED; + y = SDL_WINDOWPOS_UNDEFINED; + } + #endif - g_window = SDL_CreateWindow(g_config.appName, SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED, width, height, flags); + g_window = SDL_CreateWindow(g_config.appName, x, y, width, height, flags); if (g_window == nullptr) { Log.report(LOG_WARNING, FMT_STRING("Failed to create window: {}"), SDL_GetError()); return false; @@ -196,7 +211,8 @@ void show_window() { bool initialize() { /* We don't want to initialize anything input related here, otherwise the add events will get lost to the void */ - ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) == 0, "Error initializing SDL: {}", SDL_GetError()); + ASSERT(SDL_Init(SDL_INIT_EVERYTHING & ~(SDL_INIT_HAPTIC | SDL_INIT_JOYSTICK | SDL_INIT_GAMECONTROLLER)) == 0, + "Error initializing SDL: {}", SDL_GetError()); #if !defined(_WIN32) && !defined(__APPLE__) SDL_SetHint(SDL_HINT_VIDEO_X11_NET_WM_BYPASS_COMPOSITOR, "0");