Skip to content

Instantly share code, notes, and snippets.

@digulla
Created December 4, 2011 11:43
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save digulla/1429985 to your computer and use it in GitHub Desktop.
Save digulla/1429985 to your computer and use it in GitHub Desktop.
Patch to force a certain window/screen size in SDL games
--- SDL-1.2.14/src/video/x11/SDL_x11modes.c 2009-10-13 01:07:15.000000000 +0200
+++ SDL-1.2.14/src/video/x11/SDL_x11modes.c 2011-12-04 12:34:55.000000000 +0100
@@ -33,7 +33,7 @@
#include "SDL_x11modes_c.h"
#include "SDL_x11image_c.h"
-/*#define X11MODES_DEBUG*/
+#define X11MODES_DEBUG
#define MAX(a, b) (a > b ? a : b)
@@ -538,6 +538,9 @@
use_xme = 0;
screen_w = DisplayWidth(SDL_Display, SDL_Screen);
screen_h = DisplayHeight(SDL_Display, SDL_Screen);
+#ifdef X11MODES_DEBUG
+ printf("screen_w=%d screen_h=%d\n", screen_w, screen_h);
+#endif
#if SDL_VIDEO_DRIVER_X11_XINERAMA
/* Query Xinerama extention */
@@ -556,7 +559,7 @@
desired = SDL_atoi(variable);
}
#ifdef X11MODES_DEBUG
- printf("X11 detected Xinerama:\n");
+ printf("X11 detected Xinerama. desired=%d\n", desired);
#endif
xinerama = SDL_NAME(XineramaQueryScreens)(SDL_Display, &screens);
for ( i = 0; i < screens; i++ ) {
@@ -841,6 +844,43 @@
XFree(pf);
}
+ char * videoSize = getenv( "SDL_VIDEO_SIZE" );
+ if ( videoSize ) {
+ char * splitPos = strchr( videoSize, 'x' );
+ if( ! splitPos ) {
+ fprintf(stderr, "Unexpected value in SDL_VIDEO_SIZE: Missing 'x' %s\n", videoSize);
+ }
+ char buffer[64];
+ strncpy( buffer, videoSize, sizeof( buffer ) - 1 );
+ char * ptr = strtok(buffer, "x");
+
+ int width = atoi(ptr);
+ ptr = strtok(NULL, "x");
+ int height = atoi(ptr);
+
+ printf("Overriding size: %d x %d\n", width, height);
+
+ if ( SDL_modelist ) {
+ for ( i = 0; SDL_modelist[i]; ++i ) {
+ SDL_free(SDL_modelist[i]);
+ }
+ SDL_free(SDL_modelist);
+ }
+ SDL_modelist = (SDL_Rect **)SDL_malloc(2*sizeof(SDL_Rect *));
+ if ( !SDL_modelist ) {
+ SDL_OutOfMemory();
+ return -1;
+ }
+
+ SDL_modelist[0] = (SDL_Rect *)SDL_malloc(sizeof(SDL_Rect));
+ SDL_modelist[0]->x = 0;
+ SDL_modelist[0]->y = 0;
+ SDL_modelist[0]->w = width;
+ SDL_modelist[0]->h = height;
+
+ SDL_modelist[1] = NULL;
+ }
+
if ( SDL_modelist == NULL ) {
SDL_modelist = (SDL_Rect **)SDL_malloc((1+1)*sizeof(SDL_Rect *));
if ( !SDL_modelist ) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment