rotate test
authorElias Woods <EliasWoods@gmail.com>
Tue, 11 Jan 2011 02:40:13 +0000 (21:40 -0500)
committerElias Woods <EliasWoods@gmail.com>
Tue, 11 Jan 2011 02:40:13 +0000 (21:40 -0500)
qmaemo5rotator.cpp
qmaemo5rotator.h

index 7515550..1e11b4b 100644 (file)
@@ -1,5 +1,7 @@
 
 #include "qmaemo5rotator.h"
+#include <X11/extensions/Xrandr.h>
+#include <X11/Xlib.h>
 #if defined(Q_WS_MAEMO_5) || defined(Q_WS_HILDON)
 #include <mce/dbus-names.h>
 #include <mce/mode-names.h>
@@ -56,6 +58,10 @@ void QMaemo5Rotator::setCurrentBehavior(QMaemo5Rotator::RotationBehavior value)
         }
     }
 }
+void QMaemo5Rotator::test()
+{
+    QMaemo5Rotator::setRotation(up);
+}
 
 void QMaemo5Rotator::setCurrentOrientation(QMaemo5Rotator::Orientation value)
 {
@@ -96,4 +102,55 @@ void QMaemo5Rotator::on_orientation_changed(const QString& newOrientation)
     }
     QApplication::desktop()->updateGeometry();
 }
+
+
+
+
+
+
+
+static bool QMaemo5Rotator::setRotation(direction dir)
+{
+    Rotation rotation = dir;
+    int reflection = 0;
+    Display * dpy = XOpenDisplay(NULL);
+    if ( dpy == NULL )
+    {
+        printf ( "Cannot open display %s\n", displayname ) ;
+        return false ;
+    }
+    int screen = DefaultScreen ( dpy ) ;
+    Window root = RootWindow ( dpy, screen ) ;
+
+    XSelectInput (dpy, root, StructureNotifyMask);
+    XRRSelectInput (dpy, root, RRScreenChangeNotifyMask);
+    int eventbase ;
+    int errorbase ;
+    XRRQueryExtension ( dpy, &eventbase, &errorbase ) ;
+
+    XRRScreenConfiguration * sc = XRRGetScreenInfo (dpy, root);
+    if ( sc == NULL )
+    {
+        printf ( "Cannot get screen info\n" ) ;
+        return false ;
+    }
+    int nsize ;
+    XRRScreenSize * sizes = XRRConfigSizes(sc, &nsize);
+    int sizeindex = 0 ;
+    if ( nsize = 0 )
+    {
+        printf ( "XRandr not available\n") ;
+        return false ;
+    }
+    Status status = XRRSetScreenConfig ( dpy, sc, DefaultRootWindow (dpy), (SizeID) sizeindex, (Rotation) (rotation | reflection), CurrentTime);
+    XEvent event;
+    bool rcvdrrnotify = false ;
+    bool rcvdconfignotify = false ;
+    if ( status == RRSetConfigSuccess)
+    {
+        printf("Screen rotation changed");
+    }
+    XCloseDisplay(dpy);
+    return true ;
+}
 #endif
index 82b2afa..db51603 100644 (file)
@@ -21,6 +21,13 @@ public:
         LandscapeBehavior = 1,
         PortraitBehavior = 2
     };
+    enum direction
+    {
+        up = RR_Rotate_180,
+        down = RR_Rotate_0,
+        right = RR_Rotate_90,
+        left = RR_Rotate_270
+    };
 
     enum Orientation
     {
@@ -33,6 +40,7 @@ private:
     bool isSetUp;
     RotationBehavior _currentBehavior;
     Orientation _currentOrientation;
+    static bool setRotation(direction);
 
 public:
 
@@ -43,6 +51,7 @@ public:
     const Orientation currentOrientation();
     void setCurrentBehavior(RotationBehavior value);
     void setCurrentOrientation(Orientation value);
+    void test();
 
 private slots: