1 /****************************************************************************
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
6 ** This file is part of the plugins of the Qt Toolkit.
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** GNU Lesser General Public License Usage
10 ** This file may be used under the terms of the GNU Lesser General Public
11 ** License version 2.1 as published by the Free Software Foundation and
12 ** appearing in the file LICENSE.LGPL included in the packaging of this
13 ** file. Please review the following information to ensure the GNU Lesser
14 ** General Public License version 2.1 requirements will be met:
15 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
17 ** In addition, as a special exception, Nokia gives you certain additional
18 ** rights. These rights are described in the Nokia Qt LGPL Exception
19 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
21 ** GNU General Public License Usage
22 ** Alternatively, this file may be used under the terms of the GNU General
23 ** Public License version 3.0 as published by the Free Software Foundation
24 ** and appearing in the file LICENSE.GPL included in the packaging of this
25 ** file. Please review the following information to ensure the GNU General
26 ** Public License version 3.0 requirements will be met:
27 ** http://www.gnu.org/copyleft/gpl.html.
30 ** Alternatively, this file may be used in accordance with the terms and
31 ** conditions contained in a signed written agreement between you and Nokia.
40 ****************************************************************************/
42 #include "qwaylandextendedoutput.h"
44 #include "qwaylandscreen.h"
46 #include "wayland-output-extension-client-protocol.h"
48 #include <QtGui/QWindowSystemInterface>
50 #include <QtCore/QDebug>
52 QWaylandOutputExtension::QWaylandOutputExtension(QWaylandDisplay *display, uint32_t id)
54 m_output_extension = static_cast<struct wl_output_extension *>(
55 wl_display_bind(display->wl_display(),id, &wl_output_extension_interface));
57 QList<QPlatformScreen *> platformScreens = display->screens();
58 for (int i = 0; i < platformScreens.size(); i++) {
59 QWaylandScreen *waylandScreen = static_cast<QWaylandScreen *>(platformScreens.at(i));
60 if (!waylandScreen->extendedOutput()) {
61 QWaylandExtendedOutput *extendedOutput = getExtendedOutput(waylandScreen);
62 waylandScreen->setExtendedOutput(extendedOutput);
63 qDebug() << "extended output enabled";
68 QWaylandExtendedOutput *QWaylandOutputExtension::getExtendedOutput(QWaylandScreen *screen)
70 qDebug() << "getExtendedOutput";
71 struct wl_extended_output *extended_output =
72 wl_output_extension_get_extended_output(m_output_extension,screen->output());
73 return new QWaylandExtendedOutput(screen,extended_output);
76 QWaylandExtendedOutput::QWaylandExtendedOutput(QWaylandScreen *screen, wl_extended_output *extended_output)
77 : m_extended_output(extended_output)
79 , m_orientation(m_screen->orientation())
81 wl_extended_output_add_listener(m_extended_output,&extended_output_listener,this);
84 Qt::ScreenOrientation QWaylandExtendedOutput::currentOrientation() const
89 void QWaylandExtendedOutput::setOrientationUpdateMask(Qt::ScreenOrientations orientations)
92 if (orientations & Qt::PortraitOrientation)
93 mask |= WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION;
94 if (orientations & Qt::LandscapeOrientation)
95 mask |= WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION;
96 if (orientations & Qt::InvertedPortraitOrientation)
97 mask |= WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION;
98 if (orientations & Qt::InvertedLandscapeOrientation)
99 mask |= WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION;
100 wl_extended_output_set_orientation_update_mask(m_extended_output, mask);
103 void QWaylandExtendedOutput::set_screen_rotation(void *data, wl_extended_output *wl_extended_output, int32_t rotation)
105 Q_UNUSED(wl_extended_output);
106 QWaylandExtendedOutput *extended_output = static_cast<QWaylandExtendedOutput *>(data);
108 case WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION:
109 extended_output->m_orientation = Qt::PortraitOrientation;
111 case WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION:
112 extended_output->m_orientation = Qt::LandscapeOrientation;
114 case WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION:
115 extended_output->m_orientation = Qt::InvertedPortraitOrientation;
117 case WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION:
118 extended_output->m_orientation = Qt::InvertedLandscapeOrientation;
121 extended_output->m_orientation = Qt::PortraitOrientation;
124 QWindowSystemInterface::handleScreenOrientationChange(extended_output->m_screen->screen(), extended_output->m_orientation);
127 const struct wl_extended_output_listener QWaylandExtendedOutput::extended_output_listener = {
128 QWaylandExtendedOutput::set_screen_rotation