1 /***************************************************************************
2 vidmode.cpp - video mode switching
4 begin : Tue June 3 03:08:00 CET 2002
5 copyright : (C) 2002 by Tim Jansen
7 ***************************************************************************/
9 /***************************************************************************
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
16 ***************************************************************************/
18 #include <config-krdc.h>
21 #ifdef HAVE_VIDMODE_EXTENSION
22 #include <X11/extensions/xf86vmode.h>
27 #ifdef HAVE_VIDMODE_EXTENSION
29 void vidmodeNormalSwitch(Display
*dpy
, Resolution oldResolution
)
31 if (!oldResolution
.valid
)
34 XF86VidModeModeInfo
**modes
;
38 if (!XF86VidModeQueryExtension(dpy
, &eventB
, &errorB
))
41 if (!XF86VidModeGetAllModeLines(dpy
,oldResolution
.screen
,&modecount
, &modes
))
44 for (int i
= 0; i
< modecount
; i
++) {
45 int w
= (*modes
[i
]).hdisplay
;
46 int h
= (*modes
[i
]).vdisplay
;
48 if ((oldResolution
.width
== w
) &&
49 (oldResolution
.height
== h
)) {
50 XF86VidModeSwitchToMode(dpy
,oldResolution
.screen
,modes
[i
]);
52 XF86VidModeSetViewPort(dpy
,DefaultScreen(dpy
),0,0);
59 Resolution
vidmodeFullscreenSwitch(Display
*dpy
, int screen
,
60 int sw
, int sh
, int &nx
, int &ny
)
62 XF86VidModeModeInfo
**modes
;
71 if (!XF86VidModeQueryExtension(dpy
, &eventB
, &errorB
))
74 if (!XF86VidModeGetAllModeLines(dpy
,screen
,&modecount
, &modes
))
77 int cw
= (*modes
[0]).hdisplay
;
78 int ch
= (*modes
[0]).vdisplay
;
81 if ((cw
== sw
) && (ch
== sh
))
83 bool foundLargeEnoughRes
= (cw
>=sw
) && (ch
>=sh
);
87 for (int i
= 1; i
< modecount
; i
++) {
88 int w
= (*modes
[i
]).hdisplay
;
89 int h
= (*modes
[i
]).vdisplay
;
91 if ((w
== cw
) && (h
== ch
))
94 /* If resolution matches framebuffer, take it */
95 if ((w
== sw
) && (h
== sh
)) {
101 /* if resolution larger than framebuffer... */
102 if ((w
>=sw
) && (h
>=sh
)) {
103 /* and no other previously found resoltion was smaller or
104 this is smaller than the best resolution so far, take it*/
105 if ((!foundLargeEnoughRes
) ||
106 (w
*h
< bestw
*besth
)) {
110 foundLargeEnoughRes
= true;
113 /* If all resolutions so far were smaller than framebuffer... */
114 else if (!foundLargeEnoughRes
) {
115 /* take this one it it is bigger then they were */
116 if (w
*h
> bestw
*besth
) {
129 XF86VidModeSwitchToMode(dpy
,screen
,modes
[bestmode
]);
130 XF86VidModeSetViewPort(dpy
,screen
,0,0);
133 return Resolution(cw
, ch
, screen
);
138 void vidmodeNormalSwitch(Display
*dpy
, Resolution oldResolution
)
142 Resolution
vidmodeFullscreenSwitch(Display
*dpy
, int screen
, int sw
, int sh
, int &nx
, int &ny
)
149 void grabInput(Display
*dpy
, unsigned int winId
) {
150 XGrabPointer(dpy
, winId
, True
, 0,
151 GrabModeAsync
, GrabModeAsync
,
152 winId
, None
, CurrentTime
);
156 void ungrabInput(Display
*dpy
) {
157 XUngrabPointer(dpy
, CurrentTime
);