Mir

Merge lp:~alan-griffiths/mir/fix-1454128-by-getting-select_active_surface-right into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Daniel van Vugt
Approved revision: no longer in the source branch.
Merged at revision: 2572
Proposed branch: lp:~alan-griffiths/mir/fix-1454128-by-getting-select_active_surface-right
Merge into: lp:mir
Diff against target: 225 lines (+72/-44)
4 files modified
examples/server_example_canonical_window_manager.cpp (+18/-7)
src/server/shell/abstract_shell.cpp (+30/-24)
src/server/shell/canonical_window_manager.cpp (+21/-9)
tests/integration-tests/test_default_window_manager.cpp (+3/-4)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1454128-by-getting-select_active_surface-right
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Kevin DuBois (community) Approve
Alexandros Frantzis (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+258865@code.launchpad.net

Commit message

shell, examples: Fix the select_active_surface() implementation(s) in msh::CanonicalWindowManagerPolicy and me::CanonicalWindowManagerPolicyCopy (fixes lp:1454128)

Description of the change

shell, examples: Fix the select_active_surface() implementation(s) in msh::CanonicalWindowManagerPolicy and me::CanonicalWindowManagerPolicyCopy (fixes lp:1454128)

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
Alan Griffiths (alan-griffiths) wrote :

I made some changes to TestDefaultWindowManager.sets_input_focus because:

/1/ using two different shared_ptr<>s for the one mock_surface is just wrong.
/2/ And the second call to input_targeter.clear_focus()) when focus is already cleared shouldn't have been happening.

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.

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

lgtm

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

Confirmed bug fixed.

Ran into bug 1452579 again, but that's unrelated.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'examples/server_example_canonical_window_manager.cpp'
2--- examples/server_example_canonical_window_manager.cpp 2015-05-08 15:50:18 +0000
3+++ examples/server_example_canonical_window_manager.cpp 2015-05-12 16:14:17 +0000
4@@ -418,6 +418,7 @@
5
6 if (!--tools->info_for(session).surfaces && session == tools->focused_session())
7 {
8+ active_surface_.reset();
9 tools->focus_next_session();
10 select_active_surface(tools->focused_surface());
11 }
12@@ -690,16 +691,19 @@
13 if (surface == active_surface_.lock())
14 return;
15
16- if (auto const active_surface = active_surface_.lock())
17+ if (!surface)
18 {
19- if (auto const titlebar = tools->info_for(active_surface).titlebar)
20+ if (auto const active_surface = active_surface_.lock())
21 {
22- paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);
23+ if (auto const titlebar = tools->info_for(active_surface).titlebar)
24+ {
25+ paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);
26+ }
27 }
28- }
29-
30- if (!surface)
31- {
32+
33+ if (active_surface_.lock())
34+ tools->set_focus_to({}, {});
35+
36 active_surface_.reset();
37 return;
38 }
39@@ -715,6 +719,13 @@
40 case mir_surface_type_freestyle:
41 case mir_surface_type_menu:
42 case mir_surface_type_inputmethod: /**< AKA "OSK" or handwriting etc. */
43+ if (auto const active_surface = active_surface_.lock())
44+ {
45+ if (auto const titlebar = tools->info_for(active_surface).titlebar)
46+ {
47+ paint_titlebar(titlebar, tools->info_for(titlebar), 0x3F);
48+ }
49+ }
50 if (auto const titlebar = tools->info_for(surface).titlebar)
51 {
52 paint_titlebar(titlebar, tools->info_for(titlebar), 0xFF);
53
54=== modified file 'src/server/shell/abstract_shell.cpp'
55--- src/server/shell/abstract_shell.cpp 2015-04-17 14:33:09 +0000
56+++ src/server/shell/abstract_shell.cpp 2015-05-12 16:14:17 +0000
57@@ -169,35 +169,41 @@
58 std::shared_ptr<ms::Session> const& session,
59 std::shared_ptr<ms::Surface> const& surface)
60 {
61- if (surface)
62+ auto const current_focus = focus_surface.lock();
63+
64+ if (surface != current_focus)
65 {
66- auto current_focus = focus_surface.lock();
67-
68- if (surface != current_focus)
69+ focus_surface = surface;
70+
71+ if (current_focus)
72+ current_focus->configure(mir_surface_attrib_focus, mir_surface_unfocused);
73+
74+ if (surface)
75 {
76 // Ensure the surface has really taken the focus before notifying it that it is focused
77 input_targeter->set_focus(surface);
78- if (current_focus)
79- current_focus->configure(mir_surface_attrib_focus, mir_surface_unfocused);
80-
81 surface->configure(mir_surface_attrib_focus, mir_surface_focused);
82- focus_surface = surface;
83- }
84- }
85- else
86- {
87- input_targeter->clear_focus();
88- }
89-
90- focus_session = session;
91-
92- if (session)
93- {
94- session_coordinator->set_focus_to(session);
95- }
96- else
97- {
98- session_coordinator->unset_focus();
99+ }
100+ else
101+ {
102+ input_targeter->clear_focus();
103+ }
104+ }
105+
106+ auto const current_session = focus_session.lock();
107+
108+ if (session != current_session)
109+ {
110+ focus_session = session;
111+
112+ if (session)
113+ {
114+ session_coordinator->set_focus_to(session);
115+ }
116+ else
117+ {
118+ session_coordinator->unset_focus();
119+ }
120 }
121 }
122
123
124=== modified file 'src/server/shell/canonical_window_manager.cpp'
125--- src/server/shell/canonical_window_manager.cpp 2015-05-08 23:34:48 +0000
126+++ src/server/shell/canonical_window_manager.cpp 2015-05-12 16:14:17 +0000
127@@ -196,11 +196,15 @@
128 public std::enable_shared_from_this<SurfaceReadyObserver>
129 {
130 public:
131+ using ActivateFunction = std::function<void(
132+ std::shared_ptr<ms::Session> const& session,
133+ std::shared_ptr<ms::Surface> const& surface)>;
134+
135 SurfaceReadyObserver(
136- msh::CanonicalWindowManagerPolicy::Tools* const focus_controller,
137+ ActivateFunction const& activate,
138 std::shared_ptr<ms::Session> const& session,
139 std::shared_ptr<ms::Surface> const& surface) :
140- focus_controller{focus_controller},
141+ activate{activate},
142 session{session},
143 surface{surface}
144 {
145@@ -211,12 +215,12 @@
146 {
147 if (auto const s = surface.lock())
148 {
149- focus_controller->set_focus_to(session.lock(), s);
150+ activate(session.lock(), s);
151 s->remove_observer(shared_from_this());
152 }
153 }
154
155- msh::CanonicalWindowManagerPolicy::Tools* const focus_controller;
156+ ActivateFunction const activate;
157 std::weak_ptr<ms::Session> const session;
158 std::weak_ptr<ms::Surface> const surface;
159 };
160@@ -243,8 +247,14 @@
161 // TODO There's currently no way to insert surfaces into an active (or inactive)
162 // TODO window tree while keeping the order stable or consistent with spec.
163 // TODO Nor is there a way to update the "default surface" when appropriate!!
164- surface->add_observer(std::make_shared<SurfaceReadyObserver>(tools, session, surface));
165- active_surface_ = surface;
166+ surface->add_observer(std::make_shared<SurfaceReadyObserver>(
167+ [this](std::shared_ptr<scene::Session> const& /*session*/,
168+ std::shared_ptr<scene::Surface> const& surface)
169+ {
170+ select_active_surface(surface);
171+ },
172+ session,
173+ surface));
174 break;
175
176 case mir_surface_type_gloss:
177@@ -317,12 +327,11 @@
178 }
179 }
180
181-
182 if (!--tools->info_for(session).surfaces && session == tools->focused_session())
183 {
184+ active_surface_.reset();
185 tools->focus_next_session();
186- if (auto const surface = tools->focused_surface())
187- tools->raise({surface});
188+ select_active_surface(tools->focused_surface());
189 }
190 }
191
192@@ -550,6 +559,9 @@
193 {
194 if (!surface)
195 {
196+ if (active_surface_.lock())
197+ tools->set_focus_to({}, {});
198+
199 active_surface_.reset();
200 return;
201 }
202
203=== modified file 'tests/integration-tests/test_default_window_manager.cpp'
204--- tests/integration-tests/test_default_window_manager.cpp 2015-05-04 19:18:26 +0000
205+++ tests/integration-tests/test_default_window_manager.cpp 2015-05-12 16:14:17 +0000
206@@ -157,16 +157,15 @@
207 mtd::StubSceneSession app1;
208 NiceMock<mtd::MockSurface> mock_surface;
209
210+ auto const surface = mt::fake_shared(mock_surface);
211 {
212 InSequence seq;
213- EXPECT_CALL(input_targeter, set_focus(Eq(mt::fake_shared(mock_surface)))).Times(1);
214+ EXPECT_CALL(input_targeter, set_focus(Eq(surface))).Times(1);
215 // When we have no default surface.
216 EXPECT_CALL(input_targeter, clear_focus()).Times(1);
217- // When we have no session.
218- EXPECT_CALL(input_targeter, clear_focus()).Times(1);
219 }
220
221- shell.set_focus_to(mt::fake_shared(app1), mt::fake_shared(mock_surface));
222+ shell.set_focus_to(mt::fake_shared(app1), surface);
223 shell.set_focus_to(mt::fake_shared(app1), std::shared_ptr<ms::Surface>());
224 shell.set_focus_to(std::shared_ptr<ms::Session>(), std::shared_ptr<ms::Surface>());
225 }

Subscribers

People subscribed via source and target branches