1 /****************************************************************************
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
6 ** This file is part of the Qt Compositor.
8 ** $QT_BEGIN_LICENSE:BSD$
9 ** You may use this file under the terms of the BSD license as follows:
11 ** "Redistribution and use in source and binary forms, with or without
12 ** modification, are permitted provided that the following conditions are
14 ** * Redistributions of source code must retain the above copyright
15 ** notice, this list of conditions and the following disclaimer.
16 ** * Redistributions in binary form must reproduce the above copyright
17 ** notice, this list of conditions and the following disclaimer in
18 ** the documentation and/or other materials provided with the
20 ** * Neither the name of Digia Plc and its Subsidiary(-ies) nor the names
21 ** of its contributors may be used to endorse or promote products derived
22 ** from this software without specific prior written permission.
25 ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
26 ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
27 ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
28 ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
29 ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
30 ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
31 ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
32 ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
33 ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
34 ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
35 ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE."
39 ****************************************************************************/
41 #include "wlsubsurface.h"
43 #include "wlcompositor.h"
44 #include "waylandsurface.h"
48 SubSurfaceExtensionGlobal::SubSurfaceExtensionGlobal(Compositor *compositor)
49 : m_compositor(compositor)
51 wl_display_add_global(m_compositor->wl_display(),
52 &wl_sub_surface_extension_interface,
54 SubSurfaceExtensionGlobal::bind_func);
57 void SubSurfaceExtensionGlobal::bind_func(wl_client *client, void *data, uint32_t version, uint32_t id)
60 wl_client_add_object(client, &wl_sub_surface_extension_interface,&sub_surface_extension_interface,id,data);
63 void SubSurfaceExtensionGlobal::get_sub_surface_aware_surface(wl_client *client, wl_resource *sub_surface_extension_resource, uint32_t id, wl_resource *surface_resource)
65 Q_UNUSED(sub_surface_extension_resource);
66 Surface *surface = resolve<Surface>(surface_resource);
67 new SubSurface(client,id,surface);
70 const struct wl_sub_surface_extension_interface SubSurfaceExtensionGlobal::sub_surface_extension_interface = {
71 SubSurfaceExtensionGlobal::get_sub_surface_aware_surface
74 SubSurface::SubSurface(wl_client *client, uint32_t id, Surface *surface)
78 surface->setSubSurface(this);
79 m_sub_surface_resource = wl_client_add_object(client,
80 &wl_sub_surface_interface,
81 &sub_surface_interface,
86 SubSurface::~SubSurface()
89 m_parent->removeSubSurface(this);
91 QLinkedList<WaylandSurface *>::iterator it;
92 for (it = m_sub_surfaces.begin(); it != m_sub_surfaces.end(); ++it) {
93 (*it)->handle()->subSurface()->parentDestroyed();
97 void SubSurface::setSubSurface(SubSurface *subSurface, int x, int y)
99 if (!m_sub_surfaces.contains(subSurface->m_surface->waylandSurface())) {
100 m_sub_surfaces.append(subSurface->m_surface->waylandSurface());
101 subSurface->setParent(this);
103 subSurface->m_surface->setPos(QPointF(x,y));
106 void SubSurface::removeSubSurface(SubSurface *subSurfaces)
108 Q_ASSERT(m_sub_surfaces.contains(subSurfaces->m_surface->waylandSurface()));
109 m_sub_surfaces.removeOne(subSurfaces->m_surface->waylandSurface());
112 SubSurface *SubSurface::parent() const
117 void SubSurface::setParent(SubSurface *parent)
119 if (m_parent == parent)
122 WaylandSurface *oldParent = 0;
123 WaylandSurface *newParent = 0;
126 oldParent = m_parent->m_surface->waylandSurface();
127 m_parent->removeSubSurface(this);
130 newParent = parent->m_surface->waylandSurface();
134 m_surface->waylandSurface()->parentChanged(newParent,oldParent);
137 QLinkedList<WaylandSurface *> SubSurface::subSurfaces() const
139 return m_sub_surfaces;
142 void SubSurface::parentDestroyed()
146 void SubSurface::attach_sub_surface(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource, int32_t x, int32_t y)
149 SubSurface *parent_sub_surface = static_cast<SubSurface *>(sub_surface_parent_resource->data);
150 SubSurface *child_sub_surface = static_cast<SubSurface *>(sub_surface_child_resource->data);
151 parent_sub_surface->setSubSurface(child_sub_surface,x,y);
154 void SubSurface::move_sub_surface(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource, int32_t x, int32_t y)
159 SubSurface *parent_sub_surface = static_cast<SubSurface *>(sub_surface_parent_resource->data);
160 SubSurface *child_sub_surface = static_cast<SubSurface *>(sub_surface_child_resource->data);
161 Q_UNUSED(parent_sub_surface);
162 Q_UNUSED(child_sub_surface);
165 void SubSurface::raise(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource)
168 Q_UNUSED(sub_surface_parent_resource);
169 Q_UNUSED(sub_surface_child_resource);
172 void SubSurface::lower(wl_client *client, wl_resource *sub_surface_parent_resource, wl_resource *sub_surface_child_resource)
175 Q_UNUSED(sub_surface_parent_resource);
176 Q_UNUSED(sub_surface_child_resource);
179 const struct wl_sub_surface_interface SubSurface::sub_surface_interface = {
180 SubSurface::attach_sub_surface,
181 SubSurface::move_sub_surface,