5f94bc087c3f8f9c7d928164989bcc11496fad94
[qemu] / qemu-gtk / xvid_fs.c
1 /* Use X11 Xvid extension to implement fullscreen mode */
2
3 #include <stdlib.h>
4 #include <X11/Xlib.h>
5 #include <X11/Xutil.h>
6 #include <X11/keysym.h>
7 #include <X11/extensions/xf86dga.h>
8 #include <X11/extensions/xf86vmode.h>
9
10 static Display *dpy = NULL;
11 static XF86VidModeModeInfo **mode_list = NULL;
12 static XF86VidModeModeInfo * modeinfo = NULL;
13 static int count = 0;
14
15 int fullscreen_init(void)
16 {
17         int event, error, dotclock;
18         XF86VidModeModeLine * modeline;
19
20         /* load up X display and make sure we have the Xvid extention */
21         dpy = XOpenDisplay(""); /* FIXME: make this the one that Gtk uses */
22         if (dpy == NULL)
23                 return 0;
24         if (!XF86VidModeQueryExtension(dpy, &event, &error))
25                 return 0;
26
27         /* get list of all modes */
28         XF86VidModeGetAllModeLines(dpy, XDefaultScreen(dpy), &count, &mode_list);
29
30         /* get current modeline */
31         modeline = (XF86VidModeModeLine *)malloc(sizeof(XF86VidModeModeLine));
32         XF86VidModeGetModeLine(dpy, XDefaultScreen(dpy), &dotclock, modeline);
33
34         /* convert to ModeInfo structure */
35         modeinfo = (XF86VidModeModeInfo *)malloc(sizeof(XF86VidModeModeInfo));
36         modeinfo->dotclock = dotclock;
37         modeinfo->hdisplay = modeline->hdisplay;
38         modeinfo->hsyncstart = modeline->hsyncstart;
39         modeinfo->hsyncend = modeline->hsyncend;
40         modeinfo->htotal = modeline->htotal;
41         modeinfo->vdisplay = modeline->vdisplay;
42         modeinfo->vsyncstart = modeline->vsyncstart;
43         modeinfo->vsyncend = modeline->vsyncend;
44         modeinfo->vtotal = modeline->vtotal;
45         modeinfo->flags = modeline->flags;
46         modeinfo->privsize = modeline->privsize;
47         modeinfo->private = modeline->private;
48         free(modeline);
49
50         return 1;
51 }
52
53 int fullscreen_switch(int x, int y, int w, int h)
54 {
55         int i;
56         for (i = 0; i < count; i++)
57         {
58                 if (w == mode_list[i]->hdisplay)
59                         if (h == mode_list[i]->vdisplay)
60                         {
61                                 XF86VidModeSwitchToMode(dpy, XDefaultScreen(dpy), mode_list[i]);
62                                 XF86VidModeSetViewPort(dpy, XDefaultScreen(dpy), 0, 0);
63                                 XFlush(dpy);
64                                 return 1;
65                         }
66         }
67         return 0;
68 }
69
70 int fullscreen_reset(void)
71 {
72         XF86VidModeSwitchToMode(dpy, XDefaultScreen(dpy), modeinfo);
73         XFlush(dpy);
74         return 1;
75 }
76
77 void fullscreen_cleanup(void)
78 {
79         int i;
80         if (modeinfo)
81         {
82                 if (modeinfo->privsize != 0)
83                         free(modeinfo->private);
84                 free(modeinfo);
85         }
86         if (mode_list)
87         {
88                 for (i = 0; i < count; i++)
89                 {
90                         if (mode_list[i])
91                         {
92                                 if (mode_list[i]->privsize != 0)
93                                         free(mode_list[i]->private);
94                                 //free(mode_list[i]);
95                         }
96                 }
97                 free(mode_list);
98         }
99 }