Merge lp:~andreas-pokorny/mir/example-configure-input-devices into lp:mir
- example-configure-input-devices
- Merge into development-branch
Status: | Merged |
---|---|
Approved by: | Alexandros Frantzis |
Approved revision: | no longer in the source branch. |
Merged at revision: | 3138 |
Proposed branch: | lp:~andreas-pokorny/mir/example-configure-input-devices |
Merge into: | lp:mir |
Prerequisite: | lp:~andreas-pokorny/mir/input-configuration-api |
Diff against target: |
327 lines (+267/-0) 6 files modified
examples/CMakeLists.txt (+1/-0) examples/server_example.cpp (+2/-0) examples/server_example_input_device_config.cpp (+162/-0) examples/server_example_input_device_config.h (+73/-0) include/server/mir/server.h (+8/-0) src/server/server.cpp (+21/-0) |
To merge this branch: | bzr merge lp:~andreas-pokorny/mir/example-configure-input-devices |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Alan Griffiths | Approve | ||
Alexandros Frantzis (community) | Approve | ||
PS Jenkins bot (community) | continuous-integration | Approve | |
Cemil Azizoglu (community) | Approve | ||
Review via email: mp+277845@code.launchpad.net |
This proposal supersedes a proposal from 2015-11-18.
Commit message
Add program options to mir_demo_server for input devices
touchpad and mouse cursor and scroll speeds can be configured separately.
Description of the change
Extend examples to provide a few settings that affect input devices.
To test this properly on touchpads, this MP is essential: lp:~andreas-pokorny/mir/fix-missing-pointer-flag-at-touchpads
PS Jenkins bot (ps-jenkins) wrote : | # |
Cemil Azizoglu (cemil-azizoglu) wrote : | # |
Looks good.
Nits:
1. s/touch pad/touchpad
90 + "Disable touch pad while typing on keyboard configuration [true, false]",
2. s/scrolll/scroll
+ "Select scrolll mode for touchpads: [{two-finger, edge}]",
3. s/accleration/
mouse_cursor_
mouse_cursor_
4.
174 +void me::InputDevice
A more compact implementation would be
if (contains(
{
mi:
pointer_
pointer_
pointer_
device-
if (contains(
{
}
}
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3107
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
None: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
PS Jenkins bot (ps-jenkins) wrote : | # |
PASSED: Continuous integration, rev:3108
http://
Executed test runs:
SUCCESS: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild:
http://
Alexandros Frantzis (afrantzis) wrote : | # |
Looks good.
Nit:
+ "Scales mice scroll events, use negative values for natural scrolling",
+ "Scales touchpad scroll events, use negative values for natural scrolling",
Should be "Scale..." for consistency (e.g. "Disable touchpad...", "Select scroll...")
Preview Diff
1 | === modified file 'examples/CMakeLists.txt' |
2 | --- examples/CMakeLists.txt 2015-10-20 03:30:00 +0000 |
3 | +++ examples/CMakeLists.txt 2015-11-26 08:55:29 +0000 |
4 | @@ -21,6 +21,7 @@ |
5 | server_example_basic_window_manager.h |
6 | server_example_canonical_window_manager.cpp |
7 | server_example_display_configuration_policy.cpp |
8 | + server_example_input_device_config.cpp |
9 | server_example_input_event_filter.cpp |
10 | server_example_log_options.cpp |
11 | server_example_input_filter.cpp |
12 | |
13 | === modified file 'examples/server_example.cpp' |
14 | --- examples/server_example.cpp 2015-10-07 16:39:31 +0000 |
15 | +++ examples/server_example.cpp 2015-11-26 08:55:29 +0000 |
16 | @@ -25,6 +25,7 @@ |
17 | #include "server_example_custom_compositor.h" |
18 | #include "server_example_test_client.h" |
19 | #include "server_example_cursor_images.h" |
20 | +#include "server_example_input_device_config.h" |
21 | |
22 | #include "mir/server.h" |
23 | #include "mir/main_loop.h" |
24 | @@ -92,6 +93,7 @@ |
25 | me::add_glog_options_to(server); |
26 | me::add_window_manager_option_to(server); |
27 | me::add_custom_compositor_option_to(server); |
28 | + me::add_input_device_configuration_options_to(server); |
29 | add_launcher_option_to(server); |
30 | add_timeout_option_to(server); |
31 | me::add_x_cursor_images(server); |
32 | |
33 | === added file 'examples/server_example_input_device_config.cpp' |
34 | --- examples/server_example_input_device_config.cpp 1970-01-01 00:00:00 +0000 |
35 | +++ examples/server_example_input_device_config.cpp 2015-11-26 08:55:29 +0000 |
36 | @@ -0,0 +1,162 @@ |
37 | +/* |
38 | + * Copyright © 2015 Canonical Ltd. |
39 | + * |
40 | + * This program is free software: you can redistribute it and/or modify it |
41 | + * under the terms of the GNU General Public License version 3, |
42 | + * as published by the Free Software Foundation. |
43 | + * |
44 | + * This program is distributed in the hope that it will be useful, |
45 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
46 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
47 | + * GNU General Public License for more details. |
48 | + * |
49 | + * You should have received a copy of the GNU General Public License |
50 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
51 | + * |
52 | + * Authored By: Andreas Pokorny <andreas.pokorny@canonical.com> |
53 | + */ |
54 | + |
55 | +#include "server_example_input_device_config.h" |
56 | + |
57 | +#include "mir/input/device_capability.h" |
58 | +#include "mir/input/pointer_configuration.h" |
59 | +#include "mir/input/touchpad_configuration.h" |
60 | +#include "mir/input/input_device_hub.h" |
61 | +#include "mir/input/device.h" |
62 | +#include "mir/options/option.h" |
63 | +#include "mir/server.h" |
64 | + |
65 | +namespace me = mir::examples; |
66 | +namespace mi = mir::input; |
67 | + |
68 | +///\example server_example_input_device_config.cpp |
69 | +/// Demonstrate input device configuration |
70 | + |
71 | +char const* const me::disable_while_typing_opt = "disable-while-typing"; |
72 | +char const* const me::mouse_cursor_acceleration_bias_opt = "mouse-cursor-acceleration-bias"; |
73 | +char const* const me::mouse_scroll_speed_scale_opt = "mouse-scroll-speed-scale"; |
74 | +char const* const me::touchpad_cursor_acceleration_bias_opt = "touchpad-cursor-acceleration-bias"; |
75 | +char const* const me::touchpad_scroll_speed_scale_opt = "touchpad-scroll-speed-scale"; |
76 | +char const* const me::touchpad_scroll_mode_opt = "touchpad-scroll-mode"; |
77 | + |
78 | +char const* const touchpad_scroll_mode_two_finger = "two-finger"; |
79 | +char const* const touchpad_scroll_mode_edge = "edge"; |
80 | + |
81 | +char const* const me::touchpad_click_mode_opt= "touchpad-click-mode"; |
82 | + |
83 | +char const* const touchpad_click_mode_area = "area"; |
84 | +char const* const touchpad_click_mode_finger_count = "finger-count"; |
85 | + |
86 | +void me::add_input_device_configuration_options_to(mir::Server& server) |
87 | +{ |
88 | + // Add choice of monitor configuration |
89 | + server.add_configuration_option(disable_while_typing_opt, |
90 | + "Disable touchpad while typing on keyboard configuration [true, false]", |
91 | + false); |
92 | + server.add_configuration_option(mouse_cursor_acceleration_bias_opt, |
93 | + "Bias to the acceleration curve within the range [-1.0, 1.0] for mice", |
94 | + 0.0); |
95 | + server.add_configuration_option(mouse_scroll_speed_scale_opt, |
96 | + "Scales mice scroll events, use negative values for natural scrolling", |
97 | + 1.0); |
98 | + server.add_configuration_option(touchpad_cursor_acceleration_bias_opt, |
99 | + "Bias to the acceleration curve within the range [-1.0, 1.0] for touchpads", |
100 | + 0.0); |
101 | + server.add_configuration_option(touchpad_scroll_speed_scale_opt, |
102 | + "Scales touchpad scroll events, use negative values for natural scrolling", |
103 | + -1.0); |
104 | + |
105 | + server.add_configuration_option(touchpad_scroll_mode_opt, |
106 | + "Select scroll mode for touchpads: [{two-finger, edge}]", |
107 | + touchpad_scroll_mode_two_finger); |
108 | + |
109 | + server.add_configuration_option(touchpad_click_mode_opt, |
110 | + "Select click mode for touchpads: [{area, finger-count}]", |
111 | + touchpad_click_mode_finger_count); |
112 | + |
113 | + auto clamp_to_range = [](double val) |
114 | + { |
115 | + if (val < -1.0) |
116 | + val = -1.0; |
117 | + else if (val > 1.0) |
118 | + val = 1.0; |
119 | + return val; |
120 | + }; |
121 | + |
122 | + // TODO the configuration api allows a combination of values. We might want to expose that in the command line api too. |
123 | + auto convert_to_scroll_mode = [](std::string const& val) |
124 | + { |
125 | + if (val == touchpad_scroll_mode_edge) |
126 | + return mir_touchpad_scroll_mode_edge_scroll; |
127 | + if (val == touchpad_scroll_mode_two_finger) |
128 | + return mir_touchpad_scroll_mode_two_finger_scroll; |
129 | + return mir_touchpad_scroll_mode_none; |
130 | + }; |
131 | + |
132 | + auto convert_to_click_mode = [](std::string const& val) |
133 | + { |
134 | + if (val == touchpad_click_mode_finger_count) |
135 | + return mir_touchpad_click_mode_finger_count; |
136 | + if (val == touchpad_click_mode_area) |
137 | + return mir_touchpad_click_mode_area_to_click; |
138 | + return mir_touchpad_click_mode_none; |
139 | + }; |
140 | + |
141 | + server.add_init_callback([&]() |
142 | + { |
143 | + auto const options = server.get_options(); |
144 | + auto const input_config = std::make_shared<me::InputDeviceConfig>( |
145 | + options->get<bool>(disable_while_typing_opt), |
146 | + clamp_to_range(options->get<double>(mouse_cursor_acceleration_bias_opt)), |
147 | + options->get<double>(mouse_scroll_speed_scale_opt), |
148 | + clamp_to_range(options->get<double>(touchpad_cursor_acceleration_bias_opt)), |
149 | + options->get<double>(touchpad_scroll_speed_scale_opt), |
150 | + convert_to_click_mode(options->get<std::string>(touchpad_click_mode_opt)), |
151 | + convert_to_scroll_mode(options->get<std::string>(touchpad_scroll_mode_opt)) |
152 | + ); |
153 | + server.the_input_device_hub()->add_observer(input_config); |
154 | + }); |
155 | +} |
156 | + |
157 | +///\example server_example_input_device_config.cpp |
158 | +/// Demonstrate how to implement an InputDeviceObserver that identifies and configures input devices. |
159 | + |
160 | +me::InputDeviceConfig::InputDeviceConfig(bool disable_while_typing, |
161 | + double mouse_cursor_acceleration_bias, |
162 | + double mouse_scroll_speed_scale, |
163 | + double touchpad_scroll_speed_scale, |
164 | + double touchpad_cursor_acceleration_bias, |
165 | + MirTouchpadClickModes click_mode, |
166 | + MirTouchpadClickModes scroll_mode) |
167 | + : disable_while_typing(disable_while_typing), mouse_cursor_acceleration_bias(mouse_cursor_acceleration_bias), |
168 | + mouse_scroll_speed_scale(mouse_scroll_speed_scale), |
169 | + touchpad_cursor_acceleration_bias(touchpad_cursor_acceleration_bias), |
170 | + touchpad_scroll_speed_scale(touchpad_scroll_speed_scale), click_mode(click_mode), scroll_mode(scroll_mode) |
171 | +{ |
172 | +} |
173 | + |
174 | +void me::InputDeviceConfig::device_added(std::shared_ptr<mi::Device> const& device) |
175 | +{ |
176 | + if (contains(device->capabilities(), mi::DeviceCapability::touchpad)) |
177 | + { |
178 | + mi::PointerConfiguration pointer_config( device->pointer_configuration().value() ); |
179 | + pointer_config.cursor_acceleration_bias = touchpad_cursor_acceleration_bias; |
180 | + pointer_config.vertical_scroll_scale = touchpad_scroll_speed_scale; |
181 | + pointer_config.horizontal_scroll_scale = touchpad_scroll_speed_scale; |
182 | + device->apply_pointer_configuration(pointer_config); |
183 | + |
184 | + mi::TouchpadConfiguration touch_config( device->touchpad_configuration().value() ); |
185 | + touch_config.disable_while_typing = disable_while_typing; |
186 | + touch_config.click_mode = click_mode; |
187 | + touch_config.scroll_mode = scroll_mode; |
188 | + device->apply_touchpad_configuration(touch_config); |
189 | + } |
190 | + else if (contains(device->capabilities(), mi::DeviceCapability::pointer)) |
191 | + { |
192 | + mi::PointerConfiguration pointer_config( device->pointer_configuration().value() ); |
193 | + pointer_config.cursor_acceleration_bias = mouse_cursor_acceleration_bias; |
194 | + pointer_config.vertical_scroll_scale = mouse_scroll_speed_scale; |
195 | + pointer_config.horizontal_scroll_scale = mouse_scroll_speed_scale; |
196 | + device->apply_pointer_configuration(pointer_config); |
197 | + } |
198 | +} |
199 | |
200 | === added file 'examples/server_example_input_device_config.h' |
201 | --- examples/server_example_input_device_config.h 1970-01-01 00:00:00 +0000 |
202 | +++ examples/server_example_input_device_config.h 2015-11-26 08:55:29 +0000 |
203 | @@ -0,0 +1,73 @@ |
204 | +/* |
205 | + * Copyright © 2015 Canonical Ltd. |
206 | + * |
207 | + * This program is free software: you can redistribute it and/or modify it |
208 | + * under the terms of the GNU General Public License version 3, |
209 | + * as published by the Free Software Foundation. |
210 | + * |
211 | + * This program is distributed in the hope that it will be useful, |
212 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
213 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
214 | + * GNU General Public License for more details. |
215 | + * |
216 | + * You should have received a copy of the GNU General Public License |
217 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
218 | + * |
219 | + * Authored By: Andreas Pokorny <andreas.pokorny@canonical.com> |
220 | + */ |
221 | + |
222 | +#ifndef MIR_EXAMPLES_INPUT_DEVICE_CONFIG_H_ |
223 | +#define MIR_EXAMPLES_INPUT_DEVICE_CONFIG_H_ |
224 | + |
225 | +#include "mir/input/input_device_observer.h" |
226 | +#include "mir_toolkit/mir_input_device.h" |
227 | + |
228 | +namespace mir |
229 | +{ |
230 | +class Server; |
231 | + |
232 | +namespace input |
233 | +{ |
234 | +class Device; |
235 | +} |
236 | + |
237 | +namespace examples |
238 | +{ |
239 | +extern char const* const disable_while_typing_opt; |
240 | +extern char const* const mouse_cursor_acceleration_bias_opt; |
241 | +extern char const* const mouse_scroll_speed_scale_opt; |
242 | +extern char const* const touchpad_cursor_acceleration_bias_opt; |
243 | +extern char const* const touchpad_scroll_speed_scale_opt; |
244 | +extern char const* const touchpad_click_mode_opt; |
245 | +extern char const* const touchpad_scroll_mode_opt; |
246 | + |
247 | +void add_input_device_configuration_options_to(Server& server); |
248 | + |
249 | +class InputDeviceConfig : public mir::input::InputDeviceObserver |
250 | +{ |
251 | +public: |
252 | + InputDeviceConfig(bool disable_while_typing, |
253 | + double mouse_cursor_acceleration_bias, |
254 | + double mouse_scroll_speed_scale, |
255 | + double touchpad_scroll_speed_scale, |
256 | + double touchpad_cursor_acceleration_bias, |
257 | + MirTouchpadClickModes click_mode, |
258 | + MirTouchpadScrollModes scroll_mode); |
259 | + void device_added(std::shared_ptr<input::Device> const& device) override; |
260 | + void device_changed(std::shared_ptr<input::Device> const&) override {}; |
261 | + void device_removed(std::shared_ptr<input::Device> const&) override {}; |
262 | + void changes_complete() override {} |
263 | +private: |
264 | + bool disable_while_typing; |
265 | + double mouse_cursor_acceleration_bias; |
266 | + double mouse_scroll_speed_scale; |
267 | + double touchpad_cursor_acceleration_bias; |
268 | + double touchpad_scroll_speed_scale; |
269 | + MirTouchpadClickModes click_mode; |
270 | + MirTouchpadScrollModes scroll_mode; |
271 | +}; |
272 | + |
273 | +} |
274 | +} |
275 | + |
276 | +#endif |
277 | |
278 | === modified file 'include/server/mir/server.h' |
279 | --- include/server/mir/server.h 2015-11-16 23:36:29 +0000 |
280 | +++ include/server/mir/server.h 2015-11-26 08:55:29 +0000 |
281 | @@ -128,6 +128,14 @@ |
282 | void add_configuration_option( |
283 | std::string const& option, |
284 | std::string const& description, |
285 | + double default_value); |
286 | + |
287 | + /// Add user configuration option(s) to Mir's option handling. |
288 | + /// These will be resolved during initialisation from the command line, |
289 | + /// environment variables, a config file or the supplied default. |
290 | + void add_configuration_option( |
291 | + std::string const& option, |
292 | + std::string const& description, |
293 | std::string const& default_value); |
294 | |
295 | /// Add user configuration option(s) to Mir's option handling. |
296 | |
297 | === modified file 'src/server/server.cpp' |
298 | --- src/server/server.cpp 2015-11-16 23:36:29 +0000 |
299 | +++ src/server/server.cpp 2015-11-26 08:55:29 +0000 |
300 | @@ -508,6 +508,27 @@ |
301 | void mir::Server::add_configuration_option( |
302 | std::string const& option, |
303 | std::string const& description, |
304 | + double default_) |
305 | +{ |
306 | + verify_setting_allowed(self->server_config); |
307 | + namespace po = boost::program_options; |
308 | + |
309 | + auto const& existing = self->add_configuration_options; |
310 | + |
311 | + auto const option_adder = [=](options::DefaultConfiguration& config) |
312 | + { |
313 | + existing(config); |
314 | + |
315 | + config.add_options() |
316 | + (option.c_str(), po::value<double>()->default_value(default_), description.c_str()); |
317 | + }; |
318 | + |
319 | + self->set_add_configuration_options(option_adder); |
320 | +} |
321 | + |
322 | +void mir::Server::add_configuration_option( |
323 | + std::string const& option, |
324 | + std::string const& description, |
325 | std::string const& default_) |
326 | { |
327 | verify_setting_allowed(self->server_config); |
FAILED: Continuous integration, rev:3106 jenkins. qa.ubuntu. com/job/ mir-ci/ 5576/ jenkins. qa.ubuntu. com/job/ mir-android- vivid-i386- build/4905 jenkins. qa.ubuntu. com/job/ mir-clang- vivid-amd64- build/3812/ console jenkins. qa.ubuntu. com/job/ mir-mediumtests -vivid- touch/4848 jenkins. qa.ubuntu. com/job/ mir-mediumtests -wily-touch/ 805/console jenkins. qa.ubuntu. com/job/ mir-wily- amd64-ci/ 1730 jenkins. qa.ubuntu. com/job/ mir-wily- amd64-ci/ 1730/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- vivid-armhf/ 4849 jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- vivid-armhf/ 4849/artifact/ work/output/ *zip*/output. zip jenkins. qa.ubuntu. com/job/ mir-mediumtests -runner- touch/7427 s-jenkins. ubuntu- ci:8080/ job/touch- flash-device/ 25226 jenkins. qa.ubuntu. com/job/ mir-mediumtests -builder- wily-armhf/ 807/console
http://
Executed test runs:
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
FAILURE: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
deb: http://
SUCCESS: http://
SUCCESS: http://
FAILURE: http://
Click here to trigger a rebuild: s-jenkins. ubuntu- ci:8080/ job/mir- ci/5576/ rebuild
http://