-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsdlnolock.c
56 lines (43 loc) · 1.22 KB
/
sdlnolock.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
* LD_PRELOAD interposer library for SDL to prevent full-screen grabbing.
*
* - Replaces SDL_FULLSCREEN flag with SDL_NOFRAME in SDL_SetVideoMode.
* - Replaces SDL_GRAB_ON mode with SDL_GRAB_OFF in SDL_WM_GrabInput.
*
* 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);
}
typedef enum {
SDL_GRAB_QUERY = -1,
SDL_GRAB_OFF = 0,
SDL_GRAB_ON = 1
} SDL_GrabMode;
SDL_GrabMode SDL_WM_GrabInput(SDL_GrabMode mode) {
static SDL_GrabMode(*real_func)(SDL_GrabMode) = NULL;
if (real_func == NULL) {
real_func = dlsym(RTLD_NEXT, "SDL_WM_GrabInput");
assert(real_func != NULL);
}
if (mode == SDL_GRAB_ON) {
mode = SDL_GRAB_OFF;
}
return real_func(mode);
}