Mir

Merge lp:~andreas-pokorny/mir/fix-1549701-0.21.0 into lp:mir/0.21

Proposed by Andreas Pokorny
Status: Merged
Approved by: Alberto Aguirre
Approved revision: no longer in the source branch.
Merged at revision: 3423
Proposed branch: lp:~andreas-pokorny/mir/fix-1549701-0.21.0
Merge into: lp:mir/0.21
Diff against target: 302 lines (+133/-21)
4 files modified
src/server/input/default_configuration.cpp (+32/-1)
src/server/input/key_repeat_dispatcher.cpp (+34/-15)
src/server/input/key_repeat_dispatcher.h (+7/-1)
tests/unit-tests/input/test_key_repeat_dispatcher.cpp (+60/-4)
To merge this branch: bzr merge lp:~andreas-pokorny/mir/fix-1549701-0.21.0
Reviewer Review Type Date Requested Status
Alberto Aguirre (community) Approve
Brandon Schaefer (community) Approve
Review via email: mp+290358@code.launchpad.net

Commit message

Loads libandroid-properties.so.1 and property_get to disable key repeats on the mx4 touchscreen

Description of the change

Disable repeats on arale.

To post a comment you must log in.
Revision history for this message
Brandon Schaefer (brandontschaefer) wrote :

LGTM (for a workaround?) Not sure why arale is self has issues with key repeat

review: Approve
Revision history for this message
Alberto Aguirre (albaguirre) wrote :

ok as a workaround...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/server/input/default_configuration.cpp'
--- src/server/input/default_configuration.cpp 2016-03-17 22:23:47 +0000
+++ src/server/input/default_configuration.cpp 2016-03-29 19:32:00 +0000
@@ -48,6 +48,7 @@
48#include "mir/abnormal_exit.h"48#include "mir/abnormal_exit.h"
49#include "mir/glib_main_loop.h"49#include "mir/glib_main_loop.h"
50#include "mir/log.h"50#include "mir/log.h"
51#include "mir/shared_library.h"
51#include "mir/dispatch/action_queue.h"52#include "mir/dispatch/action_queue.h"
5253
53#include "mir_toolkit/cursors.h"54#include "mir_toolkit/cursors.h"
@@ -60,6 +61,36 @@
60namespace msh = mir::shell;61namespace msh = mir::shell;
61namespace md = mir::dispatch;62namespace md = mir::dispatch;
6263
64namespace
65{
66
67bool is_arale()
68{
69 try
70 {
71 mir::SharedLibrary android_properties("libandroid-properties.so.1");
72 int (*property_get)(char const*, char*, char const*) = nullptr;
73 property_get = android_properties.load_function<decltype(property_get)>("property_get");
74
75 const int property_value_max = 92;
76 char default_value[] = "";
77 char value[property_value_max];
78
79 if (property_get == nullptr)
80 return false;
81
82 property_get("ro.product.device", value, default_value);
83
84 return std::strcmp("arale", value) == 0;
85 }
86 catch(...)
87 {
88 }
89 return false;
90}
91
92}
93
63std::shared_ptr<mi::InputRegion> mir::DefaultServerConfiguration::the_input_region()94std::shared_ptr<mi::InputRegion> mir::DefaultServerConfiguration::the_input_region()
64{95{
65 return input_region(96 return input_region(
@@ -151,7 +182,7 @@
151182
152 return std::make_shared<mi::KeyRepeatDispatcher>(183 return std::make_shared<mi::KeyRepeatDispatcher>(
153 the_event_filter_chain_dispatcher(), the_main_loop(), the_cookie_authority(),184 the_event_filter_chain_dispatcher(), the_main_loop(), the_cookie_authority(),
154 enable_repeat, key_repeat_timeout, key_repeat_delay);185 enable_repeat, key_repeat_timeout, key_repeat_delay, is_arale());
155 });186 });
156}187}
157188
158189
=== modified file 'src/server/input/key_repeat_dispatcher.cpp'
--- src/server/input/key_repeat_dispatcher.cpp 2016-03-17 22:23:47 +0000
+++ src/server/input/key_repeat_dispatcher.cpp 2016-03-29 19:32:00 +0000
@@ -37,11 +37,16 @@
37{37{
38struct DeviceRemovalFilter : mi::InputDeviceObserver38struct DeviceRemovalFilter : mi::InputDeviceObserver
39{39{
40 DeviceRemovalFilter(std::function<void(MirInputDeviceId)> const& on_removal)40 DeviceRemovalFilter(mi::KeyRepeatDispatcher* dispatcher)
41 : on_removal(on_removal) {}41 : dispatcher{dispatcher} {}
4242
43 void device_added(std::shared_ptr<mi::Device> const&) override43 void device_added(std::shared_ptr<mi::Device> const& device) override
44 {44 {
45 if (device->name() == "mtk-tpd")
46 {
47 dispatcher->set_mtk_device(device->id());
48 }
49
45 }50 }
4651
47 void device_changed(std::shared_ptr<mi::Device> const&) override52 void device_changed(std::shared_ptr<mi::Device> const&) override
@@ -50,13 +55,13 @@
5055
51 void device_removed(std::shared_ptr<mi::Device> const& device) override56 void device_removed(std::shared_ptr<mi::Device> const& device) override
52 {57 {
53 on_removal(device->id());58 dispatcher->remove_device(device->id());
54 }59 }
5560
56 void changes_complete() override61 void changes_complete() override
57 {62 {
58 }63 }
59 std::function<void(MirInputDeviceId)> on_removal;64 mi::KeyRepeatDispatcher* dispatcher;
60};65};
6166
62}67}
@@ -67,25 +72,35 @@
67 std::shared_ptr<mir::cookie::Authority> const& cookie_authority,72 std::shared_ptr<mir::cookie::Authority> const& cookie_authority,
68 bool repeat_enabled,73 bool repeat_enabled,
69 std::chrono::milliseconds repeat_timeout,74 std::chrono::milliseconds repeat_timeout,
70 std::chrono::milliseconds repeat_delay)75 std::chrono::milliseconds repeat_delay,
76 bool disable_repeat_on_mtk_touchpad)
71 : next_dispatcher(next_dispatcher),77 : next_dispatcher(next_dispatcher),
72 alarm_factory(factory),78 alarm_factory(factory),
73 cookie_authority(cookie_authority),79 cookie_authority(cookie_authority),
74 repeat_enabled(repeat_enabled),80 repeat_enabled(repeat_enabled),
75 repeat_timeout(repeat_timeout),81 repeat_timeout(repeat_timeout),
76 repeat_delay(repeat_delay)82 repeat_delay(repeat_delay),
83 disable_repeat_on_mtk_touchpad(disable_repeat_on_mtk_touchpad)
77{84{
78}85}
7986
80void mi::KeyRepeatDispatcher::set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub)87void mi::KeyRepeatDispatcher::set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub)
81{88{
82 hub->add_observer(std::make_shared<DeviceRemovalFilter>(89 hub->add_observer(std::make_shared<DeviceRemovalFilter>(this));
83 [this](MirInputDeviceId id)90}
84 {91
85 std::unique_lock<std::mutex> lock(repeat_state_mutex);92void mi::KeyRepeatDispatcher::set_mtk_device(MirInputDeviceId id)
86 repeat_state_by_device.erase(id); // destructor cancels alarms93{
87 }94 std::lock_guard<std::mutex> lock(repeat_state_mutex);
88 ));95 mtk_tpd_id = id;
96}
97
98void mi::KeyRepeatDispatcher::remove_device(MirInputDeviceId id)
99{
100 std::lock_guard<std::mutex> lock(repeat_state_mutex);
101 repeat_state_by_device.erase(id); // destructor cancels alarms
102 if (mtk_tpd_id.is_set() && mtk_tpd_id.value() == id)
103 mtk_tpd_id.consume();
89}104}
90105
91mi::KeyRepeatDispatcher::KeyboardState& mi::KeyRepeatDispatcher::ensure_state_for_device_locked(std::lock_guard<std::mutex> const&, MirInputDeviceId id)106mi::KeyRepeatDispatcher::KeyboardState& mi::KeyRepeatDispatcher::ensure_state_for_device_locked(std::lock_guard<std::mutex> const&, MirInputDeviceId id)
@@ -100,12 +115,16 @@
100 {115 {
101 return next_dispatcher->dispatch(event);116 return next_dispatcher->dispatch(event);
102 }117 }
103 118
104 if (mir_event_get_type(&event) == mir_event_type_input)119 if (mir_event_get_type(&event) == mir_event_type_input)
105 {120 {
106 auto iev = mir_event_get_input_event(&event);121 auto iev = mir_event_get_input_event(&event);
107 if (mir_input_event_get_type(iev) != mir_input_event_type_key)122 if (mir_input_event_get_type(iev) != mir_input_event_type_key)
108 return next_dispatcher->dispatch(event);123 return next_dispatcher->dispatch(event);
124 auto device_id = mir_input_event_get_device_id(iev);
125 if (disable_repeat_on_mtk_touchpad && mtk_tpd_id.is_set() && device_id == mtk_tpd_id.value())
126 return next_dispatcher->dispatch(event);
127
109 if (!handle_key_input(mir_input_event_get_device_id(iev), mir_input_event_get_keyboard_event(iev)))128 if (!handle_key_input(mir_input_event_get_device_id(iev), mir_input_event_get_keyboard_event(iev)))
110 return next_dispatcher->dispatch(event);129 return next_dispatcher->dispatch(event);
111 else130 else
112131
=== modified file 'src/server/input/key_repeat_dispatcher.h'
--- src/server/input/key_repeat_dispatcher.h 2016-03-17 22:23:47 +0000
+++ src/server/input/key_repeat_dispatcher.h 2016-03-29 19:32:00 +0000
@@ -21,6 +21,7 @@
2121
22#include "mir/input/input_dispatcher.h"22#include "mir/input/input_dispatcher.h"
23#include "mir/input/input_device_observer.h"23#include "mir/input/input_device_observer.h"
24#include "mir/optional_value.h"
2425
25#include <memory>26#include <memory>
26#include <chrono>27#include <chrono>
@@ -49,7 +50,8 @@
49 std::shared_ptr<cookie::Authority> const& cookie_authority,50 std::shared_ptr<cookie::Authority> const& cookie_authority,
50 bool repeat_enabled,51 bool repeat_enabled,
51 std::chrono::milliseconds repeat_timeout, /* timeout before sending first repeat */52 std::chrono::milliseconds repeat_timeout, /* timeout before sending first repeat */
52 std::chrono::milliseconds repeat_delay /* delay between repeated keys */);53 std::chrono::milliseconds repeat_delay, /* delay between repeated keys */
54 bool disable_repeat_on_mtk_touchpad);
5355
54 // InputDispatcher56 // InputDispatcher
55 bool dispatch(MirEvent const& event) override;57 bool dispatch(MirEvent const& event) override;
@@ -58,6 +60,8 @@
5860
59 void set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub);61 void set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub);
6062
63 void set_mtk_device(MirInputDeviceId id);
64 void remove_device(MirInputDeviceId id);
61private:65private:
62 std::mutex repeat_state_mutex;66 std::mutex repeat_state_mutex;
6367
@@ -67,6 +71,8 @@
67 bool const repeat_enabled;71 bool const repeat_enabled;
68 std::chrono::milliseconds repeat_timeout;72 std::chrono::milliseconds repeat_timeout;
69 std::chrono::milliseconds repeat_delay;73 std::chrono::milliseconds repeat_delay;
74 bool const disable_repeat_on_mtk_touchpad;
75 optional_value<MirInputDeviceId> mtk_tpd_id;
7076
71 struct KeyboardState77 struct KeyboardState
72 {78 {
7379
=== modified file 'tests/unit-tests/input/test_key_repeat_dispatcher.cpp'
--- tests/unit-tests/input/test_key_repeat_dispatcher.cpp 2016-03-17 22:23:47 +0000
+++ tests/unit-tests/input/test_key_repeat_dispatcher.cpp 2016-03-29 19:32:00 +0000
@@ -33,6 +33,8 @@
33#include "mir/test/doubles/mock_input_dispatcher.h"33#include "mir/test/doubles/mock_input_dispatcher.h"
34#include "mir/test/doubles/mock_input_device_hub.h"34#include "mir/test/doubles/mock_input_device_hub.h"
3535
36#include "linux/input-event-codes.h"
37
36#include <gtest/gtest.h>38#include <gtest/gtest.h>
37#include <gmock/gmock.h>39#include <gmock/gmock.h>
3840
@@ -76,10 +78,18 @@
76struct StubDevice : public mi::Device78struct StubDevice : public mi::Device
77{79{
78 MirInputDeviceId device_id;80 MirInputDeviceId device_id;
81 std::string device_name;
82
79 StubDevice(MirInputDeviceId id) : device_id(id) {}83 StubDevice(MirInputDeviceId id) : device_id(id) {}
80 MirInputDeviceId id() const { return device_id;}84 StubDevice(MirInputDeviceId id, std::string device_name) : device_id{id}, device_name{device_name}
85 {
86 }
87 MirInputDeviceId id() const
88 {
89 return device_id;
90 }
81 mi::DeviceCapabilities capabilities() const {return mi::DeviceCapability::keyboard;}91 mi::DeviceCapabilities capabilities() const {return mi::DeviceCapability::keyboard;}
82 std::string name() const {return {};}92 std::string name() const {return device_name;}
83 std::string unique_id() const {return {};}93 std::string unique_id() const {return {};}
8494
85 mir::optional_value<mi::PointerConfiguration> pointer_configuration() const {return {};}95 mir::optional_value<mi::PointerConfiguration> pointer_configuration() const {return {};}
@@ -90,8 +100,8 @@
90100
91struct KeyRepeatDispatcher : public testing::Test101struct KeyRepeatDispatcher : public testing::Test
92{102{
93 KeyRepeatDispatcher()103 KeyRepeatDispatcher(bool on_arale = false)
94 : dispatcher(mock_next_dispatcher, mock_alarm_factory, cookie_authority, true, repeat_time, repeat_delay)104 : dispatcher(mock_next_dispatcher, mock_alarm_factory, cookie_authority, true, repeat_time, repeat_delay, on_arale)
95 {105 {
96 ON_CALL(hub,add_observer(_)).WillByDefault(SaveArg<0>(&observer));106 ON_CALL(hub,add_observer(_)).WillByDefault(SaveArg<0>(&observer));
97 dispatcher.set_input_device_hub(mt::fake_shared(hub));107 dispatcher.set_input_device_hub(mt::fake_shared(hub));
@@ -123,6 +133,24 @@
123 return mev::make_event(test_device, std::chrono::nanoseconds(0), std::vector<uint8_t>{}, mir_keyboard_action_up, 0, 0, mir_input_event_modifier_alt);133 return mev::make_event(test_device, std::chrono::nanoseconds(0), std::vector<uint8_t>{}, mir_keyboard_action_up, 0, 0, mir_input_event_modifier_alt);
124 }134 }
125};135};
136
137struct KeyRepeatDispatcherOnArale : KeyRepeatDispatcher
138{
139 KeyRepeatDispatcherOnArale() : KeyRepeatDispatcher(true){};
140 MirInputDeviceId mtk_id = 32;
141 void add_mtk_tpd()
142 {
143 StubDevice dev(mtk_id, "mtk-tpd");
144 observer->device_added(mt::fake_shared(dev));
145 observer->changes_complete();
146 }
147
148 mir::EventUPtr mtk_key_down_event()
149 {
150 return mev::make_event(mtk_id, std::chrono::nanoseconds(0), std::vector<uint8_t>{}, mir_keyboard_action_down, 0,
151 KEY_LEFTALT, mir_input_event_modifier_none);
152 }
153};
126}154}
127155
128TEST_F(KeyRepeatDispatcher, forwards_start_stop)156TEST_F(KeyRepeatDispatcher, forwards_start_stop)
@@ -182,3 +210,31 @@
182 simulate_device_removal();210 simulate_device_removal();
183 EXPECT_THAT(alarm_canceled, Eq(true));211 EXPECT_THAT(alarm_canceled, Eq(true));
184}212}
213
214TEST_F(KeyRepeatDispatcherOnArale, no_repeat_alarm_on_mtk_tpd)
215{
216 EXPECT_CALL(*mock_alarm_factory, create_alarm_adapter(_)).Times(0);
217 EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyDownEvent())).Times(1);
218 EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyRepeatEvent())).Times(0);
219
220 add_mtk_tpd();
221 dispatcher.dispatch(*mtk_key_down_event());
222}
223
224TEST_F(KeyRepeatDispatcherOnArale, repeat_for_regular_keys)
225{
226 MockAlarm *mock_alarm = new MockAlarm;
227 std::function<void()> alarm_function;
228
229 EXPECT_CALL(*mock_alarm_factory, create_alarm_adapter(_)).Times(1).
230 WillOnce(DoAll(SaveArg<0>(&alarm_function), Return(mock_alarm)));
231 // Once for initial down and again when invoked
232 EXPECT_CALL(*mock_alarm, reschedule_in(repeat_delay)).Times(1).WillOnce(Return(true));
233 EXPECT_CALL(*mock_alarm, reschedule_in(repeat_time)).Times(1).WillOnce(Return(true));
234 EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyDownEvent())).Times(1);
235 EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyRepeatEvent())).Times(1);
236
237 add_mtk_tpd();
238 dispatcher.dispatch(*a_key_down_event());
239 alarm_function();
240}

Subscribers

People subscribed via source and target branches