summaryrefslogtreecommitdiffstats
path: root/kipi-plugins/slideshow/screenproperties.cpp
blob: aa6e92d58b1be28adbd4a732beffc99694ebc9b8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
/* ============================================================
 *
 * This file is a part of kipi-plugins project
 * http://www.kipi-plugins.org
 *
 * Date        : 2007-11-14
 * Description : a kipi plugin to slide images.
 *
 * Copyright (C) 2007 by Valerio Fuoglio <valerio dot fuoglio at gmail dot com>
 *
 * Parts of this code are based on smoothslidesaver by Carsten Weinhold 
 * <carsten dot weinhold at gmx dot de>                                           
 *
 * This program is free software; you can redistribute it
 * and/or modify it under the terms of the GNU General
 * Public License as published by the Free Software Foundation;
 * either version 2, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * ============================================================ */

// TQt includes.

#include <tqapplication.h>

// X11 includes.

#include <X11/Xlib.h>
#include <X11/extensions/Xrandr.h>

// Local includes.

#include "screenproperties.h"

namespace KIPISlideShowPlugin
{

  ScreenProperties::ScreenProperties(TQWidget *mainWidget) {
  
      activeScreen = TQApplication::desktop()->screenNumber(mainWidget);
  }
    
  unsigned ScreenProperties::suggestFrameRate() {
  
      int eventBase, errorBase;
      if ( !XRRQueryExtension(qt_xdisplay(), &eventBase, &errorBase)) {
          // No information, make a lucky guess on based on that ;)
          return 25;
      }
  
      // ask X11 for the refresh rate of the current screen
      XRRScreenConfiguration* config;
      int screenRate;
  
      config        = XRRGetScreenInfo(qt_xdisplay(), RootWindow(qt_xdisplay(),
                                      activeScreen));
      screenRate    = XRRConfigCurrentRate(config);
      XRRFreeScreenConfigInfo(config);
      //tqDebug("monitor refresh rate %d Hz", screenRate);
  
      // Find the frame rate, that matches the monitor's refresh rate best.
      // We will choose between 25, 28 and 30 Hz, to get smooth animations.
      // The following frame rate will be chosen according to the monitor's
      // refresh rate:
      //
      // Frame rate:   Monitor refresh rate
      // 25 Hz         (50), 75, 100 Hz (PAL compliant setups)
      // 28 Hz         85 Hz, 110 Hz    (seems to work ok)
      // 30 Hz         60, 90, 120 Hz   (NTSC compliant setups)
      //
      // However, this will only work, if the kernel can schedule the
      // screensaver at the right time (a 2.6.x kernel should work fine,
      // because of the high HZ value).
      int candidateRate[3] = { 30, 25, 28 };
      int bestRate = candidateRate[0];
      int smallestError = 1000, i = 0;
      do {
          int r     = candidateRate[i];
          int error = TQMIN(screenRate % r, (screenRate + r) % r);
          
          if (error < smallestError) {
              smallestError = error;
              bestRate      = r;
          }
      } while (++i < 3);
  
      //tqDebug("using %d Hz as framerate for effects", bestRate);
      return bestRate;
  }
  
    bool ScreenProperties::enableVSync() {
  
      // currently only supported on NVidia hardware using the
      // proprietary driver
  
      // For NVidia graphics cards: always use sync-to-vblank
    //  return (setenv("__GL_SYNC_TO_VBLANK", "1", 1) == 0);
        return false;
  }

}  // NameSpace KIPISlideShowPlugin