Propagate screen orientation changes through wayland
[profile/ivi/qtwayland.git] / src / qt-compositor / compositor_api / waylandcompositor.cpp
1 /****************************************************************************
2 **
3 ** This file is part of QtCompositor**
4 **
5 ** Copyright © 2010 Nokia Corporation and/or its subsidiary(-ies).
6 ** All rights reserved.
7 **
8 ** Contact:  Nokia Corporation qt-info@nokia.com
9 **
10 ** You may use this file under the terms of the BSD license as follows:
11 **
12 ** Redistribution and use in source and binary forms, with or without
13 ** modification, are permitted provided that the following conditions are
14 ** met:
15 **
16 ** Redistributions of source code must retain the above copyright
17 ** notice, this list of conditions and the following disclaimer.
18 **
19 ** Redistributions in binary form must reproduce the above copyright
20 ** notice, this list of conditions and the following disclaimer in the
21 ** documentation and/or other materials provided with the distribution.
22 **
23 ** Neither the name of Nokia Corporation and its Subsidiary(-ies) nor the
24 ** names of its contributors may be used to endorse or promote products
25 ** derived from this software without specific prior written permission.
26 **
27 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
28 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
29 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
30 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
31 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
32 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
33 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
34 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
35 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
37 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 **
39 ****************************************************************************/
40
41 #include "waylandcompositor.h"
42
43 #include "wayland_wrapper/wlcompositor.h"
44 #include "wayland_wrapper/wlsurface.h"
45 #include "wayland_wrapper/wlselection.h"
46
47 #ifdef QT_COMPOSITOR_DECLARATIVE
48 #include "waylandsurfaceitem.h"
49 #endif
50
51 WaylandCompositor::WaylandCompositor(QWidget *topLevelWidget, const char *socketName)
52     : m_compositor(0)
53     , m_toplevel_widget(topLevelWidget)
54     , m_socket_name(socketName)
55 {
56     QStringList arguments = QCoreApplication::instance()->arguments();
57
58     int socketArg = arguments.indexOf(QLatin1String("--wayland-socket-name"));
59     if (socketArg != -1 && socketArg + 1 < arguments.size())
60         m_socket_name = arguments.at(socketArg + 1).toLocal8Bit();
61
62     m_compositor = new Wayland::Compositor(this);
63 #ifdef QT_COMPOSITOR_DECLARATIVE
64     qmlRegisterType<WaylandSurfaceItem>("WaylandCompositor", 1, 0, "WaylandSurfaceItem");
65     qRegisterMetaType<WaylandSurface*>("WaylandSurface*");
66 #endif
67     m_compositor->initializeHardwareIntegration();
68     m_compositor->initializeWindowManagerProtocol();
69 }
70
71 WaylandCompositor::~WaylandCompositor()
72 {
73     delete m_compositor;
74 }
75
76 void WaylandCompositor::frameFinished(WaylandSurface *surface)
77 {
78     Wayland::Surface *surfaceImpl = surface? surface->handle():0;
79     m_compositor->frameFinished(surfaceImpl);
80 }
81
82 void WaylandCompositor::setInputFocus(WaylandSurface *surface)
83 {
84     Wayland::Surface *surfaceImpl = surface? surface->handle():0;
85     m_compositor->setInputFocus(surfaceImpl);
86 }
87
88 WaylandSurface *WaylandCompositor::inputFocus() const
89 {
90     Wayland::Surface *surfaceImpl = m_compositor->keyFocus();
91     return surfaceImpl ? surfaceImpl->handle() : 0;
92 }
93
94 void WaylandCompositor::destroyClientForSurface(WaylandSurface *surface)
95 {
96     m_compositor->destroyClientForSurface(surface->handle());
97 }
98
99 void WaylandCompositor::setDirectRenderSurface(WaylandSurface *surface)
100 {
101     m_compositor->setDirectRenderSurface(surface ? surface->handle() : 0);
102 }
103
104 WaylandSurface *WaylandCompositor::directRenderSurface() const
105 {
106     Wayland::Surface *surf = m_compositor->directRenderSurface();
107     return surf ? surf->handle() : 0;
108 }
109
110 QWidget * WaylandCompositor::topLevelWidget() const
111 {
112     return m_toplevel_widget;
113 }
114
115 Wayland::Compositor * WaylandCompositor::handle() const
116 {
117     return m_compositor;
118 }
119
120 void WaylandCompositor::setRetainedSelectionEnabled(bool enable)
121 {
122     Wayland::Selection *sel = Wayland::Selection::instance();
123     sel->setRetainedSelection(enable);
124     sel->setRetainedSelectionWatcher(retainedSelectionChanged, this);
125 }
126
127 void WaylandCompositor::retainedSelectionChanged(QMimeData *mimeData, void *param)
128 {
129     WaylandCompositor *self = static_cast<WaylandCompositor *>(param);
130     self->retainedSelectionReceived(mimeData);
131 }
132
133 void WaylandCompositor::retainedSelectionReceived(QMimeData *)
134 {
135 }
136
137 const char *WaylandCompositor::socketName() const
138 {
139     if (m_socket_name.isEmpty())
140         return 0;
141     return m_socket_name.constData();
142 }
143
144 void WaylandCompositor::setScreenOrientation(qint32 orientationInDegrees)
145 {
146     m_compositor->setScreenOrientation(orientationInDegrees);
147 }