Source tree in arch made more compact
[AROS.git] / arch / all-hosted / hidd / x11 / fullscreen.c
blobe0173435f13cc6b3d9bf309534344d95f5299f45
1 #include <aros/config.h>
2 #include <X11/Xlib.h>
4 #if USE_VIDMODE
6 #include <X11/extensions/xf86vmode.h>
8 #define __typedef_BYTE
9 #define __typedef_BOOL
10 typedef unsigned char UBYTE;
12 #include <aros/symbolsets.h>
14 #define DEBUG 0
15 #include <aros/debug.h>
18 #include <proto/hostlib.h>
20 static void *xvm_handle = NULL;
22 static struct {
23 Bool (*XF86VidModeSwitchToMode) ( Display* , int , XF86VidModeModeInfo* );
24 Bool (*XF86VidModeSetViewPort) ( Display* , int , int , int );
25 Bool (*XF86VidModeQueryVersion) ( Display* , int* , int* );
26 Bool (*XF86VidModeQueryExtension) ( Display* , int* , int* );
27 Bool (*XF86VidModeGetAllModeLines) ( Display* , int , int* , XF86VidModeModeInfo*** );
28 } xvm_func;
30 static const char *xvm_func_names[] = {
31 "XF86VidModeSwitchToMode",
32 "XF86VidModeSetViewPort",
33 "XF86VidModeQueryVersion",
34 "XF86VidModeQueryExtension",
35 "XF86VidModeGetAllModeLines"
38 #define XVM_SOFILE "libXxf86vm.so.1"
40 #define XVMCALL(func,...) (xvm_func.func(__VA_ARGS__))
42 extern void *x11_hostlib_load_so(const char *, const char **, int, void **);
44 static int xvm_hostlib_init(void *libbase) {
45 D(bug("[x11] xvm hostlib init\n"));
47 if ((xvm_handle = x11_hostlib_load_so(XVM_SOFILE, xvm_func_names, 5, (void **) &xvm_func)) == NULL)
48 return FALSE;
50 return TRUE;
53 static int xvm_hostlib_expunge(void *libbase) {
54 D(bug("[x11] xvm hostlib expunge\n"));
56 if (xvm_handle != NULL)
57 HostLib_Close(xvm_handle, NULL);
59 return TRUE;
62 ADD2INITLIB(xvm_hostlib_init, 1)
63 ADD2EXPUNGELIB(xvm_hostlib_expunge, 1)
66 static XF86VidModeModeInfo **videomodes;
67 static int num_videomodes;
69 int x11_fullscreen_supported(Display *display)
71 int majorversion, minorversion;
72 int eventbase, errorbase;
74 if (!XVMCALL(XF86VidModeQueryVersion, display, &majorversion, &minorversion))
76 return 0;
79 if (!XVMCALL(XF86VidModeQueryExtension, display, &eventbase, &errorbase))
81 return 0;
84 if (XVMCALL(XF86VidModeGetAllModeLines, display, DefaultScreen(display), &num_videomodes, &videomodes))
86 if (num_videomodes >= 2) return 1;
89 return 0;
92 void x11_fullscreen_switchmode(Display *display, int *w, int *h)
94 int i, mode;
96 for(i = 1, mode = 0; i < num_videomodes; i++)
98 if ((videomodes[i]->hdisplay >= *w) &&
99 (videomodes[i]->vdisplay >= *h) &&
100 (videomodes[i]->hdisplay < videomodes[mode]->hdisplay) &&
101 (videomodes[i]->vdisplay < videomodes[mode]->vdisplay))
103 mode = i;
107 *w = videomodes[mode]->hdisplay;
108 *h = videomodes[mode]->vdisplay;
110 XVMCALL(XF86VidModeSwitchToMode, display, DefaultScreen(display), videomodes[mode]);
111 XVMCALL(XF86VidModeSetViewPort, display, DefaultScreen(display), 0, 0);
114 #else /* if USE_VIDMODE */
116 int x11_fullscreen_supported(Display *display)
118 return 0;
121 void x11_fullscreen_switchmode(Display *display, int *w, int *h)
124 #endif