From f267f4f92ed3e87a726d54ea71cdd8d6eaa7dcf2 Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Sat, 14 Mar 2026 08:52:59 -0700
Subject: [PATCH] Added a --geometry command line option
---
game/init.cpp | 7 ++++++-
game/init.h | 2 +-
game/main.cpp | 11 ++++++++++-
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/game/init.cpp b/game/init.cpp
index 1499f5ab..fdac46c8 100644
--- a/game/init.cpp
+++ b/game/init.cpp
@@ -746,7 +746,7 @@ void CleanUp(void)
/* ----------------------------------------------------------------- */
/* -- Perform some initializations and report failure if we choke */
-int DoInitializations(Uint32 window_flags)
+int DoInitializations(int window_width, int window_height, Uint32 window_flags)
{
int w, h;
SDL_Surface* icon;
@@ -789,10 +789,15 @@ int DoInitializations(Uint32 window_flags)
if (!InitResolutions(w, h)) {
return(-1);
}
+ window_flags |= SDL_WINDOW_HIDDEN;
if (screen->Init(w, h, window_flags, "Maelstrom", icon) < 0){
error("Fatal: %s\n", screen->Error());
return(-1);
}
+ if (window_width && window_height) {
+ SDL_SetWindowSize(screen->GetWindow(), window_width, window_height);
+ }
+ SDL_ShowWindow(screen->GetWindow());
SDL_DestroySurface(icon);
/* Get startup events, which shows the window on Mac OS X */
diff --git a/game/init.h b/game/init.h
index 8ff542f5..6bfcaa33 100644
--- a/game/init.h
+++ b/game/init.h
@@ -22,7 +22,7 @@
#ifndef _init_h
#define _init_h
-extern int DoInitializations(Uint32 window_flags);
+extern int DoInitializations(int window_width, int window_height, Uint32 window_flags);
extern void CleanUp(void);
#endif /* _init_h */
diff --git a/game/main.cpp b/game/main.cpp
index e508bd1c..a1e5bf35 100644
--- a/game/main.cpp
+++ b/game/main.cpp
@@ -138,6 +138,7 @@ void PrintUsage(const char *progname)
SDL_Log("Where <options> can be any of:\n"
" --fullscreen # Run Maelstrom in full-screen mode\n"
" --windowed # Run Maelstrom in windowed mode\n"
+" --geometry WxH # Set the window size to WxH\n"
);
}
@@ -170,6 +171,8 @@ void ShowFrame(void*)
int main(int argc, char *argv[])
{
/* Command line flags */
+ int window_width = 0;
+ int window_height = 0;
Uint32 window_flags = SDL_WINDOW_FULLSCREEN | SDL_WINDOW_RESIZABLE;
/* Initializing Steam can set up environment variables, so do this first */
@@ -191,6 +194,12 @@ int main(int argc, char *argv[])
window_flags |= SDL_WINDOW_FULLSCREEN;
} else if ( strcmp(argv[i], "--windowed") == 0 ) {
window_flags &= ~SDL_WINDOW_FULLSCREEN;
+ } else if ( strcmp(argv[i], "--geometry") == 0 && argv[i+1]) {
+ ++i;
+ if (SDL_sscanf(argv[i], "%dx%d", &window_width, &window_height) != 2) {
+ PrintUsage(argv[0]);
+ exit(1);
+ }
} else if ( strcmp(argv[i], "-NSDocumentRevisionsDebugMode") == 0 && argv[i+1] ) {
// Ignore Xcode debug option
++i;
@@ -204,7 +213,7 @@ int main(int argc, char *argv[])
}
/* Initialize everything. :) */
- if ( DoInitializations(window_flags) < 0 ) {
+ if ( DoInitializations(window_width, window_height, window_flags) < 0 ) {
/* An error message was already printed */
CleanUp();
exit(1);