summaryrefslogtreecommitdiffstats
path: root/krdc/vidmode.cpp
diff options
context:
space:
mode:
authortoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
committertoma <toma@283d02a7-25f6-0310-bc7c-ecb5cbfe19da>2009-11-25 17:56:58 +0000
commitbcb704366cb5e333a626c18c308c7e0448a8e69f (patch)
treef0d6ab7d78ecdd9207cf46536376b44b91a1ca71 /krdc/vidmode.cpp
downloadtdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.tar.gz
tdenetwork-bcb704366cb5e333a626c18c308c7e0448a8e69f.zip
Copy the KDE 3.5 branch to branches/trinity for new KDE 3.5 features.
BUG:215923 git-svn-id: svn://anonsvn.kde.org/home/kde/branches/trinity/kdenetwork@1054174 283d02a7-25f6-0310-bc7c-ecb5cbfe19da
Diffstat (limited to 'krdc/vidmode.cpp')
-rw-r--r--krdc/vidmode.cpp159
1 files changed, 159 insertions, 0 deletions
diff --git a/krdc/vidmode.cpp b/krdc/vidmode.cpp
new file mode 100644
index 00000000..4c7762fb
--- /dev/null
+++ b/krdc/vidmode.cpp
@@ -0,0 +1,159 @@
+/***************************************************************************
+ vidmode.cpp - video mode switching
+ -------------------
+ begin : Tue June 3 03:08:00 CET 2002
+ copyright : (C) 2002 by Tim Jansen
+ email : tim@tjansen.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 of the License, or *
+ * (at your option) any later version. *
+ * *
+ ***************************************************************************/
+
+#include <config.h>
+#include <X11/Xlib.h>
+
+#ifdef HAVE_VIDMODE_EXTENSION
+#include <X11/extensions/xf86vmode.h>
+#endif
+
+#include "vidmode.h"
+
+#ifdef HAVE_VIDMODE_EXTENSION
+
+void vidmodeNormalSwitch(Display *dpy, Resolution oldResolution)
+{
+ if (!oldResolution.valid)
+ return;
+
+ XF86VidModeModeInfo **modes;
+ int modecount;
+ int eventB, errorB;
+
+ if (!XF86VidModeQueryExtension(dpy, &eventB, &errorB))
+ return;
+
+ if (!XF86VidModeGetAllModeLines(dpy, oldResolution.screen, &modecount, &modes))
+ return;
+
+ for (int i = 0; i < modecount; i++) {
+ int w = (*modes[i]).hdisplay;
+ int h = (*modes[i]).vdisplay;
+
+ if ((oldResolution.width == w) &&
+ (oldResolution.height == h)) {
+ XF86VidModeSwitchToMode(dpy,oldResolution.screen,modes[i]);
+ XFlush(dpy);
+ XF86VidModeSetViewPort(dpy,DefaultScreen(dpy),0,0);
+ XFlush(dpy);
+ return;
+ }
+ }
+}
+
+Resolution vidmodeFullscreenSwitch(Display *dpy, int screen,
+ int sw, int sh, int &nx, int &ny)
+{
+ XF86VidModeModeInfo **modes;
+ int modecount;
+ int bestmode = -1;
+ int bestw, besth;
+ int eventB, errorB;
+
+ if (screen < 0)
+ return Resolution();
+
+ if (!XF86VidModeQueryExtension(dpy, &eventB, &errorB))
+ return Resolution();
+
+ if (!XF86VidModeGetAllModeLines(dpy,screen,&modecount, &modes))
+ return Resolution();
+
+ int cw = (*modes[0]).hdisplay;
+ int ch = (*modes[0]).vdisplay;
+ nx = cw;
+ ny = ch;
+ if ((cw == sw) && (ch == sh))
+ return Resolution();
+ bool foundLargeEnoughRes = (cw>=sw) && (ch>=sh);
+ bestw = cw;
+ besth = ch;
+
+ for (int i = 1; i < modecount; i++) {
+ int w = (*modes[i]).hdisplay;
+ int h = (*modes[i]).vdisplay;
+
+ if ((w == cw) && (h == ch))
+ continue;
+
+ /* If resolution matches framebuffer, take it */
+ if ((w == sw) && (h == sh)) {
+ bestw = w;
+ besth = h;
+ bestmode = i;
+ break;
+ }
+ /* if resolution larger than framebuffer... */
+ if ((w>=sw) && (h>=sh)) {
+ /* and no other previously found resoltion was smaller or
+ this is smaller than the best resolution so far, take it*/
+ if ((!foundLargeEnoughRes) ||
+ (w*h < bestw*besth)) {
+ bestw = w;
+ besth = h;
+ bestmode = i;
+ foundLargeEnoughRes = true;
+ }
+ }
+ /* If all resolutions so far were smaller than framebuffer... */
+ else if (!foundLargeEnoughRes) {
+ /* take this one it it is bigger then they were */
+ if (w*h > bestw*besth) {
+ bestw = w;
+ besth = h;
+ bestmode = i;
+ }
+ }
+ }
+
+ if (bestmode == -1)
+ return Resolution();
+
+ nx = bestw;
+ ny = besth;
+ XF86VidModeSwitchToMode(dpy,screen,modes[bestmode]);
+ XF86VidModeSetViewPort(dpy,screen,0,0);
+ XFlush(dpy);
+
+ return Resolution(cw, ch, screen);
+}
+
+#else
+
+void vidmodeNormalSwitch(Display *dpy, Resolution oldResolution)
+{
+}
+
+Resolution vidmodeFullscreenSwitch(Display *dpy, int screen, int sw, int sh, int &nx, int &ny)
+{
+ return Resolution();
+}
+
+#endif
+
+void grabInput(Display *dpy, unsigned int winId) {
+ XGrabPointer(dpy, winId, True, 0,
+ GrabModeAsync, GrabModeAsync,
+ winId, None, CurrentTime);
+ XFlush(dpy);
+}
+
+void ungrabInput(Display *dpy) {
+ XUngrabPointer(dpy, CurrentTime);
+}
+