48
48
class SystemCompositorShell : public mf::Shell
51
SystemCompositorShell(std::shared_ptr<mf::Shell> const& self,
51
SystemCompositorShell(SystemCompositor *compositor,
52
std::shared_ptr<mf::Shell> const& self,
52
53
std::shared_ptr<msh::FocusController> const& focus_controller)
53
: self(self), focus_controller{focus_controller} {}
54
: compositor{compositor}, self(self), focus_controller{focus_controller} {}
55
56
std::shared_ptr<mf::Session> session_named(std::string const& name)
60
61
void set_active_session(std::string const& name)
62
63
active_session = name;
64
if (auto session = std::static_pointer_cast<msc::Session>(session_named(name)))
65
focus_controller->set_focus_to(session);
67
std::cerr << "Unable to set active session, unknown client name " << name << std::endl;
64
update_session_focus();
70
67
void set_next_session(std::string const& name)
72
if (auto const session = std::static_pointer_cast<msc::Session>(session_named(name)))
74
focus_controller->set_focus_to(session); // raise session inside its depth id set
75
set_active_session(active_session); // to restore input focus to where it should be
78
std::cerr << "Unable to set next session, unknown client name " << name << std::endl;
70
update_session_focus();
74
void update_session_focus()
76
auto spinner = std::static_pointer_cast<msc::Session>(session_named(spinner_session));
77
auto next = std::static_pointer_cast<msc::Session>(session_named(next_session));
78
auto active = std::static_pointer_cast<msc::Session>(session_named(active_session));
85
std::cerr << "Setting next focus to session " << next_session;
86
focus_controller->set_focus_to(next);
90
std::cerr << "Setting next focus to spinner";
92
focus_controller->set_focus_to(spinner);
97
std::cerr << "; active focus to session " << active_session << std::endl;
98
focus_controller->set_focus_to(active);
102
std::cerr << "; active focus to spinner" << std::endl;
104
focus_controller->set_focus_to(spinner);
82
108
std::shared_ptr<mf::Session> open_session(
84
110
std::string const& name,
85
111
std::shared_ptr<mf::EventSink> const& sink)
113
std::cerr << "Opening session " << name << std::endl;
87
114
auto result = self->open_session(client_pid, name, sink);
88
115
sessions[name] = result;
90
// Opening a new session will steal focus from our active session, so
91
// restore the focus if needed.
92
set_active_session(active_session);
117
if (client_pid == compositor->get_spinner_pid())
118
spinner_session = name;
97
123
void close_session(std::shared_ptr<mf::Session> const& session)
125
std::cerr << "Closing session " << session->name() << std::endl;
127
if (session->name() == spinner_session)
128
spinner_session = "";
99
130
sessions.erase(session->name());
100
131
self->close_session(session);
110
141
void handle_surface_created(std::shared_ptr<mf::Session> const& session)
112
143
self->handle_surface_created(session);
145
// Opening a new surface will steal focus from our active surface, so
146
// restore the focus if needed.
147
update_session_focus();
150
SystemCompositor *compositor;
115
151
std::shared_ptr<mf::Shell> const self;
116
152
std::shared_ptr<msh::FocusController> const focus_controller;
117
153
std::map<std::string, std::shared_ptr<mf::Session>> sessions;
118
154
std::string active_session;
155
std::string next_session;
156
std::string spinner_session;
121
159
class SystemCompositorServerConfiguration : public mir::DefaultServerConfiguration
199
std::string spinner()
201
// TODO: once our default spinner is ready for use everywhere, replace
202
// default value with DEFAULT_SPINNER instead of the empty string.
203
auto x = the_options()->get("spinner", "");
161
208
bool public_socket()
163
210
return !the_options()->is_set("no-file") && the_options()->get("public-socket", true);
244
292
("to-dm-fd", po::value<int>(), "File descriptor of write end of pipe to display manager [int]")
245
293
("blacklist", po::value<std::string>(), "Video blacklist regex to use")
246
294
("version", "Show version of Unity System Compositor")
295
("spinner", po::value<std::string>(), "Path to spinner executable")
247
296
("public-socket", po::value<bool>(), "Make the socket file publicly writable")
248
297
("power-off-delay", po::value<int>(), "Delay in milliseconds before powering off screen [int]")
249
298
("enable-hardware-cursor", po::value<bool>(), "Enable the hardware cursor (disabled by default)");
354
403
active_session->set_lifecycle_state(mir_lifecycle_state_resumed);
406
pid_t SystemCompositor::get_spinner_pid() const
408
return spinner_process.pid();
357
411
void SystemCompositor::set_active_session(std::string client_name)
359
413
std::cerr << "set_active_session" << std::endl;
381
435
io_service.run();
438
void SystemCompositor::launch_spinner()
440
if (config->spinner().empty())
443
// Launch spinner process to provide default background when a session isn't ready
444
QStringList env = QProcess::systemEnvironment();
445
env << "MIR_SOCKET=" + QString(config->get_socket_file().c_str());
446
spinner_process.setEnvironment(env);
447
spinner_process.start(config->spinner().c_str());
384
450
void SystemCompositor::qt_main(int argc, char **argv)
386
452
QCoreApplication app(argc, argv);
387
453
DBusScreen dbus_screen(config, config->power_off_delay());