~alan-griffiths/miral/debug

« back to all changes in this revision

Viewing changes to miral-qt/src/platforms/mirserver/mirwindowmanager.cpp

  • Committer: Gerry Boland
  • Date: 2016-06-01 22:06:51 UTC
  • mto: This revision was merged to the branch mainline in revision 178.
  • Revision ID: gerry.boland@canonical.com-20160601220651-ge508tffql4e7u7c
Import QtMir code into miral-qt subdirectory. Disabled by default, use -DMIRAL_ENABLE_QT=1 to build.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2015-2016 Canonical, Ltd.
 
3
 *
 
4
 * This program is free software: you can redistribute it and/or modify it under
 
5
 * the terms of the GNU Lesser General Public License version 3, as published by
 
6
 * the Free Software Foundation.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful, but WITHOUT
 
9
 * ANY WARRANTY; without even the implied warranties of MERCHANTABILITY,
 
10
 * SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 
11
 * Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
 
 
17
#include "mirwindowmanager.h"
 
18
#include "logging.h"
 
19
#include "surfaceobserver.h"
 
20
#include "tracepoints.h" // generated from tracepoints.tp
 
21
 
 
22
#include <mir/geometry/rectangle.h>
 
23
#include <mir/scene/session.h>
 
24
#include <mir/scene/surface_creation_parameters.h>
 
25
#include <mir/scene/surface.h>
 
26
#include <mir/shell/display_layout.h>
 
27
 
 
28
#include <QMutexLocker>
 
29
 
 
30
namespace ms = mir::scene;
 
31
 
 
32
namespace
 
33
{
 
34
class MirWindowManagerImpl : public MirWindowManager
 
35
{
 
36
public:
 
37
 
 
38
    MirWindowManagerImpl(const std::shared_ptr<mir::shell::DisplayLayout> &displayLayout,
 
39
            std::shared_ptr<::SessionListener> sessionListener);
 
40
 
 
41
    void add_session(std::shared_ptr<mir::scene::Session> const& session) override;
 
42
 
 
43
    void remove_session(std::shared_ptr<mir::scene::Session> const& session) override;
 
44
 
 
45
    mir::frontend::SurfaceId add_surface(
 
46
        std::shared_ptr<mir::scene::Session> const& session,
 
47
        mir::scene::SurfaceCreationParameters const& params,
 
48
        std::function<mir::frontend::SurfaceId(std::shared_ptr<mir::scene::Session> const& session, mir::scene::SurfaceCreationParameters const& params)> const& build) override;
 
49
 
 
50
    void remove_surface(
 
51
        std::shared_ptr<mir::scene::Session> const& session,
 
52
        std::weak_ptr<mir::scene::Surface> const& surface) override;
 
53
 
 
54
    void add_display(mir::geometry::Rectangle const& area) override;
 
55
 
 
56
    void remove_display(mir::geometry::Rectangle const& area) override;
 
57
 
 
58
    bool handle_keyboard_event(MirKeyboardEvent const* event) override;
 
59
 
 
60
    bool handle_touch_event(MirTouchEvent const* event) override;
 
61
 
 
62
    bool handle_pointer_event(MirPointerEvent const* event) override;
 
63
 
 
64
    int set_surface_attribute(
 
65
        std::shared_ptr<mir::scene::Session> const& session,
 
66
        std::shared_ptr<mir::scene::Surface> const& surface,
 
67
        MirSurfaceAttrib attrib,
 
68
        int value) override;
 
69
 
 
70
    void handle_raise_surface(
 
71
        std::shared_ptr<mir::scene::Session> const& session,
 
72
        std::shared_ptr<mir::scene::Surface> const& surface,
 
73
        uint64_t timestamp) override;
 
74
 
 
75
    void modify_surface(
 
76
        const std::shared_ptr<mir::scene::Session>&,
 
77
        const std::shared_ptr<mir::scene::Surface>& surface,
 
78
        const mir::shell::SurfaceSpecification& modifications) override;
 
79
 
 
80
private:
 
81
    std::shared_ptr<mir::shell::DisplayLayout> const m_displayLayout;
 
82
    std::shared_ptr<::SessionListener> m_sessionListener;
 
83
};
 
84
 
 
85
}
 
86
 
 
87
MirWindowManagerImpl::MirWindowManagerImpl(const std::shared_ptr<mir::shell::DisplayLayout> &displayLayout,
 
88
        std::shared_ptr<::SessionListener> sessionListener) :
 
89
    m_displayLayout{displayLayout},
 
90
    m_sessionListener(sessionListener)
 
91
{
 
92
    qCDebug(QTMIR_MIR_MESSAGES) << "MirWindowManagerImpl::MirWindowManagerImpl";
 
93
}
 
94
 
 
95
void MirWindowManagerImpl::add_session(std::shared_ptr<ms::Session> const& /*session*/)
 
96
{
 
97
}
 
98
 
 
99
void MirWindowManagerImpl::remove_session(std::shared_ptr<ms::Session> const& /*session*/)
 
100
{
 
101
}
 
102
 
 
103
mir::frontend::SurfaceId MirWindowManagerImpl::add_surface(
 
104
    std::shared_ptr<ms::Session> const& session,
 
105
    ms::SurfaceCreationParameters const& requestParameters,
 
106
    std::function<mir::frontend::SurfaceId(std::shared_ptr<ms::Session> const& session, ms::SurfaceCreationParameters const& params)> const& build)
 
107
{
 
108
    tracepoint(qtmirserver, surfacePlacementStart);
 
109
 
 
110
    m_sessionListener->surfaceAboutToBeCreated(*session.get(), qtmir::CreationHints(requestParameters));
 
111
 
 
112
    QSize initialSize;
 
113
    // can be connected to via Qt::BlockingQueuedConnection to alter surface initial size
 
114
    {
 
115
        int surfaceType = requestParameters.type.is_set() ? requestParameters.type.value() : -1;
 
116
        Q_EMIT sessionAboutToCreateSurface(session, surfaceType, initialSize);
 
117
    }
 
118
    ms::SurfaceCreationParameters placedParameters = requestParameters;
 
119
 
 
120
    if (initialSize.isValid()) {
 
121
        placedParameters.size.width = mir::geometry::Width(initialSize.width());
 
122
        placedParameters.size.height = mir::geometry::Height(initialSize.height());
 
123
    } else {
 
124
        qCWarning(QTMIR_MIR_MESSAGES) << "MirWindowManagerImpl::add_surface(): didn't get a initial surface"
 
125
            " size from shell. Falling back to fullscreen placement";
 
126
        // This is bad. Fallback to fullscreen
 
127
        mir::geometry::Rectangle rect{requestParameters.top_left, requestParameters.size};
 
128
        m_displayLayout->size_to_output(rect);
 
129
        placedParameters.size = rect.size;
 
130
    }
 
131
 
 
132
 
 
133
    qCDebug(QTMIR_MIR_MESSAGES) << "MirWindowManagerImpl::add_surface(): size requested ("
 
134
                                << requestParameters.size.width.as_int() << "," << requestParameters.size.height.as_int() << ") and placed ("
 
135
                                << placedParameters.size.width.as_int() << "," << placedParameters.size.height.as_int() << ")";
 
136
 
 
137
    tracepoint(qtmirserver, surfacePlacementEnd);
 
138
 
 
139
    auto const result = build(session, placedParameters);
 
140
    auto const surface = session->surface(result);
 
141
 
 
142
    return result;
 
143
}
 
144
 
 
145
void MirWindowManagerImpl::remove_surface(
 
146
    std::shared_ptr<ms::Session> const& session,
 
147
    std::weak_ptr<ms::Surface> const& surface)
 
148
{
 
149
    // Called when the client releases the surface, usually is response to a surface->close()
 
150
    // request from us.
 
151
    // Just destroy straight away as we already have code to gracefully handle surfaces being
 
152
    // detroyed out of the blue (set the QML Surface::live to false and so on).
 
153
    session->destroy_surface(surface);
 
154
}
 
155
 
 
156
void MirWindowManagerImpl::add_display(mir::geometry::Rectangle const& /*area*/)
 
157
{
 
158
}
 
159
 
 
160
void MirWindowManagerImpl::remove_display(mir::geometry::Rectangle const& /*area*/)
 
161
{
 
162
}
 
163
 
 
164
bool MirWindowManagerImpl::handle_keyboard_event(MirKeyboardEvent const* /*event*/)
 
165
{
 
166
    return false;
 
167
}
 
168
 
 
169
bool MirWindowManagerImpl::handle_touch_event(MirTouchEvent const* /*event*/)
 
170
{
 
171
    return false;
 
172
}
 
173
 
 
174
bool MirWindowManagerImpl::handle_pointer_event(MirPointerEvent const* /*event*/)
 
175
{
 
176
    return false;
 
177
}
 
178
 
 
179
void MirWindowManagerImpl::handle_raise_surface(
 
180
    std::shared_ptr<mir::scene::Session> const& /*session*/,
 
181
    std::shared_ptr<mir::scene::Surface> const& /*surface*/,
 
182
    uint64_t /*timestamp*/)
 
183
{
 
184
}
 
185
 
 
186
int MirWindowManagerImpl::set_surface_attribute(
 
187
    std::shared_ptr<ms::Session> const& /*session*/,
 
188
    std::shared_ptr<ms::Surface> const& surface,
 
189
    MirSurfaceAttrib attrib,
 
190
    int value)
 
191
{
 
192
    return surface->configure(attrib, value);
 
193
}
 
194
 
 
195
void MirWindowManagerImpl::modify_surface(const std::shared_ptr<mir::scene::Session>&,
 
196
                                          const std::shared_ptr<mir::scene::Surface>& surface,
 
197
                                          const mir::shell::SurfaceSpecification& modifications)
 
198
{
 
199
    QMutexLocker(&SurfaceObserver::mutex);
 
200
    SurfaceObserver *observer = SurfaceObserver::observerForSurface(surface.get());
 
201
    if (observer) {
 
202
        observer->notifySurfaceModifications(modifications);
 
203
    }
 
204
 
 
205
    if (modifications.name.is_set()) {
 
206
        surface->rename(modifications.name.value());
 
207
    }
 
208
}
 
209
 
 
210
std::shared_ptr<MirWindowManager> MirWindowManager::create(
 
211
    const std::shared_ptr<mir::shell::DisplayLayout> &displayLayout,
 
212
    std::shared_ptr<::SessionListener> sessionListener)
 
213
{
 
214
    return std::make_shared<MirWindowManagerImpl>(displayLayout, sessionListener);
 
215
}