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
1=== modified file 'src/server/input/default_configuration.cpp'
2--- src/server/input/default_configuration.cpp 2016-03-17 22:23:47 +0000
3+++ src/server/input/default_configuration.cpp 2016-03-29 19:32:00 +0000
4@@ -48,6 +48,7 @@
5 #include "mir/abnormal_exit.h"
6 #include "mir/glib_main_loop.h"
7 #include "mir/log.h"
8+#include "mir/shared_library.h"
9 #include "mir/dispatch/action_queue.h"
10
11 #include "mir_toolkit/cursors.h"
12@@ -60,6 +61,36 @@
13 namespace msh = mir::shell;
14 namespace md = mir::dispatch;
15
16+namespace
17+{
18+
19+bool is_arale()
20+{
21+ try
22+ {
23+ mir::SharedLibrary android_properties("libandroid-properties.so.1");
24+ int (*property_get)(char const*, char*, char const*) = nullptr;
25+ property_get = android_properties.load_function<decltype(property_get)>("property_get");
26+
27+ const int property_value_max = 92;
28+ char default_value[] = "";
29+ char value[property_value_max];
30+
31+ if (property_get == nullptr)
32+ return false;
33+
34+ property_get("ro.product.device", value, default_value);
35+
36+ return std::strcmp("arale", value) == 0;
37+ }
38+ catch(...)
39+ {
40+ }
41+ return false;
42+}
43+
44+}
45+
46 std::shared_ptr<mi::InputRegion> mir::DefaultServerConfiguration::the_input_region()
47 {
48 return input_region(
49@@ -151,7 +182,7 @@
50
51 return std::make_shared<mi::KeyRepeatDispatcher>(
52 the_event_filter_chain_dispatcher(), the_main_loop(), the_cookie_authority(),
53- enable_repeat, key_repeat_timeout, key_repeat_delay);
54+ enable_repeat, key_repeat_timeout, key_repeat_delay, is_arale());
55 });
56 }
57
58
59=== modified file 'src/server/input/key_repeat_dispatcher.cpp'
60--- src/server/input/key_repeat_dispatcher.cpp 2016-03-17 22:23:47 +0000
61+++ src/server/input/key_repeat_dispatcher.cpp 2016-03-29 19:32:00 +0000
62@@ -37,11 +37,16 @@
63 {
64 struct DeviceRemovalFilter : mi::InputDeviceObserver
65 {
66- DeviceRemovalFilter(std::function<void(MirInputDeviceId)> const& on_removal)
67- : on_removal(on_removal) {}
68+ DeviceRemovalFilter(mi::KeyRepeatDispatcher* dispatcher)
69+ : dispatcher{dispatcher} {}
70
71- void device_added(std::shared_ptr<mi::Device> const&) override
72+ void device_added(std::shared_ptr<mi::Device> const& device) override
73 {
74+ if (device->name() == "mtk-tpd")
75+ {
76+ dispatcher->set_mtk_device(device->id());
77+ }
78+
79 }
80
81 void device_changed(std::shared_ptr<mi::Device> const&) override
82@@ -50,13 +55,13 @@
83
84 void device_removed(std::shared_ptr<mi::Device> const& device) override
85 {
86- on_removal(device->id());
87+ dispatcher->remove_device(device->id());
88 }
89
90 void changes_complete() override
91 {
92 }
93- std::function<void(MirInputDeviceId)> on_removal;
94+ mi::KeyRepeatDispatcher* dispatcher;
95 };
96
97 }
98@@ -67,25 +72,35 @@
99 std::shared_ptr<mir::cookie::Authority> const& cookie_authority,
100 bool repeat_enabled,
101 std::chrono::milliseconds repeat_timeout,
102- std::chrono::milliseconds repeat_delay)
103+ std::chrono::milliseconds repeat_delay,
104+ bool disable_repeat_on_mtk_touchpad)
105 : next_dispatcher(next_dispatcher),
106 alarm_factory(factory),
107 cookie_authority(cookie_authority),
108 repeat_enabled(repeat_enabled),
109 repeat_timeout(repeat_timeout),
110- repeat_delay(repeat_delay)
111+ repeat_delay(repeat_delay),
112+ disable_repeat_on_mtk_touchpad(disable_repeat_on_mtk_touchpad)
113 {
114 }
115
116 void mi::KeyRepeatDispatcher::set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub)
117 {
118- hub->add_observer(std::make_shared<DeviceRemovalFilter>(
119- [this](MirInputDeviceId id)
120- {
121- std::unique_lock<std::mutex> lock(repeat_state_mutex);
122- repeat_state_by_device.erase(id); // destructor cancels alarms
123- }
124- ));
125+ hub->add_observer(std::make_shared<DeviceRemovalFilter>(this));
126+}
127+
128+void mi::KeyRepeatDispatcher::set_mtk_device(MirInputDeviceId id)
129+{
130+ std::lock_guard<std::mutex> lock(repeat_state_mutex);
131+ mtk_tpd_id = id;
132+}
133+
134+void mi::KeyRepeatDispatcher::remove_device(MirInputDeviceId id)
135+{
136+ std::lock_guard<std::mutex> lock(repeat_state_mutex);
137+ repeat_state_by_device.erase(id); // destructor cancels alarms
138+ if (mtk_tpd_id.is_set() && mtk_tpd_id.value() == id)
139+ mtk_tpd_id.consume();
140 }
141
142 mi::KeyRepeatDispatcher::KeyboardState& mi::KeyRepeatDispatcher::ensure_state_for_device_locked(std::lock_guard<std::mutex> const&, MirInputDeviceId id)
143@@ -100,12 +115,16 @@
144 {
145 return next_dispatcher->dispatch(event);
146 }
147-
148+
149 if (mir_event_get_type(&event) == mir_event_type_input)
150 {
151 auto iev = mir_event_get_input_event(&event);
152 if (mir_input_event_get_type(iev) != mir_input_event_type_key)
153 return next_dispatcher->dispatch(event);
154+ auto device_id = mir_input_event_get_device_id(iev);
155+ if (disable_repeat_on_mtk_touchpad && mtk_tpd_id.is_set() && device_id == mtk_tpd_id.value())
156+ return next_dispatcher->dispatch(event);
157+
158 if (!handle_key_input(mir_input_event_get_device_id(iev), mir_input_event_get_keyboard_event(iev)))
159 return next_dispatcher->dispatch(event);
160 else
161
162=== modified file 'src/server/input/key_repeat_dispatcher.h'
163--- src/server/input/key_repeat_dispatcher.h 2016-03-17 22:23:47 +0000
164+++ src/server/input/key_repeat_dispatcher.h 2016-03-29 19:32:00 +0000
165@@ -21,6 +21,7 @@
166
167 #include "mir/input/input_dispatcher.h"
168 #include "mir/input/input_device_observer.h"
169+#include "mir/optional_value.h"
170
171 #include <memory>
172 #include <chrono>
173@@ -49,7 +50,8 @@
174 std::shared_ptr<cookie::Authority> const& cookie_authority,
175 bool repeat_enabled,
176 std::chrono::milliseconds repeat_timeout, /* timeout before sending first repeat */
177- std::chrono::milliseconds repeat_delay /* delay between repeated keys */);
178+ std::chrono::milliseconds repeat_delay, /* delay between repeated keys */
179+ bool disable_repeat_on_mtk_touchpad);
180
181 // InputDispatcher
182 bool dispatch(MirEvent const& event) override;
183@@ -58,6 +60,8 @@
184
185 void set_input_device_hub(std::shared_ptr<InputDeviceHub> const& hub);
186
187+ void set_mtk_device(MirInputDeviceId id);
188+ void remove_device(MirInputDeviceId id);
189 private:
190 std::mutex repeat_state_mutex;
191
192@@ -67,6 +71,8 @@
193 bool const repeat_enabled;
194 std::chrono::milliseconds repeat_timeout;
195 std::chrono::milliseconds repeat_delay;
196+ bool const disable_repeat_on_mtk_touchpad;
197+ optional_value<MirInputDeviceId> mtk_tpd_id;
198
199 struct KeyboardState
200 {
201
202=== modified file 'tests/unit-tests/input/test_key_repeat_dispatcher.cpp'
203--- tests/unit-tests/input/test_key_repeat_dispatcher.cpp 2016-03-17 22:23:47 +0000
204+++ tests/unit-tests/input/test_key_repeat_dispatcher.cpp 2016-03-29 19:32:00 +0000
205@@ -33,6 +33,8 @@
206 #include "mir/test/doubles/mock_input_dispatcher.h"
207 #include "mir/test/doubles/mock_input_device_hub.h"
208
209+#include "linux/input-event-codes.h"
210+
211 #include <gtest/gtest.h>
212 #include <gmock/gmock.h>
213
214@@ -76,10 +78,18 @@
215 struct StubDevice : public mi::Device
216 {
217 MirInputDeviceId device_id;
218+ std::string device_name;
219+
220 StubDevice(MirInputDeviceId id) : device_id(id) {}
221- MirInputDeviceId id() const { return device_id;}
222+ StubDevice(MirInputDeviceId id, std::string device_name) : device_id{id}, device_name{device_name}
223+ {
224+ }
225+ MirInputDeviceId id() const
226+ {
227+ return device_id;
228+ }
229 mi::DeviceCapabilities capabilities() const {return mi::DeviceCapability::keyboard;}
230- std::string name() const {return {};}
231+ std::string name() const {return device_name;}
232 std::string unique_id() const {return {};}
233
234 mir::optional_value<mi::PointerConfiguration> pointer_configuration() const {return {};}
235@@ -90,8 +100,8 @@
236
237 struct KeyRepeatDispatcher : public testing::Test
238 {
239- KeyRepeatDispatcher()
240- : dispatcher(mock_next_dispatcher, mock_alarm_factory, cookie_authority, true, repeat_time, repeat_delay)
241+ KeyRepeatDispatcher(bool on_arale = false)
242+ : dispatcher(mock_next_dispatcher, mock_alarm_factory, cookie_authority, true, repeat_time, repeat_delay, on_arale)
243 {
244 ON_CALL(hub,add_observer(_)).WillByDefault(SaveArg<0>(&observer));
245 dispatcher.set_input_device_hub(mt::fake_shared(hub));
246@@ -123,6 +133,24 @@
247 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);
248 }
249 };
250+
251+struct KeyRepeatDispatcherOnArale : KeyRepeatDispatcher
252+{
253+ KeyRepeatDispatcherOnArale() : KeyRepeatDispatcher(true){};
254+ MirInputDeviceId mtk_id = 32;
255+ void add_mtk_tpd()
256+ {
257+ StubDevice dev(mtk_id, "mtk-tpd");
258+ observer->device_added(mt::fake_shared(dev));
259+ observer->changes_complete();
260+ }
261+
262+ mir::EventUPtr mtk_key_down_event()
263+ {
264+ return mev::make_event(mtk_id, std::chrono::nanoseconds(0), std::vector<uint8_t>{}, mir_keyboard_action_down, 0,
265+ KEY_LEFTALT, mir_input_event_modifier_none);
266+ }
267+};
268 }
269
270 TEST_F(KeyRepeatDispatcher, forwards_start_stop)
271@@ -182,3 +210,31 @@
272 simulate_device_removal();
273 EXPECT_THAT(alarm_canceled, Eq(true));
274 }
275+
276+TEST_F(KeyRepeatDispatcherOnArale, no_repeat_alarm_on_mtk_tpd)
277+{
278+ EXPECT_CALL(*mock_alarm_factory, create_alarm_adapter(_)).Times(0);
279+ EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyDownEvent())).Times(1);
280+ EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyRepeatEvent())).Times(0);
281+
282+ add_mtk_tpd();
283+ dispatcher.dispatch(*mtk_key_down_event());
284+}
285+
286+TEST_F(KeyRepeatDispatcherOnArale, repeat_for_regular_keys)
287+{
288+ MockAlarm *mock_alarm = new MockAlarm;
289+ std::function<void()> alarm_function;
290+
291+ EXPECT_CALL(*mock_alarm_factory, create_alarm_adapter(_)).Times(1).
292+ WillOnce(DoAll(SaveArg<0>(&alarm_function), Return(mock_alarm)));
293+ // Once for initial down and again when invoked
294+ EXPECT_CALL(*mock_alarm, reschedule_in(repeat_delay)).Times(1).WillOnce(Return(true));
295+ EXPECT_CALL(*mock_alarm, reschedule_in(repeat_time)).Times(1).WillOnce(Return(true));
296+ EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyDownEvent())).Times(1);
297+ EXPECT_CALL(*mock_next_dispatcher, dispatch(mt::KeyRepeatEvent())).Times(1);
298+
299+ add_mtk_tpd();
300+ dispatcher.dispatch(*a_key_down_event());
301+ alarm_function();
302+}

Subscribers

People subscribed via source and target branches