-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver_configuration.cpp
86 lines (74 loc) · 3.06 KB
/
server_configuration.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
* Copyright © 2013-2014 Canonical Ltd.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 3 as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* Authored by: Alexandros Frantzis <[email protected]>
*/
#include "server_configuration.h"
#include "mir/options/default_configuration.h"
#include "mir/input/composite_event_filter.h"
#include "mir/graphics/default_display_configuration_policy.h"
#include "mir/main_loop.h"
#include "server_example_display_configuration_policy.h"
#include "server_example_input_event_filter.h"
namespace me = mir::examples;
namespace mg = mir::graphics;
namespace
{
std::shared_ptr<mir::options::DefaultConfiguration> const& customize(
std::shared_ptr<mir::options::DefaultConfiguration> const& opt)
{
opt->add_options()(me::display_config_opt,
boost::program_options::value<std::string>()->
default_value(me::clone_opt_val),
me::display_config_descr);
return opt;
}
}
me::ServerConfiguration::ServerConfiguration(std::shared_ptr<options::DefaultConfiguration> const& configuration_options) :
DefaultServerConfiguration(customize(configuration_options))
{
}
me::ServerConfiguration::ServerConfiguration(int argc, char const** argv) :
ServerConfiguration(std::make_shared<options::DefaultConfiguration>(argc, argv))
{
}
std::shared_ptr<mg::DisplayConfigurationPolicy>
me::ServerConfiguration::the_display_configuration_policy()
{
return display_configuration_policy(
[this]() -> std::shared_ptr<mg::DisplayConfigurationPolicy>
{
auto display_config = the_options()->get<std::string>(me::display_config_opt);
if (display_config == me::sidebyside_opt_val)
return std::make_shared<mg::SideBySideDisplayConfigurationPolicy>();
else if (display_config == me::single_opt_val)
return std::make_shared<mg::SingleDisplayConfigurationPolicy>();
else
return DefaultServerConfiguration::the_display_configuration_policy();
});
}
std::shared_ptr<mir::input::CompositeEventFilter>
me::ServerConfiguration::the_composite_event_filter()
{
return composite_event_filter(
[this]() -> std::shared_ptr<mir::input::CompositeEventFilter>
{
if (!quit_filter)
quit_filter = std::make_shared<me::QuitFilter>([this] { the_main_loop()->stop(); });
auto composite_filter = DefaultServerConfiguration::the_composite_event_filter();
composite_filter->append(quit_filter);
return composite_filter;
});
}