xcb: Added Tizen 2.3 adaptation
authorTomasz Olszak <olszak.tomasz@gmail.com>
Thu, 26 Feb 2015 14:41:37 +0000 (15:41 +0100)
committerTomasz Olszak <olszak.tomasz@gmail.com>
Thu, 26 Feb 2015 14:41:37 +0000 (15:41 +0100)
Adaptation includes:
* Application lifecycle depending on X atoms. Tizen 2.3
native application lifecycle depends on X window. So we react on
_X_ILLUME_ACTIVATE|DEACTIVATE_WINDOW atoms and suspend or activate application
accordingly.
* Platform native interface function for setting device orientation. This api
is defined in QtPlatformHeaders/qxcbfunctions.h and can be used from Tizen
application wrapper code.

Change-Id: I0105717dcb4f652dd27e891a5f6c21388d8399ca
Reviewed-by: Laszlo Agocs <laszlo.agocs@theqtcompany.com>
Reviewed-by: Tomasz Olszak <olszak.tomasz@gmail.com>
src/platformheaders/xcbfunctions/qxcbfunctions.h [new file with mode: 0644]
src/platformheaders/xcbfunctions/xcbfunctions.pri
src/plugins/platforms/xcb/qxcbconnection.cpp
src/plugins/platforms/xcb/qxcbconnection.h
src/plugins/platforms/xcb/qxcbintegration.cpp
src/plugins/platforms/xcb/qxcbnativeinterface.cpp
src/plugins/platforms/xcb/qxcbnativeinterface.h

diff --git a/src/platformheaders/xcbfunctions/qxcbfunctions.h b/src/platformheaders/xcbfunctions/qxcbfunctions.h
new file mode 100644 (file)
index 0000000..77f4886
--- /dev/null
@@ -0,0 +1,57 @@
+/****************************************************************************
+**
+** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
+** Contact: http://www.qt-project.org/legal
+**
+** This file is part of the plugins of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:LGPL21$
+** Commercial License Usage
+** Licensees holding valid commercial Qt licenses may use this file in
+** accordance with the commercial license agreement provided with the
+** Software or, alternatively, in accordance with the terms contained in
+** a written agreement between you and Digia. For licensing terms and
+** conditions see http://qt.digia.com/licensing. For further information
+** use the contact form at http://qt.digia.com/contact-us.
+**
+** GNU Lesser General Public License Usage
+** Alternatively, this file may be used under the terms of the GNU Lesser
+** General Public License version 2.1 or version 3 as published by the Free
+** Software Foundation and appearing in the file LICENSE.LGPLv21 and
+** LICENSE.LGPLv3 included in the packaging of this file. Please review the
+** following information to ensure the GNU Lesser General Public License
+** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
+** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
+**
+** In addition, as a special exception, Digia gives you certain additional
+** rights. These rights are described in the Digia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef QXCBFUNCTIONS_H
+#define QXCBFUNCTIONS_H
+
+#include <QtCore/QByteArray>
+#include <QtGui/QGuiApplication>
+
+QT_BEGIN_NAMESPACE
+
+class QXcbFunctions {
+public:
+    typedef void (*SetDeviceOrientationType)(Qt::ScreenOrientation orientation);
+    static const QByteArray setDeviceOrientationTypeIdentifier() { return QByteArrayLiteral("XcbSetDeviceOrientationType"); }
+
+    static void setDeviceOrientation(Qt::ScreenOrientation orientation)
+    {
+        SetDeviceOrientationType func = reinterpret_cast<SetDeviceOrientationType>(QGuiApplication::platformFunction(setDeviceOrientationTypeIdentifier()));
+        if (func)
+            func(orientation);
+    }
+};
+
+QT_END_NAMESPACE
+
+#endif // QXCBFUNCTIONS_H
index 8844913cd1c05145bd74faf02bc769f860c8f2ca..ac270fa1625951a70854c9fd2823489e51a0887c 100644 (file)
@@ -1 +1,3 @@
-HEADERS += $$PWD/qxcbwindowfunctions.h
+HEADERS += \
+    $$PWD/qxcbfunctions.h \
+    $$PWD/qxcbwindowfunctions.h
index 5510c3b1b4d2d070b28dbf4af419eab4c261162c..3d6adfa45ccca54504c005e9bf956c855da2befd 100644 (file)
@@ -1331,6 +1331,20 @@ void QXcbConnection::handleClientMessageEvent(const xcb_client_message_event_t *
     if (!window)
         return;
 
+#ifdef Q_OS_LINUX_TIZEN
+    if (event->type == atom(QXcbAtom::_X_ILLUME_DEACTIVATE_WINDOW)) {
+        QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationSuspended);
+        return;
+    } if (event->type == atom(QXcbAtom::_X_ILLUME_ACTIVATE_WINDOW)) {
+        QWindowSystemInterface::handleApplicationStateChanged(Qt::ApplicationActive);
+        return;
+    } else if (event->type == atom(QXcbAtom::_E_COMP_FLUSH)
+            || event->type == atom(QXcbAtom::_NET_CM_WINDOW_EFFECT_CLIENT_STATE)) {
+        //silence the Tizen Mobile X11 WM messages for now
+        return;
+    }
+#endif // Q_OS_LINUX_TIZEN
+
     window->handleClientMessageEvent(event);
 }
 
@@ -1536,6 +1550,12 @@ static const char * xcb_atomnames = {
     "Rel Vert Wheel\0"
     "Rel Horiz Scroll\0"
     "Rel Vert Scroll\0"
+#ifdef Q_OS_LINUX_TIZEN
+    "_E_COMP_FLUSH\0"
+    "_NET_CM_WINDOW_EFFECT_CLIENT_STATE\0"
+    "_X_ILLUME_ACTIVATE_WINDOW\0"
+    "_X_ILLUME_DEACTIVATE_WINDOW\0"
+#endif
     "_XSETTINGS_SETTINGS\0"
     "_COMPIZ_DECOR_PENDING\0"
     "_COMPIZ_DECOR_REQUEST\0"
index 7286b6b89b32c5f28abc3bb97d8e60d1bdb18a03..7fbe21e65b4f178d442f72899016c163665bedf0 100644 (file)
@@ -273,6 +273,12 @@ namespace QXcbAtom {
         RelHorizScroll,
         RelVertScroll,
 
+#ifdef Q_OS_LINUX_TIZEN
+        _E_COMP_FLUSH,
+        _NET_CM_WINDOW_EFFECT_CLIENT_STATE,
+        _X_ILLUME_ACTIVATE_WINDOW,
+        _X_ILLUME_DEACTIVATE_WINDOW,
+#endif
         _XSETTINGS_SETTINGS,
 
         _COMPIZ_DECOR_PENDING,
index f0c4a7f69145fc583e880db3f2ccb17a5ad9f7ba..ec006f73b77f28218b44e06b6f348bb59fbd5249 100644 (file)
@@ -321,6 +321,9 @@ bool QXcbIntegration::hasCapability(QPlatformIntegration::Capability cap) const
     case ForeignWindows: return true;
     case SyncState: return true;
     case RasterGLSurface: return true;
+#ifdef Q_OS_LINUX_TIZEN
+    case ApplicationState: return true;
+#endif
     default: return QPlatformIntegration::hasCapability(cap);
     }
 }
index 31dedd40a2ca3176546c0e716b04e478244f37fa..0b08895a3ffff16dfba6982ae26feafecfd53644 100644 (file)
@@ -53,6 +53,7 @@
 #endif
 
 #include <QtPlatformHeaders/qxcbwindowfunctions.h>
+#include <QtPlatformHeaders/qxcbfunctions.h>
 
 #ifdef XCB_USE_XLIB
 #  include <X11/Xlib.h>
@@ -334,11 +335,35 @@ QPlatformNativeInterface::NativeResourceForScreenFunction QXcbNativeInterface::n
     return 0;
 }
 
+static void _setDeviceOrientation(Qt::ScreenOrientation orientation) {
+    //QMetaObject::invokeMethod method is used here because it is possible
+    //and very probable that this function will be invoked from non-Gui thread.
+    //This way thread safety is guqranteed in easy way
+    QMetaObject::invokeMethod(QGuiApplication::platformNativeInterface(),
+                              "setDeviceOrientation",
+                              Q_ARG(int, orientation));
+}
+
+void QXcbNativeInterface::setDeviceOrientation(int orientation) {
+    //This slot is private and supposed to be invoked only by _setDeviceOrientation function
+    Qt::ScreenOrientation screenOrientation = (Qt::ScreenOrientation) orientation;
+    QScreen *screen = QGuiApplication::primaryScreen();
+    if (screen)
+        QWindowSystemInterface::handleScreenOrientationChange(screen, screenOrientation);
+    else
+        qWarning() <<  "Can't set device orientation to:" << qPrintable(screenOrientation)
+                    << "because there is no primary screen";
+}
+
 QFunctionPointer QXcbNativeInterface::platformFunction(const QByteArray &function) const
 {
     if (function == QXcbWindowFunctions::setWmWindowTypeIdentifier()) {
         return QFunctionPointer(QXcbWindow::setWmWindowTypeStatic);
     }
+    if (function == QXcbFunctions::setDeviceOrientationTypeIdentifier()) {
+        //Pointer to static function is returned because - see comment in that function
+        return QFunctionPointer(_setDeviceOrientation);
+    }
     return Q_NULLPTR;
 }
 
index 330dd008c4b23d755905de67ee51703e5e7aa40c..03a029dc8025488d6d13da579d7e0ec1506d7d83 100644 (file)
@@ -116,6 +116,7 @@ signals:
 
 private:
     xcb_window_t locateSystemTray(xcb_connection_t *conn, const QXcbScreen *screen);
+    Q_INVOKABLE void setDeviceOrientation(int orientation);
 
     const QByteArray m_genericEventFilterType;