2
* Copyright (C) 2013-2015 Canonical, Ltd.
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.
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.
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/>.
17
#include <QCoreApplication>
19
#include "mirserver.h"
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"
39
#define MESA_EGL_NO_X11_HEADERS
43
#include <mir/graphics/cursor.h>
45
namespace mg = mir::graphics;
46
namespace mo = mir::options;
47
namespace msh = mir::shell;
48
namespace ms = mir::scene;
52
void ignore_unparsed_arguments(int /*argc*/, char const* const/*argv*/[])
57
Q_LOGGING_CATEGORY(QTMIR_MIR_MESSAGES, "qtmir.mir")
59
MirServer::MirServer(int argc, char const* argv[],
60
const QSharedPointer<ScreenController> &screenController, QObject* parent)
62
, m_screenController(screenController)
64
set_command_line_handler(&ignore_unparsed_arguments);
65
set_command_line(argc, argv);
67
override_the_session_listener([]
69
return std::make_shared<SessionListener>();
72
override_the_prompt_session_listener([]
74
return std::make_shared<PromptSessionListener>();
77
override_the_session_authorizer([]
79
return std::make_shared<SessionAuthorizer>();
82
override_the_compositor([]
84
return std::make_shared<QtCompositor>();
87
override_the_cursor_images([]
89
return std::make_shared<qtmir::MirCursorImages>();
92
override_the_input_dispatcher([&screenController]
94
return std::make_shared<QtEventFeeder>(screenController);
97
override_the_gl_config([]
99
return std::make_shared<MirGLConfig>();
102
override_the_server_status_listener([]
104
return std::make_shared<MirServerStatusListener>();
107
override_the_window_manager_builder([this](mir::shell::FocusController* focus_controller)
108
-> std::shared_ptr<mir::shell::WindowManager>
110
auto windowManager = MirWindowManager::create(focus_controller, the_shell_display_layout());
111
m_windowManager = windowManager;
112
return windowManager;
115
wrap_display_configuration_policy(
116
[](const std::shared_ptr<mg::DisplayConfigurationPolicy> &wrapped)
117
-> std::shared_ptr<mg::DisplayConfigurationPolicy>
119
return std::make_shared<TiledDisplayConfigurationPolicy>(wrapped);
122
set_terminator([](int)
124
qDebug() << "Signal caught by Mir, stopping Mir server..";
125
QCoreApplication::quit();
128
add_init_callback([this, &screenController] {
129
screenController->init(the_display(), the_compositor());
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());
143
qCDebug(QTMIR_MIR_MESSAGES) << "MirServer created";
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()
150
m_screenController->terminate();
155
/************************************ Shell side ************************************/
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
169
SessionAuthorizer *MirServer::sessionAuthorizer()
171
auto sharedPtr = the_session_authorizer();
172
if (sharedPtr.unique()) return 0;
174
return static_cast<SessionAuthorizer*>(sharedPtr.get());
177
SessionListener *MirServer::sessionListener()
179
auto sharedPtr = the_session_listener();
180
if (sharedPtr.unique()) return 0;
182
return static_cast<SessionListener*>(sharedPtr.get());
185
PromptSessionListener *MirServer::promptSessionListener()
187
auto sharedPtr = the_prompt_session_listener();
188
if (sharedPtr.unique()) return 0;
190
return static_cast<PromptSessionListener*>(sharedPtr.get());
193
MirShell *MirServer::shell()
195
std::weak_ptr<MirShell> m_shell = the_shell();
196
return m_shell.lock().get();
199
MirWindowManager *MirServer::windowManager()
201
return m_windowManager.lock().get();