~ubuntu-branches/ubuntu/hoary/kdemultimedia/hoary

« back to all changes in this revision

Viewing changes to aktion/aktionVm.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Martin Schulze
  • Date: 2003-01-22 15:00:51 UTC
  • Revision ID: james.westby@ubuntu.com-20030122150051-uihwkdoxf15mi1tn
Tags: upstream-2.2.2
ImportĀ upstreamĀ versionĀ 2.2.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#include "aktionVm.h"
 
2
 
 
3
#ifdef XF86_VM
 
4
 
 
5
#include <iostream>
 
6
 
 
7
#include <X11/Xlib.h>
 
8
#include <X11/extensions/xf86dga.h>
 
9
#include <X11/extensions/xf86vmode.h>
 
10
 
 
11
 
 
12
aktionVm::aktionVm(QWidget *parent) : QWidget(parent)
 
13
{
 
14
}
 
15
 
 
16
bool aktionVm::setVideoMode(int*w,int*h)
 
17
{
 
18
   XF86VidModeModeInfo **modes;
 
19
   int nmodes;
 
20
 
 
21
   /* Get all available video modes */
 
22
   XF86VidModeGetAllModeLines( x11Display(), DefaultScreen(x11Display()), &nmodes, &modes);
 
23
 
 
24
   int i=0;
 
25
   int ratio=0;
 
26
   int winnerRatio=32000;
 
27
   XF86VidModeModeInfo *selected=0L;
 
28
 
 
29
   /* Save the original video mode settings */
 
30
   XF86DGAGetViewPortSize(x11Display(),DefaultScreen(x11Display()), &prevW, &prevH);
 
31
 
 
32
   /* Search for the closest video mode */
 
33
   for ( i=0; i<nmodes; ++i )
 
34
   {
 
35
      /* first check if the video mode fits the requested size */
 
36
      if ((modes[i]->hdisplay >= *w) && (modes[i]->vdisplay >= *h))
 
37
      {
 
38
         /* calculates a near-ratio to find the closest vm */
 
39
         ratio=(modes[i]->hdisplay - *w) + (modes[i]->vdisplay - *h);
 
40
         if (ratio < winnerRatio)
 
41
         {
 
42
            winnerRatio=ratio;
 
43
            selected=modes[i];
 
44
         }
 
45
      }
 
46
   }
 
47
 
 
48
   if ( selected!=0L )
 
49
   {
 
50
      if ((selected->hdisplay!=prevW) || (selected->vdisplay!=prevH))
 
51
      {
 
52
         /* Switch to the selected video mode */
 
53
         XF86VidModeSwitchToMode(x11Display(),DefaultScreen(x11Display()), selected);
 
54
         XF86VidModeSetViewPort(x11Display(),DefaultScreen(x11Display()),0,0);
 
55
      }
 
56
      /* return the selected video mode */
 
57
      *w=selected->hdisplay;
 
58
      *h=selected->vdisplay;
 
59
      return true;
 
60
   }
 
61
   else
 
62
      return false;
 
63
}
 
64
 
 
65
void aktionVm::resetVideoMode()
 
66
{
 
67
   XF86VidModeModeInfo **modes;
 
68
   int nmodes;
 
69
 
 
70
   /* Get all available video modes */
 
71
   XF86VidModeGetAllModeLines( x11Display(), DefaultScreen(x11Display()), &nmodes, &modes);
 
72
 
 
73
   int i=0;
 
74
   bool found=false;
 
75
   int w, h;
 
76
 
 
77
   XF86DGAGetViewPortSize(x11Display(),DefaultScreen(x11Display()), &w, &h);
 
78
   if ((w!=prevW) || (h!=prevH))
 
79
      while (!found && i<nmodes)
 
80
      {
 
81
         if ((modes[i]->hdisplay == prevW) && (modes[i]->vdisplay == prevH))
 
82
         {
 
83
            /* Switch to the previous video mode */
 
84
            XF86VidModeSwitchToMode(x11Display(),DefaultScreen(x11Display()), modes[i]);
 
85
            found=true;
 
86
         }
 
87
         else
 
88
            i++;
 
89
      }
 
90
 
 
91
}
 
92
 
 
93
#endif