~mir-team/qtmir/trunk

« back to all changes in this revision

Viewing changes to src/platforms/mirserver/mirserver.cpp

  • Committer: Bileto Bot
  • Author(s): Albert Astals Cid, Gerry Boland
  • Date: 2017-03-20 21:15:13 UTC
  • mfrom: (606.4.12 make_sure_surface_not_null)
  • Revision ID: ci-train-bot@canonical.com-20170320211513-z7v3z0ldes3gtcc0
Check for find() result not being null before using it

We do it in onWindowReady, onWindowMoved, onWindowFocusChanged, etc so no reason to not do it in onWindowRemoved

Approved by: Lukáš Tinkl, Unity8 CI Bot

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright (C) 2013-2015 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 <QCoreApplication>
18
 
 
19
 
#include "mirserver.h"
20
 
 
21
 
// local
22
 
#include "mircursorimages.h"
23
 
#include "mirwindowmanager.h"
24
 
#include "mirglconfig.h"
25
 
#include "mirserverstatuslistener.h"
26
 
#include "promptsessionlistener.h"
27
 
#include "screencontroller.h"
28
 
#include "sessionlistener.h"
29
 
#include "sessionauthorizer.h"
30
 
#include "qtcompositor.h"
31
 
#include "qteventfeeder.h"
32
 
#include "tileddisplayconfigurationpolicy.h"
33
 
#include "logging.h"
34
 
 
35
 
// std
36
 
#include <memory>
37
 
 
38
 
// egl
39
 
#define MESA_EGL_NO_X11_HEADERS
40
 
#include <EGL/egl.h>
41
 
 
42
 
// mir
43
 
#include <mir/graphics/cursor.h>
44
 
 
45
 
namespace mg = mir::graphics;
46
 
namespace mo  = mir::options;
47
 
namespace msh = mir::shell;
48
 
namespace ms = mir::scene;
49
 
 
50
 
namespace
51
 
{
52
 
void ignore_unparsed_arguments(int /*argc*/, char const* const/*argv*/[])
53
 
{
54
 
}
55
 
}
56
 
 
57
 
Q_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES, "qtmir.mir")
58
 
 
59
 
MirServer::MirServer(int argc, char const* argv[],
60
 
                     const QSharedPointer<ScreenController> &screenController, QObject* parent)
61
 
    : QObject(parent)
62
 
    , m_screenController(screenController)
63
 
{
64
 
    set_command_line_handler(&ignore_unparsed_arguments);
65
 
    set_command_line(argc, argv);
66
 
 
67
 
    override_the_session_listener([]
68
 
        {
69
 
            return std::make_shared<SessionListener>();
70
 
        });
71
 
 
72
 
    override_the_prompt_session_listener([]
73
 
        {
74
 
            return std::make_shared<PromptSessionListener>();
75
 
        });
76
 
 
77
 
    override_the_session_authorizer([]
78
 
        {
79
 
            return std::make_shared<SessionAuthorizer>();
80
 
        });
81
 
 
82
 
    override_the_compositor([]
83
 
        {
84
 
            return std::make_shared<QtCompositor>();
85
 
        });
86
 
 
87
 
    override_the_cursor_images([]
88
 
        {
89
 
            return std::make_shared<qtmir::MirCursorImages>();
90
 
        });
91
 
 
92
 
    override_the_input_dispatcher([&screenController]
93
 
        {
94
 
            return std::make_shared<QtEventFeeder>(screenController);
95
 
        });
96
 
 
97
 
    override_the_gl_config([]
98
 
        {
99
 
            return std::make_shared<MirGLConfig>();
100
 
        });
101
 
 
102
 
    override_the_server_status_listener([]
103
 
        {
104
 
            return std::make_shared<MirServerStatusListener>();
105
 
        });
106
 
 
107
 
    override_the_window_manager_builder([this](mir::shell::FocusController* focus_controller)
108
 
        -> std::shared_ptr<mir::shell::WindowManager>
109
 
        {
110
 
            auto windowManager = MirWindowManager::create(focus_controller, the_shell_display_layout());
111
 
            m_windowManager = windowManager;
112
 
            return windowManager;
113
 
        });
114
 
 
115
 
    wrap_display_configuration_policy(
116
 
        [](const std::shared_ptr<mg::DisplayConfigurationPolicy> &wrapped)
117
 
            -> std::shared_ptr<mg::DisplayConfigurationPolicy>
118
 
        {
119
 
            return std::make_shared<TiledDisplayConfigurationPolicy>(wrapped);
120
 
        });
121
 
 
122
 
    set_terminator([](int)
123
 
        {
124
 
            qDebug() << "Signal caught by Mir, stopping Mir server..";
125
 
            QCoreApplication::quit();
126
 
        });
127
 
 
128
 
    add_init_callback([this, &screenController] {
129
 
        screenController->init(the_display(), the_compositor());
130
 
    });
131
 
 
132
 
    apply_settings();
133
 
 
134
 
    // We will draw our own cursor.
135
 
    // FIXME: Call override_the_cusor() instead once this method becomes available in a
136
 
    //        future version of Mir.
137
 
    add_init_callback([this]() {
138
 
        the_cursor()->hide();
139
 
        // Hack to work around https://bugs.launchpad.net/mir/+bug/1502200
140
 
        static_cast<QtCompositor*>(the_compositor().get())->setCursor(the_cursor());
141
 
    });
142
 
 
143
 
    qCDebug(QTMIR_MIR_MESSAGES) << "MirServer created";
144
 
}
145
 
 
146
 
// Override default implementation to ensure we terminate the ScreenController first.
147
 
// Code path followed when Qt tries to shutdown the server.
148
 
void MirServer::stop()
149
 
{
150
 
    m_screenController->terminate();
151
 
    mir::Server::stop();
152
 
}
153
 
 
154
 
 
155
 
/************************************ Shell side ************************************/
156
 
 
157
 
//
158
 
// Note about the
159
 
//     if (sharedPtr.unique()) return 0;
160
 
// constructs used in the functions below.
161
 
// The rationale is that if when you do
162
 
//     the_session_authorizer()
163
 
// get a pointer that is unique means that Mir is not
164
 
// holding the pointer and thus when we return from the
165
 
//     sessionAuthorizer()
166
 
// scope the unique pointer will be destroyed so we return 0
167
 
//
168
 
 
169
 
SessionAuthorizer *MirServer::sessionAuthorizer()
170
 
{
171
 
    auto sharedPtr = the_session_authorizer();
172
 
    if (sharedPtr.unique()) return 0;
173
 
 
174
 
    return static_cast<SessionAuthorizer*>(sharedPtr.get());
175
 
}
176
 
 
177
 
SessionListener *MirServer::sessionListener()
178
 
{
179
 
    auto sharedPtr = the_session_listener();
180
 
    if (sharedPtr.unique()) return 0;
181
 
 
182
 
    return static_cast<SessionListener*>(sharedPtr.get());
183
 
}
184
 
 
185
 
PromptSessionListener *MirServer::promptSessionListener()
186
 
{
187
 
    auto sharedPtr = the_prompt_session_listener();
188
 
    if (sharedPtr.unique()) return 0;
189
 
 
190
 
    return static_cast<PromptSessionListener*>(sharedPtr.get());
191
 
}
192
 
 
193
 
MirShell *MirServer::shell()
194
 
{
195
 
    std::weak_ptr<MirShell> m_shell = the_shell();
196
 
    return m_shell.lock().get();
197
 
}
198
 
 
199
 
MirWindowManager *MirServer::windowManager()
200
 
{
201
 
    return m_windowManager.lock().get();
202
 
}