Mir

Merge lp:~afrantzis/mir/fix-1332632-input-for-resized-surfaces into lp:mir

Proposed by Alexandros Frantzis
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 1728
Proposed branch: lp:~afrantzis/mir/fix-1332632-input-for-resized-surfaces
Merge into: lp:mir
Diff against target: 174 lines (+95/-7)
4 files modified
include/server/mir/scene/surface.h (+12/-0)
src/server/scene/basic_surface.cpp (+8/-4)
src/server/scene/basic_surface.h (+1/-1)
tests/unit-tests/scene/test_basic_surface.cpp (+74/-2)
To merge this branch: bzr merge lp:~afrantzis/mir/fix-1332632-input-for-resized-surfaces
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Alan Griffiths Approve
Cemil Azizoglu (community) Approve
Review via email: mp+224575@code.launchpad.net

Commit message

server: Ensure default input region is updated when surface is resized

Description of the change

server: Ensure default input region is updated when surface is resized

This MP also clarifies the behavior of set_input_region() with both tests and doxygen comments.

To post a comment you must log in.
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

Looks good.

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

OK

review: Approve
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) :
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
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
PS Jenkins bot (ps-jenkins) :
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
Alan Griffiths (alan-griffiths) wrote :

Failure is lp:1335873 (which has yet to be reproduced)

Re-approving

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

Appears to have landed last week(?)

revno: 1728 [merge]
author: Alexandros Frantzis <email address hidden>
committer: Tarmac
branch nick: development-branch
timestamp: Fri 2014-06-27 13:40:34 +0000
message:
  server: Ensure default input region is updated when surface is resized. Fixes: https://bugs.launchpad.net/bugs/1332632.

  Approved by PS Jenkins bot, Alan Griffiths, Cemil Azizoglu.

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

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'include/server/mir/scene/surface.h'
2--- include/server/mir/scene/surface.h 2014-06-23 02:57:39 +0000
3+++ include/server/mir/scene/surface.h 2014-06-27 08:55:40 +0000
4@@ -65,6 +65,18 @@
5 virtual void show() = 0;
6 virtual void move_to(geometry::Point const& top_left) = 0;
7 virtual void take_input_focus(std::shared_ptr<shell::InputTargeter> const& targeter) = 0;
8+
9+ /**
10+ * Sets the input region for this surface.
11+ *
12+ * The input region is expressed in coordinates relative to the surface (i.e.,
13+ * use (0,0) for the top left point of the surface).
14+ *
15+ * By default the input region is the whole surface. To unset a custom input region
16+ * and revert to the default set an empty input region, i.e., set_input_region({}).
17+ * To disable input set a non-empty region containing an empty rectangle, i.e.,
18+ * set_input_region({geom::Rectangle{}}).
19+ */
20 virtual void set_input_region(std::vector<geometry::Rectangle> const& region) = 0;
21 virtual void allow_framedropping(bool) = 0;
22 virtual void resize(geometry::Size const& size) = 0;
23
24=== modified file 'src/server/scene/basic_surface.cpp'
25--- src/server/scene/basic_surface.cpp 2014-06-24 14:12:25 +0000
26+++ src/server/scene/basic_surface.cpp 2014-06-27 08:55:40 +0000
27@@ -153,7 +153,7 @@
28 hidden(false),
29 input_mode(mi::InputReceptionMode::normal),
30 nonrectangular(nonrectangular),
31- input_rectangles{geom::Rectangle{geom::Point{0, 0}, surface_rect.size}},
32+ custom_input_rectangles(),
33 surface_buffer_stream(buffer_stream),
34 server_input_channel(input_channel),
35 input_sender(input_sender),
36@@ -277,7 +277,7 @@
37 void ms::BasicSurface::set_input_region(std::vector<geom::Rectangle> const& input_rectangles)
38 {
39 std::unique_lock<std::mutex> lock(guard);
40- this->input_rectangles = input_rectangles;
41+ custom_input_rectangles = input_rectangles;
42 }
43
44 void ms::BasicSurface::resize(geom::Size const& desired_size)
45@@ -324,16 +324,20 @@
46
47 if (hidden)
48 return false;
49-
50+
51 // Restrict to bounding rectangle
52 if (!surface_rect.contains(point))
53 return false;
54
55+ // No custom input region means effective input region is whole surface
56+ if (custom_input_rectangles.empty())
57+ return true;
58+
59 // TODO: Perhaps creates some issues with transformation.
60 auto local_point = geom::Point{geom::X{point.x.as_uint32_t()-surface_rect.top_left.x.as_uint32_t()},
61 geom::Y{point.y.as_uint32_t()-surface_rect.top_left.y.as_uint32_t()}};
62
63- for (auto const& rectangle : input_rectangles)
64+ for (auto const& rectangle : custom_input_rectangles)
65 {
66 if (rectangle.contains(local_point))
67 {
68
69=== modified file 'src/server/scene/basic_surface.h'
70--- src/server/scene/basic_surface.h 2014-06-23 22:25:17 +0000
71+++ src/server/scene/basic_surface.h 2014-06-27 08:55:40 +0000
72@@ -167,7 +167,7 @@
73 bool hidden;
74 input::InputReceptionMode input_mode;
75 const bool nonrectangular;
76- std::vector<geometry::Rectangle> input_rectangles;
77+ std::vector<geometry::Rectangle> custom_input_rectangles;
78 std::shared_ptr<compositor::BufferStream> const surface_buffer_stream;
79 std::shared_ptr<input::InputChannel> const server_input_channel;
80 std::shared_ptr<input::InputSender> const input_sender;
81
82=== modified file 'tests/unit-tests/scene/test_basic_surface.cpp'
83--- tests/unit-tests/scene/test_basic_surface.cpp 2014-06-23 22:25:17 +0000
84+++ tests/unit-tests/scene/test_basic_surface.cpp 2014-06-27 08:55:40 +0000
85@@ -79,8 +79,8 @@
86
87 struct BasicSurfaceTest : public testing::Test
88 {
89- std::string name{"aa"};
90- geom::Rectangle rect{{4,7},{5,9}};
91+ std::string const name{"aa"};
92+ geom::Rectangle const rect{{4,7},{5,9}};
93
94 testing::NiceMock<MockCallback> mock_callback;
95 std::function<void()> null_change_cb{[]{}};
96@@ -383,6 +383,78 @@
97 }
98 }
99
100+TEST_F(BasicSurfaceTest, updates_default_input_region_when_surface_is_resized_to_larger_size)
101+{
102+ geom::Rectangle const new_rect{rect.top_left,{10,10}};
103+ surface.resize(new_rect.size);
104+
105+ for (auto x = new_rect.top_left.x.as_int() - 1;
106+ x <= new_rect.top_right().x.as_int();
107+ x++)
108+ {
109+ for (auto y = new_rect.top_left.y.as_int() - 1;
110+ y <= new_rect.bottom_left().y.as_int();
111+ y++)
112+ {
113+ auto const test_pt = geom::Point{x, y};
114+ auto const contains = surface.input_area_contains(test_pt);
115+ if (new_rect.contains(test_pt))
116+ {
117+ EXPECT_TRUE(contains) << " point = " << test_pt;
118+ }
119+ else
120+ {
121+ EXPECT_FALSE(contains) << " point = " << test_pt;
122+ }
123+ }
124+ }
125+}
126+
127+TEST_F(BasicSurfaceTest, updates_default_input_region_when_surface_is_resized_to_smaller_size)
128+{
129+ geom::Rectangle const new_rect{rect.top_left,{2,2}};
130+ surface.resize(new_rect.size);
131+
132+ for (auto x = rect.top_left.x.as_int() - 1;
133+ x <= rect.top_right().x.as_int();
134+ x++)
135+ {
136+ for (auto y = rect.top_left.y.as_int() - 1;
137+ y <= rect.bottom_left().y.as_int();
138+ y++)
139+ {
140+ auto const test_pt = geom::Point{x, y};
141+ auto const contains = surface.input_area_contains(test_pt);
142+ if (new_rect.contains(test_pt))
143+ {
144+ EXPECT_TRUE(contains) << " point = " << test_pt;
145+ }
146+ else
147+ {
148+ EXPECT_FALSE(contains) << " point = " << test_pt;
149+ }
150+ }
151+ }
152+}
153+
154+TEST_F(BasicSurfaceTest, restores_default_input_region_when_setting_empty_input_region)
155+{
156+ std::vector<geom::Rectangle> const rectangles = {
157+ {{geom::X{0}, geom::Y{0}}, {geom::Width{1}, geom::Height{1}}}, //region0
158+ };
159+
160+ surface.set_input_region(rectangles);
161+ EXPECT_FALSE(surface.input_area_contains(rect.bottom_right() - geom::Displacement{1,1}));
162+
163+ surface.set_input_region({});
164+ EXPECT_TRUE(surface.input_area_contains(rect.bottom_right() - geom::Displacement{1,1}));
165+}
166+
167+TEST_F(BasicSurfaceTest, disables_input_when_setting_input_region_with_empty_rectangle)
168+{
169+ surface.set_input_region({geom::Rectangle()});
170+ EXPECT_FALSE(surface.input_area_contains(rect.top_left));
171+}
172
173 TEST_F(BasicSurfaceTest, reception_mode_is_normal_by_default)
174 {

Subscribers

People subscribed via source and target branches