8
#include <X11/extensions/xf86dga.h>
9
#include <X11/extensions/xf86vmode.h>
12
aktionVm::aktionVm(QWidget *parent) : QWidget(parent)
16
bool aktionVm::setVideoMode(int*w,int*h)
18
XF86VidModeModeInfo **modes;
21
/* Get all available video modes */
22
XF86VidModeGetAllModeLines( x11Display(), DefaultScreen(x11Display()), &nmodes, &modes);
26
int winnerRatio=32000;
27
XF86VidModeModeInfo *selected=0L;
29
/* Save the original video mode settings */
30
XF86DGAGetViewPortSize(x11Display(),DefaultScreen(x11Display()), &prevW, &prevH);
32
/* Search for the closest video mode */
33
for ( i=0; i<nmodes; ++i )
35
/* first check if the video mode fits the requested size */
36
if ((modes[i]->hdisplay >= *w) && (modes[i]->vdisplay >= *h))
38
/* calculates a near-ratio to find the closest vm */
39
ratio=(modes[i]->hdisplay - *w) + (modes[i]->vdisplay - *h);
40
if (ratio < winnerRatio)
50
if ((selected->hdisplay!=prevW) || (selected->vdisplay!=prevH))
52
/* Switch to the selected video mode */
53
XF86VidModeSwitchToMode(x11Display(),DefaultScreen(x11Display()), selected);
54
XF86VidModeSetViewPort(x11Display(),DefaultScreen(x11Display()),0,0);
56
/* return the selected video mode */
57
*w=selected->hdisplay;
58
*h=selected->vdisplay;
65
void aktionVm::resetVideoMode()
67
XF86VidModeModeInfo **modes;
70
/* Get all available video modes */
71
XF86VidModeGetAllModeLines( x11Display(), DefaultScreen(x11Display()), &nmodes, &modes);
77
XF86DGAGetViewPortSize(x11Display(),DefaultScreen(x11Display()), &w, &h);
78
if ((w!=prevW) || (h!=prevH))
79
while (!found && i<nmodes)
81
if ((modes[i]->hdisplay == prevW) && (modes[i]->vdisplay == prevH))
83
/* Switch to the previous video mode */
84
XF86VidModeSwitchToMode(x11Display(),DefaultScreen(x11Display()), modes[i]);