Revert "Suppress QWindowSystemInterface inclusion warnings."
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylandextendedoutput.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Nokia Corporation and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/
5 **
6 ** This file is part of the plugins of the Qt Toolkit.
7 **
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.
16 **
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.
20 **
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.
28 **
29 ** Other Usage
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.
32 **
33 **
34 **
35 **
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwaylandextendedoutput.h"
43
44 #include "qwaylandscreen.h"
45
46 #include "wayland-output-extension-client-protocol.h"
47
48 #include <QtGui/QWindowSystemInterface>
49
50 #include <QtCore/QDebug>
51
52 QWaylandOutputExtension::QWaylandOutputExtension(QWaylandDisplay *display, uint32_t id)
53 {
54     m_output_extension = static_cast<struct wl_output_extension *>(
55                 wl_display_bind(display->wl_display(),id, &wl_output_extension_interface));
56
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";
64         }
65     }
66 }
67
68 QWaylandExtendedOutput *QWaylandOutputExtension::getExtendedOutput(QWaylandScreen *screen)
69 {
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);
74 }
75
76 QWaylandExtendedOutput::QWaylandExtendedOutput(QWaylandScreen *screen, wl_extended_output *extended_output)
77     : m_extended_output(extended_output)
78     , m_screen(screen)
79     , m_orientation(m_screen->orientation())
80 {
81     wl_extended_output_add_listener(m_extended_output,&extended_output_listener,this);
82 }
83
84 Qt::ScreenOrientation QWaylandExtendedOutput::currentOrientation() const
85 {
86     return m_orientation;
87 }
88
89 void QWaylandExtendedOutput::setOrientationUpdateMask(Qt::ScreenOrientations orientations)
90 {
91     int mask = 0;
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);
101 }
102
103 void QWaylandExtendedOutput::set_screen_rotation(void *data, wl_extended_output *wl_extended_output, int32_t rotation)
104 {
105     Q_UNUSED(wl_extended_output);
106     QWaylandExtendedOutput *extended_output = static_cast<QWaylandExtendedOutput *>(data);
107     switch (rotation) {
108     case WL_EXTENDED_OUTPUT_ROTATION_PORTRAITORIENTATION:
109         extended_output->m_orientation = Qt::PortraitOrientation;
110         break;
111     case WL_EXTENDED_OUTPUT_ROTATION_LANDSCAPEORIENTATION:
112         extended_output->m_orientation = Qt::LandscapeOrientation;
113         break;
114     case WL_EXTENDED_OUTPUT_ROTATION_INVERTEDPORTRAITORIENTATION:
115         extended_output->m_orientation = Qt::InvertedPortraitOrientation;
116         break;
117     case WL_EXTENDED_OUTPUT_ROTATION_INVERTEDLANDSCAPEORIENTATION:
118         extended_output->m_orientation = Qt::InvertedLandscapeOrientation;
119         break;
120     default:
121         extended_output->m_orientation = Qt::PortraitOrientation;
122         break;
123     }
124     QWindowSystemInterface::handleScreenOrientationChange(extended_output->m_screen->screen(), extended_output->m_orientation);
125 }
126
127 const struct wl_extended_output_listener QWaylandExtendedOutput::extended_output_listener = {
128     QWaylandExtendedOutput::set_screen_rotation
129 };