shithub: choc

Download patch

ref: cfbdd3d79d1e3cc48165536cb7b4166b94f77e9b
parent: ac37ee17e8718cfe88e0adb5c972965f7e4d2c00
author: Simon Howard <fraggle@gmail.com>
date: Sun Oct 23 19:23:15 EDT 2011

Remove hack that forces the window to always be centered within the
screen. Add a configuration file variable to control where the game
window should appear.

Subversion-branch: /branches/v2-branch
Subversion-revision: 2467

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -136,6 +136,10 @@
 
 char *video_driver = "";
 
+// Window position:
+
+static char *window_position = "";
+
 // SDL surface for the screen.
 
 static SDL_Surface *screen;
@@ -1857,6 +1861,27 @@
 #endif
 }
 
+static void SetWindowPositionVars(void)
+{
+    char buf[64];
+    int x, y;
+
+    if (window_position == NULL || !strcmp(window_position, ""))
+    {
+        return;
+    }
+
+    if (!strcmp(window_position, "center"))
+    {
+        putenv("SDL_VIDEO_CENTERED=1");
+    }
+    else if (sscanf(window_position, "%i,%i", &x, &y) == 2)
+    {
+        sprintf(buf, "SDL_VIDEO_WINDOW_POS=%i,%i", x, y);
+        putenv(buf);
+    }
+}
+
 static char *WindowBoxType(screen_mode_t *mode, int w, int h)
 {
     if (mode->width != w && mode->height != h) 
@@ -1921,8 +1946,6 @@
 #ifndef __MACOSX__
         flags |= SDL_RESIZABLE;
 #endif
-        // villsa - center window
-        SDL_putenv("SDL_VIDEO_CENTERED=1");
     }
 
     screen = SDL_SetVideoMode(w, h, screen_bpp, flags);
@@ -2030,6 +2053,7 @@
     }
 
     SetSDLVideoDriver();
+    SetWindowPositionVars();
 
     if (SDL_Init(SDL_INIT_VIDEO) < 0) 
     {
@@ -2186,6 +2210,7 @@
     M_BindVariable("mouse_acceleration",        &mouse_acceleration);
     M_BindVariable("mouse_threshold",           &mouse_threshold);
     M_BindVariable("video_driver",              &video_driver);
+    M_BindVariable("window_position",           &window_position);
     M_BindVariable("usegamma",                  &usegamma);
     M_BindVariable("vanilla_keyboard_mapping",  &vanilla_keyboard_mapping);
     M_BindVariable("novert",                    &novert);
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -770,7 +770,15 @@
     // the default video driver is used.
     //
 
-    CONFIG_VARIABLE_STRING(video_driver), 
+    CONFIG_VARIABLE_STRING(video_driver),
+
+    //!
+    // Position of the window on the screen when running in windowed
+    // mode. Accepted values are: "" (empty string) - don't care,
+    // "center" - place window at center of screen, "x,y" - place
+    // window at the specified coordinates.
+
+    CONFIG_VARIABLE_STRING(window_position),
 
 #ifdef FEATURE_MULTIPLAYER
 
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -102,6 +102,7 @@
 static int vidmode = 0;
 
 static char *video_driver = "";
+static char *window_position = "";
 static int autoadjust_video_settings = 1;
 static int aspect_ratio_correct = 1;
 static int fullscreen = 1;
@@ -790,6 +791,7 @@
     M_BindVariable("screen_bpp",                &screen_bpp);
     M_BindVariable("startup_delay",             &startup_delay);
     M_BindVariable("video_driver",              &video_driver);
+    M_BindVariable("window_position",           &window_position);
     M_BindVariable("usegamma",                  &usegamma);