Hi Thomas, Thank you for the reply. I'm actually more interested in having the content rotated automatically. Around two weeks ago Google released an android game written in Qt/QML. The game is called VoltAir and is available on github under Apache 2.0 license (https://github.com/google/VoltAir). I've thought it'd be nice to port it to Sailfish.
I took a stab at it and managed to get it to compile and run, but the first problem I encountered was that the entire game expects to be run in landscape mode, but on sailfish it was displayed in portrait mode. Digging into the code I've found that on android the screen orientation is set using manifest file. Sailfish doesn't seem to have anything like that. What I did was essentially create a new main qml file which created AplicationWindow with one Page setting the orientation to Landscape | LandscapeInverted. This worked for the game UI, but not for the content itself. The content of the game is drawn underneath qml layer using opengl. I don't know OpenGL to well, but I've figured out that If I can add a rotation matrix to the right places this part should also work. I did find a function which produces view matrix for the game and I added rotation to that. It worked, but not everywhere. The game engine assumes in a few places that the view matrix is only scale*translation. Under such assumption it does access the matrix cells directly in several places. When the view matrix is rotated the the expected data is in different cells. I can fix those code parts, but this means sailfish specific patch for the games becomes bigger and uglier. Another problem with the current solution is that even though the window contents are rotated the width() and height() getters for the window still return values for portrait mode. This means another set of sailfish ifdefs which swap width()/height() calls. It works, but does not seem right. I'll try to clean up my patches and push it to github. Maybe could look at them and see if there is a better way of handling this problem on sailfish. /ptw > Hey, > > 2014-07-17 23:05 GMT+02:00 Piotr Tworek <tworaz...@gmail.com>: >> Is there a way to lock application screen orientation to landscape >> directly from Qt/C++ code? I know it's possible from QML, but I can't >> find any docs how the same can be done from C++. > > You can e.g. subclass QWindow to a custom class (so you can handle > events, I call that QWindow subclass instance "view" in the code > snippet below), then instantiate and show the window > (.showFullScreen()) and then tell the system that the content is in > landscape like this: > > // Switch to landscape mode > view.reportContentOrientationChange(Qt::LandscapeOrientation); > view.screen()->setOrientationUpdateMask(Qt::LandscapeOrientation); > > You still have a "portrait" window (in the sense that you have to > rotate your content in your code, but that's always more efficent than > having the compositor do a rotated readout of your window buffer, even > if that's done in special 2D blitting hardware that can do > multiple-of-90-degrees readouts in hardware), but you can render in > landscape (in my case, I render everything in GL ES, so rotating is > just applying some forward-rotation to the projection matrix and > backward-rotation for handling input). What this will do is: > > 1. It will make the volume bar appear in landscape orientation > 2. It will allow closing the window from the "top" relative to > landscape orientation (right screen border on device) > 3. Everything else that a landscape window will do that I forgot here > > > HTH :) > Thomas > _______________________________________________ > SailfishOS.org Devel mailing list > To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org > _______________________________________________ SailfishOS.org Devel mailing list To unsubscribe, please send a mail to devel-unsubscr...@lists.sailfishos.org