Merge lp:~alan-griffiths/miral/BasicWindowManager-provides-active_window-logic into lp:miral
- BasicWindowManager-provides-active_window-logic
- Merge into trunk
Proposed by
Alan Griffiths
Status: | Merged |
---|---|
Approved by: | Alan Griffiths |
Approved revision: | 201 |
Merged at revision: | 176 |
Proposed branch: | lp:~alan-griffiths/miral/BasicWindowManager-provides-active_window-logic |
Merge into: | lp:miral |
Prerequisite: | lp:~alan-griffiths/miral/mru-list-of-active-windows |
Diff against target: |
688 lines (+142/-196) 10 files modified
include/miral/window_management_policy.h (+2/-1) include/miral/window_manager_tools.h (+3/-3) miral-kiosk/kiosk_window_manager.cpp (+15/-35) miral-kiosk/kiosk_window_manager.h (+3/-1) miral-shell/canonical_window_manager.cpp (+15/-69) miral-shell/canonical_window_manager.h (+3/-5) miral-shell/tiling_window_manager.cpp (+18/-36) miral-shell/tiling_window_manager.h (+3/-1) miral/basic_window_manager.cpp (+73/-40) miral/basic_window_manager.h (+7/-5) |
To merge this branch: | bzr merge lp:~alan-griffiths/miral/BasicWindowManager-provides-active_window-logic |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Mir development team | Pending | ||
Review via email: mp+295860@code.launchpad.net |
Commit message
Provide standard "active window" support in BasicWindowManager, just calling the policies for stuff that can reasonably differ.
Description of the change
Provide standard "active window" support in BasicWindowManager, just calling the policies for stuff that can reasonably differ.
To post a comment you must log in.
- 200. By Alan Griffiths
-
Use MRU list when switching applications
- 201. By Alan Griffiths
-
Extract common code
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'include/miral/window_management_policy.h' | |||
2 | --- include/miral/window_management_policy.h 2016-05-06 15:36:23 +0000 | |||
3 | +++ include/miral/window_management_policy.h 2016-05-28 07:54:16 +0000 | |||
4 | @@ -50,7 +50,8 @@ | |||
5 | 50 | virtual bool handle_pointer_event(MirPointerEvent const* event) = 0; | 50 | virtual bool handle_pointer_event(MirPointerEvent const* event) = 0; |
6 | 51 | virtual void handle_raise_window(WindowInfo& window_info) = 0; | 51 | virtual void handle_raise_window(WindowInfo& window_info) = 0; |
7 | 52 | 52 | ||
9 | 53 | virtual auto select_active_window(Window const& hint) -> Window = 0; | 53 | virtual void handle_focus_lost(miral::WindowInfo const& info) = 0; |
10 | 54 | virtual void handle_focus_gained(miral::WindowInfo const& info) = 0; | ||
11 | 54 | 55 | ||
12 | 55 | virtual ~WindowManagementPolicy() = default; | 56 | virtual ~WindowManagementPolicy() = default; |
13 | 56 | WindowManagementPolicy() = default; | 57 | WindowManagementPolicy() = default; |
14 | 57 | 58 | ||
15 | === modified file 'include/miral/window_manager_tools.h' | |||
16 | --- include/miral/window_manager_tools.h 2016-05-06 16:04:34 +0000 | |||
17 | +++ include/miral/window_manager_tools.h 2016-05-28 07:54:16 +0000 | |||
18 | @@ -55,10 +55,10 @@ | |||
19 | 55 | virtual auto info_for(std::weak_ptr<mir::scene::Session> const& session) const -> ApplicationInfo& = 0; | 55 | virtual auto info_for(std::weak_ptr<mir::scene::Session> const& session) const -> ApplicationInfo& = 0; |
20 | 56 | virtual auto info_for(std::weak_ptr<mir::scene::Surface> const& surface) const -> WindowInfo& = 0; | 56 | virtual auto info_for(std::weak_ptr<mir::scene::Surface> const& surface) const -> WindowInfo& = 0; |
21 | 57 | virtual auto info_for(Window const& window) const -> WindowInfo& = 0; | 57 | virtual auto info_for(Window const& window) const -> WindowInfo& = 0; |
24 | 58 | virtual auto focused_application() const -> Application = 0; | 58 | virtual void kill_active_application(int sig) = 0; |
25 | 59 | virtual auto focused_window() const -> Window = 0; | 59 | virtual auto active_window() const -> Window = 0; |
26 | 60 | virtual auto select_active_window(Window const& hint) -> Window = 0; | ||
27 | 60 | virtual void focus_next_application() = 0; | 61 | virtual void focus_next_application() = 0; |
28 | 61 | virtual void set_focus_to(Window const& window) = 0; | ||
29 | 62 | virtual auto window_at(mir::geometry::Point cursor) const -> Window = 0; | 62 | virtual auto window_at(mir::geometry::Point cursor) const -> Window = 0; |
30 | 63 | virtual auto active_display() -> mir::geometry::Rectangle const = 0; | 63 | virtual auto active_display() -> mir::geometry::Rectangle const = 0; |
31 | 64 | virtual void destroy(Window& window) = 0; | 64 | virtual void destroy(Window& window) = 0; |
32 | 65 | 65 | ||
33 | === modified file 'miral-kiosk/kiosk_window_manager.cpp' | |||
34 | --- miral-kiosk/kiosk_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
35 | +++ miral-kiosk/kiosk_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
36 | @@ -116,7 +116,7 @@ | |||
37 | 116 | 116 | ||
38 | 117 | void KioskWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) | 117 | void KioskWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) |
39 | 118 | { | 118 | { |
41 | 119 | select_active_window(window_info.window()); | 119 | tools->select_active_window(window_info.window()); |
42 | 120 | } | 120 | } |
43 | 121 | 121 | ||
44 | 122 | void KioskWindowManagerPolicy::handle_modify_window( | 122 | void KioskWindowManagerPolicy::handle_modify_window( |
45 | @@ -147,7 +147,7 @@ | |||
46 | 147 | 147 | ||
47 | 148 | void KioskWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) | 148 | void KioskWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) |
48 | 149 | { | 149 | { |
50 | 150 | select_active_window(window_info.window()); | 150 | tools->select_active_window(window_info.window()); |
51 | 151 | } | 151 | } |
52 | 152 | 152 | ||
53 | 153 | bool KioskWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) | 153 | bool KioskWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) |
54 | @@ -168,18 +168,18 @@ | |||
55 | 168 | modifiers == mir_input_event_modifier_alt && | 168 | modifiers == mir_input_event_modifier_alt && |
56 | 169 | scan_code == KEY_GRAVE) | 169 | scan_code == KEY_GRAVE) |
57 | 170 | { | 170 | { |
59 | 171 | if (auto const prev = tools->focused_window()) | 171 | if (auto const prev = tools->active_window()) |
60 | 172 | { | 172 | { |
61 | 173 | auto const& siblings = tools->info_for(prev.application()).windows(); | 173 | auto const& siblings = tools->info_for(prev.application()).windows(); |
62 | 174 | auto current = find(begin(siblings), end(siblings), prev); | 174 | auto current = find(begin(siblings), end(siblings), prev); |
63 | 175 | 175 | ||
65 | 176 | while (current != end(siblings) && prev == select_active_window(*current)) | 176 | while (current != end(siblings) && prev == tools->select_active_window(*current)) |
66 | 177 | ++current; | 177 | ++current; |
67 | 178 | 178 | ||
68 | 179 | if (current == end(siblings)) | 179 | if (current == end(siblings)) |
69 | 180 | { | 180 | { |
70 | 181 | current = begin(siblings); | 181 | current = begin(siblings); |
72 | 182 | while (prev != *current && prev == select_active_window(*current)) | 182 | while (prev != *current && prev == tools->select_active_window(*current)) |
73 | 183 | ++current; | 183 | ++current; |
74 | 184 | } | 184 | } |
75 | 185 | } | 185 | } |
76 | @@ -218,41 +218,12 @@ | |||
77 | 218 | 218 | ||
78 | 219 | if (action == mir_pointer_action_button_down) | 219 | if (action == mir_pointer_action_button_down) |
79 | 220 | { | 220 | { |
81 | 221 | select_active_window(tools->window_at(cursor)); | 221 | tools->select_active_window(tools->window_at(cursor)); |
82 | 222 | } | 222 | } |
83 | 223 | 223 | ||
84 | 224 | return false; | 224 | return false; |
85 | 225 | } | 225 | } |
86 | 226 | 226 | ||
87 | 227 | auto KioskWindowManagerPolicy::select_active_window(Window const& window) -> Window | ||
88 | 228 | { | ||
89 | 229 | if (!window) | ||
90 | 230 | { | ||
91 | 231 | tools->set_focus_to({}); | ||
92 | 232 | return window; | ||
93 | 233 | } | ||
94 | 234 | |||
95 | 235 | auto const& info_for = tools->info_for(window); | ||
96 | 236 | |||
97 | 237 | if (info_for.can_be_active()) | ||
98 | 238 | { | ||
99 | 239 | tools->set_focus_to(info_for.window()); | ||
100 | 240 | tools->raise_tree(window); | ||
101 | 241 | |||
102 | 242 | raise_splash_session(); | ||
103 | 243 | |||
104 | 244 | return window; | ||
105 | 245 | } | ||
106 | 246 | else | ||
107 | 247 | { | ||
108 | 248 | // Cannot have input focus - try the parent | ||
109 | 249 | if (auto const parent = info_for.parent()) | ||
110 | 250 | return select_active_window(parent); | ||
111 | 251 | |||
112 | 252 | return {}; | ||
113 | 253 | } | ||
114 | 254 | } | ||
115 | 255 | |||
116 | 256 | void KioskWindowManagerPolicy::raise_splash_session() const | 227 | void KioskWindowManagerPolicy::raise_splash_session() const |
117 | 257 | { | 228 | { |
118 | 258 | if (auto session = splash.session().lock()) | 229 | if (auto session = splash.session().lock()) |
119 | @@ -263,3 +234,12 @@ | |||
120 | 263 | tools->raise_tree(s); | 234 | tools->raise_tree(s); |
121 | 264 | } | 235 | } |
122 | 265 | } | 236 | } |
123 | 237 | |||
124 | 238 | void KioskWindowManagerPolicy::handle_focus_gained(WindowInfo const& info) | ||
125 | 239 | { | ||
126 | 240 | tools->raise_tree(info.window()); | ||
127 | 241 | } | ||
128 | 242 | |||
129 | 243 | void KioskWindowManagerPolicy::handle_focus_lost(WindowInfo const& /*info*/) | ||
130 | 244 | { | ||
131 | 245 | } | ||
132 | 266 | 246 | ||
133 | === modified file 'miral-kiosk/kiosk_window_manager.h' | |||
134 | --- miral-kiosk/kiosk_window_manager.h 2016-05-06 14:38:26 +0000 | |||
135 | +++ miral-kiosk/kiosk_window_manager.h 2016-05-28 07:54:16 +0000 | |||
136 | @@ -57,7 +57,9 @@ | |||
137 | 57 | 57 | ||
138 | 58 | void handle_raise_window(miral::WindowInfo& window_info) override; | 58 | void handle_raise_window(miral::WindowInfo& window_info) override; |
139 | 59 | 59 | ||
141 | 60 | auto select_active_window(miral::Window const& window) -> miral::Window override; | 60 | void handle_focus_lost(miral::WindowInfo const& info) override; |
142 | 61 | |||
143 | 62 | void handle_focus_gained(miral::WindowInfo const& info) override; | ||
144 | 61 | 63 | ||
145 | 62 | private: | 64 | private: |
146 | 63 | static const int modifier_mask = | 65 | static const int modifier_mask = |
147 | 64 | 66 | ||
148 | === modified file 'miral-shell/canonical_window_manager.cpp' | |||
149 | --- miral-shell/canonical_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
150 | +++ miral-shell/canonical_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
151 | @@ -58,7 +58,7 @@ | |||
152 | 58 | void CanonicalWindowManagerPolicy::click(Point cursor) | 58 | void CanonicalWindowManagerPolicy::click(Point cursor) |
153 | 59 | { | 59 | { |
154 | 60 | if (auto const window = tools->window_at(cursor)) | 60 | if (auto const window = tools->window_at(cursor)) |
156 | 61 | select_active_window(window); | 61 | tools->select_active_window(window); |
157 | 62 | } | 62 | } |
158 | 63 | 63 | ||
159 | 64 | void CanonicalWindowManagerPolicy::handle_app_info_updated(Rectangles const& /*displays*/) | 64 | void CanonicalWindowManagerPolicy::handle_app_info_updated(Rectangles const& /*displays*/) |
160 | @@ -86,8 +86,8 @@ | |||
161 | 86 | bool CanonicalWindowManagerPolicy::resize(Point cursor) | 86 | bool CanonicalWindowManagerPolicy::resize(Point cursor) |
162 | 87 | { | 87 | { |
163 | 88 | if (!resizing) | 88 | if (!resizing) |
166 | 89 | select_active_window(tools->window_at(old_cursor)); | 89 | tools->select_active_window(tools->window_at(old_cursor)); |
167 | 90 | return resize(active_window(), cursor, old_cursor); | 90 | return resize(tools->active_window(), cursor, old_cursor); |
168 | 91 | } | 91 | } |
169 | 92 | 92 | ||
170 | 93 | 93 | ||
171 | @@ -279,7 +279,7 @@ | |||
172 | 279 | 279 | ||
173 | 280 | void CanonicalWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) | 280 | void CanonicalWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) |
174 | 281 | { | 281 | { |
176 | 282 | select_active_window(window_info.window()); | 282 | tools->select_active_window(window_info.window()); |
177 | 283 | } | 283 | } |
178 | 284 | 284 | ||
179 | 285 | void CanonicalWindowManagerPolicy::handle_modify_window( | 285 | void CanonicalWindowManagerPolicy::handle_modify_window( |
180 | @@ -370,9 +370,6 @@ | |||
181 | 370 | { | 370 | { |
182 | 371 | tools->destroy(titlebar->window); | 371 | tools->destroy(titlebar->window); |
183 | 372 | } | 372 | } |
184 | 373 | |||
185 | 374 | if (active_window() == window_info.window()) | ||
186 | 375 | active_window_.reset(); | ||
187 | 376 | } | 373 | } |
188 | 377 | 374 | ||
189 | 378 | auto CanonicalWindowManagerPolicy::handle_set_state(WindowInfo& window_info, MirSurfaceState value) | 375 | auto CanonicalWindowManagerPolicy::handle_set_state(WindowInfo& window_info, MirSurfaceState value) |
190 | @@ -505,13 +502,13 @@ | |||
191 | 505 | 502 | ||
192 | 506 | void CanonicalWindowManagerPolicy::drag(Point cursor) | 503 | void CanonicalWindowManagerPolicy::drag(Point cursor) |
193 | 507 | { | 504 | { |
196 | 508 | select_active_window(tools->window_at(old_cursor)); | 505 | tools->select_active_window(tools->window_at(old_cursor)); |
197 | 509 | drag(active_window(), cursor, old_cursor, display_area); | 506 | drag(tools->active_window(), cursor, old_cursor, display_area); |
198 | 510 | } | 507 | } |
199 | 511 | 508 | ||
200 | 512 | void CanonicalWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) | 509 | void CanonicalWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) |
201 | 513 | { | 510 | { |
203 | 514 | select_active_window(window_info.window()); | 511 | tools->select_active_window(window_info.window()); |
204 | 515 | } | 512 | } |
205 | 516 | 513 | ||
206 | 517 | bool CanonicalWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) | 514 | bool CanonicalWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) |
207 | @@ -545,13 +542,11 @@ | |||
208 | 545 | switch (modifiers & modifier_mask) | 542 | switch (modifiers & modifier_mask) |
209 | 546 | { | 543 | { |
210 | 547 | case mir_input_event_modifier_alt: | 544 | case mir_input_event_modifier_alt: |
214 | 548 | if (auto const application = tools->focused_application()) | 545 | tools->kill_active_application(SIGTERM); |
212 | 549 | miral::kill(application, SIGTERM); | ||
213 | 550 | |||
215 | 551 | return true; | 546 | return true; |
216 | 552 | 547 | ||
217 | 553 | case mir_input_event_modifier_ctrl: | 548 | case mir_input_event_modifier_ctrl: |
219 | 554 | if (auto const window = tools->focused_window()) | 549 | if (auto const window = tools->active_window()) |
220 | 555 | window.request_client_surface_close(); | 550 | window.request_client_surface_close(); |
221 | 556 | 551 | ||
222 | 557 | return true; | 552 | return true; |
223 | @@ -572,18 +567,18 @@ | |||
224 | 572 | modifiers == mir_input_event_modifier_alt && | 567 | modifiers == mir_input_event_modifier_alt && |
225 | 573 | scan_code == KEY_GRAVE) | 568 | scan_code == KEY_GRAVE) |
226 | 574 | { | 569 | { |
228 | 575 | if (auto const prev = tools->focused_window()) | 570 | if (auto const prev = tools->active_window()) |
229 | 576 | { | 571 | { |
230 | 577 | auto const& siblings = tools->info_for(prev.application()).windows(); | 572 | auto const& siblings = tools->info_for(prev.application()).windows(); |
231 | 578 | auto current = find(begin(siblings), end(siblings), prev); | 573 | auto current = find(begin(siblings), end(siblings), prev); |
232 | 579 | 574 | ||
234 | 580 | while (current != end(siblings) && prev == select_active_window(*current)) | 575 | while (current != end(siblings) && prev == tools->select_active_window(*current)) |
235 | 581 | ++current; | 576 | ++current; |
236 | 582 | 577 | ||
237 | 583 | if (current == end(siblings)) | 578 | if (current == end(siblings)) |
238 | 584 | { | 579 | { |
239 | 585 | current = begin(siblings); | 580 | current = begin(siblings); |
241 | 586 | while (prev != *current && prev == select_active_window(*current)) | 581 | while (prev != *current && prev == tools->select_active_window(*current)) |
242 | 587 | ++current; | 582 | ++current; |
243 | 588 | } | 583 | } |
244 | 589 | } | 584 | } |
245 | @@ -702,7 +697,7 @@ | |||
246 | 702 | 697 | ||
247 | 703 | void CanonicalWindowManagerPolicy::toggle(MirSurfaceState state) | 698 | void CanonicalWindowManagerPolicy::toggle(MirSurfaceState state) |
248 | 704 | { | 699 | { |
250 | 705 | if (auto window = active_window()) | 700 | if (auto const window = tools->active_window()) |
251 | 706 | { | 701 | { |
252 | 707 | auto& info = tools->info_for(window); | 702 | auto& info = tools->info_for(window); |
253 | 708 | 703 | ||
254 | @@ -713,54 +708,13 @@ | |||
255 | 713 | } | 708 | } |
256 | 714 | } | 709 | } |
257 | 715 | 710 | ||
258 | 716 | auto CanonicalWindowManagerPolicy::select_active_window(Window const& hint) -> miral::Window | ||
259 | 717 | { | ||
260 | 718 | auto const prev_window = active_window(); | ||
261 | 719 | |||
262 | 720 | if (hint == prev_window) | ||
263 | 721 | return hint; | ||
264 | 722 | |||
265 | 723 | if (!hint) | ||
266 | 724 | { | ||
267 | 725 | if (prev_window) | ||
268 | 726 | { | ||
269 | 727 | tools->set_focus_to({}); | ||
270 | 728 | handle_focus_lost(tools->info_for(prev_window)); | ||
271 | 729 | } | ||
272 | 730 | |||
273 | 731 | return hint; | ||
274 | 732 | } | ||
275 | 733 | |||
276 | 734 | auto const& info_for_hint = tools->info_for(hint); | ||
277 | 735 | |||
278 | 736 | if (info_for_hint.can_be_active()) | ||
279 | 737 | { | ||
280 | 738 | tools->set_focus_to(hint); | ||
281 | 739 | tools->raise_tree(hint); | ||
282 | 740 | |||
283 | 741 | if (prev_window) | ||
284 | 742 | handle_focus_lost(tools->info_for(prev_window)); | ||
285 | 743 | |||
286 | 744 | handle_focus_gained(info_for_hint); | ||
287 | 745 | return hint; | ||
288 | 746 | } | ||
289 | 747 | else | ||
290 | 748 | { | ||
291 | 749 | // Cannot have input focus - try the parent | ||
292 | 750 | if (auto const parent = info_for_hint.parent()) | ||
293 | 751 | return select_active_window(parent); | ||
294 | 752 | } | ||
295 | 753 | |||
296 | 754 | return {}; | ||
297 | 755 | } | ||
298 | 756 | |||
299 | 757 | void CanonicalWindowManagerPolicy::handle_focus_gained(WindowInfo const& info) | 711 | void CanonicalWindowManagerPolicy::handle_focus_gained(WindowInfo const& info) |
300 | 758 | { | 712 | { |
301 | 713 | tools->raise_tree(info.window()); | ||
302 | 714 | |||
303 | 759 | if (auto const titlebar = std::static_pointer_cast<CanonicalWindowManagementPolicyData>(info.userdata())) | 715 | if (auto const titlebar = std::static_pointer_cast<CanonicalWindowManagementPolicyData>(info.userdata())) |
304 | 760 | titlebar->paint_titlebar(0xFF); | 716 | titlebar->paint_titlebar(0xFF); |
305 | 761 | 717 | ||
306 | 762 | active_window_ = info.window(); | ||
307 | 763 | |||
308 | 764 | // Frig to force the spinner to the top | 718 | // Frig to force the spinner to the top |
309 | 765 | if (auto const spinner_session = spinner.session()) | 719 | if (auto const spinner_session = spinner.session()) |
310 | 766 | { | 720 | { |
311 | @@ -775,14 +729,6 @@ | |||
312 | 775 | { | 729 | { |
313 | 776 | if (auto const titlebar = std::static_pointer_cast<CanonicalWindowManagementPolicyData>(info.userdata())) | 730 | if (auto const titlebar = std::static_pointer_cast<CanonicalWindowManagementPolicyData>(info.userdata())) |
314 | 777 | titlebar->paint_titlebar(0x3F); | 731 | titlebar->paint_titlebar(0x3F); |
315 | 778 | |||
316 | 779 | active_window_.reset(); | ||
317 | 780 | } | ||
318 | 781 | |||
319 | 782 | auto CanonicalWindowManagerPolicy::active_window() const | ||
320 | 783 | -> Window | ||
321 | 784 | { | ||
322 | 785 | return active_window_; | ||
323 | 786 | } | 732 | } |
324 | 787 | 733 | ||
325 | 788 | bool CanonicalWindowManagerPolicy::resize(Window const& window, Point cursor, Point old_cursor) | 734 | bool CanonicalWindowManagerPolicy::resize(Window const& window, Point cursor, Point old_cursor) |
326 | 789 | 735 | ||
327 | === modified file 'miral-shell/canonical_window_manager.h' | |||
328 | --- miral-shell/canonical_window_manager.h 2016-05-28 07:54:16 +0000 | |||
329 | +++ miral-shell/canonical_window_manager.h 2016-05-28 07:54:16 +0000 | |||
330 | @@ -74,7 +74,9 @@ | |||
331 | 74 | 74 | ||
332 | 75 | void handle_raise_window(miral::WindowInfo& window_info) override; | 75 | void handle_raise_window(miral::WindowInfo& window_info) override; |
333 | 76 | 76 | ||
335 | 77 | auto select_active_window(miral::Window const& hint) -> miral::Window override; | 77 | void handle_focus_lost(miral::WindowInfo const& info) override; |
336 | 78 | |||
337 | 79 | void handle_focus_gained(miral::WindowInfo const& info) override; | ||
338 | 78 | 80 | ||
339 | 79 | private: | 81 | private: |
340 | 80 | static const int modifier_mask = | 82 | static const int modifier_mask = |
341 | @@ -89,9 +91,6 @@ | |||
342 | 89 | bool resize(Point cursor); | 91 | bool resize(Point cursor); |
343 | 90 | void toggle(MirSurfaceState state); | 92 | void toggle(MirSurfaceState state); |
344 | 91 | 93 | ||
345 | 92 | auto active_window() const -> miral::Window; | ||
346 | 93 | void handle_focus_lost(miral::WindowInfo const& info); | ||
347 | 94 | void handle_focus_gained(miral::WindowInfo const& info); | ||
348 | 95 | 94 | ||
349 | 96 | bool resize(miral::Window const& window, Point cursor, Point old_cursor); | 95 | bool resize(miral::Window const& window, Point cursor, Point old_cursor); |
350 | 97 | bool drag(miral::Window window, Point to, Point from, Rectangle bounds); | 96 | bool drag(miral::Window window, Point to, Point from, Rectangle bounds); |
351 | @@ -105,7 +104,6 @@ | |||
352 | 105 | 104 | ||
353 | 106 | Rectangle display_area; | 105 | Rectangle display_area; |
354 | 107 | Point old_cursor{}; | 106 | Point old_cursor{}; |
355 | 108 | miral::Window active_window_; | ||
356 | 109 | using FullscreenSurfaces = std::set<miral::Window>; | 107 | using FullscreenSurfaces = std::set<miral::Window>; |
357 | 110 | 108 | ||
358 | 111 | FullscreenSurfaces fullscreen_surfaces; | 109 | FullscreenSurfaces fullscreen_surfaces; |
359 | 112 | 110 | ||
360 | === modified file 'miral-shell/tiling_window_manager.cpp' | |||
361 | --- miral-shell/tiling_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
362 | +++ miral-shell/tiling_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
363 | @@ -57,7 +57,7 @@ | |||
364 | 57 | void TilingWindowManagerPolicy::click(Point cursor) | 57 | void TilingWindowManagerPolicy::click(Point cursor) |
365 | 58 | { | 58 | { |
366 | 59 | auto const window = tools->window_at(cursor); | 59 | auto const window = tools->window_at(cursor); |
368 | 60 | select_active_window(window); | 60 | tools->select_active_window(window); |
369 | 61 | } | 61 | } |
370 | 62 | 62 | ||
371 | 63 | void TilingWindowManagerPolicy::handle_app_info_updated(Rectangles const& displays) | 63 | void TilingWindowManagerPolicy::handle_app_info_updated(Rectangles const& displays) |
372 | @@ -76,7 +76,7 @@ | |||
373 | 76 | { | 76 | { |
374 | 77 | if (application == application_under(old_cursor)) | 77 | if (application == application_under(old_cursor)) |
375 | 78 | { | 78 | { |
377 | 79 | if (auto const window = select_active_window(tools->window_at(old_cursor))) | 79 | if (auto const window = tools->select_active_window(tools->window_at(old_cursor))) |
378 | 80 | { | 80 | { |
379 | 81 | resize(window, cursor, old_cursor, tile_for(tools->info_for(application))); | 81 | resize(window, cursor, old_cursor, tile_for(tools->info_for(application))); |
380 | 82 | } | 82 | } |
381 | @@ -154,7 +154,7 @@ | |||
382 | 154 | 154 | ||
383 | 155 | void TilingWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) | 155 | void TilingWindowManagerPolicy::handle_window_ready(WindowInfo& window_info) |
384 | 156 | { | 156 | { |
386 | 157 | select_active_window(window_info.window()); | 157 | tools->select_active_window(window_info.window()); |
387 | 158 | } | 158 | } |
388 | 159 | 159 | ||
389 | 160 | void TilingWindowManagerPolicy::handle_modify_window( | 160 | void TilingWindowManagerPolicy::handle_modify_window( |
390 | @@ -240,7 +240,7 @@ | |||
391 | 240 | { | 240 | { |
392 | 241 | if (application == application_under(old_cursor)) | 241 | if (application == application_under(old_cursor)) |
393 | 242 | { | 242 | { |
395 | 243 | if (auto const window = select_active_window(tools->window_at(old_cursor))) | 243 | if (auto const window = tools->select_active_window(tools->window_at(old_cursor))) |
396 | 244 | { | 244 | { |
397 | 245 | drag(tools->info_for(window), cursor, old_cursor, tile_for(tools->info_for(application))); | 245 | drag(tools->info_for(window), cursor, old_cursor, tile_for(tools->info_for(application))); |
398 | 246 | } | 246 | } |
399 | @@ -250,7 +250,7 @@ | |||
400 | 250 | 250 | ||
401 | 251 | void TilingWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) | 251 | void TilingWindowManagerPolicy::handle_raise_window(WindowInfo& window_info) |
402 | 252 | { | 252 | { |
404 | 253 | select_active_window(window_info.window()); | 253 | tools-> select_active_window(window_info.window()); |
405 | 254 | } | 254 | } |
406 | 255 | 255 | ||
407 | 256 | bool TilingWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) | 256 | bool TilingWindowManagerPolicy::handle_keyboard_event(MirKeyboardEvent const* event) |
408 | @@ -284,13 +284,12 @@ | |||
409 | 284 | switch (modifiers & modifier_mask) | 284 | switch (modifiers & modifier_mask) |
410 | 285 | { | 285 | { |
411 | 286 | case mir_input_event_modifier_alt: | 286 | case mir_input_event_modifier_alt: |
414 | 287 | if (auto const application = tools->focused_application()) | 287 | tools->kill_active_application(SIGTERM); |
413 | 288 | miral::kill(application, SIGTERM); | ||
415 | 289 | 288 | ||
416 | 290 | return true; | 289 | return true; |
417 | 291 | 290 | ||
418 | 292 | case mir_input_event_modifier_ctrl: | 291 | case mir_input_event_modifier_ctrl: |
420 | 293 | if (auto const window = tools->focused_window()) | 292 | if (auto const window = tools->active_window()) |
421 | 294 | window.request_client_surface_close(); | 293 | window.request_client_surface_close(); |
422 | 295 | 294 | ||
423 | 296 | return true; | 295 | return true; |
424 | @@ -311,18 +310,18 @@ | |||
425 | 311 | modifiers == mir_input_event_modifier_alt && | 310 | modifiers == mir_input_event_modifier_alt && |
426 | 312 | scan_code == KEY_GRAVE) | 311 | scan_code == KEY_GRAVE) |
427 | 313 | { | 312 | { |
429 | 314 | if (auto const prev = tools->focused_window()) | 313 | if (auto const prev = tools->active_window()) |
430 | 315 | { | 314 | { |
431 | 316 | auto const& siblings = tools->info_for(prev.application()).windows(); | 315 | auto const& siblings = tools->info_for(prev.application()).windows(); |
432 | 317 | auto current = find(begin(siblings), end(siblings), prev); | 316 | auto current = find(begin(siblings), end(siblings), prev); |
433 | 318 | 317 | ||
435 | 319 | while (current != end(siblings) && prev == select_active_window(*current)) | 318 | while (current != end(siblings) && prev == tools->select_active_window(*current)) |
436 | 320 | ++current; | 319 | ++current; |
437 | 321 | 320 | ||
438 | 322 | if (current == end(siblings)) | 321 | if (current == end(siblings)) |
439 | 323 | { | 322 | { |
440 | 324 | current = begin(siblings); | 323 | current = begin(siblings); |
442 | 325 | while (prev != *current && prev == select_active_window(*current)) | 324 | while (prev != *current && prev == tools->select_active_window(*current)) |
443 | 326 | ++current; | 325 | ++current; |
444 | 327 | } | 326 | } |
445 | 328 | } | 327 | } |
446 | @@ -420,7 +419,7 @@ | |||
447 | 420 | 419 | ||
448 | 421 | void TilingWindowManagerPolicy::toggle(MirSurfaceState state) | 420 | void TilingWindowManagerPolicy::toggle(MirSurfaceState state) |
449 | 422 | { | 421 | { |
451 | 423 | if (auto window = tools->focused_window()) | 422 | if (auto window = tools->active_window()) |
452 | 424 | { | 423 | { |
453 | 425 | auto& window_info = tools->info_for(window); | 424 | auto& window_info = tools->info_for(window); |
454 | 426 | 425 | ||
455 | @@ -583,28 +582,11 @@ | |||
456 | 583 | } | 582 | } |
457 | 584 | } | 583 | } |
458 | 585 | 584 | ||
483 | 586 | auto TilingWindowManagerPolicy::select_active_window(Window const& window) -> Window | 585 | void TilingWindowManagerPolicy::handle_focus_gained(WindowInfo const& info) |
484 | 587 | { | 586 | { |
485 | 588 | if (!window) | 587 | tools->raise_tree(info.window()); |
486 | 589 | { | 588 | } |
487 | 590 | tools->set_focus_to({}); | 589 | |
488 | 591 | return window; | 590 | void TilingWindowManagerPolicy::handle_focus_lost(WindowInfo const& /*info*/) |
489 | 592 | } | 591 | { |
466 | 593 | |||
467 | 594 | auto const& info_for = tools->info_for(window); | ||
468 | 595 | |||
469 | 596 | if (info_for.can_be_active()) | ||
470 | 597 | { | ||
471 | 598 | tools->set_focus_to(info_for.window()); | ||
472 | 599 | tools->raise_tree(window); | ||
473 | 600 | return window; | ||
474 | 601 | } | ||
475 | 602 | else | ||
476 | 603 | { | ||
477 | 604 | // Cannot have input focus - try the parent | ||
478 | 605 | if (auto const parent = info_for.parent()) | ||
479 | 606 | return select_active_window(parent); | ||
480 | 607 | |||
481 | 608 | return {}; | ||
482 | 609 | } | ||
490 | 610 | } | 592 | } |
491 | 611 | 593 | ||
492 | === modified file 'miral-shell/tiling_window_manager.h' | |||
493 | --- miral-shell/tiling_window_manager.h 2016-05-06 14:38:26 +0000 | |||
494 | +++ miral-shell/tiling_window_manager.h 2016-05-28 07:54:16 +0000 | |||
495 | @@ -68,7 +68,9 @@ | |||
496 | 68 | 68 | ||
497 | 69 | void handle_raise_window(miral::WindowInfo& window_info) override; | 69 | void handle_raise_window(miral::WindowInfo& window_info) override; |
498 | 70 | 70 | ||
500 | 71 | auto select_active_window(miral::Window const& window) -> miral::Window override; | 71 | void handle_focus_lost(miral::WindowInfo const& info) override; |
501 | 72 | |||
502 | 73 | void handle_focus_gained(miral::WindowInfo const& info) override; | ||
503 | 72 | 74 | ||
504 | 73 | private: | 75 | private: |
505 | 74 | static const int modifier_mask = | 76 | static const int modifier_mask = |
506 | 75 | 77 | ||
507 | === modified file 'miral/basic_window_manager.cpp' | |||
508 | --- miral/basic_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
509 | +++ miral/basic_window_manager.cpp 2016-05-28 07:54:16 +0000 | |||
510 | @@ -151,38 +151,21 @@ | |||
511 | 151 | if (is_active_window) | 151 | if (is_active_window) |
512 | 152 | { | 152 | { |
513 | 153 | // Try to make the parent active | 153 | // Try to make the parent active |
538 | 154 | if (parent) | 154 | if (parent && select_active_window(parent)) |
539 | 155 | { | 155 | return; |
540 | 156 | if (policy->select_active_window(parent)) | 156 | |
541 | 157 | return; | 157 | if (can_activate_window_for_session(session)) |
542 | 158 | } | 158 | return; |
519 | 159 | |||
520 | 160 | // TODO the policy for choosing a window is mixed with implementing the choice. | ||
521 | 161 | // I.e. select_active_window() calls set_focus_to() which updates mru_active_windows | ||
522 | 162 | // during the iteration. There must be a better way to sequence the logic. | ||
523 | 163 | // Until then we copy the list. | ||
524 | 164 | auto const copy_mru_windows = mru_active_windows; | ||
525 | 165 | |||
526 | 166 | // Try to activate to recently active window of same application | ||
527 | 167 | { | ||
528 | 168 | Window new_focus; | ||
529 | 169 | |||
530 | 170 | copy_mru_windows.enumerate([&](Window& window) | ||
531 | 171 | { | ||
532 | 172 | return window.application() != session || | ||
533 | 173 | !(new_focus = policy->select_active_window(window)); | ||
534 | 174 | }); | ||
535 | 175 | |||
536 | 176 | if (new_focus) return; | ||
537 | 177 | } | ||
543 | 178 | 159 | ||
544 | 179 | // Try to activate to recently active window of any application | 160 | // Try to activate to recently active window of any application |
545 | 180 | { | 161 | { |
546 | 181 | Window new_focus; | 162 | Window new_focus; |
547 | 182 | 163 | ||
549 | 183 | copy_mru_windows.enumerate([&](Window& window) | 164 | mru_active_windows.enumerate([&](Window& window) |
550 | 184 | { | 165 | { |
552 | 185 | return !(new_focus = policy->select_active_window(window)); | 166 | // select_active_window() calls set_focus_to() which updates mru_active_windows and changes window |
553 | 167 | auto const w = window; | ||
554 | 168 | return !(new_focus = select_active_window(w)); | ||
555 | 186 | }); | 169 | }); |
556 | 187 | 170 | ||
557 | 188 | if (new_focus) return; | 171 | if (new_focus) return; |
558 | @@ -315,29 +298,27 @@ | |||
559 | 315 | return info_for(std::weak_ptr<mir::scene::Surface>(window)); | 298 | return info_for(std::weak_ptr<mir::scene::Surface>(window)); |
560 | 316 | } | 299 | } |
561 | 317 | 300 | ||
564 | 318 | auto miral::BasicWindowManager::focused_application() const | 301 | void miral::BasicWindowManager::kill_active_application(int sig) |
563 | 319 | -> Application | ||
565 | 320 | { | 302 | { |
567 | 321 | return focus_controller->focused_session(); | 303 | if (auto const application = focus_controller->focused_session()) |
568 | 304 | miral::kill(application, sig); | ||
569 | 322 | } | 305 | } |
570 | 323 | 306 | ||
573 | 324 | auto miral::BasicWindowManager::focused_window() const | 307 | auto miral::BasicWindowManager::active_window() const -> Window |
572 | 325 | -> Window | ||
574 | 326 | { | 308 | { |
577 | 327 | auto focussed_surface = focus_controller->focused_surface(); | 309 | return mru_active_windows.top(); |
576 | 328 | return focussed_surface ? info_for(focussed_surface).window() : Window{}; | ||
578 | 329 | } | 310 | } |
579 | 330 | 311 | ||
580 | 331 | void miral::BasicWindowManager::focus_next_application() | 312 | void miral::BasicWindowManager::focus_next_application() |
581 | 332 | { | 313 | { |
582 | 333 | focus_controller->focus_next_session(); | 314 | focus_controller->focus_next_session(); |
590 | 334 | policy->select_active_window(focused_window()); | 315 | |
591 | 335 | } | 316 | if (can_activate_window_for_session(focus_controller->focused_session())) |
592 | 336 | 317 | return; | |
593 | 337 | void miral::BasicWindowManager::set_focus_to(Window const& window) | 318 | |
594 | 338 | { | 319 | // Last resort: accept wherever focus_controller placed focus |
595 | 339 | if (window) mru_active_windows.push(window); | 320 | auto const focussed_surface = focus_controller->focused_surface(); |
596 | 340 | focus_controller->set_focus_to(window.application(), window); | 321 | select_active_window(focussed_surface ? info_for(focussed_surface).window() : Window{}); |
597 | 341 | } | 322 | } |
598 | 342 | 323 | ||
599 | 343 | auto miral::BasicWindowManager::window_at(geometry::Point cursor) const | 324 | auto miral::BasicWindowManager::window_at(geometry::Point cursor) const |
600 | @@ -462,3 +443,55 @@ | |||
601 | 462 | std::lock_guard<decltype(mutex)> lock(mutex); | 443 | std::lock_guard<decltype(mutex)> lock(mutex); |
602 | 463 | callback(); | 444 | callback(); |
603 | 464 | } | 445 | } |
604 | 446 | |||
605 | 447 | auto miral::BasicWindowManager::select_active_window(Window const& hint) -> miral::Window | ||
606 | 448 | { | ||
607 | 449 | auto const prev_window = active_window(); | ||
608 | 450 | |||
609 | 451 | if (!hint) | ||
610 | 452 | { | ||
611 | 453 | if (prev_window) | ||
612 | 454 | { | ||
613 | 455 | focus_controller->set_focus_to(hint.application(), hint); | ||
614 | 456 | policy->handle_focus_lost(info_for(prev_window)); | ||
615 | 457 | } | ||
616 | 458 | |||
617 | 459 | return hint; | ||
618 | 460 | } | ||
619 | 461 | |||
620 | 462 | auto const& info_for_hint = info_for(hint); | ||
621 | 463 | |||
622 | 464 | if (info_for_hint.can_be_active()) | ||
623 | 465 | { | ||
624 | 466 | mru_active_windows.push(hint); | ||
625 | 467 | focus_controller->set_focus_to(hint.application(), hint); | ||
626 | 468 | |||
627 | 469 | if (prev_window && prev_window != hint) | ||
628 | 470 | policy->handle_focus_lost(info_for(prev_window)); | ||
629 | 471 | |||
630 | 472 | policy->handle_focus_gained(info_for_hint); | ||
631 | 473 | return hint; | ||
632 | 474 | } | ||
633 | 475 | else | ||
634 | 476 | { | ||
635 | 477 | // Cannot have input focus - try the parent | ||
636 | 478 | if (auto const parent = info_for_hint.parent()) | ||
637 | 479 | return select_active_window(parent); | ||
638 | 480 | } | ||
639 | 481 | |||
640 | 482 | return {}; | ||
641 | 483 | } | ||
642 | 484 | |||
643 | 485 | auto miral::BasicWindowManager::can_activate_window_for_session(miral::Application const& session) -> bool | ||
644 | 486 | { | ||
645 | 487 | miral::Window new_focus; | ||
646 | 488 | |||
647 | 489 | mru_active_windows.enumerate([&](miral::Window& window) | ||
648 | 490 | { | ||
649 | 491 | // select_active_window() calls set_focus_to() which updates mru_active_windows and changes window | ||
650 | 492 | auto const w = window; | ||
651 | 493 | return w.application() != session || !(new_focus = miral::BasicWindowManager::select_active_window(w)); | ||
652 | 494 | }); | ||
653 | 495 | |||
654 | 496 | return new_focus; | ||
655 | 497 | } | ||
656 | 465 | \ No newline at end of file | 498 | \ No newline at end of file |
657 | 466 | 499 | ||
658 | === modified file 'miral/basic_window_manager.h' | |||
659 | --- miral/basic_window_manager.h 2016-05-28 07:54:16 +0000 | |||
660 | +++ miral/basic_window_manager.h 2016-05-28 07:54:16 +0000 | |||
661 | @@ -114,14 +114,14 @@ | |||
662 | 114 | 114 | ||
663 | 115 | auto info_for(Window const& window) const -> WindowInfo& override; | 115 | auto info_for(Window const& window) const -> WindowInfo& override; |
664 | 116 | 116 | ||
668 | 117 | auto focused_application() const -> Application override; | 117 | void kill_active_application(int sig) override; |
669 | 118 | 118 | ||
670 | 119 | auto focused_window() const -> Window override; | 119 | auto active_window() const -> Window override; |
671 | 120 | |||
672 | 121 | auto select_active_window(Window const& hint) -> Window override; | ||
673 | 120 | 122 | ||
674 | 121 | void focus_next_application() override; | 123 | void focus_next_application() override; |
675 | 122 | 124 | ||
676 | 123 | void set_focus_to(Window const& window) override; | ||
677 | 124 | |||
678 | 125 | auto window_at(mir::geometry::Point cursor) const -> Window override; | 125 | auto window_at(mir::geometry::Point cursor) const -> Window override; |
679 | 126 | 126 | ||
680 | 127 | auto active_display() -> mir::geometry::Rectangle const override; | 127 | auto active_display() -> mir::geometry::Rectangle const override; |
681 | @@ -156,6 +156,8 @@ | |||
682 | 156 | void update_event_timestamp(MirKeyboardEvent const* kev); | 156 | void update_event_timestamp(MirKeyboardEvent const* kev); |
683 | 157 | void update_event_timestamp(MirPointerEvent const* pev); | 157 | void update_event_timestamp(MirPointerEvent const* pev); |
684 | 158 | void update_event_timestamp(MirTouchEvent const* tev); | 158 | void update_event_timestamp(MirTouchEvent const* tev); |
685 | 159 | |||
686 | 160 | auto can_activate_window_for_session(miral::Application const& session) -> bool; | ||
687 | 159 | }; | 161 | }; |
688 | 160 | } | 162 | } |
689 | 161 | 163 |