todo
[hband-ld-preload-libs.git] / src / xopenhook.c
blob9956bf3a6b89e04b65ac2e2309ca403c2c7d5d5e
2 #include <stdlib.h>
3 #include <stdio.h>
4 #include <dlfcn.h>
5 #include <unistd.h>
6 #include <err.h>
7 #include <errno.h>
8 #include <string.h>
9 #include <sys/stat.h>
10 #include <X11/Xlib.h>
12 void _xopenhook_preload_run(const char * phase)
14 char * xopenhook_enable = getenv("XOPENHOOK_ENABLE");
15 if(xopenhook_enable != NULL && strcmp(xopenhook_enable, "1")==0)
17 unsetenv("XOPENHOOK_ENABLE");
18 setenv("XOPENHOOK_PHASE", phase, 1);
19 system(getenv("XOPENHOOK_COMMAND"));
20 unsetenv("XOPENHOOK_PHASE");
21 setenv("XOPENHOOK_ENABLE", xopenhook_enable, 1);
25 Display* XOpenDisplay(const char * display_name)
27 Display* (*real_XOpenDisplay)(const char *) = dlsym(RTLD_NEXT, "XOpenDisplay");
29 Display* display_handle = real_XOpenDisplay(display_name);
30 if(display_handle != NULL) _xopenhook_preload_run("post-XOpenDisplay");
32 return display_handle;
36 #include <Xvlibint.h>
38 XvImageFormatValues * XvListImageFormats (
39 Display *dpy,
40 XvPortID port,
41 int *num
43 XvImageFormatValues* (*real_XvListImageFormats)(Display*, XvPortID, int*) = dlsym(RTLD_NEXT, "XvListImageFormats");
45 _xopenhook_preload_run("pre-XvListImageFormats");
46 XvImageFormatValues *ret = real_XvListImageFormats(dpy, port, num);
47 _xopenhook_preload_run("post-XvListImageFormats");
49 return ret;