Use wayland core interfaces to signal output rotation

The wl_output interface has an event for signaling the rotation of
the display, so use that instead of our own thing.

Change-Id: I8a017d575ee456a7a81649e19a015085fb784805
Reviewed-by: Gunnar Sletta <gunnar.sletta@jollamobile.com>
This commit is contained in:
Giulio Camuffo 2014-03-03 17:24:26 +02:00 committed by Pier Luigi Fiorini
parent 40ce144ae3
commit 755eefab6a
10 changed files with 65 additions and 66 deletions

View File

@ -46,19 +46,6 @@
</interface>
<interface name="qt_extended_output" version="1">
<enum name="rotation">
<entry name="PortraitOrientation" value="1"/>
<entry name="LandscapeOrientation" value="2"/>
<entry name="InvertedPortraitOrientation" value="4"/>
<entry name="InvertedLandscapeOrientation" value="8"/>
</enum>
<event name="set_screen_rotation">
<arg name="rotation" type="int"/>
</event>
<request name="set_orientation_update_mask">
<arg name="orientation" type="int"/>
</request>
</interface>
</protocol>

View File

@ -74,6 +74,9 @@
<request name="set_content_orientation">
<arg name="orientation" type="int"/>
</request>
<request name="set_content_orientation_mask">
<arg name="orientation" type="int"/>
</request>
<enum name="windowflag">
<entry name="OverridesSystemGestures" value="1"/>

View File

@ -52,49 +52,7 @@ QT_BEGIN_NAMESPACE
QWaylandExtendedOutput::QWaylandExtendedOutput(QWaylandScreen *screen, ::qt_extended_output *extended_output)
: QtWayland::qt_extended_output(extended_output)
, m_screen(screen)
, m_orientation(m_screen->orientation())
{
}
Qt::ScreenOrientation QWaylandExtendedOutput::currentOrientation() const
{
return m_orientation;
}
void QWaylandExtendedOutput::setOrientationUpdateMask(Qt::ScreenOrientations orientations)
{
int mask = 0;
if (orientations & Qt::PortraitOrientation)
mask |= QT_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
if (orientations & Qt::LandscapeOrientation)
mask |= QT_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION;
if (orientations & Qt::InvertedPortraitOrientation)
mask |= QT_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION;
if (orientations & Qt::InvertedLandscapeOrientation)
mask |= QT_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION;
set_orientation_update_mask(mask);
}
void QWaylandExtendedOutput::extended_output_set_screen_rotation(int32_t rotation)
{
switch (rotation) {
case QT_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION:
m_orientation = Qt::PortraitOrientation;
break;
case QT_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION:
m_orientation = Qt::LandscapeOrientation;
break;
case QT_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION:
m_orientation = Qt::InvertedPortraitOrientation;
break;
case QT_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION:
m_orientation = Qt::InvertedLandscapeOrientation;
break;
default:
m_orientation = Qt::PortraitOrientation;
break;
}
QWindowSystemInterface::handleScreenOrientationChange(m_screen->screen(), m_orientation);
}
QT_END_NAMESPACE

View File

@ -56,14 +56,9 @@ class Q_WAYLAND_CLIENT_EXPORT QWaylandExtendedOutput : public QtWayland::qt_exte
public:
QWaylandExtendedOutput(QWaylandScreen *screen, struct ::qt_extended_output *extended_output);
Qt::ScreenOrientation currentOrientation() const;
void setOrientationUpdateMask(Qt::ScreenOrientations mask);
private:
void extended_output_set_screen_rotation(int32_t rotation) Q_DECL_OVERRIDE;
QWaylandScreen *m_screen;
Qt::ScreenOrientation m_orientation;
};
QT_END_NAMESPACE

View File

@ -94,6 +94,22 @@ void QWaylandExtendedSurface::setContentOrientation(Qt::ScreenOrientation orient
set_content_orientation(waylandRotationFromScreenOrientation(orientation));
}
void QWaylandExtendedSurface::setContentOrientationMask(Qt::ScreenOrientations mask)
{
int32_t wlmask = 0;
if (mask & Qt::PrimaryOrientation)
wlmask |= QT_EXTENDED_SURFACE_ORIENTATION_PRIMARYORIENTATION;
if (mask & Qt::PortraitOrientation)
wlmask |= QT_EXTENDED_SURFACE_ORIENTATION_PORTRAITORIENTATION;
if (mask & Qt::LandscapeOrientation)
wlmask |= QT_EXTENDED_SURFACE_ORIENTATION_LANDSCAPEORIENTATION;
if (mask & Qt::InvertedPortraitOrientation)
wlmask |= QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDPORTRAITORIENTATION;
if (mask & Qt::InvertedLandscapeOrientation)
wlmask |= QT_EXTENDED_SURFACE_ORIENTATION_INVERTEDLANDSCAPEORIENTATION;
set_content_orientation_mask(wlmask);
}
QVariantMap QWaylandExtendedSurface::properties() const
{
return m_properties;

View File

@ -62,6 +62,7 @@ public:
~QWaylandExtendedSurface();
void setContentOrientation(Qt::ScreenOrientation orientation);
void setContentOrientationMask(Qt::ScreenOrientations mask);
void updateGenericProperty(const QString &name, const QVariant &value);

View File

@ -44,8 +44,12 @@
#include "qwaylanddisplay_p.h"
#include "qwaylandcursor_p.h"
#include "qwaylandextendedoutput_p.h"
#include "qwaylandwindow_p.h"
#include <QtGui/QGuiApplication>
#include <qpa/qwindowsysteminterface.h>
#include <qpa/qplatformwindow.h>
QT_BEGIN_NAMESPACE
@ -57,6 +61,7 @@ QWaylandScreen::QWaylandScreen(QWaylandDisplay *waylandDisplay, uint32_t id)
, mRefreshRate(60000)
, mFormat(QImage::Format_ARGB32_Premultiplied)
, mOutputName(QStringLiteral("Screen%1").arg(id))
, m_orientation(Qt::PrimaryOrientation)
, mWaylandCursor(new QWaylandCursor(this))
{
// handle case of output extension global being sent after outputs
@ -99,15 +104,16 @@ QDpi QWaylandScreen::logicalDpi() const
void QWaylandScreen::setOrientationUpdateMask(Qt::ScreenOrientations mask)
{
if (mExtendedOutput)
mExtendedOutput->setOrientationUpdateMask(mask);
foreach (QWindow *window, QGuiApplication::allWindows()) {
QWaylandWindow *w = static_cast<QWaylandWindow *>(window->handle());
if (w && w->screen() == this)
w->setOrientationMask(mask);
}
}
Qt::ScreenOrientation QWaylandScreen::orientation() const
{
if (mExtendedOutput)
return mExtendedOutput->currentOrientation();
return QPlatformScreen::orientation();
return m_orientation;
}
qreal QWaylandScreen::refreshRate() const
@ -166,7 +172,30 @@ void QWaylandScreen::output_geometry(int32_t x, int32_t y,
{
Q_UNUSED(subpixel);
Q_UNUSED(make);
Q_UNUSED(transform);
bool isPortrait = screen() && screen()->primaryOrientation() == Qt::PortraitOrientation;
switch (transform) {
case WL_OUTPUT_TRANSFORM_NORMAL:
m_orientation = isPortrait ? Qt::PortraitOrientation : Qt::LandscapeOrientation;
break;
case WL_OUTPUT_TRANSFORM_90:
m_orientation = isPortrait ? Qt::InvertedLandscapeOrientation : Qt::PortraitOrientation;
break;
case WL_OUTPUT_TRANSFORM_180:
m_orientation = isPortrait ? Qt::InvertedPortraitOrientation : Qt::InvertedLandscapeOrientation;
break;
case WL_OUTPUT_TRANSFORM_270:
m_orientation = isPortrait ? Qt::LandscapeOrientation : Qt::InvertedPortraitOrientation;
break;
// Ignore these ones, at least for now
case WL_OUTPUT_TRANSFORM_FLIPPED:
case WL_OUTPUT_TRANSFORM_FLIPPED_90:
case WL_OUTPUT_TRANSFORM_FLIPPED_180:
case WL_OUTPUT_TRANSFORM_FLIPPED_270:
break;
}
QWindowSystemInterface::handleScreenOrientationChange(screen(), m_orientation);
if (!model.isEmpty())
mOutputName = model;

View File

@ -101,6 +101,7 @@ private:
QImage::Format mFormat;
QSize mPhysicalSize;
QString mOutputName;
Qt::ScreenOrientation m_orientation;
QWaylandCursor *mWaylandCursor;
};

View File

@ -130,6 +130,7 @@ QWaylandWindow::QWaylandWindow(QWindow *window)
mShellSurface->setTopLevel();
}
setOrientationMask(window->screen()->orientationUpdateMask());
setWindowFlags(window->flags());
setGeometry_helper(window->geometry());
setWindowStateInternal(window->windowState());
@ -438,6 +439,12 @@ void QWaylandWindow::handleContentOrientationChange(Qt::ScreenOrientation orient
mExtendedWindow->setContentOrientation(orientation);
}
void QWaylandWindow::setOrientationMask(Qt::ScreenOrientations mask)
{
if (mExtendedWindow)
mExtendedWindow->setContentOrientationMask(mask);
}
void QWaylandWindow::setWindowState(Qt::WindowState state)
{
if (setWindowStateInternal(state))

View File

@ -128,8 +128,10 @@ public:
QWaylandShellSurface *shellSurface() const;
QWaylandExtendedSurface *extendedWindow() const;
QWaylandSubSurface *subSurfaceWindow() const;
QWaylandScreen *screen() const { return mScreen; }
void handleContentOrientationChange(Qt::ScreenOrientation orientation);
void setOrientationMask(Qt::ScreenOrientations mask);
void setWindowState(Qt::WindowState state);
void setWindowFlags(Qt::WindowFlags flags);