Mir

Merge lp:~andreas-pokorny/mir/libinput-platform-touch-pad-settings into lp:mir

Proposed by Andreas Pokorny
Status: Merged
Approved by: Andreas Pokorny
Approved revision: no longer in the source branch.
Merged at revision: 3052
Proposed branch: lp:~andreas-pokorny/mir/libinput-platform-touch-pad-settings
Merge into: lp:mir
Prerequisite: lp:~andreas-pokorny/mir/libinput-platform-pointer-settings
Diff against target: 1248 lines (+546/-274)
12 files modified
include/client/mir_toolkit/mir_input_device.h (+17/-0)
include/platform/mir/input/input_device.h (+4/-1)
include/platform/mir/input/touchpad_settings.h (+46/-0)
include/server/mir/input/device.h (+1/-1)
src/platforms/evdev/libinput_device.cpp (+75/-0)
src/platforms/evdev/libinput_device.h (+3/-1)
src/platforms/mesa/server/x11/input/input_device.cpp (+14/-0)
src/platforms/mesa/server/x11/input/input_device.h (+3/-1)
tests/mir_test_framework/fake_input_device_impl.cpp (+16/-0)
tests/mir_test_framework/fake_input_device_impl.h (+2/-0)
tests/unit-tests/input/evdev/test_libinput_device.cpp (+362/-270)
tests/unit-tests/input/test_default_input_device_hub.cpp (+3/-0)
To merge this branch: bzr merge lp:~andreas-pokorny/mir/libinput-platform-touch-pad-settings
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Daniel van Vugt Abstain
Alan Griffiths Approve
Kevin DuBois (community) Approve
Review via email: mp+272845@code.launchpad.net

Commit message

Add mir::input::TouchPadSettings and support for it in libinput platform

Description of the change

Adds settings for touch pads. So far again only supported within libinput...

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ char const* path = setup_mouse(fake_device);

There's an awful lot of this. Would it be worth creating a fixture that does this in SetUp() instead of repeating it in so many tests? Or setting up all the devices in SetUp()?

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ EXPECT_CALL(mock_libinput, libinput_device_config_click_get_method(dev))
+ .WillRepeatedly(Return(static_cast<libinput_config_click_method>(click_method.value())));
+ EXPECT_CALL(mock_libinput, libinput_device_config_scroll_get_method(dev))
+ .WillRepeatedly(Return(static_cast<libinput_config_scroll_method>(scroll_method.value())));
+ EXPECT_CALL(mock_libinput, libinput_device_config_scroll_get_button(dev))
+ .WillRepeatedly(Return(scroll_button));
+ EXPECT_CALL(mock_libinput, libinput_device_config_tap_get_enabled(dev))
+ .WillRepeatedly(Return(tap_to_click?
+ LIBINPUT_CONFIG_TAP_ENABLED:
+ LIBINPUT_CONFIG_TAP_DISABLED));
+ EXPECT_CALL(mock_libinput, libinput_device_config_dwt_get_enabled(dev))
+ .WillRepeatedly(Return(disable_while_typing?
+ LIBINPUT_CONFIG_DWT_ENABLED:
+ LIBINPUT_CONFIG_DWT_DISABLED));
+ EXPECT_CALL(mock_libinput, libinput_device_config_send_events_get_mode(dev))
+ .WillRepeatedly(Return(disable_with_mouse?
+ LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
+ LIBINPUT_CONFIG_SEND_EVENTS_ENABLED));
+ EXPECT_CALL(mock_libinput, libinput_device_config_middle_emulation_get_enabled(dev))
+ .WillRepeatedly(Return(middle_button_emulation?
+ LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED:
+ LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED));

Setting expectations in the test setup is best avoided (admittedly not always possible).

But these look like they could be replaced with:

ON_CALL(...).WillByDefault(...);

Is there something I'm missing?

review: Needs Fixing
Revision history for this message
Kevin DuBois (kdub) wrote :

just some nits:

+ TouchPadSettings() {}
not needed

+const int no_scroll_button = 0;
const ordering

+ // forwards aldready interpreted events.
typo

review: Needs Fixing
Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

> just some nits:
>
> + TouchPadSettings() {}
> not needed

This is needed when I want to use that with mir::optional_value, as it initializes stuff with curly braces. Also the = default constructor is not enough... Without that clang treats it as a pod and assumes a by member initialization.

fixiing the rest now

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Kevin DuBois (kdub) wrote :

thanks, okay by me

review: Approve
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

+ TouchPadSettings() {}

I think our current practice is to write "TouchPadSettings() = default;" - but I don't know if that avoids the problems you note with clang. (And isn't a blocker.)

Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

OK

review: Approve
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Your plural/singulars are backwards :)

MirTouchPadClickModes a_single_mode;
MirTouchPadClickMode a_set_of_modes;

8 +typedef enum MirTouchPadClickModes
9 +{
10 + mir_touch_pad_click_mode_none = 0,
11 + mir_touch_pad_click_mode_area_to_click = 1 << 1,
12 + mir_touch_pad_click_mode_finger_count = 1 << 2
13 +} MirTouchPadClickModes;
14 +typedef unsigned int MirTouchPadClickMode;
15 +
16 +typedef enum MirTouchPadScrollModes
17 +{
18 + mir_touch_pad_scroll_mode_none = 0,
19 + mir_touch_pad_scroll_mode_two_finger_scroll = 1 << 1,
20 + mir_touch_pad_scroll_mode_edge_scroll = 1 << 2,
21 + mir_touch_pad_scroll_mode_button_down_scroll = 1 << 3
22 +} MirTouchPadScrollModes;
23 +typedef unsigned int MirTouchPadScrollMode;

review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

(2) Also your forgot to make use of bit zero: foo = 1 << 0;

Revision history for this message
Andreas Pokorny (andreas-pokorny) wrote :

> (2) Also your forgot to make use of bit zero: foo = 1 << 0;

ack done.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Thanks.

review: Abstain
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Although Touchpad is a single word, so maybe also:

s/mir_touch_pad/mir_touchpad/

Revision history for this message
Daniel van Vugt (vanvugt) :
review: Needs Fixing
Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Minor spelling correction suggested per above.

review: Abstain
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'include/client/mir_toolkit/mir_input_device.h'
--- include/client/mir_toolkit/mir_input_device.h 2015-10-19 10:45:47 +0000
+++ include/client/mir_toolkit/mir_input_device.h 2015-10-23 10:50:47 +0000
@@ -32,6 +32,23 @@
32 mir_pointer_handedness_left = 132 mir_pointer_handedness_left = 1
33} MirPointerHandedness;33} MirPointerHandedness;
3434
35typedef enum MirTouchpadClickMode
36{
37 mir_touchpad_click_mode_none = 0,
38 mir_touchpad_click_mode_area_to_click = 1 << 0,
39 mir_touchpad_click_mode_finger_count = 1 << 1
40} MirTouchpadClickMode;
41typedef unsigned int MirTouchpadClickModes;
42
43typedef enum MirTouchpadScrollMode
44{
45 mir_touchpad_scroll_mode_none = 0,
46 mir_touchpad_scroll_mode_two_finger_scroll = 1 << 0,
47 mir_touchpad_scroll_mode_edge_scroll = 1 << 1,
48 mir_touchpad_scroll_mode_button_down_scroll = 1 << 2
49} MirTouchpadScrollMode;
50typedef unsigned int MirTouchpadScrollModes;
51
35#ifdef __cplusplus52#ifdef __cplusplus
36}53}
37#endif54#endif
3855
=== modified file 'include/platform/mir/input/input_device.h'
--- include/platform/mir/input/input_device.h 2015-10-20 03:30:00 +0000
+++ include/platform/mir/input/input_device.h 2015-10-23 10:50:47 +0000
@@ -38,6 +38,7 @@
38class EventBuilder;38class EventBuilder;
3939
40class PointerSettings;40class PointerSettings;
41class TouchpadSettings;
4142
42/**43/**
43 * Represents an input device.44 * Represents an input device.
@@ -59,9 +60,11 @@
5960
60 virtual InputDeviceInfo get_device_info() = 0;61 virtual InputDeviceInfo get_device_info() = 0;
6162
62 virtual mir::optional_value<PointerSettings> get_pointer_settings() const = 0;63 virtual optional_value<PointerSettings> get_pointer_settings() const = 0;
63 virtual void apply_settings(PointerSettings const&) = 0;64 virtual void apply_settings(PointerSettings const&) = 0;
6465
66 virtual optional_value<TouchpadSettings> get_touchpad_settings() const = 0;
67 virtual void apply_settings(TouchpadSettings const&) = 0;
65protected:68protected:
66 InputDevice(InputDevice const&) = delete;69 InputDevice(InputDevice const&) = delete;
67 InputDevice& operator=(InputDevice const&) = delete;70 InputDevice& operator=(InputDevice const&) = delete;
6871
=== added file 'include/platform/mir/input/touchpad_settings.h'
--- include/platform/mir/input/touchpad_settings.h 1970-01-01 00:00:00 +0000
+++ include/platform/mir/input/touchpad_settings.h 2015-10-23 10:50:47 +0000
@@ -0,0 +1,46 @@
1/*
2 * Copyright © 2015 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU Lesser General Public License version 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU Lesser General Public License for more details.
12 *
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/>.
15 *
16 * Authored by:
17 * Andreas Pokorny <andreas.pokorny@canonical.com>
18 */
19
20#ifndef MIR_INPUT_TOUCH_PAD_SETTINGS_H_
21#define MIR_INPUT_TOUCH_PAD_SETTINGS_H_
22
23#include "mir_toolkit/mir_input_device.h"
24
25namespace mir
26{
27namespace input
28{
29int const no_scroll_button = 0;
30
31struct TouchpadSettings
32{
33 TouchpadSettings() {}
34 MirTouchpadClickModes click_mode{mir_touchpad_click_mode_finger_count};
35 MirTouchpadScrollModes scroll_mode{mir_touchpad_scroll_mode_two_finger_scroll};
36 int button_down_scroll_button{no_scroll_button};
37 bool tap_to_click{true};
38 bool disable_while_typing{false};
39 bool disable_with_mouse{false};
40 bool middle_mouse_button_emulation{true};
41};
42
43}
44}
45
46#endif
047
=== modified file 'include/server/mir/input/device.h'
--- include/server/mir/input/device.h 2015-10-01 09:52:28 +0000
+++ include/server/mir/input/device.h 2015-10-23 10:50:47 +0000
@@ -31,7 +31,7 @@
31{31{
3232
33class PointerSettings;33class PointerSettings;
34class TouchPadSettings;34class TouchpadSettings;
3535
36class Device36class Device
37{37{
3838
=== modified file 'src/platforms/evdev/libinput_device.cpp'
--- src/platforms/evdev/libinput_device.cpp 2015-10-20 03:30:00 +0000
+++ src/platforms/evdev/libinput_device.cpp 2015-10-23 10:50:47 +0000
@@ -26,6 +26,7 @@
26#include "mir/input/input_report.h"26#include "mir/input/input_report.h"
27#include "mir/input/device_capability.h"27#include "mir/input/device_capability.h"
28#include "mir/input/pointer_settings.h"28#include "mir/input/pointer_settings.h"
29#include "mir/input/touchpad_settings.h"
29#include "mir/input/input_device_info.h"30#include "mir/input/input_device_info.h"
30#include "mir/events/event_builders.h"31#include "mir/events/event_builders.h"
31#include "mir/geometry/displacement.h"32#include "mir/geometry/displacement.h"
@@ -393,3 +394,77 @@
393 vertical_scroll_scale = settings.vertical_scroll_scale;394 vertical_scroll_scale = settings.vertical_scroll_scale;
394 horizontal_scroll_scale = settings.horizontal_scroll_scale;395 horizontal_scroll_scale = settings.horizontal_scroll_scale;
395}396}
397
398mir::optional_value<mi::TouchpadSettings> mie::LibInputDevice::get_touchpad_settings() const
399{
400 if (!contains(info.capabilities, mi::DeviceCapability::touchpad))
401 return {};
402
403 auto dev = device();
404 auto click_modes = libinput_device_config_click_get_method(dev);
405 auto scroll_modes = libinput_device_config_scroll_get_method(dev);
406
407 TouchpadSettings settings;
408
409 settings.click_mode = mir_touchpad_click_mode_none;
410 if (click_modes & LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS)
411 settings.click_mode |= mir_touchpad_click_mode_area_to_click;
412 if (click_modes & LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER)
413 settings.click_mode |= mir_touchpad_click_mode_finger_count;
414
415 settings.scroll_mode = mir_touchpad_scroll_mode_none;
416 if (scroll_modes & LIBINPUT_CONFIG_SCROLL_2FG)
417 settings.scroll_mode |= mir_touchpad_scroll_mode_two_finger_scroll;
418 if (scroll_modes & LIBINPUT_CONFIG_SCROLL_EDGE)
419 settings.scroll_mode |= mir_touchpad_scroll_mode_edge_scroll;
420 if (scroll_modes & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN)
421 settings.scroll_mode |= mir_touchpad_scroll_mode_button_down_scroll;
422
423 settings.tap_to_click = libinput_device_config_tap_get_enabled(dev) == LIBINPUT_CONFIG_TAP_ENABLED;
424 settings.disable_while_typing = libinput_device_config_dwt_get_enabled(dev) == LIBINPUT_CONFIG_DWT_ENABLED;
425 settings.disable_with_mouse =
426 libinput_device_config_send_events_get_mode(dev) == LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE;
427 settings.middle_mouse_button_emulation =
428 libinput_device_config_middle_emulation_get_enabled(dev) == LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED;
429
430 return settings;
431}
432
433void mie::LibInputDevice::apply_settings(mi::TouchpadSettings const& settings)
434{
435 auto dev = device();
436
437 uint32_t click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
438 if (settings.click_mode & mir_touchpad_click_mode_area_to_click)
439 click_method |= LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
440 if (settings.click_mode & mir_touchpad_click_mode_finger_count)
441 click_method |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
442
443 uint32_t scroll_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
444 if (settings.scroll_mode & mir_touchpad_scroll_mode_button_down_scroll)
445 {
446 scroll_method |= LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
447 libinput_device_config_scroll_set_button(dev, settings.button_down_scroll_button);
448 }
449 if (settings.scroll_mode & mir_touchpad_scroll_mode_edge_scroll)
450 scroll_method |= LIBINPUT_CONFIG_SCROLL_EDGE;
451 if (settings.scroll_mode & mir_touchpad_scroll_mode_two_finger_scroll)
452 scroll_method |= LIBINPUT_CONFIG_SCROLL_2FG;
453
454 libinput_device_config_click_set_method(dev, static_cast<libinput_config_click_method>(click_method));
455 libinput_device_config_scroll_set_method(dev, static_cast<libinput_config_scroll_method>(scroll_method));
456
457 libinput_device_config_tap_set_enabled(
458 dev, settings.tap_to_click ? LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED);
459
460 libinput_device_config_dwt_set_enabled(
461 dev, settings.disable_while_typing ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED);
462
463 libinput_device_config_send_events_set_mode(dev, settings.disable_with_mouse ?
464 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE :
465 LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
466
467 libinput_device_config_middle_emulation_set_enabled(dev, settings.middle_mouse_button_emulation ?
468 LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
469 LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
470}
396471
=== modified file 'src/platforms/evdev/libinput_device.h'
--- src/platforms/evdev/libinput_device.h 2015-10-20 03:30:00 +0000
+++ src/platforms/evdev/libinput_device.h 2015-10-23 10:50:47 +0000
@@ -54,8 +54,10 @@
54 void start(InputSink* sink, EventBuilder* builder) override;54 void start(InputSink* sink, EventBuilder* builder) override;
55 void stop() override;55 void stop() override;
56 InputDeviceInfo get_device_info() override;56 InputDeviceInfo get_device_info() override;
57 mir::optional_value<PointerSettings> get_pointer_settings() const override;57 optional_value<PointerSettings> get_pointer_settings() const override;
58 void apply_settings(PointerSettings const&) override;58 void apply_settings(PointerSettings const&) override;
59 optional_value<TouchpadSettings> get_touchpad_settings() const override;
60 void apply_settings(TouchpadSettings const&) override;
5961
60 void process_event(libinput_event* event);62 void process_event(libinput_event* event);
61 ::libinput_device* device() const;63 ::libinput_device* device() const;
6264
=== modified file 'src/platforms/mesa/server/x11/input/input_device.cpp'
--- src/platforms/mesa/server/x11/input/input_device.cpp 2015-10-20 03:30:00 +0000
+++ src/platforms/mesa/server/x11/input/input_device.cpp 2015-10-23 10:50:47 +0000
@@ -19,6 +19,7 @@
19#include "input_device.h"19#include "input_device.h"
2020
21#include "mir/input/pointer_settings.h"21#include "mir/input/pointer_settings.h"
22#include "mir/input/touchpad_settings.h"
22#include "mir/input/input_device_info.h"23#include "mir/input/input_device_info.h"
23#include "mir/input/device_capability.h"24#include "mir/input/device_capability.h"
2425
@@ -60,3 +61,16 @@
60{61{
61 // TODO Make use if X11-XInput262 // TODO Make use if X11-XInput2
62}63}
64
65mir::optional_value<mi::TouchpadSettings> mix::XInputDevice::get_touchpad_settings() const
66{
67 optional_value<TouchpadSettings> ret;
68 if (contains(info.capabilities, DeviceCapability::touchpad))
69 ret = TouchpadSettings();
70
71 return ret;
72}
73
74void mix::XInputDevice::apply_settings(TouchpadSettings const&)
75{
76}
6377
=== modified file 'src/platforms/mesa/server/x11/input/input_device.h'
--- src/platforms/mesa/server/x11/input/input_device.h 2015-10-20 03:30:00 +0000
+++ src/platforms/mesa/server/x11/input/input_device.h 2015-10-23 10:50:47 +0000
@@ -41,8 +41,10 @@
41 void stop() override;41 void stop() override;
42 InputDeviceInfo get_device_info() override;42 InputDeviceInfo get_device_info() override;
4343
44 mir::optional_value<PointerSettings> get_pointer_settings() const override;44 optional_value<PointerSettings> get_pointer_settings() const override;
45 void apply_settings(PointerSettings const& settings) override;45 void apply_settings(PointerSettings const& settings) override;
46 optional_value<TouchpadSettings> get_touchpad_settings() const override;
47 void apply_settings(TouchpadSettings const& settings) override;
4648
47 InputSink* sink{nullptr};49 InputSink* sink{nullptr};
48 EventBuilder* builder{nullptr};50 EventBuilder* builder{nullptr};
4951
=== modified file 'tests/mir_test_framework/fake_input_device_impl.cpp'
--- tests/mir_test_framework/fake_input_device_impl.cpp 2015-10-20 03:30:00 +0000
+++ tests/mir_test_framework/fake_input_device_impl.cpp 2015-10-23 10:50:47 +0000
@@ -23,6 +23,7 @@
23#include "mir/input/input_device_info.h"23#include "mir/input/input_device_info.h"
24#include "mir/input/input_sink.h"24#include "mir/input/input_sink.h"
25#include "mir/input/pointer_settings.h"25#include "mir/input/pointer_settings.h"
26#include "mir/input/touchpad_settings.h"
26#include "mir/input/event_builder.h"27#include "mir/input/event_builder.h"
27#include "mir/dispatch/action_queue.h"28#include "mir/dispatch/action_queue.h"
28#include "mir/geometry/displacement.h"29#include "mir/geometry/displacement.h"
@@ -246,6 +247,21 @@
246 this->settings = settings;247 this->settings = settings;
247}248}
248249
250mir::optional_value<mi::TouchpadSettings> mtf::FakeInputDeviceImpl::InputDevice::get_touchpad_settings() const
251{
252 mir::optional_value<mi::TouchpadSettings> ret;
253 if (contains(info.capabilities, mi::DeviceCapability::pointer))
254 ret = mi::TouchpadSettings();
255
256 return ret;
257}
258
259void mtf::FakeInputDeviceImpl::InputDevice::apply_settings(mi::TouchpadSettings const&)
260{
261 // Not applicable for configuration since FakeInputDevice just
262 // forwards already interpreted events.
263}
264
249void mtf::FakeInputDeviceImpl::InputDevice::map_touch_coordinates(float& x, float& y)265void mtf::FakeInputDeviceImpl::InputDevice::map_touch_coordinates(float& x, float& y)
250{266{
251 // TODO take orientation of input sink into account?267 // TODO take orientation of input sink into account?
252268
=== modified file 'tests/mir_test_framework/fake_input_device_impl.h'
--- tests/mir_test_framework/fake_input_device_impl.h 2015-10-20 03:30:00 +0000
+++ tests/mir_test_framework/fake_input_device_impl.h 2015-10-23 10:50:47 +0000
@@ -67,6 +67,8 @@
6767
68 mir::optional_value<mir::input::PointerSettings> get_pointer_settings() const override;68 mir::optional_value<mir::input::PointerSettings> get_pointer_settings() const override;
69 void apply_settings(mir::input::PointerSettings const& settings) override;69 void apply_settings(mir::input::PointerSettings const& settings) override;
70 mir::optional_value<mir::input::TouchpadSettings> get_touchpad_settings() const override;
71 void apply_settings(mir::input::TouchpadSettings const& settings) override;
7072
71 private:73 private:
72 MirPointerAction update_buttons(synthesis::EventAction action, MirPointerButton button);74 MirPointerAction update_buttons(synthesis::EventAction action, MirPointerButton button);
7375
=== modified file 'tests/unit-tests/input/evdev/test_libinput_device.cpp'
--- tests/unit-tests/input/evdev/test_libinput_device.cpp 2015-10-20 03:30:00 +0000
+++ tests/unit-tests/input/evdev/test_libinput_device.cpp 2015-10-23 10:50:47 +0000
@@ -23,17 +23,21 @@
23#include "mir/input/input_device_registry.h"23#include "mir/input/input_device_registry.h"
24#include "mir/input/input_sink.h"24#include "mir/input/input_sink.h"
25#include "mir/input/pointer_settings.h"25#include "mir/input/pointer_settings.h"
26#include "mir/input/touchpad_settings.h"
27#include "mir/flags.h"
26#include "mir/geometry/point.h"28#include "mir/geometry/point.h"
27#include "mir/geometry/rectangle.h"29#include "mir/geometry/rectangle.h"
28#include "mir/test/event_matchers.h"30#include "mir/test/event_matchers.h"
29#include "mir/test/doubles/mock_libinput.h"31#include "mir/test/doubles/mock_libinput.h"
30#include "mir/test/gmock_fixes.h"32#include "mir/test/gmock_fixes.h"
33#include "mir/udev/wrapper.h"
31#include "mir/cookie_factory.h"34#include "mir/cookie_factory.h"
32#include "mir_test_framework/udev_environment.h"35#include "mir_test_framework/udev_environment.h"
3336
34#include <gmock/gmock.h>37#include <gmock/gmock.h>
35#include <gtest/gtest.h>38#include <gtest/gtest.h>
36#include <linux/input.h>39#include <linux/input.h>
40#include <libinput.h>
3741
38#include <chrono>42#include <chrono>
3943
@@ -125,6 +129,7 @@
125 ::testing::NiceMock<mir::test::doubles::MockLibInput> mock_libinput;129 ::testing::NiceMock<mir::test::doubles::MockLibInput> mock_libinput;
126 ::testing::NiceMock<MockInputSink> mock_sink;130 ::testing::NiceMock<MockInputSink> mock_sink;
127 ::testing::NiceMock<MockEventBuilder> mock_builder;131 ::testing::NiceMock<MockEventBuilder> mock_builder;
132 std::shared_ptr<libinput> lib;
128133
129 libinput* fake_input = reinterpret_cast<libinput*>(0xF4C3);134 libinput* fake_input = reinterpret_cast<libinput*>(0xF4C3);
130 libinput_device* fake_device = reinterpret_cast<libinput_device*>(0xF4C4);135 libinput_device* fake_device = reinterpret_cast<libinput_device*>(0xF4C4);
@@ -144,96 +149,186 @@
144 const mi::EventBuilder::Timestamp time_stamp_4{std::chrono::microseconds{event_time_4}};149 const mi::EventBuilder::Timestamp time_stamp_4{std::chrono::microseconds{event_time_4}};
145150
146 char const* laptop_keyboard_device_path = "/dev/input/event4";151 char const* laptop_keyboard_device_path = "/dev/input/event4";
147 char const* path{laptop_keyboard_device_path};152 char const* trackpad_dev_path = "/dev/input/event13";
153 char const* touch_screen_dev_path = "/dev/input/event4";
154 char const* usb_mouse_dev_path = "/dev/input/event13";
155 char const* touchpad_dev_path = "/dev/input/event12";
148156
149 LibInputDevice()157 LibInputDevice()
150 {158 {
151 setup_device(fake_device, path, "laptop-keyboard", 5252, 3113);
152
153 ON_CALL(mock_libinput, libinput_path_create_context(_,_))159 ON_CALL(mock_libinput, libinput_path_create_context(_,_))
154 .WillByDefault(Return(fake_input));160 .WillByDefault(Return(fake_input));
155 }161 lib = mie::make_libinput();
156162 }
157 void setup_device(libinput_device* dev, char const* device_path, char const* umock_name, unsigned int vendor_id, unsigned int product_id)163
164 char const* setup_laptop_keyboard(libinput_device* dev)
165 {
166 return setup_device(dev, laptop_keyboard_device_path, "laptop-keyboard", 5252, 3113);
167 }
168
169 char const* setup_trackpad(libinput_device* dev)
170 {
171 return setup_device(dev, trackpad_dev_path, "bluetooth-magic-trackpad", 9663, 1234);
172 }
173
174 char const* setup_touch_screen(libinput_device* dev)
175 {
176 return setup_device(dev, touch_screen_dev_path, "mt-screen-detection", 858, 484);
177 }
178
179 char const* setup_touchpad(libinput_device* dev)
180 {
181 return setup_device(dev, touchpad_dev_path, "synaptics-touchpad", 858, 484);
182 }
183
184 char const* setup_mouse(libinput_device* dev)
185 {
186 return setup_device(dev, usb_mouse_dev_path, "usb-mouse", 858, 484);
187 }
188
189 void remove_devices()
190 {
191 mir::udev::Enumerator devices{std::make_shared<mir::udev::Context>()};
192 devices.scan_devices();
193
194 for (auto& device : devices)
195 {
196 if (device.devnode() && (std::string(device.devnode()).find("input/event") != std::string::npos))
197 {
198 env.remove_device((std::string("/sys") + device.devpath()).c_str());
199 }
200 }
201 }
202
203 char const* setup_device(libinput_device* dev, char const* device_path, char const* umock_name, unsigned int vendor_id, unsigned int product_id)
158 {204 {
159 env.add_standard_device(umock_name);205 env.add_standard_device(umock_name);
160 mock_libinput.setup_device(fake_input, dev, device_path, umock_name, vendor_id, product_id);206 mock_libinput.setup_device(fake_input, dev, device_path, umock_name, vendor_id, product_id);
207 return device_path;
161 }208 }
162209
163 void setup_pointer_configuration(libinput_device* dev, double accel_speed, MirPointerHandedness handedness)210 void setup_pointer_configuration(libinput_device* dev, double accel_speed, MirPointerHandedness handedness)
164 {211 {
165 EXPECT_CALL(mock_libinput, libinput_device_config_accel_get_speed(dev))212 ON_CALL(mock_libinput, libinput_device_config_accel_get_speed(dev))
166 .WillRepeatedly(Return(accel_speed));213 .WillByDefault(Return(accel_speed));
167 EXPECT_CALL(mock_libinput, libinput_device_config_left_handed_get(dev))214 ON_CALL(mock_libinput, libinput_device_config_left_handed_get(dev))
168 .WillRepeatedly(Return(handedness == mir_pointer_handedness_left));215 .WillByDefault(Return(handedness == mir_pointer_handedness_left));
216 }
217
218 void setup_touchpad_configuration(libinput_device* dev,
219 MirTouchpadClickMode click_mode,
220 MirTouchpadScrollMode scroll_mode,
221 int scroll_button,
222 bool tap_to_click,
223 bool disable_while_typing,
224 bool disable_with_mouse,
225 bool middle_button_emulation)
226 {
227 mir::Flags<libinput_config_click_method> click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE;
228 if (click_mode & mir_touchpad_click_mode_finger_count)
229 click_method |= LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER;
230 if (click_mode & mir_touchpad_click_mode_area_to_click)
231 click_method |= LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS;
232
233 mir::Flags<libinput_config_scroll_method> scroll_method = LIBINPUT_CONFIG_SCROLL_NO_SCROLL;
234 if (scroll_mode & mir_touchpad_scroll_mode_two_finger_scroll)
235 scroll_method |= LIBINPUT_CONFIG_SCROLL_2FG;
236 if (scroll_mode & mir_touchpad_scroll_mode_edge_scroll)
237 scroll_method |= LIBINPUT_CONFIG_SCROLL_EDGE;
238 if (scroll_mode & mir_touchpad_scroll_mode_button_down_scroll)
239 scroll_method |= LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN;
240
241 ON_CALL(mock_libinput, libinput_device_config_click_get_method(dev))
242 .WillByDefault(Return(static_cast<libinput_config_click_method>(click_method.value())));
243 ON_CALL(mock_libinput, libinput_device_config_scroll_get_method(dev))
244 .WillByDefault(Return(static_cast<libinput_config_scroll_method>(scroll_method.value())));
245 ON_CALL(mock_libinput, libinput_device_config_scroll_get_button(dev))
246 .WillByDefault(Return(scroll_button));
247 ON_CALL(mock_libinput, libinput_device_config_tap_get_enabled(dev))
248 .WillByDefault(Return(tap_to_click?
249 LIBINPUT_CONFIG_TAP_ENABLED:
250 LIBINPUT_CONFIG_TAP_DISABLED));
251 ON_CALL(mock_libinput, libinput_device_config_dwt_get_enabled(dev))
252 .WillByDefault(Return(disable_while_typing?
253 LIBINPUT_CONFIG_DWT_ENABLED:
254 LIBINPUT_CONFIG_DWT_DISABLED));
255 ON_CALL(mock_libinput, libinput_device_config_send_events_get_mode(dev))
256 .WillByDefault(Return(disable_with_mouse?
257 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE:
258 LIBINPUT_CONFIG_SEND_EVENTS_ENABLED));
259 ON_CALL(mock_libinput, libinput_device_config_middle_emulation_get_enabled(dev))
260 .WillByDefault(Return(middle_button_emulation?
261 LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED:
262 LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED));
263
169 }264 }
170265
171 void setup_key_event(libinput_event* event, uint64_t event_time, uint32_t key, libinput_key_state state)266 void setup_key_event(libinput_event* event, uint64_t event_time, uint32_t key, libinput_key_state state)
172 {267 {
173 auto key_event = reinterpret_cast<libinput_event_keyboard*>(event);268 auto key_event = reinterpret_cast<libinput_event_keyboard*>(event);
174269
175 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))270 ON_CALL(mock_libinput, libinput_event_get_type(event))
176 .WillRepeatedly(Return(LIBINPUT_EVENT_KEYBOARD_KEY));271 .WillByDefault(Return(LIBINPUT_EVENT_KEYBOARD_KEY));
177 EXPECT_CALL(mock_libinput, libinput_event_get_keyboard_event(event))272 ON_CALL(mock_libinput, libinput_event_get_keyboard_event(event))
178 .WillRepeatedly(Return(key_event));273 .WillByDefault(Return(key_event));
179 EXPECT_CALL(mock_libinput, libinput_event_keyboard_get_time_usec(key_event))274 ON_CALL(mock_libinput, libinput_event_keyboard_get_time_usec(key_event))
180 .WillRepeatedly(Return(event_time));275 .WillByDefault(Return(event_time));
181 EXPECT_CALL(mock_libinput, libinput_event_keyboard_get_key(key_event))276 ON_CALL(mock_libinput, libinput_event_keyboard_get_key(key_event))
182 .WillRepeatedly(Return(key));277 .WillByDefault(Return(key));
183 EXPECT_CALL(mock_libinput, libinput_event_keyboard_get_key_state(key_event))278 ON_CALL(mock_libinput, libinput_event_keyboard_get_key_state(key_event))
184 .WillRepeatedly(Return(state));279 .WillByDefault(Return(state));
185 }280 }
186281
187 void setup_pointer_event(libinput_event* event, uint64_t event_time, float relatve_x, float relatve_y)282 void setup_pointer_event(libinput_event* event, uint64_t event_time, float relatve_x, float relatve_y)
188 {283 {
189 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);284 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);
190285
191 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))286 ON_CALL(mock_libinput, libinput_event_get_type(event))
192 .WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_MOTION));287 .WillByDefault(Return(LIBINPUT_EVENT_POINTER_MOTION));
193 EXPECT_CALL(mock_libinput, libinput_event_get_pointer_event(event))288 ON_CALL(mock_libinput, libinput_event_get_pointer_event(event))
194 .WillRepeatedly(Return(pointer_event));289 .WillByDefault(Return(pointer_event));
195 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))290 ON_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))
196 .WillRepeatedly(Return(event_time));291 .WillByDefault(Return(event_time));
197 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_dx(pointer_event))292 ON_CALL(mock_libinput, libinput_event_pointer_get_dx(pointer_event))
198 .WillRepeatedly(Return(relatve_x));293 .WillByDefault(Return(relatve_x));
199 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_dy(pointer_event))294 ON_CALL(mock_libinput, libinput_event_pointer_get_dy(pointer_event))
200 .WillRepeatedly(Return(relatve_y));295 .WillByDefault(Return(relatve_y));
201 }296 }
202297
203 void setup_button_event(libinput_event* event, uint64_t event_time, int button, libinput_button_state state)298 void setup_button_event(libinput_event* event, uint64_t event_time, int button, libinput_button_state state)
204 {299 {
205 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);300 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);
206301
207 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))302 ON_CALL(mock_libinput, libinput_event_get_type(event))
208 .WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_BUTTON));303 .WillByDefault(Return(LIBINPUT_EVENT_POINTER_BUTTON));
209 EXPECT_CALL(mock_libinput, libinput_event_get_pointer_event(event))304 ON_CALL(mock_libinput, libinput_event_get_pointer_event(event))
210 .WillRepeatedly(Return(pointer_event));305 .WillByDefault(Return(pointer_event));
211 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))306 ON_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))
212 .WillRepeatedly(Return(event_time));307 .WillByDefault(Return(event_time));
213 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_button(pointer_event))308 ON_CALL(mock_libinput, libinput_event_pointer_get_button(pointer_event))
214 .WillRepeatedly(Return(button));309 .WillByDefault(Return(button));
215 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_button_state(pointer_event))310 ON_CALL(mock_libinput, libinput_event_pointer_get_button_state(pointer_event))
216 .WillRepeatedly(Return(state));311 .WillByDefault(Return(state));
217 }312 }
218313
219 void setup_axis_event(libinput_event* event, uint64_t event_time, double horizontal, double vertical)314 void setup_axis_event(libinput_event* event, uint64_t event_time, double horizontal, double vertical)
220 {315 {
221 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);316 auto pointer_event = reinterpret_cast<libinput_event_pointer*>(event);
222317
223 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))318 ON_CALL(mock_libinput, libinput_event_get_type(event))
224 .WillRepeatedly(Return(LIBINPUT_EVENT_POINTER_AXIS));319 .WillByDefault(Return(LIBINPUT_EVENT_POINTER_AXIS));
225 EXPECT_CALL(mock_libinput, libinput_event_get_pointer_event(event))320 ON_CALL(mock_libinput, libinput_event_get_pointer_event(event))
226 .WillRepeatedly(Return(pointer_event));321 .WillByDefault(Return(pointer_event));
227 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))322 ON_CALL(mock_libinput, libinput_event_pointer_get_time_usec(pointer_event))
228 .WillRepeatedly(Return(event_time));323 .WillByDefault(Return(event_time));
229 EXPECT_CALL(mock_libinput, libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))324 ON_CALL(mock_libinput, libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
230 .WillRepeatedly(Return(horizontal!=0.0));325 .WillByDefault(Return(horizontal!=0.0));
231 EXPECT_CALL(mock_libinput, libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))326 ON_CALL(mock_libinput, libinput_event_pointer_has_axis(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
232 .WillRepeatedly(Return(vertical!=0.0));327 .WillByDefault(Return(vertical!=0.0));
233 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_axis_value(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))328 ON_CALL(mock_libinput, libinput_event_pointer_get_axis_value(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_VERTICAL))
234 .WillRepeatedly(Return(vertical));329 .WillByDefault(Return(vertical));
235 EXPECT_CALL(mock_libinput, libinput_event_pointer_get_axis_value(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))330 ON_CALL(mock_libinput, libinput_event_pointer_get_axis_value(pointer_event, LIBINPUT_POINTER_AXIS_SCROLL_HORIZONTAL))
236 .WillRepeatedly(Return(horizontal));331 .WillByDefault(Return(horizontal));
237 }332 }
238333
239 void setup_touch_event(libinput_event* event, libinput_event_type type, uint64_t event_time, int slot, float x,334 void setup_touch_event(libinput_event* event, libinput_event_type type, uint64_t event_time, int slot, float x,
@@ -241,73 +336,91 @@
241 {336 {
242 auto touch_event = reinterpret_cast<libinput_event_touch*>(event);337 auto touch_event = reinterpret_cast<libinput_event_touch*>(event);
243338
244 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))339 ON_CALL(mock_libinput, libinput_event_get_type(event))
245 .WillRepeatedly(Return(type));340 .WillByDefault(Return(type));
246 EXPECT_CALL(mock_libinput, libinput_event_get_touch_event(event))341 ON_CALL(mock_libinput, libinput_event_get_touch_event(event))
247 .WillRepeatedly(Return(touch_event));342 .WillByDefault(Return(touch_event));
248 EXPECT_CALL(mock_libinput, libinput_event_touch_get_slot(touch_event))343 ON_CALL(mock_libinput, libinput_event_touch_get_slot(touch_event))
249 .WillRepeatedly(Return(slot));344 .WillByDefault(Return(slot));
250 EXPECT_CALL(mock_libinput, libinput_event_touch_get_x_transformed(touch_event, _))345 ON_CALL(mock_libinput, libinput_event_touch_get_x_transformed(touch_event, _))
251 .WillRepeatedly(Return(x));346 .WillByDefault(Return(x));
252 EXPECT_CALL(mock_libinput, libinput_event_touch_get_y_transformed(touch_event, _))347 ON_CALL(mock_libinput, libinput_event_touch_get_y_transformed(touch_event, _))
253 .WillRepeatedly(Return(y));348 .WillByDefault(Return(y));
254 EXPECT_CALL(mock_libinput, libinput_event_touch_get_time_usec(touch_event))349 ON_CALL(mock_libinput, libinput_event_touch_get_time_usec(touch_event))
255 .WillRepeatedly(Return(event_time));350 .WillByDefault(Return(event_time));
256 EXPECT_CALL(mock_libinput, libinput_event_touch_get_major_transformed(touch_event, _, _))351 ON_CALL(mock_libinput, libinput_event_touch_get_major_transformed(touch_event, _, _))
257 .WillRepeatedly(Return(major));352 .WillByDefault(Return(major));
258 EXPECT_CALL(mock_libinput, libinput_event_touch_get_minor_transformed(touch_event, _, _))353 ON_CALL(mock_libinput, libinput_event_touch_get_minor_transformed(touch_event, _, _))
259 .WillRepeatedly(Return(minor));354 .WillByDefault(Return(minor));
260 EXPECT_CALL(mock_libinput, libinput_event_touch_get_pressure(touch_event))355 ON_CALL(mock_libinput, libinput_event_touch_get_pressure(touch_event))
261 .WillRepeatedly(Return(pressure));356 .WillByDefault(Return(pressure));
262 }357 }
263358
264 void setup_touch_up_event(libinput_event* event, uint64_t event_time, int slot)359 void setup_touch_up_event(libinput_event* event, uint64_t event_time, int slot)
265 {360 {
266 auto touch_event = reinterpret_cast<libinput_event_touch*>(event);361 auto touch_event = reinterpret_cast<libinput_event_touch*>(event);
267362
268 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))363 ON_CALL(mock_libinput, libinput_event_get_type(event))
269 .WillRepeatedly(Return(LIBINPUT_EVENT_TOUCH_UP));364 .WillByDefault(Return(LIBINPUT_EVENT_TOUCH_UP));
270 EXPECT_CALL(mock_libinput, libinput_event_get_touch_event(event))365 ON_CALL(mock_libinput, libinput_event_get_touch_event(event))
271 .WillRepeatedly(Return(touch_event));366 .WillByDefault(Return(touch_event));
272 EXPECT_CALL(mock_libinput, libinput_event_touch_get_slot(touch_event))367 ON_CALL(mock_libinput, libinput_event_touch_get_slot(touch_event))
273 .WillRepeatedly(Return(slot));368 .WillByDefault(Return(slot));
274 EXPECT_CALL(mock_libinput, libinput_event_touch_get_x_transformed(touch_event, _))369 ON_CALL(mock_libinput, libinput_event_touch_get_time_usec(touch_event))
275 .Times(0);370 .WillByDefault(Return(event_time));
276 EXPECT_CALL(mock_libinput, libinput_event_touch_get_y_transformed(touch_event, _))
277 .Times(0);
278 EXPECT_CALL(mock_libinput, libinput_event_touch_get_x(touch_event))
279 .Times(0);
280 EXPECT_CALL(mock_libinput, libinput_event_touch_get_y(touch_event))
281 .Times(0);
282 EXPECT_CALL(mock_libinput, libinput_event_touch_get_time_usec(touch_event))
283 .WillRepeatedly(Return(event_time));
284 EXPECT_CALL(mock_libinput, libinput_event_touch_get_major_transformed(touch_event, _, _))
285 .Times(0);
286 EXPECT_CALL(mock_libinput, libinput_event_touch_get_minor_transformed(touch_event, _, _))
287 .Times(0);
288 EXPECT_CALL(mock_libinput, libinput_event_touch_get_pressure(touch_event))
289 .Times(0);
290
291 }371 }
292372
293 void setup_touch_frame(libinput_event* event)373 void setup_touch_frame(libinput_event* event)
294 {374 {
295 EXPECT_CALL(mock_libinput, libinput_event_get_type(event))375 ON_CALL(mock_libinput, libinput_event_get_type(event))
296 .WillRepeatedly(Return(LIBINPUT_EVENT_TOUCH_FRAME));376 .WillByDefault(Return(LIBINPUT_EVENT_TOUCH_FRAME));
297 }377 }
298};378};
299379
380struct LibInputDeviceOnLaptopKeyboard : public LibInputDevice
381{
382 char const* keyboard_path = setup_laptop_keyboard(fake_device);
383 mie::LibInputDevice keyboard{mir::report::null_input_report(), keyboard_path, mie::make_libinput_device(lib.get(), keyboard_path)};
384};
385
386struct LibInputDeviceOnMouse : public LibInputDevice
387{
388 char const* mouse_path = setup_mouse(fake_device);
389 mie::LibInputDevice mouse{mir::report::null_input_report(), mouse_path, mie::make_libinput_device(lib.get(), mouse_path)};
390};
391
392struct LibInputDeviceOnLaptopKeyboardAndMouse : public LibInputDevice
393{
394 char const* mouse_path = setup_mouse(fake_device);
395 char const* keyboard_path = setup_laptop_keyboard(fake_device);
396 mie::LibInputDevice keyboard{mir::report::null_input_report(), keyboard_path, mie::make_libinput_device(lib.get(), keyboard_path)};
397 mie::LibInputDevice mouse{mir::report::null_input_report(), mouse_path, mie::make_libinput_device(lib.get(), mouse_path)};
398};
399
400struct LibInputDeviceOnTouchScreen : public LibInputDevice
401{
402 char const* touch_screen_path = setup_touch_screen(fake_device);
403 mie::LibInputDevice touch_screen{mir::report::null_input_report(), touch_screen_path, mie::make_libinput_device(lib.get(), touch_screen_path)};
404};
405
406struct LibInputDeviceOnTouchpad : public LibInputDevice
407{
408 char const* touchpad_path = setup_touchpad(fake_device);
409 mie::LibInputDevice touchpad{mir::report::null_input_report(), touchpad_path, mie::make_libinput_device(lib.get(), touchpad_path)};
410};
300}411}
301412
302TEST_F(LibInputDevice, start_creates_and_unrefs_libinput_device_from_path)413TEST_F(LibInputDevice, start_creates_and_unrefs_libinput_device_from_path)
303{414{
415 char const * path = setup_laptop_keyboard(fake_device);
416
304 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(path)))417 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(path)))
305 .Times(1);418 .Times(1);
306 // according to manual libinput_path_add_device creates a temporary device with a ref count 0.419 // according to manual libinput_path_add_device creates a temporary device with a ref count 0.
307 // hence it needs a manual ref call420 // hence it needs a manual ref call
308 EXPECT_CALL(mock_libinput, libinput_device_ref(fake_device))421 EXPECT_CALL(mock_libinput, libinput_device_ref(fake_device))
309 .Times(1);422 .Times(1);
310 std::shared_ptr<libinput> lib = mie::make_libinput();423
311 mie::LibInputDevice dev(mir::report::null_input_report(),424 mie::LibInputDevice dev(mir::report::null_input_report(),
312 path,425 path,
313 std::move(mie::make_libinput_device(lib.get(), path)));426 std::move(mie::make_libinput_device(lib.get(), path)));
@@ -316,38 +429,32 @@
316429
317TEST_F(LibInputDevice, open_device_of_group)430TEST_F(LibInputDevice, open_device_of_group)
318{431{
319 std::shared_ptr<libinput> lib = mie::make_libinput();432 char const* first_path = setup_laptop_keyboard(fake_device);
320 char const* second_dev = "/dev/input/event13";433 char const* second_path = setup_trackpad(second_fake_device);
321 char const* second_umock_dev_name = "bluetooth-magic-trackpad";
322
323 setup_device(second_fake_device, second_dev, second_umock_dev_name, 9663, 1234);
324434
325 InSequence seq;435 InSequence seq;
326 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(path))).Times(1);436 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(first_path))).Times(1);
327 // according to manual libinput_path_add_device creates a temporary device with a ref count 0.437 // according to manual libinput_path_add_device creates a temporary device with a ref count 0.
328 // hence it needs a manual ref call438 // hence it needs a manual ref call
329 EXPECT_CALL(mock_libinput, libinput_device_ref(fake_device)).Times(1);439 EXPECT_CALL(mock_libinput, libinput_device_ref(fake_device)).Times(1);
330 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(second_dev))).Times(1);440 EXPECT_CALL(mock_libinput, libinput_path_add_device(fake_input,StrEq(second_path))).Times(1);
331 EXPECT_CALL(mock_libinput, libinput_device_ref(second_fake_device)).Times(1);441 EXPECT_CALL(mock_libinput, libinput_device_ref(second_fake_device)).Times(1);
332442
333 mie::LibInputDevice dev(mir::report::null_input_report(),443 mie::LibInputDevice dev(mir::report::null_input_report(),
334 path,444 first_path,
335 std::move(mie::make_libinput_device(lib.get(), path)));445 std::move(mie::make_libinput_device(lib.get(), first_path)));
336 dev.add_device_of_group(second_dev, mie::make_libinput_device(lib.get(), second_dev));446 dev.add_device_of_group(second_path, mie::make_libinput_device(lib.get(), second_path));
337 dev.start(&mock_sink, &mock_builder);447 dev.start(&mock_sink, &mock_builder);
338}448}
339449
340TEST_F(LibInputDevice, input_info_combines_capabilities)450TEST_F(LibInputDevice, input_info_combines_capabilities)
341{451{
342 std::shared_ptr<libinput> lib = mie::make_libinput();452 char const* first_dev = setup_laptop_keyboard(fake_device);
343 char const* second_dev = "/dev/input/event13";453 char const* second_dev = setup_trackpad(second_fake_device);
344 char const* second_umock_dev_name = "bluetooth-magic-trackpad";
345
346 setup_device(second_fake_device, second_dev, second_umock_dev_name, 9663, 1234);
347454
348 mie::LibInputDevice dev(mir::report::null_input_report(),455 mie::LibInputDevice dev(mir::report::null_input_report(),
349 path,456 first_dev,
350 mie::make_libinput_device(lib.get(), path));457 mie::make_libinput_device(lib.get(), first_dev));
351 dev.add_device_of_group(second_dev, mie::make_libinput_device(lib.get(), second_dev));458 dev.add_device_of_group(second_dev, mie::make_libinput_device(lib.get(), second_dev));
352 auto info = dev.get_device_info();459 auto info = dev.get_device_info();
353460
@@ -358,7 +465,7 @@
358465
359TEST_F(LibInputDevice, removal_unrefs_libinput_device)466TEST_F(LibInputDevice, removal_unrefs_libinput_device)
360{467{
361 std::shared_ptr<libinput> lib = mie::make_libinput();468 char const* path = setup_laptop_keyboard(fake_device);
362469
363 EXPECT_CALL(mock_libinput, libinput_device_unref(fake_device))470 EXPECT_CALL(mock_libinput, libinput_device_unref(fake_device))
364 .Times(1);471 .Times(1);
@@ -366,12 +473,8 @@
366 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));473 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
367}474}
368475
369476TEST_F(LibInputDeviceOnLaptopKeyboard, process_event_converts_key_event)
370TEST_F(LibInputDevice, process_event_converts_key_event)
371{477{
372 std::shared_ptr<libinput> lib = mie::make_libinput();
373 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
374
375 setup_key_event(fake_event_1, event_time_1, KEY_A, LIBINPUT_KEY_STATE_PRESSED);478 setup_key_event(fake_event_1, event_time_1, KEY_A, LIBINPUT_KEY_STATE_PRESSED);
376 setup_key_event(fake_event_2, event_time_2, KEY_A, LIBINPUT_KEY_STATE_RELEASED);479 setup_key_event(fake_event_2, event_time_2, KEY_A, LIBINPUT_KEY_STATE_RELEASED);
377480
@@ -380,17 +483,13 @@
380 EXPECT_CALL(mock_builder, key_event(time_stamp_2, mir_keyboard_action_up, _, KEY_A, mir_input_event_modifier_none));483 EXPECT_CALL(mock_builder, key_event(time_stamp_2, mir_keyboard_action_up, _, KEY_A, mir_input_event_modifier_none));
381 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_A),mt::KeyUpEvent())));484 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_A),mt::KeyUpEvent())));
382485
383 dev.start(&mock_sink, &mock_builder);486 keyboard.start(&mock_sink, &mock_builder);
384 dev.process_event(fake_event_1);487 keyboard.process_event(fake_event_1);
385 dev.process_event(fake_event_2);488 keyboard.process_event(fake_event_2);
386}489}
387490
388TEST_F(LibInputDevice, process_event_accumulates_key_state)491TEST_F(LibInputDeviceOnLaptopKeyboard, process_event_accumulates_key_state)
389{492{
390 std::shared_ptr<libinput> lib = mie::make_libinput();
391 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
392
393
394 setup_key_event(fake_event_1, event_time_1, KEY_C, LIBINPUT_KEY_STATE_PRESSED);493 setup_key_event(fake_event_1, event_time_1, KEY_C, LIBINPUT_KEY_STATE_PRESSED);
395 setup_key_event(fake_event_2, event_time_2, KEY_LEFTALT, LIBINPUT_KEY_STATE_PRESSED);494 setup_key_event(fake_event_2, event_time_2, KEY_LEFTALT, LIBINPUT_KEY_STATE_PRESSED);
396 setup_key_event(fake_event_3, event_time_3, KEY_C, LIBINPUT_KEY_STATE_RELEASED);495 setup_key_event(fake_event_3, event_time_3, KEY_C, LIBINPUT_KEY_STATE_RELEASED);
@@ -400,56 +499,45 @@
400 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_C),mt::KeyDownEvent())));499 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_C),mt::KeyDownEvent())));
401 EXPECT_CALL(mock_builder, key_event(time_stamp_2, mir_keyboard_action_down, _, KEY_LEFTALT, mir_input_event_modifier_none));500 EXPECT_CALL(mock_builder, key_event(time_stamp_2, mir_keyboard_action_down, _, KEY_LEFTALT, mir_input_event_modifier_none));
402 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_LEFTALT),mt::KeyDownEvent())));501 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_LEFTALT),mt::KeyDownEvent())));
403 EXPECT_CALL(mock_builder, key_event(time_stamp_3, mir_keyboard_action_up, _, KEY_C, mir_input_event_modifier_alt|mir_input_event_modifier_alt_left));502 EXPECT_CALL(mock_builder, key_event(time_stamp_3, mir_keyboard_action_up, _, KEY_C,
503 mir_input_event_modifier_alt | mir_input_event_modifier_alt_left));
404 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_C),504 EXPECT_CALL(mock_sink, handle_input(AllOf(mt::KeyOfScanCode(KEY_C),
405 mt::KeyWithModifiers(505 mt::KeyWithModifiers(MirInputEventModifiers{
406 MirInputEventModifiers{506 mir_input_event_modifier_alt | mir_input_event_modifier_alt_left}),
407 mir_input_event_modifier_alt|
408 mir_input_event_modifier_alt_left
409 }),
410 mt::KeyUpEvent())));507 mt::KeyUpEvent())));
411508
412 dev.start(&mock_sink, &mock_builder);509 keyboard.start(&mock_sink, &mock_builder);
413 dev.process_event(fake_event_1);510 keyboard.process_event(fake_event_1);
414 dev.process_event(fake_event_2);511 keyboard.process_event(fake_event_2);
415 dev.process_event(fake_event_3);512 keyboard.process_event(fake_event_3);
416}513}
417514
418TEST_F(LibInputDevice, process_event_converts_pointer_event)515TEST_F(LibInputDeviceOnMouse, process_event_converts_pointer_event)
419{516{
420 std::shared_ptr<libinput> lib = mie::make_libinput();
421 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
422
423 float x = 15;517 float x = 15;
424 float y = 17;518 float y = 17;
425 setup_pointer_event(fake_event_1, event_time_1, x, y);519 setup_pointer_event(fake_event_1, event_time_1, x, y);
426520
427 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x,y)));521 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x,y)));
428522
429 dev.start(&mock_sink, &mock_builder);523 mouse.start(&mock_sink, &mock_builder);
430 dev.process_event(fake_event_1);524 mouse.process_event(fake_event_1);
431}525}
432526
433TEST_F(LibInputDevice, process_event_provides_relative_coordinates)527TEST_F(LibInputDeviceOnMouse, process_event_provides_relative_coordinates)
434{528{
435 std::shared_ptr<libinput> lib = mie::make_libinput();
436 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
437
438 float x = -5;529 float x = -5;
439 float y = 20;530 float y = 20;
440 setup_pointer_event(fake_event_1, event_time_1, x, y);531 setup_pointer_event(fake_event_1, event_time_1, x, y);
441532
442 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithDiff(x,y)));533 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithDiff(x,y)));
443534
444 dev.start(&mock_sink, &mock_builder);535 mouse.start(&mock_sink, &mock_builder);
445 dev.process_event(fake_event_1);536 mouse.process_event(fake_event_1);
446}537}
447538
448TEST_F(LibInputDevice, process_event_accumulates_pointer_movement)539TEST_F(LibInputDeviceOnMouse, process_event_accumulates_pointer_movement)
449{540{
450 std::shared_ptr<libinput> lib = mie::make_libinput();
451 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
452
453 float x1 = 15, x2 = 23;541 float x1 = 15, x2 = 23;
454 float y1 = 17, y2 = 21;542 float y1 = 17, y2 = 21;
455543
@@ -459,18 +547,16 @@
459 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x1,y1)));547 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x1,y1)));
460 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x1+x2,y1+y2)));548 EXPECT_CALL(mock_sink, handle_input(mt::PointerEventWithPosition(x1+x2,y1+y2)));
461549
462 dev.start(&mock_sink, &mock_builder);550 mouse.start(&mock_sink, &mock_builder);
463 dev.process_event(fake_event_1);551 mouse.process_event(fake_event_1);
464 dev.process_event(fake_event_2);552 mouse.process_event(fake_event_2);
465}553}
466554
467TEST_F(LibInputDevice, process_event_handles_press_and_release)555TEST_F(LibInputDeviceOnMouse, process_event_handles_press_and_release)
468{556{
469 std::shared_ptr<libinput> lib = mie::make_libinput();
470 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
471 float const x = 0;557 float const x = 0;
472 float const y = 0;558 float const y = 0;
473 geom::Point const pos{x,y};559 geom::Point const pos{x, y};
474560
475 setup_button_event(fake_event_1, event_time_1, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);561 setup_button_event(fake_event_1, event_time_1, BTN_LEFT, LIBINPUT_BUTTON_STATE_PRESSED);
476 setup_button_event(fake_event_2, event_time_2, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);562 setup_button_event(fake_event_2, event_time_2, BTN_RIGHT, LIBINPUT_BUTTON_STATE_PRESSED);
@@ -483,38 +569,34 @@
483 EXPECT_CALL(mock_sink, handle_input(mt::ButtonUpEventWithButton(pos, mir_pointer_button_secondary)));569 EXPECT_CALL(mock_sink, handle_input(mt::ButtonUpEventWithButton(pos, mir_pointer_button_secondary)));
484 EXPECT_CALL(mock_sink, handle_input(mt::ButtonUpEventWithButton(pos, mir_pointer_button_primary)));570 EXPECT_CALL(mock_sink, handle_input(mt::ButtonUpEventWithButton(pos, mir_pointer_button_primary)));
485571
486 dev.start(&mock_sink, &mock_builder);572 mouse.start(&mock_sink, &mock_builder);
487 dev.process_event(fake_event_1);573 mouse.process_event(fake_event_1);
488 dev.process_event(fake_event_2);574 mouse.process_event(fake_event_2);
489 dev.process_event(fake_event_3);575 mouse.process_event(fake_event_3);
490 dev.process_event(fake_event_4);576 mouse.process_event(fake_event_4);
491}577}
492578
493TEST_F(LibInputDevice, process_event_handles_scroll)579TEST_F(LibInputDeviceOnMouse, process_event_handles_scroll)
494{580{
495 std::shared_ptr<libinput> lib = mie::make_libinput();
496 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
497
498 setup_axis_event(fake_event_1, event_time_1, 0.0, 20.0);581 setup_axis_event(fake_event_1, event_time_1, 0.0, 20.0);
499 setup_axis_event(fake_event_2, event_time_2, 5.0, 0.0);582 setup_axis_event(fake_event_2, event_time_2, 5.0, 0.0);
500583
501 InSequence seq;584 InSequence seq;
502 // expect two scroll events..585 // expect two scroll events..
503 EXPECT_CALL(mock_builder, pointer_event(time_stamp_1, mir_input_event_modifier_none, mir_pointer_action_motion, 0, 0.0f, 0.0f, 0.0f, 20.0f, 0.0f, 0.0f));586 EXPECT_CALL(mock_builder, pointer_event(time_stamp_1, mir_input_event_modifier_none, mir_pointer_action_motion, 0,
587 0.0f, 0.0f, 0.0f, 20.0f, 0.0f, 0.0f));
504 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_vscroll, 20.0f)));588 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_vscroll, 20.0f)));
505 EXPECT_CALL(mock_builder, pointer_event(time_stamp_2, mir_input_event_modifier_none, mir_pointer_action_motion, 0, 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f));589 EXPECT_CALL(mock_builder, pointer_event(time_stamp_2, mir_input_event_modifier_none, mir_pointer_action_motion, 0,
590 0.0f, 0.0f, 5.0f, 0.0f, 0.0f, 0.0f));
506 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_hscroll, 5.0f)));591 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_hscroll, 5.0f)));
507592
508 dev.start(&mock_sink, &mock_builder);593 mouse.start(&mock_sink, &mock_builder);
509 dev.process_event(fake_event_1);594 mouse.process_event(fake_event_1);
510 dev.process_event(fake_event_2);595 mouse.process_event(fake_event_2);
511}596}
512597
513TEST_F(LibInputDevice, process_event_handles_touch_down_events)598TEST_F(LibInputDeviceOnTouchScreen, process_event_handles_touch_down_events)
514{599{
515 std::shared_ptr<libinput> lib = mie::make_libinput();
516 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
517
518 int slot = 0;600 int slot = 0;
519 float major = 6;601 float major = 6;
520 float minor = 5;602 float minor = 5;
@@ -529,18 +611,15 @@
529 EXPECT_CALL(mock_builder, touch_event(time_stamp_1, mir_input_event_modifier_none));611 EXPECT_CALL(mock_builder, touch_event(time_stamp_1, mir_input_event_modifier_none));
530 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{0}, mir_touch_action_down, mir_touch_tooltype_finger, x, y,612 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{0}, mir_touch_action_down, mir_touch_tooltype_finger, x, y,
531 pressure, major, minor, major));613 pressure, major, minor, major));
532 EXPECT_CALL(mock_sink, handle_input(mt::TouchEvent(x,y)));614 EXPECT_CALL(mock_sink, handle_input(mt::TouchEvent(x, y)));
533615
534 dev.start(&mock_sink, &mock_builder);616 touch_screen.start(&mock_sink, &mock_builder);
535 dev.process_event(fake_event_1);617 touch_screen.process_event(fake_event_1);
536 dev.process_event(fake_event_2);618 touch_screen.process_event(fake_event_2);
537}619}
538620
539TEST_F(LibInputDevice, process_event_handles_touch_move_events)621TEST_F(LibInputDeviceOnTouchScreen, process_event_handles_touch_move_events)
540{622{
541 std::shared_ptr<libinput> lib = mie::make_libinput();
542 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
543
544 int slot = 0;623 int slot = 0;
545 float major = 6;624 float major = 6;
546 float minor = 5;625 float minor = 5;
@@ -557,16 +636,13 @@
557 pressure, major, minor, major));636 pressure, major, minor, major));
558 EXPECT_CALL(mock_sink, handle_input(mt::TouchMovementEvent()));637 EXPECT_CALL(mock_sink, handle_input(mt::TouchMovementEvent()));
559638
560 dev.start(&mock_sink, &mock_builder);639 touch_screen.start(&mock_sink, &mock_builder);
561 dev.process_event(fake_event_1);640 touch_screen.process_event(fake_event_1);
562 dev.process_event(fake_event_2);641 touch_screen.process_event(fake_event_2);
563}642}
564643
565TEST_F(LibInputDevice, process_event_handles_touch_up_events_without_querying_properties)644TEST_F(LibInputDeviceOnTouchScreen, process_event_handles_touch_up_events_without_querying_properties)
566{645{
567 std::shared_ptr<libinput> lib = mie::make_libinput();
568 mie::LibInputDevice dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
569
570 int slot = 3;646 int slot = 3;
571 float major = 6;647 float major = 6;
572 float minor = 5;648 float minor = 5;
@@ -583,44 +659,30 @@
583 EXPECT_CALL(mock_builder, touch_event(time_stamp_1, mir_input_event_modifier_none));659 EXPECT_CALL(mock_builder, touch_event(time_stamp_1, mir_input_event_modifier_none));
584 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{slot}, mir_touch_action_down, mir_touch_tooltype_finger, x, y,660 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{slot}, mir_touch_action_down, mir_touch_tooltype_finger, x, y,
585 pressure, major, minor, major));661 pressure, major, minor, major));
586 EXPECT_CALL(mock_sink, handle_input(mt::TouchEvent(x,y)));662 EXPECT_CALL(mock_sink, handle_input(mt::TouchEvent(x, y)));
587663
588 EXPECT_CALL(mock_builder, touch_event(time_stamp_2, mir_input_event_modifier_none));664 EXPECT_CALL(mock_builder, touch_event(time_stamp_2, mir_input_event_modifier_none));
589 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{slot}, mir_touch_action_up, mir_touch_tooltype_finger, x, y,665 EXPECT_CALL(mock_builder, add_touch(_, MirTouchId{slot}, mir_touch_action_up, mir_touch_tooltype_finger, x, y,
590 pressure, major, minor, major));666 pressure, major, minor, major));
591 EXPECT_CALL(mock_sink, handle_input(mt::TouchUpEvent(x,y)));667 EXPECT_CALL(mock_sink, handle_input(mt::TouchUpEvent(x, y)));
592668
593 dev.start(&mock_sink, &mock_builder);669 touch_screen.start(&mock_sink, &mock_builder);
594 dev.process_event(fake_event_1);670 touch_screen.process_event(fake_event_1);
595 dev.process_event(fake_event_2);671 touch_screen.process_event(fake_event_2);
596 dev.process_event(fake_event_3);672 touch_screen.process_event(fake_event_3);
597 dev.process_event(fake_event_4);673 touch_screen.process_event(fake_event_4);
598}674}
599675
600TEST_F(LibInputDevice, provides_no_pointer_settings_for_non_pointing_devices)676TEST_F(LibInputDeviceOnLaptopKeyboard, provides_no_pointer_settings_for_non_pointing_devices)
601{677{
602 char const keyboard_name[] = "usb-keyboard";678 auto settings = keyboard.get_pointer_settings();
603 char const keyboard_device_path[] = "/dev/input/event14";679 EXPECT_THAT(settings.is_set(), Eq(false));
604 setup_device(second_fake_device, keyboard_device_path, keyboard_name, 1231, 4124);680}
605681
606 std::shared_ptr<libinput> lib = mie::make_libinput();682TEST_F(LibInputDeviceOnMouse, reads_pointer_settings_from_libinput)
607 mie::LibInputDevice dev(mir::report::null_input_report(), keyboard_device_path, mie::make_libinput_device(lib.get(), keyboard_device_path));683{
608684 setup_pointer_configuration(mouse.device(), 1, mir_pointer_handedness_right);
609 auto ptr = dev.get_pointer_settings();685 auto optional_settings = mouse.get_pointer_settings();
610 EXPECT_THAT(ptr.is_set(), Eq(false));
611}
612
613TEST_F(LibInputDevice, reads_pointer_settings_from_libinput)
614{
615 char const mouse_device_path[] = "/dev/input/event13";
616 char const mouse_name[] = "usb-mouse";
617 setup_device(second_fake_device, mouse_device_path, mouse_name, 1231, 4124);
618
619 std::shared_ptr<libinput> lib = mie::make_libinput();
620 mie::LibInputDevice dev(mir::report::null_input_report(), mouse_device_path, mie::make_libinput_device(lib.get(), mouse_device_path));
621
622 setup_pointer_configuration(dev.device(), 1, mir_pointer_handedness_right);
623 auto optional_settings = dev.get_pointer_settings();
624686
625 EXPECT_THAT(optional_settings.is_set(), Eq(true));687 EXPECT_THAT(optional_settings.is_set(), Eq(true));
626688
@@ -630,8 +692,8 @@
630 EXPECT_THAT(ptr_settings.horizontal_scroll_scale, Eq(1.0));692 EXPECT_THAT(ptr_settings.horizontal_scroll_scale, Eq(1.0));
631 EXPECT_THAT(ptr_settings.vertical_scroll_scale, Eq(1.0));693 EXPECT_THAT(ptr_settings.vertical_scroll_scale, Eq(1.0));
632694
633 setup_pointer_configuration(dev.device(), 0.0, mir_pointer_handedness_left);695 setup_pointer_configuration(mouse.device(), 0.0, mir_pointer_handedness_left);
634 optional_settings = dev.get_pointer_settings();696 optional_settings = mouse.get_pointer_settings();
635697
636 EXPECT_THAT(optional_settings.is_set(), Eq(true));698 EXPECT_THAT(optional_settings.is_set(), Eq(true));
637699
@@ -642,53 +704,31 @@
642 EXPECT_THAT(ptr_settings.vertical_scroll_scale, Eq(1.0));704 EXPECT_THAT(ptr_settings.vertical_scroll_scale, Eq(1.0));
643}705}
644706
645TEST_F(LibInputDevice, applies_pointer_settings)707TEST_F(LibInputDeviceOnMouse, applies_pointer_settings)
646{708{
647 char const mouse_device_path[] = "/dev/input/event13";709 setup_pointer_configuration(mouse.device(), 1, mir_pointer_handedness_right);
648 char const mouse_name[] = "usb-mouse";710 mi::PointerSettings settings(mouse.get_pointer_settings().value());
649 setup_device(second_fake_device, mouse_device_path, mouse_name, 1231, 4124);
650
651 std::shared_ptr<libinput> lib = mie::make_libinput();
652 mie::LibInputDevice dev(mir::report::null_input_report(), mouse_device_path, mie::make_libinput_device(lib.get(), path));
653
654 setup_pointer_configuration(dev.device(), 1, mir_pointer_handedness_right);
655 mi::PointerSettings settings(dev.get_pointer_settings().value());
656 settings.cursor_acceleration_bias = 1.1;711 settings.cursor_acceleration_bias = 1.1;
657 settings.handedness = mir_pointer_handedness_left;712 settings.handedness = mir_pointer_handedness_left;
658713
659 EXPECT_CALL(mock_libinput,libinput_device_config_accel_set_speed(dev.device(), 1.1)).Times(1);714 EXPECT_CALL(mock_libinput,libinput_device_config_accel_set_speed(mouse.device(), 1.1)).Times(1);
660 EXPECT_CALL(mock_libinput,libinput_device_config_left_handed_set(dev.device(), true)).Times(1);715 EXPECT_CALL(mock_libinput,libinput_device_config_left_handed_set(mouse.device(), true)).Times(1);
661716
662 dev.apply_settings(settings);717 mouse.apply_settings(settings);
663}718}
664719
665TEST_F(LibInputDevice, denies_pointer_settings_on_keyboards)720TEST_F(LibInputDeviceOnLaptopKeyboardAndMouse, denies_pointer_settings_on_keyboards)
666{721{
667 char const mouse_device_path[] = "/dev/input/event13";722 auto settings_from_mouse = mouse.get_pointer_settings();
668 char const mouse_name[] = "usb-mouse";
669 setup_device(second_fake_device, mouse_device_path, mouse_name, 1231, 4124);
670
671 std::shared_ptr<libinput> lib = mie::make_libinput();
672 mie::LibInputDevice keyboard_dev(mir::report::null_input_report(), path, mie::make_libinput_device(lib.get(), path));
673 mie::LibInputDevice mouse_dev(mir::report::null_input_report(), mouse_device_path, mie::make_libinput_device(lib.get(), path));
674
675 auto settings_from_mouse = mouse_dev.get_pointer_settings();
676723
677 EXPECT_CALL(mock_libinput,libinput_device_config_accel_set_speed(_, _)).Times(0);724 EXPECT_CALL(mock_libinput,libinput_device_config_accel_set_speed(_, _)).Times(0);
678 EXPECT_CALL(mock_libinput,libinput_device_config_left_handed_set(_, _)).Times(0);725 EXPECT_CALL(mock_libinput,libinput_device_config_left_handed_set(_, _)).Times(0);
679726
680 keyboard_dev.apply_settings(settings_from_mouse.value());727 keyboard.apply_settings(settings_from_mouse.value());
681}728}
682729
683TEST_F(LibInputDevice, scroll_speed_scales_scroll_events)730TEST_F(LibInputDeviceOnMouse, scroll_speed_scales_scroll_events)
684{731{
685 char const mouse_device_path[] = "/dev/input/event13";
686 char const mouse_name[] = "usb-mouse";
687 setup_device(second_fake_device, mouse_device_path, mouse_name, 1231, 4124);
688
689 std::shared_ptr<libinput> lib = mie::make_libinput();
690 mie::LibInputDevice dev(mir::report::null_input_report(), mouse_device_path, mie::make_libinput_device(lib.get(), mouse_device_path));
691
692 setup_axis_event(fake_event_1, event_time_1, 0.0, 3.0);732 setup_axis_event(fake_event_1, event_time_1, 0.0, 3.0);
693 setup_axis_event(fake_event_2, event_time_2, -2.0, 0.0);733 setup_axis_event(fake_event_2, event_time_2, -2.0, 0.0);
694734
@@ -696,13 +736,65 @@
696 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_vscroll, -3.0f)));736 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_vscroll, -3.0f)));
697 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_hscroll, -10.0f)));737 EXPECT_CALL(mock_sink, handle_input(mt::PointerAxisChange(mir_pointer_axis_hscroll, -10.0f)));
698738
699 setup_pointer_configuration(dev.device(), 1, mir_pointer_handedness_right);739 setup_pointer_configuration(mouse.device(), 1, mir_pointer_handedness_right);
700 mi::PointerSettings settings(dev.get_pointer_settings().value());740 mi::PointerSettings settings(mouse.get_pointer_settings().value());
701 settings.vertical_scroll_scale = -1.0;741 settings.vertical_scroll_scale = -1.0;
702 settings.horizontal_scroll_scale = 5.0;742 settings.horizontal_scroll_scale = 5.0;
703 dev.apply_settings(settings);743 mouse.apply_settings(settings);
704744
705 dev.start(&mock_sink, &mock_builder);745 mouse.start(&mock_sink, &mock_builder);
706 dev.process_event(fake_event_1);746 mouse.process_event(fake_event_1);
707 dev.process_event(fake_event_2);747 mouse.process_event(fake_event_2);
748}
749
750TEST_F(LibInputDeviceOnLaptopKeyboardAndMouse, provides_no_touchpad_settings_for_non_touchpad_devices)
751{
752 auto val = keyboard.get_touchpad_settings();
753 EXPECT_THAT(val.is_set(), Eq(false));
754 val = mouse.get_touchpad_settings();
755 EXPECT_THAT(val.is_set(), Eq(false));
756}
757
758TEST_F(LibInputDeviceOnTouchpad, reads_touchpad_settings_from_libinput)
759{
760 setup_touchpad_configuration(fake_device, mir_touchpad_click_mode_finger_count,
761 mir_touchpad_scroll_mode_edge_scroll, 0, true, false, true, false);
762
763 auto settings = touchpad.get_touchpad_settings().value();
764 EXPECT_THAT(settings.click_mode, Eq(mir_touchpad_click_mode_finger_count));
765 EXPECT_THAT(settings.scroll_mode, Eq(mir_touchpad_scroll_mode_edge_scroll));
766 EXPECT_THAT(settings.tap_to_click, Eq(true));
767 EXPECT_THAT(settings.disable_while_typing, Eq(false));
768 EXPECT_THAT(settings.disable_with_mouse, Eq(true));
769 EXPECT_THAT(settings.middle_mouse_button_emulation, Eq(false));
770}
771
772TEST_F(LibInputDeviceOnTouchpad, applies_touchpad_settings)
773{
774 setup_touchpad_configuration(fake_device, mir_touchpad_click_mode_finger_count,
775 mir_touchpad_scroll_mode_two_finger_scroll, 0, true, false, true, false);
776
777 mi::TouchpadSettings settings(touchpad.get_touchpad_settings().value());
778 settings.scroll_mode = mir_touchpad_scroll_mode_button_down_scroll;
779 settings.click_mode = mir_touchpad_click_mode_finger_count;
780 settings.button_down_scroll_button = KEY_A;
781 settings.tap_to_click = true;
782 settings.disable_while_typing = false;
783 settings.disable_with_mouse = true;
784 settings.middle_mouse_button_emulation = true;
785
786 EXPECT_CALL(mock_libinput,
787 libinput_device_config_scroll_set_method(touchpad.device(), LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN));
788 EXPECT_CALL(mock_libinput,
789 libinput_device_config_click_set_method(touchpad.device(), LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER));
790 EXPECT_CALL(mock_libinput, libinput_device_config_scroll_set_button(touchpad.device(), KEY_A));
791 EXPECT_CALL(mock_libinput, libinput_device_config_tap_set_enabled(touchpad.device(), LIBINPUT_CONFIG_TAP_ENABLED));
792 EXPECT_CALL(mock_libinput,
793 libinput_device_config_dwt_set_enabled(touchpad.device(), LIBINPUT_CONFIG_DWT_DISABLED));
794 EXPECT_CALL(mock_libinput, libinput_device_config_send_events_set_mode(
795 touchpad.device(), LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE));
796 EXPECT_CALL(mock_libinput, libinput_device_config_middle_emulation_set_enabled(
797 touchpad.device(), LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED));
798
799 touchpad.apply_settings(settings);
708}800}
709801
=== modified file 'tests/unit-tests/input/test_default_input_device_hub.cpp'
--- tests/unit-tests/input/test_default_input_device_hub.cpp 2015-10-20 03:30:00 +0000
+++ tests/unit-tests/input/test_default_input_device_hub.cpp 2015-10-23 10:50:47 +0000
@@ -26,6 +26,7 @@
2626
27#include "mir/input/input_device.h"27#include "mir/input/input_device.h"
28#include "mir/input/pointer_settings.h"28#include "mir/input/pointer_settings.h"
29#include "mir/input/touchpad_settings.h"
29#include "mir/input/device.h"30#include "mir/input/device.h"
30#include "mir/input/touch_visualizer.h"31#include "mir/input/touch_visualizer.h"
31#include "mir/input/input_device_observer.h"32#include "mir/input/input_device_observer.h"
@@ -88,6 +89,8 @@
88 MOCK_METHOD0(get_device_info, mi::InputDeviceInfo());89 MOCK_METHOD0(get_device_info, mi::InputDeviceInfo());
89 MOCK_CONST_METHOD0(get_pointer_settings, mir::optional_value<mi::PointerSettings>());90 MOCK_CONST_METHOD0(get_pointer_settings, mir::optional_value<mi::PointerSettings>());
90 MOCK_METHOD1(apply_settings, void(mi::PointerSettings const&));91 MOCK_METHOD1(apply_settings, void(mi::PointerSettings const&));
92 MOCK_CONST_METHOD0(get_touchpad_settings, mir::optional_value<mi::TouchpadSettings>());
93 MOCK_METHOD1(apply_settings, void(mi::TouchpadSettings const&));
91};94};
9295
93template<typename Type>96template<typename Type>

Subscribers

People subscribed via source and target branches