Change copyrights from Nokia to Digia
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylandshellsurface.cpp
1 /****************************************************************************
2 **
3 ** Copyright (C) 2012 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the config.tests of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia.  For licensing terms and
14 ** conditions see http://qt.digia.com/licensing.  For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights.  These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file.  Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41
42 #include "qwaylandshellsurface.h"
43
44 #include "qwaylanddisplay.h"
45 #include "qwaylandwindow.h"
46 #include "qwaylandinputdevice.h"
47 #include "qwaylanddecoration.h"
48
49 #include <QtCore/QDebug>
50
51 QWaylandShellSurface::QWaylandShellSurface(struct wl_shell_surface *shell_surface, QWaylandWindow *window)
52     : m_shell_surface(shell_surface)
53     , m_window(window)
54 {
55     wl_shell_surface_add_listener(m_shell_surface,&m_shell_surface_listener,this);
56 }
57
58 QWaylandShellSurface::~QWaylandShellSurface()
59 {
60     wl_shell_surface_destroy(m_shell_surface);
61 }
62
63 void QWaylandShellSurface::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
64 {
65     wl_shell_surface_resize(m_shell_surface,inputDevice->wl_seat(),
66                             QWaylandDisplay::currentTimeMillisec(),
67                             edges);
68 }
69
70 void QWaylandShellSurface::move(QWaylandInputDevice *inputDevice)
71 {
72     wl_shell_surface_move(m_shell_surface,
73                           inputDevice->wl_seat(),
74                           QWaylandDisplay::currentTimeMillisec());
75 }
76
77 void QWaylandShellSurface::setTopLevel()
78 {
79     wl_shell_surface_set_toplevel(m_shell_surface);
80 }
81
82 void QWaylandShellSurface::updateTransientParent(QWindow *parent)
83 {
84     QWaylandWindow *parent_wayland_window = static_cast<QWaylandWindow *>(parent->handle());
85     if (!parent_wayland_window || !parent_wayland_window->shellSurface())
86         return;
87
88     // set_transient expects a position relative to the parent
89     QPoint transientPos = m_window->geometry().topLeft(); // this is absolute
90     QWindow *parentWin = m_window->window()->transientParent();
91     transientPos -= parentWin->geometry().topLeft();
92     if (parent_wayland_window->decoration()) {
93         transientPos.setX(transientPos.x() + parent_wayland_window->decoration()->margins().left());
94         transientPos.setY(transientPos.y() + parent_wayland_window->decoration()->margins().top());
95     }
96
97     uint32_t flags = 0;
98     Qt::WindowFlags wf = m_window->window()->windowFlags();
99     if (wf.testFlag(Qt::ToolTip)
100             || wf.testFlag(Qt::WindowTransparentForInput))
101         flags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE;
102
103     wl_shell_surface_set_transient(m_shell_surface,
104                                    parent_wayland_window->wl_surface(),
105                                    transientPos.x(),
106                                    transientPos.y(),
107                                    flags);
108 }
109
110 void QWaylandShellSurface::setTitle(const char *title)
111 {
112     wl_shell_surface_set_title(m_shell_surface, title);
113 }
114
115 void QWaylandShellSurface::ping(void *data,
116                                 struct wl_shell_surface *wl_shell_surface,
117                                 uint32_t serial)
118 {
119     Q_UNUSED(data);
120     wl_shell_surface_pong(wl_shell_surface, serial);
121 }
122
123 void QWaylandShellSurface::configure(void *data,
124                                      wl_shell_surface *wl_shell_surface,
125                                      uint32_t edges,
126                                      int32_t width,
127                                      int32_t height)
128 {
129     Q_UNUSED(wl_shell_surface);
130     QWaylandShellSurface *shell_surface = static_cast<QWaylandShellSurface *>(data);
131     shell_surface->m_window->configure(edges, width, height);
132 }
133
134 void QWaylandShellSurface::popup_done(void *data,
135                                       struct wl_shell_surface *wl_shell_surface)
136 {
137     Q_UNUSED(data);
138     Q_UNUSED(wl_shell_surface);
139 }
140
141 const wl_shell_surface_listener QWaylandShellSurface::m_shell_surface_listener = {
142     QWaylandShellSurface::ping,
143     QWaylandShellSurface::configure,
144     QWaylandShellSurface::popup_done
145 };