Permalink
Browse files

Initial commit of sdlnolock

  • Loading branch information...
0 parents commit 69fa24d82a15ff3652f0c225d3d20f3348da4179 @dreiss committed Oct 15, 2011
Showing with 73 additions and 0 deletions.
  1. +11 −0 Makefile
  2. +29 −0 README
  3. +33 −0 sdlnolock.c
@@ -0,0 +1,11 @@
+all: sdlnolock.so
+
+sdlnolock.so: sdlnolock.o
+ $(CC) -shared -fpic -o $@ $<
+
+CFLAGS = -fpic -g -O0 -Wall -Wextra -Werror
+
+.PHONY: clean
+
+clean:
+ $(RM) sdlnolock.so sdlnolock.o
@@ -0,0 +1,29 @@
+sdlnolock: prevent SDL from locking the screen
+
+Many Linux games use the SDL fullscreen option.
+On my system, this prevents me from alt-tabbing out
+or even using my volume keys.
+This LD_PRELOAD library wraps SDL_SetVideoMode
+to replace the SDL_FULLSCREEN flag with SDL_NOFRAME.
+I've gotten much better results with this.
+
+
+Copyright (c) David Reiss
+
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+SOFTWARE.
@@ -0,0 +1,33 @@
+/*
+ * LD_PRELOAD interposer library for SDL to prevent full-screen grabbing.
+ *
+ * - Replaces SDL_FULLSCREEN flag with SDL_NOFRAME in SDL_SetVideoMode.
+ *
+ * Copyright David Reiss. MIT License
+ */
+
+#define _GNU_SOURCE
+#include <assert.h>
+#include <dlfcn.h>
+#include <stddef.h>
+#include <stdint.h>
+
+
+#define SDL_FULLSCREEN 0x80000000u
+#define SDL_NOFRAME 0x00000020u
+
+void* SDL_SetVideoMode(int width, int height, int bitsperpixel, uint32_t flags) {
+ static void*(*real_func)(int,int,int,uint32_t) = NULL;
+
+ if (real_func == NULL) {
+ real_func = dlsym(RTLD_NEXT, "SDL_SetVideoMode");
+ assert(real_func != NULL);
+ }
+
+ if (flags & SDL_FULLSCREEN) {
+ flags &= ~SDL_FULLSCREEN;
+ flags |= SDL_NOFRAME;
+ }
+
+ return real_func(width, height, bitsperpixel, flags);
+}

0 comments on commit 69fa24d

Please sign in to comment.