shithub: choc

Download patch

ref: 075ca5a7617457cb189fcd5ba071dc38b9067582
parent: 3c5aa343cb825f1182f4cc25863cae5a345bc6a3
author: Simon Howard <fraggle@soulsphere.org>
date: Tue May 31 19:27:44 EDT 2016

video: Add a back door for non-desktop fullscreen.

There are some circumstances where it may be useful to be able to
specify plain SDL_WINDOW_FULLSCREEN rather than the "desktop window"
variant. Examples are for embedded devices. Implement this as two
new separate config file variables, but default them to 0x0 to mean
"use SDL_WINDOW_FULLSCREEN_DESKTOP".

--- a/src/i_video.c
+++ b/src/i_video.c
@@ -112,6 +112,10 @@
 int window_width = SCREENWIDTH * 2;
 int window_height = SCREENHEIGHT_4_3 * 2;
 
+// Fullscreen mode, 0x0 for SDL_WINDOW_FULLSCREEN_DESKTOP.
+
+int fullscreen_width = 0, fullscreen_height = 0;
+
 // Run in full screen mode?  (int type for config code)
 
 int fullscreen = true;
@@ -370,6 +374,14 @@
 {
     unsigned int flags = 0;
 
+    // TODO: Consider implementing fullscreen toggle for SDL_WINDOW_FULLSCREEN
+    // (mode-changing) setup. This is hard because we have to shut down and
+    // restart again.
+    if (fullscreen_width != 0 || fullscreen_height != 0)
+    {
+        return;
+    }
+
     fullscreen = !fullscreen;
 
     if (fullscreen)
@@ -376,6 +388,7 @@
     {
         flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
     }
+
     SDL_SetWindowFullscreen(screen, flags);
 
     if (!fullscreen)
@@ -1005,6 +1018,7 @@
 static void SetVideoMode(void)
 {
     byte *doompal;
+    int w, h;
     int flags = 0;
 
     doompal = W_CacheLumpName(DEH_String("PLAYPAL"), PU_CACHE);
@@ -1026,6 +1040,9 @@
         screen = NULL;
     }
 
+    w = window_width;
+    h = window_height;
+
     // In windowed mode, the window can be resized while the game is
     // running.
     flags = SDL_WINDOW_RESIZABLE;
@@ -1036,9 +1053,18 @@
 
     if (fullscreen)
     {
-        // This flags means "Never change the screen resolution! Instead,
-        // draw to the entire screen by scaling the texture appropriately".
-        flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+        if (fullscreen_width == 0 && fullscreen_height == 0)
+        {
+            // This flags means "Never change the screen resolution! Instead,
+            // draw to the entire screen by scaling the texture appropriately".
+            flags |= SDL_WINDOW_FULLSCREEN_DESKTOP;
+        }
+        else
+        {
+            w = fullscreen_width;
+            h = fullscreen_height;
+            flags |= SDL_WINDOW_FULLSCREEN;
+        }
     }
 
     // Create window and renderer contexts. We set the window title
@@ -1047,7 +1073,7 @@
 
     screen = SDL_CreateWindow(NULL,
                               SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
-                              window_width, window_height, flags);
+                              w, h, flags);
 
     if (screen == NULL)
     {
@@ -1215,6 +1241,8 @@
     M_BindIntVariable("fullscreen",                &fullscreen);
     M_BindIntVariable("aspect_ratio_correct",      &aspect_ratio_correct);
     M_BindIntVariable("startup_delay",             &startup_delay);
+    M_BindIntVariable("fullscreen_width",          &fullscreen_width);
+    M_BindIntVariable("fullscreen_height",         &fullscreen_height);
     M_BindIntVariable("window_width",              &window_width);
     M_BindIntVariable("window_height",             &window_height);
     M_BindIntVariable("grabmouse",                 &grabmouse);
--- a/src/m_config.c
+++ b/src/m_config.c
@@ -732,6 +732,21 @@
     CONFIG_VARIABLE_INT(window_height),
 
     //!
+    // Width for screen mode when running fullscreen.
+    // If this and fullscreen_height are both set to zero, we run
+    // fullscreen as a desktop window that covers the entire screen,
+    // rather than ever switching screen modes. It should usually
+    // be unnecessary to set this value.
+    //
+    CONFIG_VARIABLE_INT(fullscreen_width),
+
+    //!
+    // Height for screen mode when running fullscreen.
+    // See documentation for fullscreen_width.
+    //
+    CONFIG_VARIABLE_INT(fullscreen_height),
+
+    //!
     // If this is non-zero, the mouse will be "grabbed" when running
     // in windowed mode so that it can be used as an input device.
     // When running full screen, this has no effect.
--- a/src/setup/display.c
+++ b/src/setup/display.c
@@ -71,8 +71,8 @@
 static char *window_position = "";
 static int aspect_ratio_correct = 1;
 static int fullscreen = 1;
-static int window_width = 640;
-static int window_height = 480;
+static int fullscreen_width = 0, fullscreen_height = 0;
+static int window_width = 640, window_height = 480;
 static int startup_delay = 1000;
 static int usegamma = 0;
 
@@ -341,6 +341,8 @@
 {
     M_BindIntVariable("aspect_ratio_correct",      &aspect_ratio_correct);
     M_BindIntVariable("fullscreen",                &fullscreen);
+    M_BindIntVariable("fullscreen_width",          &fullscreen_width);
+    M_BindIntVariable("fullscreen_height",         &fullscreen_height);
     M_BindIntVariable("window_width",              &window_width);
     M_BindIntVariable("window_height",             &window_height);
     M_BindIntVariable("startup_delay",             &startup_delay);