Merge lp:~andreas-pokorny/mir/example-configure-input-devices into lp:mir
- example-configure-input-devices
- Merge into development-branch
Proposed by
Andreas Pokorny
Status: | Superseded |
---|---|
Proposed branch: | lp:~andreas-pokorny/mir/example-configure-input-devices |
Merge into: | lp:mir |
Diff against target: |
1135 lines (+744/-44) 17 files modified
examples/CMakeLists.txt (+1/-0) examples/server_example.cpp (+2/-0) examples/server_example_input_device_config.cpp (+163/-0) examples/server_example_input_device_config.h (+73/-0) include/server/mir/input/device.h (+9/-2) include/server/mir/input/pointer_configuration.h (+71/-0) include/server/mir/input/touchpad_configuration.h (+82/-0) include/server/mir/server.h (+8/-0) src/server/input/CMakeLists.txt (+10/-12) src/server/input/default_device.cpp (+82/-3) src/server/input/default_device.h (+22/-4) src/server/input/default_input_device_hub.cpp (+5/-3) src/server/input/default_input_device_hub.h (+2/-0) src/server/server.cpp (+21/-0) tests/unit-tests/input/CMakeLists.txt (+1/-0) tests/unit-tests/input/test_default_device.cpp (+135/-0) tests/unit-tests/input/test_default_input_device_hub.cpp (+57/-20) |
To merge this branch: | bzr merge lp:~andreas-pokorny/mir/example-configure-input-devices |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+277844@code.launchpad.net |
This proposal has been superseded by 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 post a comment you must log in.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'examples/CMakeLists.txt' |
2 | --- examples/CMakeLists.txt 2015-10-20 03:30:00 +0000 |
3 | +++ examples/CMakeLists.txt 2015-11-18 14:50:22 +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-18 14:50:22 +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-18 14:50:22 +0000 |
36 | @@ -0,0 +1,163 @@ |
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_accleration_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_accleration_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 touch pad while typing on keyboard configuration [true, false]", |
91 | + false); |
92 | + server.add_configuration_option(mouse_cursor_accleration_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_accleration_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 scrolll 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_accleration_bias_opt)), |
147 | + options->get<double>(mouse_scroll_speed_scale_opt), |
148 | + clamp_to_range(options->get<double>(touchpad_cursor_accleration_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_accleration_bias, |
162 | + double mouse_scroll_speed_scale, |
163 | + double touchpad_scroll_speed_scale, |
164 | + double touchpad_cursor_accleration_bias, |
165 | + MirTouchpadClickModes click_mode, |
166 | + MirTouchpadClickModes scroll_mode) |
167 | + : disable_while_typing(disable_while_typing), mouse_cursor_accleration_bias(mouse_cursor_accleration_bias), |
168 | + mouse_scroll_speed_scale(mouse_scroll_speed_scale), |
169 | + touchpad_cursor_accleration_bias(touchpad_cursor_accleration_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::pointer) && |
177 | + contains(device->capabilities(), mi::DeviceCapability::touchpad)) |
178 | + { |
179 | + mi::PointerConfiguration pointer_config( device->pointer_configuration().value() ); |
180 | + pointer_config.cursor_acceleration_bias = touchpad_cursor_accleration_bias; |
181 | + pointer_config.vertical_scroll_scale = touchpad_scroll_speed_scale; |
182 | + pointer_config.horizontal_scroll_scale = touchpad_scroll_speed_scale; |
183 | + device->apply_pointer_configuration(pointer_config); |
184 | + |
185 | + mi::TouchpadConfiguration touch_config( device->touchpad_configuration().value() ); |
186 | + touch_config.disable_while_typing = disable_while_typing; |
187 | + touch_config.click_mode = click_mode; |
188 | + touch_config.scroll_mode = scroll_mode; |
189 | + device->apply_touchpad_configuration(touch_config); |
190 | + } |
191 | + else if (contains(device->capabilities(), mi::DeviceCapability::pointer)) |
192 | + { |
193 | + mi::PointerConfiguration pointer_config( device->pointer_configuration().value() ); |
194 | + pointer_config.cursor_acceleration_bias = mouse_cursor_accleration_bias; |
195 | + pointer_config.vertical_scroll_scale = mouse_scroll_speed_scale; |
196 | + pointer_config.horizontal_scroll_scale = mouse_scroll_speed_scale; |
197 | + device->apply_pointer_configuration(pointer_config); |
198 | + } |
199 | +} |
200 | |
201 | === added file 'examples/server_example_input_device_config.h' |
202 | --- examples/server_example_input_device_config.h 1970-01-01 00:00:00 +0000 |
203 | +++ examples/server_example_input_device_config.h 2015-11-18 14:50:22 +0000 |
204 | @@ -0,0 +1,73 @@ |
205 | +/* |
206 | + * Copyright © 2015 Canonical Ltd. |
207 | + * |
208 | + * This program is free software: you can redistribute it and/or modify it |
209 | + * under the terms of the GNU General Public License version 3, |
210 | + * as published by the Free Software Foundation. |
211 | + * |
212 | + * This program is distributed in the hope that it will be useful, |
213 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
214 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
215 | + * GNU General Public License for more details. |
216 | + * |
217 | + * You should have received a copy of the GNU General Public License |
218 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
219 | + * |
220 | + * Authored By: Andreas Pokorny <andreas.pokorny@canonical.com> |
221 | + */ |
222 | + |
223 | +#ifndef MIR_EXAMPLES_INPUT_DEVICE_CONFIG_H_ |
224 | +#define MIR_EXAMPLES_INPUT_DEVICE_CONFIG_H_ |
225 | + |
226 | +#include "mir/input/input_device_observer.h" |
227 | +#include "mir_toolkit/mir_input_device.h" |
228 | + |
229 | +namespace mir |
230 | +{ |
231 | +class Server; |
232 | + |
233 | +namespace input |
234 | +{ |
235 | +class Device; |
236 | +} |
237 | + |
238 | +namespace examples |
239 | +{ |
240 | +extern char const* const disable_while_typing_opt; |
241 | +extern char const* const mouse_cursor_accleration_bias_opt; |
242 | +extern char const* const mouse_scroll_speed_scale_opt; |
243 | +extern char const* const touchpad_cursor_accleration_bias_opt; |
244 | +extern char const* const touchpad_scroll_speed_scale_opt; |
245 | +extern char const* const touchpad_click_mode_opt; |
246 | +extern char const* const touchpad_scroll_mode_opt; |
247 | + |
248 | +void add_input_device_configuration_options_to(Server& server); |
249 | + |
250 | +class InputDeviceConfig : public mir::input::InputDeviceObserver |
251 | +{ |
252 | +public: |
253 | + InputDeviceConfig(bool disable_while_typing, |
254 | + double mouse_cursor_accleration_bias, |
255 | + double mouse_scroll_speed_scale, |
256 | + double touchpad_scroll_speed_scale, |
257 | + double touchpad_cursor_accleration_bias, |
258 | + MirTouchpadClickModes click_mode, |
259 | + MirTouchpadScrollModes scroll_mode); |
260 | + void device_added(std::shared_ptr<input::Device> const& device) override; |
261 | + void device_changed(std::shared_ptr<input::Device> const&) override {}; |
262 | + void device_removed(std::shared_ptr<input::Device> const&) override {}; |
263 | + void changes_complete() override {} |
264 | +private: |
265 | + bool disable_while_typing; |
266 | + double mouse_cursor_accleration_bias; |
267 | + double mouse_scroll_speed_scale; |
268 | + double touchpad_cursor_accleration_bias; |
269 | + double touchpad_scroll_speed_scale; |
270 | + MirTouchpadClickModes click_mode; |
271 | + MirTouchpadScrollModes scroll_mode; |
272 | +}; |
273 | + |
274 | +} |
275 | +} |
276 | + |
277 | +#endif |
278 | |
279 | === modified file 'include/server/mir/input/device.h' |
280 | --- include/server/mir/input/device.h 2015-10-26 03:33:22 +0000 |
281 | +++ include/server/mir/input/device.h 2015-11-18 14:50:22 +0000 |
282 | @@ -22,6 +22,7 @@ |
283 | |
284 | #include "mir/input/device_capability.h" |
285 | #include "mir_toolkit/event.h" |
286 | +#include "mir/optional_value.h" |
287 | |
288 | #include <memory> |
289 | |
290 | @@ -30,8 +31,8 @@ |
291 | namespace input |
292 | { |
293 | |
294 | -class PointerSettings; |
295 | -class TouchpadSettings; |
296 | +class PointerConfiguration; |
297 | +class TouchpadConfiguration; |
298 | |
299 | class Device |
300 | { |
301 | @@ -43,6 +44,12 @@ |
302 | virtual std::string name() const = 0; |
303 | virtual std::string unique_id() const = 0; |
304 | |
305 | + virtual mir::optional_value<PointerConfiguration> pointer_configuration() const = 0; |
306 | + virtual void apply_pointer_configuration(PointerConfiguration const&) = 0; |
307 | + |
308 | + virtual mir::optional_value<TouchpadConfiguration> touchpad_configuration() const = 0; |
309 | + virtual void apply_touchpad_configuration(TouchpadConfiguration const&) = 0; |
310 | + |
311 | private: |
312 | Device(Device const&) = delete; |
313 | Device& operator=(Device const&) = delete; |
314 | |
315 | === added file 'include/server/mir/input/pointer_configuration.h' |
316 | --- include/server/mir/input/pointer_configuration.h 1970-01-01 00:00:00 +0000 |
317 | +++ include/server/mir/input/pointer_configuration.h 2015-11-18 14:50:22 +0000 |
318 | @@ -0,0 +1,71 @@ |
319 | +/* |
320 | + * Copyright © 2015 Canonical Ltd. |
321 | + * |
322 | + * This program is free software: you can redistribute it and/or modify it |
323 | + * under the terms of the GNU General Public License version 3, |
324 | + * as published by the Free Software Foundation. |
325 | + * |
326 | + * This program is distributed in the hope that it will be useful, |
327 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
328 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
329 | + * GNU General Public License for more details. |
330 | + * |
331 | + * You should have received a copy of the GNU General Public License |
332 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
333 | + * |
334 | + * Authored by: |
335 | + * Andreas Pokorny <andreas.pokorny@canonical.com> |
336 | + */ |
337 | + |
338 | +#ifndef MIR_INPUT_POINTER_CONFIGURATION_H_ |
339 | +#define MIR_INPUT_POINTER_CONFIGURATION_H_ |
340 | + |
341 | +#include "mir_toolkit/common.h" |
342 | +#include "mir_toolkit/client_types.h" |
343 | +#include "mir_toolkit/mir_input_device.h" |
344 | + |
345 | +namespace mir |
346 | +{ |
347 | +namespace input |
348 | +{ |
349 | + |
350 | +struct PointerConfiguration |
351 | +{ |
352 | + PointerConfiguration() {} |
353 | + |
354 | + PointerConfiguration(MirPointerHandedness handedness, double acceleration_bias, double horizontal_scroll_scale, |
355 | + double vertical_scroll_scale) |
356 | + : handedness{handedness}, cursor_acceleration_bias{acceleration_bias}, |
357 | + horizontal_scroll_scale{horizontal_scroll_scale}, vertical_scroll_scale{vertical_scroll_scale} |
358 | + { |
359 | + } |
360 | + |
361 | + /*! |
362 | + * Configure which button shall be used as primary button. That way the input device is configured to be either |
363 | + * right or left handed. |
364 | + */ |
365 | + MirPointerHandedness handedness{mir_pointer_handedness_right}; |
366 | + |
367 | + /*! |
368 | + * Configures the intensity of the cursor acceleration. Values within the range of [-1, 1] are allowed. |
369 | + * - 0: default acceleration |
370 | + * - [-1, 0): reduced acceleration |
371 | + * - (0, 1]: increased acceleration |
372 | + */ |
373 | + double cursor_acceleration_bias{0.0}; |
374 | + |
375 | + /*! |
376 | + * Configures a signed scale of the horizontal scrolling. Use negative values to configure 'natural scrolling' |
377 | + */ |
378 | + double horizontal_scroll_scale{1.0}; |
379 | + |
380 | + /*! |
381 | + * Configures a signed scale of the vertical scrolling. Use negative values to configure 'natural scrolling' |
382 | + */ |
383 | + double vertical_scroll_scale{1.0}; |
384 | +}; |
385 | + |
386 | +} |
387 | +} |
388 | + |
389 | +#endif |
390 | |
391 | === added file 'include/server/mir/input/touchpad_configuration.h' |
392 | --- include/server/mir/input/touchpad_configuration.h 1970-01-01 00:00:00 +0000 |
393 | +++ include/server/mir/input/touchpad_configuration.h 2015-11-18 14:50:22 +0000 |
394 | @@ -0,0 +1,82 @@ |
395 | +/* |
396 | + * Copyright © 2015 Canonical Ltd. |
397 | + * |
398 | + * This program is free software: you can redistribute it and/or modify it |
399 | + * under the terms of the GNU General Public License version 3, |
400 | + * as published by the Free Software Foundation. |
401 | + * |
402 | + * This program is distributed in the hope that it will be useful, |
403 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
404 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
405 | + * GNU General Public License for more details. |
406 | + * |
407 | + * You should have received a copy of the GNU General Public License |
408 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
409 | + * |
410 | + * Authored by: |
411 | + * Andreas Pokorny <andreas.pokorny@canonical.com> |
412 | + */ |
413 | + |
414 | +#ifndef MIR_INPUT_TOUCH_PAD_CONFIGURATION_H_ |
415 | +#define MIR_INPUT_TOUCH_PAD_CONFIGURATION_H_ |
416 | + |
417 | +#include "mir_toolkit/common.h" |
418 | +#include "mir_toolkit/mir_input_device.h" |
419 | + |
420 | +namespace mir |
421 | +{ |
422 | +namespace input |
423 | +{ |
424 | + |
425 | +struct TouchpadConfiguration |
426 | +{ |
427 | + TouchpadConfiguration() {} |
428 | + TouchpadConfiguration(MirTouchpadClickModes click_mode, |
429 | + MirTouchpadScrollModes scroll_mode, |
430 | + int button_down_scroll_button, |
431 | + bool tap_to_click, |
432 | + bool disable_while_typing, |
433 | + bool disable_with_mouse, |
434 | + bool middle_mouse_button_emulation) |
435 | + : click_mode{click_mode}, scroll_mode{scroll_mode}, button_down_scroll_button{button_down_scroll_button}, |
436 | + tap_to_click{tap_to_click}, middle_mouse_button_emulation{middle_mouse_button_emulation}, |
437 | + disable_with_mouse{disable_with_mouse}, disable_while_typing{disable_while_typing} |
438 | + { |
439 | + } |
440 | + |
441 | + /*! |
442 | + * The click mode defines when the touchpad generates software emulated button events. |
443 | + */ |
444 | + MirTouchpadClickModes click_mode{mir_touchpad_click_mode_finger_count}; |
445 | +/*! |
446 | + * The scroll mode defines when the touchpad generates scroll events instead of pointer motion events. |
447 | + */ |
448 | + MirTouchpadScrollModes scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll}; |
449 | + |
450 | + /*! |
451 | + * Configures the button used for the on-button-down scroll mode |
452 | + */ |
453 | + int button_down_scroll_button{0}; |
454 | + |
455 | + /*! |
456 | + * When tap to click is enabled the system will interpret short finger touch down/up sequences as button clicks. |
457 | + */ |
458 | + bool tap_to_click{true}; |
459 | + /*! |
460 | + * Emulates a middle mouse button press when the left and right buttons on a touchpad are pressed. |
461 | + */ |
462 | + bool middle_mouse_button_emulation{true}; |
463 | + /*! |
464 | + * When disable-with-mouse is enabled the touchpad will stop to emit user input events when another pointing device is plugged in. |
465 | + */ |
466 | + bool disable_with_mouse{false}; |
467 | + /*! |
468 | + * When disable-with-mouse is enabled the touchpad will stop to emit user input events when the user starts to use a keyboard and a short period after. |
469 | + */ |
470 | + bool disable_while_typing{false}; |
471 | +}; |
472 | + |
473 | +} |
474 | +} |
475 | + |
476 | +#endif |
477 | |
478 | === modified file 'include/server/mir/server.h' |
479 | --- include/server/mir/server.h 2015-10-07 16:41:50 +0000 |
480 | +++ include/server/mir/server.h 2015-11-18 14:50:22 +0000 |
481 | @@ -127,6 +127,14 @@ |
482 | void add_configuration_option( |
483 | std::string const& option, |
484 | std::string const& description, |
485 | + double default_value); |
486 | + |
487 | + /// Add user configuration option(s) to Mir's option handling. |
488 | + /// These will be resolved during initialisation from the command line, |
489 | + /// environment variables, a config file or the supplied default. |
490 | + void add_configuration_option( |
491 | + std::string const& option, |
492 | + std::string const& description, |
493 | std::string const& default_value); |
494 | |
495 | /// Add user configuration option(s) to Mir's option handling. |
496 | |
497 | === modified file 'src/server/input/CMakeLists.txt' |
498 | --- src/server/input/CMakeLists.txt 2015-11-04 07:43:28 +0000 |
499 | +++ src/server/input/CMakeLists.txt 2015-11-18 14:50:22 +0000 |
500 | @@ -4,26 +4,24 @@ |
501 | set( |
502 | INPUT_SOURCES |
503 | |
504 | + builtin_cursor_images.cpp |
505 | + cursor_controller.cpp |
506 | + default_configuration.cpp |
507 | default_device.cpp |
508 | default_event_builder.cpp |
509 | + default_input_device_hub.cpp |
510 | default_input_manager.cpp |
511 | - default_input_device_hub.cpp |
512 | + display_input_region.cpp |
513 | + event_filter_chain_dispatcher.cpp |
514 | input_modifier_utils.cpp |
515 | + key_repeat_dispatcher.cpp |
516 | + null_input_channel_factory.cpp |
517 | + null_input_dispatcher.cpp |
518 | seat.cpp |
519 | - |
520 | surface_input_dispatcher.cpp |
521 | - event_filter_chain_dispatcher.cpp |
522 | - |
523 | - null_input_channel_factory.cpp |
524 | - null_input_dispatcher.cpp |
525 | - display_input_region.cpp |
526 | - vt_filter.cpp |
527 | - cursor_controller.cpp |
528 | - default_configuration.cpp |
529 | - builtin_cursor_images.cpp |
530 | touchspot_controller.cpp |
531 | - key_repeat_dispatcher.cpp |
532 | validator.cpp |
533 | + vt_filter.cpp |
534 | ) |
535 | |
536 | add_subdirectory(android) |
537 | |
538 | === modified file 'src/server/input/default_device.cpp' |
539 | --- src/server/input/default_device.cpp 2015-09-30 20:33:59 +0000 |
540 | +++ src/server/input/default_device.cpp 2015-11-18 14:50:22 +0000 |
541 | @@ -17,12 +17,21 @@ |
542 | * Andreas Pokorny <andreas.pokorny@canonical.com> |
543 | */ |
544 | |
545 | -#include "device_handle.h" |
546 | +#include "default_device.h" |
547 | +#include "mir/dispatch/action_queue.h" |
548 | +#include "mir/input/device_capability.h" |
549 | +#include "mir/input/input_device.h" |
550 | +#include "mir/input/touchpad_configuration.h" |
551 | +#include "mir/input/pointer_configuration.h" |
552 | + |
553 | +#include <boost/throw_exception.hpp> |
554 | +#include <stdexcept> |
555 | |
556 | namespace mi = mir::input; |
557 | |
558 | -mi::DefaultDevice::DefaultDevice(MirInputDeviceId id, mi::InputDeviceInfo const& info) : |
559 | - device_id{id}, info(info) |
560 | +mi::DefaultDevice::DefaultDevice(MirInputDeviceId id, std::shared_ptr<dispatch::ActionQueue> const& actions, |
561 | + std::shared_ptr<InputDevice> const& device) : |
562 | + device_id{id}, device{device}, info(device->get_device_info()), pointer{device->get_pointer_settings()}, touchpad{device->get_touchpad_settings()}, actions{actions} |
563 | { |
564 | } |
565 | |
566 | @@ -45,3 +54,73 @@ |
567 | { |
568 | return device_id; |
569 | } |
570 | + |
571 | +mir::optional_value<mi::PointerConfiguration> mi::DefaultDevice::pointer_configuration() const |
572 | +{ |
573 | + if (!pointer.is_set()) |
574 | + return {}; |
575 | + |
576 | + auto const& settings = pointer.value(); |
577 | + |
578 | + return PointerConfiguration(settings.handedness, settings.cursor_acceleration_bias, |
579 | + settings.horizontal_scroll_scale, settings.vertical_scroll_scale); |
580 | +} |
581 | + |
582 | +mir::optional_value<mi::TouchpadConfiguration> mi::DefaultDevice::touchpad_configuration() const |
583 | +{ |
584 | + if (!touchpad.is_set()) |
585 | + return {}; |
586 | + |
587 | + auto const& settings = touchpad.value(); |
588 | + |
589 | + return TouchpadConfiguration(settings.click_mode, settings.scroll_mode, settings.button_down_scroll_button, |
590 | + settings.tap_to_click, settings.disable_while_typing, settings.disable_with_mouse, |
591 | + settings.middle_mouse_button_emulation); |
592 | +} |
593 | + |
594 | +void mi::DefaultDevice::apply_pointer_configuration(mi::PointerConfiguration const& conf) |
595 | +{ |
596 | + if (!pointer.is_set()) |
597 | + BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot apply a pointer configuration")); |
598 | + |
599 | + if (conf.cursor_acceleration_bias < -1.0 || conf.cursor_acceleration_bias > 1.0) |
600 | + BOOST_THROW_EXCEPTION(std::invalid_argument("Cursor acceleration bias out of range")); |
601 | + |
602 | + PointerSettings settings; |
603 | + settings.handedness = conf.handedness; |
604 | + settings.cursor_acceleration_bias = conf.cursor_acceleration_bias; |
605 | + settings.vertical_scroll_scale = conf.vertical_scroll_scale; |
606 | + settings.horizontal_scroll_scale = conf.horizontal_scroll_scale; |
607 | + |
608 | + pointer = settings; |
609 | + |
610 | + actions->enqueue([settings = std::move(settings), dev=device] |
611 | + { |
612 | + dev->apply_settings(settings); |
613 | + }); |
614 | +} |
615 | + |
616 | +void mi::DefaultDevice::apply_touchpad_configuration(mi::TouchpadConfiguration const& conf) |
617 | +{ |
618 | + if (!touchpad.is_set()) |
619 | + BOOST_THROW_EXCEPTION(std::invalid_argument("Cannot apply a touchpad configuration")); |
620 | + |
621 | + if (conf.scroll_mode & mir_touchpad_scroll_mode_button_down_scroll && conf.button_down_scroll_button == mi::no_scroll_button) |
622 | + BOOST_THROW_EXCEPTION(std::invalid_argument("No scroll button configured")); |
623 | + |
624 | + TouchpadSettings settings; |
625 | + settings.click_mode = conf.click_mode; |
626 | + settings.scroll_mode = conf.scroll_mode; |
627 | + settings.button_down_scroll_button = conf.button_down_scroll_button; |
628 | + settings.disable_with_mouse = conf.disable_with_mouse; |
629 | + settings.disable_while_typing = conf.disable_while_typing; |
630 | + settings.tap_to_click = conf.tap_to_click; |
631 | + settings.middle_mouse_button_emulation = conf.middle_mouse_button_emulation; |
632 | + |
633 | + touchpad = settings; |
634 | + |
635 | + actions->enqueue([settings = std::move(settings), dev=device] |
636 | + { |
637 | + dev->apply_settings(settings); |
638 | + }); |
639 | +} |
640 | |
641 | === renamed file 'src/server/input/device_handle.h' => 'src/server/input/default_device.h' |
642 | --- src/server/input/device_handle.h 2015-10-01 09:52:28 +0000 |
643 | +++ src/server/input/default_device.h 2015-11-18 14:50:22 +0000 |
644 | @@ -23,26 +23,44 @@ |
645 | #include "mir_toolkit/event.h" |
646 | #include "mir/input/device.h" |
647 | #include "mir/input/input_device_info.h" |
648 | -#include "mir/module_deleter.h" |
649 | +#include "mir/input/pointer_settings.h" |
650 | +#include "mir/input/touchpad_settings.h" |
651 | +#include "mir/optional_value.h" |
652 | |
653 | #include <memory> |
654 | |
655 | namespace mir |
656 | { |
657 | +namespace dispatch |
658 | +{ |
659 | +class ActionQueue; |
660 | +} |
661 | namespace input |
662 | { |
663 | |
664 | +class InputDevice; |
665 | + |
666 | class DefaultDevice : public Device |
667 | { |
668 | public: |
669 | - DefaultDevice(MirInputDeviceId id, InputDeviceInfo const& info); |
670 | + DefaultDevice(MirInputDeviceId id, std::shared_ptr<dispatch::ActionQueue> const& actions, |
671 | + std::shared_ptr<InputDevice> const& device); |
672 | MirInputDeviceId id() const override; |
673 | DeviceCapabilities capabilities() const override; |
674 | std::string name() const override; |
675 | std::string unique_id() const override; |
676 | + |
677 | + optional_value<PointerConfiguration> pointer_configuration() const override; |
678 | + void apply_pointer_configuration(PointerConfiguration const&) override; |
679 | + optional_value<TouchpadConfiguration> touchpad_configuration() const override; |
680 | + void apply_touchpad_configuration(TouchpadConfiguration const&) override; |
681 | private: |
682 | - MirInputDeviceId device_id; |
683 | - InputDeviceInfo info; |
684 | + MirInputDeviceId const device_id; |
685 | + std::shared_ptr<InputDevice> const device; |
686 | + InputDeviceInfo const info; |
687 | + optional_value<PointerSettings> pointer; |
688 | + optional_value<TouchpadSettings> touchpad; |
689 | + std::shared_ptr<dispatch::ActionQueue> const actions; |
690 | }; |
691 | |
692 | } |
693 | |
694 | === modified file 'src/server/input/default_input_device_hub.cpp' |
695 | --- src/server/input/default_input_device_hub.cpp 2015-11-04 07:43:28 +0000 |
696 | +++ src/server/input/default_input_device_hub.cpp 2015-11-18 14:50:22 +0000 |
697 | @@ -17,7 +17,7 @@ |
698 | */ |
699 | |
700 | #include "default_input_device_hub.h" |
701 | -#include "device_handle.h" |
702 | +#include "default_device.h" |
703 | |
704 | #include "seat.h" |
705 | #include "mir/input/input_dispatcher.h" |
706 | @@ -27,6 +27,7 @@ |
707 | #include "mir/geometry/point.h" |
708 | #include "mir/events/event_builders.h" |
709 | #include "mir/dispatch/multiplexing_dispatchable.h" |
710 | +#include "mir/dispatch/action_queue.h" |
711 | #include "mir/server_action_queue.h" |
712 | #include "mir/cookie_factory.h" |
713 | #define MIR_LOG_COMPONENT "Input" |
714 | @@ -52,11 +53,13 @@ |
715 | : input_dispatcher(input_dispatcher), |
716 | input_dispatchable{input_multiplexer}, |
717 | observer_queue(observer_queue), |
718 | + device_queue(std::make_shared<dispatch::ActionQueue>()), |
719 | input_region(input_region), |
720 | cookie_factory(cookie_factory), |
721 | seat(touch_visualizer, cursor_listener), |
722 | device_id_generator{0} |
723 | { |
724 | + input_dispatchable->add_watch(device_queue); |
725 | } |
726 | |
727 | void mi::DefaultInputDeviceHub::add_device(std::shared_ptr<InputDevice> const& device) |
728 | @@ -80,8 +83,7 @@ |
729 | auto const& dev = devices.back(); |
730 | seat.add_device(dev->id()); |
731 | |
732 | - auto handle = std::make_shared<DefaultDevice>( |
733 | - dev->id(), device->get_device_info()); |
734 | + auto handle = std::make_shared<DefaultDevice>(dev->id(), device_queue, device); |
735 | |
736 | // pass input device handle to observer loop.. |
737 | observer_queue->enqueue(this, |
738 | |
739 | === modified file 'src/server/input/default_input_device_hub.h' |
740 | --- src/server/input/default_input_device_hub.h 2015-11-04 07:43:28 +0000 |
741 | +++ src/server/input/default_input_device_hub.h 2015-11-18 14:50:22 +0000 |
742 | @@ -44,6 +44,7 @@ |
743 | { |
744 | class Dispatchable; |
745 | class MultiplexingDispatchable; |
746 | +class ActionQueue; |
747 | } |
748 | namespace input |
749 | { |
750 | @@ -82,6 +83,7 @@ |
751 | std::shared_ptr<InputDispatcher> const input_dispatcher; |
752 | std::shared_ptr<dispatch::MultiplexingDispatchable> const input_dispatchable; |
753 | std::shared_ptr<ServerActionQueue> const observer_queue; |
754 | + std::shared_ptr<dispatch::ActionQueue> const device_queue; |
755 | std::shared_ptr<InputRegion> const input_region; |
756 | std::shared_ptr<cookie::CookieFactory> const cookie_factory; |
757 | Seat seat; |
758 | |
759 | === modified file 'src/server/server.cpp' |
760 | --- src/server/server.cpp 2015-10-09 14:59:25 +0000 |
761 | +++ src/server/server.cpp 2015-11-18 14:50:22 +0000 |
762 | @@ -507,6 +507,27 @@ |
763 | void mir::Server::add_configuration_option( |
764 | std::string const& option, |
765 | std::string const& description, |
766 | + double default_) |
767 | +{ |
768 | + verify_setting_allowed(self->server_config); |
769 | + namespace po = boost::program_options; |
770 | + |
771 | + auto const& existing = self->add_configuration_options; |
772 | + |
773 | + auto const option_adder = [=](options::DefaultConfiguration& config) |
774 | + { |
775 | + existing(config); |
776 | + |
777 | + config.add_options() |
778 | + (option.c_str(), po::value<double>()->default_value(default_), description.c_str()); |
779 | + }; |
780 | + |
781 | + self->set_add_configuration_options(option_adder); |
782 | +} |
783 | + |
784 | +void mir::Server::add_configuration_option( |
785 | + std::string const& option, |
786 | + std::string const& description, |
787 | std::string const& default_) |
788 | { |
789 | verify_setting_allowed(self->server_config); |
790 | |
791 | === modified file 'tests/unit-tests/input/CMakeLists.txt' |
792 | --- tests/unit-tests/input/CMakeLists.txt 2015-10-29 03:39:10 +0000 |
793 | +++ tests/unit-tests/input/CMakeLists.txt 2015-11-18 14:50:22 +0000 |
794 | @@ -9,6 +9,7 @@ |
795 | ${CMAKE_CURRENT_SOURCE_DIR}/test_touchspot_controller.cpp |
796 | ${CMAKE_CURRENT_SOURCE_DIR}/test_input_event.cpp |
797 | ${CMAKE_CURRENT_SOURCE_DIR}/test_event_builders.cpp |
798 | + ${CMAKE_CURRENT_SOURCE_DIR}/test_default_device.cpp |
799 | ${CMAKE_CURRENT_SOURCE_DIR}/test_default_input_device_hub.cpp |
800 | ${CMAKE_CURRENT_SOURCE_DIR}/test_default_input_manager.cpp |
801 | ${CMAKE_CURRENT_SOURCE_DIR}/test_surface_input_dispatcher.cpp |
802 | |
803 | === added file 'tests/unit-tests/input/test_default_device.cpp' |
804 | --- tests/unit-tests/input/test_default_device.cpp 1970-01-01 00:00:00 +0000 |
805 | +++ tests/unit-tests/input/test_default_device.cpp 2015-11-18 14:50:22 +0000 |
806 | @@ -0,0 +1,135 @@ |
807 | +/* |
808 | + * Copyright © 2015 Canonical Ltd. |
809 | + * |
810 | + * This program is free software: you can redistribute it and/or modify |
811 | + * it under the terms of the GNU General Public License version 3 as |
812 | + * published by the Free Software Foundation. |
813 | + * |
814 | + * This program is distributed in the hope that it will be useful, |
815 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
816 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
817 | + * GNU General Public License for more details. |
818 | + * |
819 | + * You should have received a copy of the GNU General Public License |
820 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
821 | + * |
822 | + * Authored by: Andreas Pokorny <andreas.pokorny@canonical.com> |
823 | + */ |
824 | + |
825 | +#include "src/server/input/default_device.h" |
826 | +#include "mir/input/input_device.h" |
827 | +#include "mir/input/touchpad_configuration.h" |
828 | +#include "mir/input/pointer_configuration.h" |
829 | +#include "mir/dispatch/action_queue.h" |
830 | +#include "mir/test/fake_shared.h" |
831 | +#include <gtest/gtest.h> |
832 | +#include <gmock/gmock.h> |
833 | +#include <stdexcept> |
834 | + |
835 | +namespace mi = mir::input; |
836 | +namespace mt = mir::test; |
837 | +namespace md = mir::dispatch; |
838 | +using namespace ::testing; |
839 | +namespace |
840 | +{ |
841 | +struct MockInputDevice : public mi::InputDevice |
842 | +{ |
843 | + MOCK_METHOD2(start, void(mi::InputSink* destination, mi::EventBuilder* builder)); |
844 | + MOCK_METHOD0(stop, void()); |
845 | + MOCK_METHOD0(get_device_info, mi::InputDeviceInfo()); |
846 | + MOCK_CONST_METHOD0(get_pointer_settings, mir::optional_value<mi::PointerSettings>()); |
847 | + MOCK_METHOD1(apply_settings, void(mi::PointerSettings const&)); |
848 | + MOCK_CONST_METHOD0(get_touchpad_settings, mir::optional_value<mi::TouchpadSettings>()); |
849 | + MOCK_METHOD1(apply_settings, void(mi::TouchpadSettings const&)); |
850 | +}; |
851 | + |
852 | +struct DefaultDevice : Test |
853 | +{ |
854 | + NiceMock<MockInputDevice> touchpad; |
855 | + NiceMock<MockInputDevice> mouse; |
856 | + NiceMock<MockInputDevice> keyboard; |
857 | + std::shared_ptr<md::ActionQueue> queue{std::make_shared<md::ActionQueue>()}; |
858 | + |
859 | + DefaultDevice() |
860 | + { |
861 | + using optional_pointer_settings = mir::optional_value<mi::PointerSettings>; |
862 | + using optional_touchpad_settings = mir::optional_value<mi::TouchpadSettings>; |
863 | + ON_CALL(touchpad, get_device_info()) |
864 | + .WillByDefault(Return(mi::InputDeviceInfo{"name", "unique", mi::DeviceCapability::touchpad|mi::DeviceCapability::pointer})); |
865 | + ON_CALL(touchpad, get_pointer_settings()) |
866 | + .WillByDefault(Return(optional_pointer_settings{mi::PointerSettings{}})); |
867 | + ON_CALL(touchpad, get_touchpad_settings()) |
868 | + .WillByDefault(Return(optional_touchpad_settings{mi::TouchpadSettings{}})); |
869 | + |
870 | + ON_CALL(mouse, get_device_info()) |
871 | + .WillByDefault(Return(mi::InputDeviceInfo{"name", "unique", mi::DeviceCapability::pointer})); |
872 | + ON_CALL(mouse, get_pointer_settings()).WillByDefault(Return(optional_pointer_settings{mi::PointerSettings{}})); |
873 | + ON_CALL(mouse, get_touchpad_settings()).WillByDefault(Return(optional_touchpad_settings{})); |
874 | + |
875 | + ON_CALL(keyboard, get_device_info()) |
876 | + .WillByDefault(Return(mi::InputDeviceInfo{"name", "unique", mi::DeviceCapability::keyboard})); |
877 | + ON_CALL(keyboard, get_pointer_settings()).WillByDefault(Return(optional_pointer_settings{})); |
878 | + ON_CALL(keyboard, get_touchpad_settings()).WillByDefault(Return(optional_touchpad_settings{})); |
879 | + } |
880 | +}; |
881 | + |
882 | +} |
883 | + |
884 | +TEST_F(DefaultDevice, refuses_touchpad_config_on_mice) |
885 | +{ |
886 | + mi::DefaultDevice dev(MirInputDeviceId{17}, queue, mt::fake_shared(mouse)); |
887 | + mi::TouchpadConfiguration touch_conf; |
888 | + |
889 | + EXPECT_THROW({dev.apply_touchpad_configuration(touch_conf);}, std::invalid_argument); |
890 | +} |
891 | + |
892 | +TEST_F(DefaultDevice, refuses_touchpad_and_pointer_settings_on_keyboards) |
893 | +{ |
894 | + mi::DefaultDevice dev(MirInputDeviceId{17}, queue, mt::fake_shared(keyboard)); |
895 | + mi::TouchpadConfiguration touch_conf; |
896 | + mi::PointerConfiguration pointer_conf; |
897 | + |
898 | + EXPECT_THROW({dev.apply_touchpad_configuration(touch_conf);}, std::invalid_argument); |
899 | + EXPECT_THROW({dev.apply_pointer_configuration(pointer_conf);}, std::invalid_argument); |
900 | +} |
901 | + |
902 | + |
903 | +TEST_F(DefaultDevice, accepts_pointer_config_on_mice) |
904 | +{ |
905 | + mi::DefaultDevice dev(MirInputDeviceId{17}, queue, mt::fake_shared(mouse)); |
906 | + mi::PointerConfiguration pointer_conf; |
907 | + |
908 | + EXPECT_CALL(mouse, apply_settings(Matcher<mi::PointerSettings const&>(_))); |
909 | + |
910 | + dev.apply_pointer_configuration(pointer_conf); |
911 | + queue->dispatch(md::FdEvent::readable); |
912 | +} |
913 | + |
914 | +TEST_F(DefaultDevice, accepts_touchpad_and_pointer_config_on_touchpads) |
915 | +{ |
916 | + mi::DefaultDevice dev(MirInputDeviceId{17}, queue, mt::fake_shared(touchpad)); |
917 | + mi::TouchpadConfiguration touch_conf; |
918 | + mi::PointerConfiguration pointer_conf; |
919 | + |
920 | + EXPECT_CALL(touchpad, apply_settings(Matcher<mi::PointerSettings const&>(_))); |
921 | + EXPECT_CALL(touchpad, apply_settings(Matcher<mi::TouchpadSettings const&>(_))); |
922 | + |
923 | + dev.apply_touchpad_configuration(touch_conf); |
924 | + dev.apply_pointer_configuration(pointer_conf); |
925 | + queue->dispatch(md::FdEvent::readable); |
926 | + queue->dispatch(md::FdEvent::readable); |
927 | +} |
928 | + |
929 | +TEST_F(DefaultDevice, ensures_cursor_accleration_bias_is_in_range) |
930 | +{ |
931 | + mi::DefaultDevice dev(MirInputDeviceId{17}, queue, mt::fake_shared(touchpad)); |
932 | + |
933 | + mi::PointerConfiguration pointer_conf; |
934 | + pointer_conf.cursor_acceleration_bias = 3.0; |
935 | + EXPECT_THROW({dev.apply_pointer_configuration(pointer_conf);}, std::invalid_argument); |
936 | + pointer_conf.cursor_acceleration_bias = -2.0; |
937 | + EXPECT_THROW({dev.apply_pointer_configuration(pointer_conf);}, std::invalid_argument); |
938 | + |
939 | + pointer_conf.cursor_acceleration_bias = 1.0; |
940 | + EXPECT_NO_THROW(dev.apply_pointer_configuration(pointer_conf)); |
941 | +} |
942 | |
943 | === modified file 'tests/unit-tests/input/test_default_input_device_hub.cpp' |
944 | --- tests/unit-tests/input/test_default_input_device_hub.cpp 2015-11-04 07:43:28 +0000 |
945 | +++ tests/unit-tests/input/test_default_input_device_hub.cpp 2015-11-18 14:50:22 +0000 |
946 | @@ -29,6 +29,8 @@ |
947 | #include "mir/input/touchpad_settings.h" |
948 | #include "mir/input/device.h" |
949 | #include "mir/input/touch_visualizer.h" |
950 | +#include "mir/input/pointer_configuration.h" |
951 | +#include "mir/input/touchpad_configuration.h" |
952 | #include "mir/input/input_device_observer.h" |
953 | #include "mir/dispatch/multiplexing_dispatchable.h" |
954 | #include "mir/dispatch/action_queue.h" |
955 | @@ -48,6 +50,7 @@ |
956 | namespace mtd = mt::doubles; |
957 | namespace geom = mir::geometry; |
958 | using namespace std::literals::chrono_literals; |
959 | +using namespace ::testing; |
960 | |
961 | namespace mir |
962 | { |
963 | @@ -112,25 +115,43 @@ |
964 | Nice<MockInputDevice> device; |
965 | Nice<MockInputDevice> another_device; |
966 | Nice<MockInputDevice> third_device; |
967 | + Nice<MockInputDevice> touchpad; |
968 | |
969 | std::chrono::nanoseconds arbitrary_timestamp; |
970 | |
971 | InputDeviceHubTest() |
972 | { |
973 | - using namespace testing; |
974 | - ON_CALL(device,get_device_info()) |
975 | + ON_CALL(device, get_device_info()) |
976 | .WillByDefault(Return(mi::InputDeviceInfo{"device","dev-1", mi::DeviceCapability::unknown})); |
977 | + ON_CALL(device, get_pointer_settings()) |
978 | + .WillByDefault(Return(mir::optional_value<mi::PointerSettings>())); |
979 | + ON_CALL(device, get_touchpad_settings()) |
980 | + .WillByDefault(Return(mir::optional_value<mi::TouchpadSettings>())); |
981 | |
982 | - ON_CALL(another_device,get_device_info()) |
983 | + ON_CALL(another_device, get_device_info()) |
984 | .WillByDefault(Return(mi::InputDeviceInfo{"another_device","dev-2", mi::DeviceCapability::keyboard})); |
985 | + ON_CALL(another_device, get_pointer_settings()) |
986 | + .WillByDefault(Return(mir::optional_value<mi::PointerSettings>())); |
987 | + ON_CALL(another_device, get_touchpad_settings()) |
988 | + .WillByDefault(Return(mir::optional_value<mi::TouchpadSettings>())); |
989 | |
990 | ON_CALL(third_device,get_device_info()) |
991 | .WillByDefault(Return(mi::InputDeviceInfo{"third_device","dev-3", mi::DeviceCapability::keyboard})); |
992 | + ON_CALL(third_device, get_pointer_settings()) |
993 | + .WillByDefault(Return(mir::optional_value<mi::PointerSettings>())); |
994 | + ON_CALL(third_device, get_touchpad_settings()) |
995 | + .WillByDefault(Return(mir::optional_value<mi::TouchpadSettings>())); |
996 | + |
997 | + ON_CALL(touchpad, get_device_info()) |
998 | + .WillByDefault(Return(mi::InputDeviceInfo{"touchpad", "dev-4", mi::DeviceCapability::touchpad|mi::DeviceCapability::pointer})); |
999 | + ON_CALL(touchpad, get_pointer_settings()) |
1000 | + .WillByDefault(Return(mi::PointerSettings())); |
1001 | + ON_CALL(touchpad, get_touchpad_settings()) |
1002 | + .WillByDefault(Return(mi::TouchpadSettings())); |
1003 | } |
1004 | |
1005 | void capture_input_sink(Nice<MockInputDevice>& dev, mi::InputSink*& sink, mi::EventBuilder*& builder) |
1006 | { |
1007 | - using namespace ::testing; |
1008 | ON_CALL(dev,start(_,_)) |
1009 | .WillByDefault(Invoke([&sink,&builder](mi::InputSink* input_sink, mi::EventBuilder* event_builder) |
1010 | { |
1011 | @@ -143,8 +164,6 @@ |
1012 | |
1013 | TEST_F(InputDeviceHubTest, input_device_hub_starts_device) |
1014 | { |
1015 | - using namespace ::testing; |
1016 | - |
1017 | EXPECT_CALL(device,start(_,_)); |
1018 | |
1019 | hub.add_device(mt::fake_shared(device)); |
1020 | @@ -152,8 +171,6 @@ |
1021 | |
1022 | TEST_F(InputDeviceHubTest, input_device_hub_stops_device_on_removal) |
1023 | { |
1024 | - using namespace ::testing; |
1025 | - |
1026 | EXPECT_CALL(device,stop()); |
1027 | |
1028 | hub.add_device(mt::fake_shared(device)); |
1029 | @@ -162,7 +179,6 @@ |
1030 | |
1031 | TEST_F(InputDeviceHubTest, input_device_hub_ignores_removal_of_unknown_devices) |
1032 | { |
1033 | - using namespace ::testing; |
1034 | |
1035 | EXPECT_CALL(device,start(_,_)).Times(0); |
1036 | EXPECT_CALL(device,stop()).Times(0); |
1037 | @@ -172,7 +188,6 @@ |
1038 | |
1039 | TEST_F(InputDeviceHubTest, input_device_hub_start_stop_happens_in_order) |
1040 | { |
1041 | - using namespace ::testing; |
1042 | |
1043 | InSequence seq; |
1044 | EXPECT_CALL(device, start(_,_)); |
1045 | @@ -199,8 +214,6 @@ |
1046 | |
1047 | TEST_F(InputDeviceHubTest, observers_receive_devices_on_add) |
1048 | { |
1049 | - using namespace ::testing; |
1050 | - |
1051 | std::shared_ptr<mi::Device> handle_1, handle_2; |
1052 | |
1053 | InSequence seq; |
1054 | @@ -239,8 +252,6 @@ |
1055 | |
1056 | TEST_F(InputDeviceHubTest, observers_receive_device_changes) |
1057 | { |
1058 | - using namespace ::testing; |
1059 | - |
1060 | InSequence seq; |
1061 | EXPECT_CALL(mock_observer, changes_complete()); |
1062 | EXPECT_CALL(mock_observer, device_added(WithName("device"))); |
1063 | @@ -257,8 +268,6 @@ |
1064 | |
1065 | TEST_F(InputDeviceHubTest, input_sink_posts_events_to_input_dispatcher) |
1066 | { |
1067 | - using namespace ::testing; |
1068 | - |
1069 | mi::InputSink* sink; |
1070 | mi::EventBuilder* builder; |
1071 | std::shared_ptr<mi::Device> handle; |
1072 | @@ -283,7 +292,6 @@ |
1073 | |
1074 | TEST_F(InputDeviceHubTest, forwards_touch_spots_to_visualizer) |
1075 | { |
1076 | - using namespace ::testing; |
1077 | mi::InputSink* sink; |
1078 | mi::EventBuilder* builder; |
1079 | |
1080 | @@ -352,7 +360,6 @@ |
1081 | |
1082 | TEST_F(InputDeviceHubTest, confines_pointer_movement) |
1083 | { |
1084 | - using namespace ::testing; |
1085 | geom::Point confined_pos{10, 18}; |
1086 | |
1087 | ON_CALL(mock_region,confine(_)) |
1088 | @@ -375,8 +382,6 @@ |
1089 | |
1090 | TEST_F(InputDeviceHubTest, forwards_pointer_updates_to_cursor_listener) |
1091 | { |
1092 | - using namespace ::testing; |
1093 | - |
1094 | auto x = 12.2f, y = 14.3f; |
1095 | |
1096 | mi::InputSink* sink; |
1097 | @@ -391,6 +396,38 @@ |
1098 | sink->handle_input(*event); |
1099 | } |
1100 | |
1101 | +TEST_F(InputDeviceHubTest, forwards_pointer_settings_to_input_device) |
1102 | +{ |
1103 | + std::shared_ptr<mi::Device> dev; |
1104 | + ON_CALL(mock_observer, device_added(_)).WillByDefault(SaveArg<0>(&dev)); |
1105 | + |
1106 | + hub.add_observer(mt::fake_shared(mock_observer)); |
1107 | + hub.add_device(mt::fake_shared(touchpad)); |
1108 | + observer_loop.trigger_server_actions(); |
1109 | + |
1110 | + EXPECT_CALL(touchpad, apply_settings(Matcher<mi::PointerSettings const&>(_))); |
1111 | + |
1112 | + auto conf = dev->pointer_configuration(); |
1113 | + dev->apply_pointer_configuration(conf.value()); |
1114 | + multiplexer.dispatch(mir::dispatch::FdEvent::readable); |
1115 | +} |
1116 | + |
1117 | +TEST_F(InputDeviceHubTest, forwards_touchpad_settings_to_input_device) |
1118 | +{ |
1119 | + std::shared_ptr<mi::Device> dev; |
1120 | + ON_CALL(mock_observer, device_added(_)).WillByDefault(SaveArg<0>(&dev)); |
1121 | + |
1122 | + hub.add_observer(mt::fake_shared(mock_observer)); |
1123 | + hub.add_device(mt::fake_shared(touchpad)); |
1124 | + observer_loop.trigger_server_actions(); |
1125 | + |
1126 | + EXPECT_CALL(touchpad, apply_settings(Matcher<mi::TouchpadSettings const&>(_))); |
1127 | + |
1128 | + auto conf = dev->touchpad_configuration(); |
1129 | + dev->apply_touchpad_configuration(conf.value()); |
1130 | + multiplexer.dispatch(mir::dispatch::FdEvent::readable); |
1131 | +} |
1132 | + |
1133 | TEST_F(InputDeviceHubTest, input_sink_tracks_modifier) |
1134 | { |
1135 | using namespace ::testing; |