Merge lp:~andreas-pokorny/unity-system-compositor/fix-1514059-and-keep-display-on-for-key-presses into lp:unity-system-compositor

Proposed by Andreas Pokorny
Status: Merged
Approved by: Alexandros Frantzis
Approved revision: 257
Merged at revision: 262
Proposed branch: lp:~andreas-pokorny/unity-system-compositor/fix-1514059-and-keep-display-on-for-key-presses
Merge into: lp:unity-system-compositor
Diff against target: 162 lines (+81/-14)
2 files modified
src/screen_event_handler.cpp (+20/-10)
tests/unit-tests/test_screen_event_handler.cpp (+61/-4)
To merge this branch: bzr merge lp:~andreas-pokorny/unity-system-compositor/fix-1514059-and-keep-display-on-for-key-presses
Reviewer Review Type Date Requested Status
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+276925@code.launchpad.net

Commit message

Change keyboard handling to scan codes.

Additionally relevant for ubuntu-pd: use none-phone keys to keep display on

Description of the change

USC always used the key code to identify the power key instead of the scan code. That worked up to now because input reader had a hard coded key map. It is more robust to just test for the scan code.

This has been discovered during qa tests on usc with the new libinput library.

Additionally while looking at the problem it seems that the inactivity timers are not reset for non-phone keys.

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: 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
Andreas Pokorny (andreas-pokorny) wrote :
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Alexandros Frantzis (afrantzis) wrote :

Looks good.

I am not sure about:

// do not keep display on when interacting with media player

but we can revisit.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/screen_event_handler.cpp'
--- src/screen_event_handler.cpp 2015-07-13 12:35:41 +0000
+++ src/screen_event_handler.cpp 2015-11-07 14:07:54 +0000
@@ -21,6 +21,7 @@
21#include <mir/time/alarm_factory.h>21#include <mir/time/alarm_factory.h>
22#include <mir_toolkit/events/input/input_event.h>22#include <mir_toolkit/events/input/input_event.h>
2323
24#include "linux/input.h"
24#include <cstdio>25#include <cstdio>
2526
26usc::ScreenEventHandler::ScreenEventHandler(27usc::ScreenEventHandler::ScreenEventHandler(
@@ -45,8 +46,6 @@
4546
46bool usc::ScreenEventHandler::handle(MirEvent const& event)47bool usc::ScreenEventHandler::handle(MirEvent const& event)
47{48{
48 static const int32_t POWER_KEY_CODE = 26;
49
50 if (mir_event_get_type(&event) != mir_event_type_input)49 if (mir_event_get_type(&event) != mir_event_type_input)
51 return false;50 return false;
5251
@@ -56,14 +55,25 @@
56 if (input_event_type == mir_input_event_type_key)55 if (input_event_type == mir_input_event_type_key)
57 {56 {
58 auto const kev = mir_input_event_get_keyboard_event(input_event);57 auto const kev = mir_input_event_get_keyboard_event(input_event);
59 if (mir_keyboard_event_key_code(kev) != POWER_KEY_CODE)58 if (mir_keyboard_event_scan_code(kev) == KEY_POWER)
60 return false;59 {
6160 auto const action = mir_keyboard_event_action(kev);
62 auto const action = mir_keyboard_event_action(kev);61 if (action == mir_keyboard_action_down)
63 if (action == mir_keyboard_action_down)62 power_key_down();
64 power_key_down();63 else if (action == mir_keyboard_action_up)
65 else if (action == mir_keyboard_action_up)64 power_key_up();
66 power_key_up();65 }
66 // we might want to come up with a whole range of media player related keys
67 else if (mir_keyboard_event_scan_code(kev) == KEY_VOLUMEDOWN||
68 mir_keyboard_event_scan_code(kev) == KEY_VOLUMEUP)
69 {
70 // do not keep display on when interacting with media player
71 }
72 else
73 {
74 std::lock_guard<std::mutex> lock{guard};
75 screen->keep_display_on_temporarily();
76 }
67 }77 }
68 else if (input_event_type == mir_input_event_type_touch ||78 else if (input_event_type == mir_input_event_type_touch ||
69 input_event_type == mir_input_event_type_pointer)79 input_event_type == mir_input_event_type_pointer)
7080
=== modified file 'tests/unit-tests/test_screen_event_handler.cpp'
--- tests/unit-tests/test_screen_event_handler.cpp 2015-10-07 12:09:26 +0000
+++ tests/unit-tests/test_screen_event_handler.cpp 2015-11-07 14:07:54 +0000
@@ -28,6 +28,7 @@
28#include <gtest/gtest.h>28#include <gtest/gtest.h>
29#include <gmock/gmock.h>29#include <gmock/gmock.h>
3030
31#include "linux/input.h"
31#include <atomic>32#include <atomic>
3233
33namespace34namespace
@@ -64,6 +65,19 @@
64 screen_event_handler.handle(*power_key_up_event);65 screen_event_handler.handle(*power_key_up_event);
65 }66 }
6667
68 void press_a_key()
69 {
70 screen_event_handler.handle(*another_key_down_event);
71 }
72
73 void press_volume_keys()
74 {
75 screen_event_handler.handle(*vol_plus_key_down_event);
76 screen_event_handler.handle(*vol_plus_key_up_event);
77 screen_event_handler.handle(*vol_minus_key_down_event);
78 screen_event_handler.handle(*vol_minus_key_up_event);
79 }
80
67 void touch_screen()81 void touch_screen()
68 {82 {
69 screen_event_handler.handle(*touch_event);83 screen_event_handler.handle(*touch_event);
@@ -74,21 +88,50 @@
74 screen_event_handler.handle(*pointer_event);88 screen_event_handler.handle(*pointer_event);
75 }89 }
7690
77 static const int32_t POWER_KEY_CODE = 26;
78 mir::EventUPtr power_key_down_event = mir::events::make_event(91 mir::EventUPtr power_key_down_event = mir::events::make_event(
79 MirInputDeviceId{1}, std::chrono::nanoseconds(0),92 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
80 0, mir_keyboard_action_down,93 0, mir_keyboard_action_down,
81 POWER_KEY_CODE, 0, mir_input_event_modifier_none);94 0, KEY_POWER, mir_input_event_modifier_none);
8295
83 mir::EventUPtr power_key_up_event = mir::events::make_event(96 mir::EventUPtr power_key_up_event = mir::events::make_event(
84 MirInputDeviceId{1}, std::chrono::nanoseconds(0),97 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
85 0, mir_keyboard_action_up,98 0, mir_keyboard_action_up,
86 POWER_KEY_CODE, 0, mir_input_event_modifier_none);99 0, KEY_POWER, mir_input_event_modifier_none);
100
101 mir::EventUPtr vol_plus_key_down_event = mir::events::make_event(
102 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
103 0, mir_keyboard_action_down,
104 0, KEY_VOLUMEUP, mir_input_event_modifier_none);
105
106 mir::EventUPtr vol_plus_key_up_event = mir::events::make_event(
107 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
108 0, mir_keyboard_action_up,
109 0, KEY_VOLUMEUP, mir_input_event_modifier_none);
110
111 mir::EventUPtr vol_minus_key_down_event = mir::events::make_event(
112 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
113 0, mir_keyboard_action_down,
114 0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
115
116 mir::EventUPtr vol_minus_key_up_event = mir::events::make_event(
117 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
118 0, mir_keyboard_action_up,
119 0, KEY_VOLUMEDOWN, mir_input_event_modifier_none);
120
121 mir::EventUPtr another_key_down_event = mir::events::make_event(
122 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
123 0, mir_keyboard_action_down,
124 0, KEY_A, mir_input_event_modifier_none);
125
126 mir::EventUPtr another_key_up_event = mir::events::make_event(
127 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
128 0, mir_keyboard_action_up,
129 0, KEY_A, mir_input_event_modifier_none);
87130
88 mir::EventUPtr touch_event = mir::events::make_event(131 mir::EventUPtr touch_event = mir::events::make_event(
89 MirInputDeviceId{1}, std::chrono::nanoseconds(0),132 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
90 0, mir_input_event_modifier_none);133 0, mir_input_event_modifier_none);
91 134
92 mir::EventUPtr pointer_event = mir::events::make_event(135 mir::EventUPtr pointer_event = mir::events::make_event(
93 MirInputDeviceId{1}, std::chrono::nanoseconds(0),136 MirInputDeviceId{1}, std::chrono::nanoseconds(0),
94 0, mir_input_event_modifier_none,137 0, mir_input_event_modifier_none,
@@ -167,6 +210,20 @@
167 move_pointer();210 move_pointer();
168}211}
169212
213TEST_F(AScreenEventHandler, keeps_display_on_temporarily_on_other_keys)
214{
215 EXPECT_CALL(mock_screen, keep_display_on_temporarily());
216
217 press_a_key();
218}
219
220TEST_F(AScreenEventHandler, does_not_keep_display_on_for_volume_keys)
221{
222 EXPECT_CALL(mock_screen, keep_display_on_temporarily()).Times(0);
223
224 press_volume_keys();
225}
226
170TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)227TEST_F(AScreenEventHandler, sets_screen_mode_off_normal_press_release)
171{228{
172 EXPECT_CALL(mock_screen,229 EXPECT_CALL(mock_screen,

Subscribers

People subscribed via source and target branches