Fix broken handling of inactive transient surfaces
[profile/ivi/qtwayland.git] / src / plugins / platforms / wayland / qwaylandshellsurface.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 config.tests 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 "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 void QWaylandShellSurface::resize(QWaylandInputDevice *inputDevice, enum wl_shell_surface_resize edges)
59 {
60     wl_shell_surface_resize(m_shell_surface,inputDevice->wl_seat(),
61                             QWaylandDisplay::currentTimeMillisec(),
62                             edges);
63 }
64
65 void QWaylandShellSurface::move(QWaylandInputDevice *inputDevice)
66 {
67     wl_shell_surface_move(m_shell_surface,
68                           inputDevice->wl_seat(),
69                           QWaylandDisplay::currentTimeMillisec());
70 }
71
72 void QWaylandShellSurface::setTopLevel()
73 {
74     wl_shell_surface_set_toplevel(m_shell_surface);
75 }
76
77 void QWaylandShellSurface::updateTransientParent(QWindow *parent)
78 {
79     QWaylandWindow *parent_wayland_window = static_cast<QWaylandWindow *>(parent->handle());
80     if (!parent_wayland_window || !parent_wayland_window->shellSurface())
81         return;
82
83     // set_transient expects a position relative to the parent
84     QPoint transientPos = m_window->geometry().topLeft(); // this is absolute
85     QWindow *parentWin = m_window->window()->transientParent();
86     transientPos -= parentWin->geometry().topLeft();
87     if (parent_wayland_window->decoration()) {
88         transientPos.setX(transientPos.x() + parent_wayland_window->decoration()->margins().left());
89         transientPos.setY(transientPos.y() + parent_wayland_window->decoration()->margins().top());
90     }
91
92     uint32_t flags = 0;
93     Qt::WindowFlags wf = m_window->window()->windowFlags();
94     if (wf.testFlag(Qt::ToolTip)
95             || wf.testFlag(Qt::WindowTransparentForInput))
96         flags |= WL_SHELL_SURFACE_TRANSIENT_INACTIVE;
97
98     wl_shell_surface_set_transient(m_shell_surface,
99                                    parent_wayland_window->shellSurface()->m_shell_surface,
100                                    transientPos.x(),
101                                    transientPos.y(),
102                                    flags);
103 }
104
105 void QWaylandShellSurface::setTitle(const char *title)
106 {
107     wl_shell_surface_set_title(m_shell_surface, title);
108 }
109
110 void QWaylandShellSurface::ping(void *data,
111                                 struct wl_shell_surface *wl_shell_surface,
112                                 uint32_t serial)
113 {
114     Q_UNUSED(data);
115     wl_shell_surface_pong(wl_shell_surface, serial);
116 }
117
118 void QWaylandShellSurface::configure(void *data,
119                                      wl_shell_surface *wl_shell_surface,
120                                      uint32_t edges,
121                                      int32_t width,
122                                      int32_t height)
123 {
124     Q_UNUSED(wl_shell_surface);
125     QWaylandShellSurface *shell_surface = static_cast<QWaylandShellSurface *>(data);
126     shell_surface->m_window->configure(edges, width, height);
127 }
128
129 void QWaylandShellSurface::popup_done(void *data,
130                                       struct wl_shell_surface *wl_shell_surface)
131 {
132     Q_UNUSED(data);
133     Q_UNUSED(wl_shell_surface);
134 }
135
136 const wl_shell_surface_listener QWaylandShellSurface::m_shell_surface_listener = {
137     QWaylandShellSurface::ping,
138     QWaylandShellSurface::configure,
139     QWaylandShellSurface::popup_done
140 };