Update to new QScreen orientation API.
authorSamuel Rødal <samuel.rodal@nokia.com>
Thu, 6 Oct 2011 10:01:33 +0000 (12:01 +0200)
committerPaul Olav Tvete <paul.tvete@nokia.com>
Tue, 11 Oct 2011 09:11:39 +0000 (11:11 +0200)
Change-Id: I375e7fdf0db1f1817c3e1bfea0b652cfc72ac854
Reviewed-on: http://codereview.qt-project.org/6307
Sanity-Review: Paul Olav Tvete <paul.tvete@nokia.com>
Reviewed-by: Paul Olav Tvete <paul.tvete@nokia.com>
16 files changed:
src/plugins/platforms/wayland/qwaylanddisplay.cpp
src/plugins/platforms/wayland/qwaylanddisplay.h
src/plugins/platforms/wayland/qwaylandscreen.cpp
src/plugins/platforms/wayland/qwaylandscreen.h
src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.cpp
src/plugins/platforms/wayland/windowmanager_integration/qwaylandwindowmanagerintegration.h
src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-client-protocol.h
src/plugins/platforms/wayland/windowmanager_integration/wayland-windowmanager-protocol.c
src/qt-compositor/compositor_api/waylandcompositor.cpp
src/qt-compositor/compositor_api/waylandcompositor.h
src/qt-compositor/wayland_wrapper/wlcompositor.cpp
src/qt-compositor/wayland_wrapper/wlcompositor.h
src/qt-compositor/windowmanagerprotocol/wayland-windowmanager-protocol.c
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.cpp
src/qt-compositor/windowmanagerprotocol/waylandwindowmanagerintegration.h
src/qt-compositor/windowmanagerprotocol/windowmanager.xml

index 5880969..f6e7a1b 100644 (file)
@@ -234,6 +234,16 @@ int QWaylandDisplay::sourceUpdate(uint32_t mask, void *data)
     return 0;
 }
 
+QWaylandScreen *QWaylandDisplay::screenForOutput(struct wl_output *output) const
+{
+    for (int i = 0; i < mScreens.size(); ++i) {
+        QWaylandScreen *screen = static_cast<QWaylandScreen *>(mScreens.at(i));
+        if (screen->output() == output)
+            return screen;
+    }
+    return 0;
+}
+
 void QWaylandDisplay::outputHandleGeometry(void *data,
                                            wl_output *output,
                                            int32_t x, int32_t y,
index 2b7f33f..852842f 100644 (file)
@@ -66,6 +66,9 @@ public:
     ~QWaylandDisplay(void);
 
     QList<QPlatformScreen *> screens() const { return mScreens; }
+
+    QWaylandScreen *screenForOutput(struct wl_output *output) const;
+
     struct wl_surface *createSurface(void *handle);
     struct wl_buffer *createShmBuffer(int fd, int width, int height,
                                       uint32_t stride,
index 7b064ba..1543508 100644 (file)
@@ -44,6 +44,8 @@
 #include "qwaylanddisplay.h"
 #include "qwaylandcursor.h"
 
+#include <QWindowSystemInterface>
+
 QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, struct wl_output *output, QRect geometry)
     : QPlatformScreen()
     , mWaylandDisplay(waylandDisplay)
@@ -51,6 +53,7 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, struct wl_output
     , mGeometry(geometry)
     , mDepth(32)
     , mFormat(QImage::Format_ARGB32_Premultiplied)
+    , mOrientation(primaryOrientation())
     , mWaylandCursor(new QWaylandCursor(this))
 {
 }
@@ -80,6 +83,17 @@ QImage::Format QWaylandScreen::format() const
     return mFormat;
 }
 
+Qt::ScreenOrientation QWaylandScreen::currentOrientation() const
+{
+    return mOrientation;
+}
+
+void QWaylandScreen::setOrientation(const Qt::ScreenOrientation orientation)
+{
+    mOrientation = orientation;
+    QWindowSystemInterface::handleScreenOrientationChange(screen());
+}
+
 QWaylandScreen * QWaylandScreen::waylandScreenFromWindow(QWindow *window)
 {
     QPlatformScreen *platformScreen = QPlatformScreen::platformScreenForWindow(window);
index 9bf4f65..7d05626 100644 (file)
@@ -60,7 +60,11 @@ public:
     int depth() const;
     QImage::Format format() const;
 
+    Qt::ScreenOrientation currentOrientation() const;
+    void setOrientation(const Qt::ScreenOrientation orientation);
+
     wl_visual *visual() const;
+    wl_output *output() const { return mOutput; }
 
     static QWaylandScreen *waylandScreenFromWindow(QWindow *window);
 
@@ -71,6 +75,7 @@ private:
     int mDepth;
     QImage::Format mFormat;
     QSize mPhysicalSize;
+    Qt::ScreenOrientation mOrientation;
     QWaylandCursor *mWaylandCursor;
 };
 
index 7d68571..04754ed 100644 (file)
@@ -41,6 +41,7 @@
 
 #include "qwaylandwindowmanagerintegration.h"
 #include "wayland-windowmanager-client-protocol.h"
+#include "qwaylandscreen.h"
 #include "qwaylandwindow.h"
 
 #include <stdint.h>
@@ -212,12 +213,13 @@ void QWaylandWindowManagerIntegration::wlHandleOnScreenVisibilityChange(void *da
     QCoreApplication::sendEvent(QCoreApplication::instance(), &evt);
 }
 
-void QWaylandWindowManagerIntegration::wlHandleScreenOrientationChange(void *data, struct wl_windowmanager *wl_windowmanager, int screenOrientation)
+void QWaylandWindowManagerIntegration::wlHandleScreenOrientationChange(void *data, struct wl_windowmanager *wl_windowmanager,
+                                                                       struct wl_output *wl_output, int screenOrientation)
 {
-    Q_UNUSED(data);
-    Q_UNUSED(wl_windowmanager);
-    QScreenOrientationChangeEvent event(screenOrientation);
-    QCoreApplication::sendEvent(QCoreApplication::instance(), &event);
+    QWaylandWindowManagerIntegration *integration = QWaylandWindowManagerIntegration::instance();
+    QWaylandScreen *screen = integration->d_ptr->m_waylandDisplay->screenForOutput(wl_output);
+    if (screen)
+        screen->setOrientation(Qt::ScreenOrientation(screenOrientation));
 }
 
 void QWaylandWindowManagerIntegration::wlHandleWindowPropertyChange(void *data, struct wl_windowmanager *wl_windowmanager,
index 1372fb8..50cd232 100644 (file)
@@ -79,7 +79,8 @@ private:
                                        const char *interface, uint32_t version, void *data);
 
     static void wlHandleOnScreenVisibilityChange(void *data, struct wl_windowmanager *wl_windowmanager, int visible);
-    static void wlHandleScreenOrientationChange(void *data, struct wl_windowmanager *wl_windowmanager, int screenOrientation);
+    static void wlHandleScreenOrientationChange(void *data, struct wl_windowmanager *wl_windowmanager,
+                                                struct wl_output *wl_output, int screenOrientation);
     static void wlHandleWindowPropertyChange(void *data, struct wl_windowmanager *wl_windowmanager,
                                              struct wl_surface *surface,
                                              const char *propertyName, struct wl_array *propertyValue);
index ffcf60f..a8d01c5 100644 (file)
@@ -59,10 +59,11 @@ extern const struct wl_interface wl_windowmanager_interface;
 struct wl_windowmanager_listener {
        void (*client_onscreen_visibility)(void *data,
                                           struct wl_windowmanager *wl_windowmanager,
-                                          int32_t visible);
+                                          int visible);
        void (*set_screen_rotation)(void *data,
                                    struct wl_windowmanager *wl_windowmanager,
-                                   int32_t rotation);
+                                   struct wl_output *output,
+                                   int rotation);
        void (*set_generic_property)(void *data,
                                     struct wl_windowmanager *wl_windowmanager,
                                     struct wl_surface *surface,
index b69d386..3e1f36b 100644 (file)
 #include <stdint.h>
 #include "wayland-util.h"
 
-extern const struct wl_interface wl_surface_interface;
-
-static const struct wl_interface *types[] = {
-       NULL,
-       &wl_surface_interface,
-       NULL,
-       NULL,
-       &wl_surface_interface,
-       NULL,
-       NULL,
-};
-
 static const struct wl_message wl_windowmanager_requests[] = {
-       { "map_client_to_process", "u", types + 0 },
-       { "authenticate_with_token", "s", types + 0 },
-       { "update_generic_property", "osa", types + 1 },
+       { "map_client_to_process", "u", NULL },
+       { "authenticate_with_token", "s", NULL },
+       { "update_generic_property", "osa", NULL },
 };
 
 static const struct wl_message wl_windowmanager_events[] = {
-       { "client_onscreen_visibility", "i", types + 0 },
-       { "set_screen_rotation", "i", types + 0 },
-       { "set_generic_property", "osa", types + 4 },
+       { "client_onscreen_visibility", "i", NULL },
+       { "set_screen_rotation", "oi", NULL },
+       { "set_generic_property", "osa", NULL },
 };
 
 WL_EXPORT const struct wl_interface wl_windowmanager_interface = {
index a682237..96030f2 100644 (file)
@@ -149,9 +149,12 @@ const char *WaylandCompositor::socketName() const
     return m_socket_name.constData();
 }
 
-void WaylandCompositor::setScreenOrientation(qint32 orientationInDegrees)
+/*!
+  Set the screen orientation based on accelerometer data or similar.
+*/
+void WaylandCompositor::setScreenOrientation(Qt::ScreenOrientation orientation)
 {
-    m_compositor->setScreenOrientation(orientationInDegrees);
+    m_compositor->setScreenOrientation(orientation);
 }
 
 void WaylandCompositor::setOutputGeometry(const QRect &geometry)
index 11660b8..160b4ad 100644 (file)
@@ -83,7 +83,7 @@ public:
 
     const char *socketName() const;
 
-    void setScreenOrientation(qint32 orientationInDegrees);
+    void setScreenOrientation(Qt::ScreenOrientation orientation);
     void setOutputGeometry(const QRect &outputGeometry);
 
     bool isDragging() const;
index 1bab077..04ef22e 100644 (file)
@@ -214,6 +214,7 @@ Compositor::Compositor(WaylandCompositor *qt_compositor)
     , m_current_frame(0)
     , m_last_queued_buf(-1)
     , m_qt_compositor(qt_compositor)
+    , m_orientation(Qt::UnknownOrientation)
     , m_pointerFocusSurface(0)
     , m_keyFocusSurface(0)
     , m_directRenderSurface(0)
@@ -286,13 +287,14 @@ void Compositor::createSurface(struct wl_client *client, int id)
     addClientResource(client, &surface->base()->resource, id, &wl_surface_interface,
             &surface_interface, destroy_surface);
 
-    m_windowManagerWaylandProtocol->updateOrientation(client);
-    m_qt_compositor->surfaceCreated(surface->handle());
-
     QList<struct wl_client *> prevClientList = clients();
     m_surfaces << surface;
-    if (!prevClientList.contains(client))
+    if (!prevClientList.contains(client)) {
+        m_windowManagerWaylandProtocol->setScreenOrientation(client, m_output.base(), m_orientation);
         emit clientAdded(client);
+    }
+
+    m_qt_compositor->surfaceCreated(surface->handle());
 }
 
 struct wl_client *Compositor::getClientFromWinId(uint winId) const
@@ -464,12 +466,14 @@ QList<struct wl_client *> Compositor::clients() const
     return list;
 }
 
-void Compositor::setScreenOrientation(qint32 orientationInDegrees)
+void Compositor::setScreenOrientation(Qt::ScreenOrientation orientation)
 {
+    m_orientation = orientation;
+
     QList<struct wl_client*> clientList = clients();
     for (int i = 0; i < clientList.length(); ++i) {
         struct wl_client *client = clientList.at(i);
-        m_windowManagerWaylandProtocol->setScreenOrientation(client, orientationInDegrees);
+        m_windowManagerWaylandProtocol->setScreenOrientation(client, m_output.base(), orientation);
     }
 }
 
index 6f357ab..ee72646 100644 (file)
@@ -106,7 +106,7 @@ public:
 
     QList<struct wl_client *> clients() const;
 
-    void setScreenOrientation(qint32 orientationInDegrees);
+    void setScreenOrientation(Qt::ScreenOrientation orientation);
     void setOutputGeometry(const QRect &geometry);
 
     bool isDragging() const;
@@ -143,6 +143,7 @@ private:
     wl_event_loop *m_loop;
 
     WaylandCompositor *m_qt_compositor;
+    Qt::ScreenOrientation m_orientation;
 
     Surface *m_pointerFocusSurface;
     Surface *m_keyFocusSurface;
index 1d231f5..aea56d6 100644 (file)
@@ -2,28 +2,16 @@
 #include <stdint.h>
 #include "wayland-util.h"
 
-extern const struct wl_interface wl_surface_interface;
-
-static const struct wl_interface *types[] = {
-       NULL,
-       &wl_surface_interface,
-       NULL,
-       NULL,
-       &wl_surface_interface,
-       NULL,
-       NULL,
-};
-
 static const struct wl_message wl_windowmanager_requests[] = {
-       { "map_client_to_process", "u", types + 0 },
-       { "authenticate_with_token", "s", types + 0 },
-       { "update_generic_property", "osa", types + 1 },
+       { "map_client_to_process", "u", NULL },
+       { "authenticate_with_token", "s", NULL },
+       { "update_generic_property", "osa", NULL },
 };
 
 static const struct wl_message wl_windowmanager_events[] = {
-       { "client_onscreen_visibility", "i", types + 0 },
-       { "set_screen_rotation", "i", types + 0 },
-       { "set_generic_property", "osa", types + 4 },
+       { "client_onscreen_visibility", "i", NULL },
+       { "set_screen_rotation", "oi", NULL },
+       { "set_generic_property", "osa", NULL },
 };
 
 WL_EXPORT const struct wl_interface wl_windowmanager_interface = {
index 3d47173..76d9714 100644 (file)
@@ -106,7 +106,6 @@ WindowManagerServerIntegration *WindowManagerServerIntegration::m_instance = 0;
 
 WindowManagerServerIntegration::WindowManagerServerIntegration(QObject *parent)
     : QObject(parent)
-    , m_orientationInDegrees(0)
 {
     m_instance = this;
 }
@@ -148,16 +147,10 @@ void WindowManagerServerIntegration::setVisibilityOnScreen(wl_client *client, bo
                          WL_WINDOWMANAGER_CLIENT_ONSCREEN_VISIBILITY, visible ? 1 : 0);
 }
 
-void WindowManagerServerIntegration::setScreenOrientation(wl_client *client, qint32 orientationInDegrees)
+void WindowManagerServerIntegration::setScreenOrientation(wl_client *client, wl_object *output, Qt::ScreenOrientation orientation)
 {
-    m_orientationInDegrees = orientationInDegrees;
     wl_client_post_event(client, m_windowManagerObject->base(),
-                         WL_WINDOWMANAGER_SET_SCREEN_ROTATION, orientationInDegrees);
-}
-
-void WindowManagerServerIntegration::updateOrientation(wl_client *client)
-{
-    setScreenOrientation(client, m_orientationInDegrees);
+                         WL_WINDOWMANAGER_SET_SCREEN_ROTATION, output, qint32(orientation));
 }
 
 // client -> server
index 1692688..950fed1 100644 (file)
@@ -50,6 +50,7 @@
 #include <QVariant>
 
 struct wl_client;
+struct wl_object;
 
 namespace Wayland {
     class Display;
@@ -70,7 +71,7 @@ public:
     WaylandManagedClient *managedClient(wl_client *client) const;
 
     void setVisibilityOnScreen(wl_client *client, bool visible);
-    void setScreenOrientation(wl_client *client, qint32 orientationInDegrees);
+    void setScreenOrientation(wl_client *client, wl_object *output, Qt::ScreenOrientation orientationInDegrees);
     void updateOrientation(wl_client *client);
 
     void updateWindowProperty(wl_client *client, struct wl_surface *surface, const char *name, struct wl_array *value);
@@ -89,7 +90,6 @@ private:
     static WindowManagerServerIntegration *m_instance;
 
     WindowManagerObject *m_windowManagerObject;
-    qint32 m_orientationInDegrees;
 
     friend class WindowManagerObject;
 };
index f69f658..659dcae 100644 (file)
@@ -26,6 +26,7 @@
 
         <!-- Sets screen rotation, typically based on accelerometer/orientation sensor reading data -->
         <event name="set_screen_rotation">
+            <arg name="output" type="object" interface="wl_output"/>
             <arg name="rotation" type="int"/>
         </event>