foxygit / doom Log in
commit cfbdd3d79d1e3cc48165536cb7b4166b94f77e9b
Author:     Simon Howard <fraggle@gmail.com>
AuthorDate: Sun Oct 23 23:23:15 2011 +0000
Commit:     Simon Howard <fraggle@gmail.com>
CommitDate: Sun Oct 23 23:23:15 2011 +0000

    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
---
 src/i_video.c       | 29 +++++++++++++++++++++++++++--
 src/m_config.c      | 10 +++++++++-
 src/setup/display.c |  2 ++
 3 files changed, 38 insertions(+), 3 deletions(-)

diff --git a/src/i_video.c b/src/i_video.c
index 14a78279..7ba4c8cd 100644
--- a/src/i_video.c
+++ b/src/i_video.c
@@ -136,6 +136,10 @@ static screen_mode_t *screen_modes_corrected[] = {

 char *video_driver = "";

+// Window position:
+
+static char *window_position = "";
+
 // SDL surface for the screen.

 static SDL_Surface *screen;
@@ -1857,6 +1861,27 @@ static void SetSDLVideoDriver(void)
 #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 @@ static void SetVideoMode(screen_mode_t *mode, int w, int h)
 #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 @@ void I_InitGraphics(void)
     }

     SetSDLVideoDriver();
+    SetWindowPositionVars();

     if (SDL_Init(SDL_INIT_VIDEO) < 0)
     {
@@ -2186,6 +2210,7 @@ void I_BindVideoVariables(void)
     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);
diff --git a/src/m_config.c b/src/m_config.c
index 762e6eaf..e66e28e7 100644
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -770,7 +770,15 @@ static default_t extra_defaults_list[] =
     // 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

diff --git a/src/setup/display.c b/src/setup/display.c
index 92b436b7..d22cc67b 100644
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -102,6 +102,7 @@ static int num_screen_modes_fullscreen;
 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 @@ void BindDisplayVariables(void)
     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);