Merge lp:~alan-griffiths/miral/revised-resize into lp:miral

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: 165
Merged at revision: 164
Proposed branch: lp:~alan-griffiths/miral/revised-resize
Merge into: lp:miral
Prerequisite: lp:~alan-griffiths/miral/fix-1575211
Diff against target: 148 lines (+53/-23)
2 files modified
miral-shell/canonical_window_manager.cpp (+48/-22)
miral-shell/canonical_window_manager.h (+5/-1)
To merge this branch: bzr merge lp:~alan-griffiths/miral/revised-resize
Reviewer Review Type Date Requested Status
Cemil Azizoglu (community) Approve
Review via email: mp+293125@code.launchpad.net

Commit message

Update the resize logic in CanonicalWindowManagerPolicy following the discussion on lp:1447886

Description of the change

Update the resize logic in CanonicalWindowManagerPolicy following the discussion on lp:1447886

It now looks at the gesture as a whole and only does position checking at the start of the resize gesture. Thereafter the gesture continues until the button is released, regardless of whether the cursor is still inside the surface/titlebar.

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

Looks good

review: Approve
165. By Alan Griffiths

Tweak after trying backport to Mir

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'miral-shell/canonical_window_manager.cpp'
2--- miral-shell/canonical_window_manager.cpp 2016-04-22 09:06:25 +0000
3+++ miral-shell/canonical_window_manager.cpp 2016-04-28 09:25:50 +0000
4@@ -83,10 +83,11 @@
5 }
6 }
7
8-void CanonicalWindowManagerPolicy::resize(Point cursor)
9+bool CanonicalWindowManagerPolicy::resize(Point cursor)
10 {
11- select_active_window(tools->window_at(old_cursor));
12- resize(active_window(), cursor, old_cursor);
13+ if (!resizing)
14+ select_active_window(tools->window_at(old_cursor));
15+ return resize(active_window(), cursor, old_cursor);
16 }
17
18
19@@ -653,6 +654,7 @@
20 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
21
22 bool consumes_event = false;
23+ bool resize_event = false;
24
25 if (action == mir_pointer_action_button_down)
26 {
27@@ -669,7 +671,7 @@
28
29 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))
30 {
31- resize(cursor);
32+ resize_event = resize(cursor);
33 consumes_event = true;
34 }
35 }
36@@ -692,6 +694,7 @@
37 }
38 }
39
40+ resizing = resize_event;
41 old_cursor = cursor;
42 return consumes_event;
43 }
44@@ -782,39 +785,62 @@
45
46 bool CanonicalWindowManagerPolicy::resize(Window const& window, Point cursor, Point old_cursor)
47 {
48- if (!window || !window.input_area_contains(old_cursor))
49+ if (!window)
50 return false;
51
52+ auto& window_info = tools->info_for(window);
53+
54 auto const top_left = window.top_left();
55 Rectangle const old_pos{top_left, window.size()};
56
57- auto anchor = top_left;
58-
59- for (auto const& corner : {
60- old_pos.top_right(),
61- old_pos.bottom_left(),
62- old_pos.bottom_right()})
63+ if (!resizing)
64 {
65- if ((old_cursor - anchor).length_squared() <
66- (old_cursor - corner).length_squared())
67+ auto anchor = old_pos.bottom_right();
68+
69+ for (auto const& corner : {
70+ old_pos.top_right(),
71+ old_pos.bottom_left(),
72+ top_left})
73 {
74- anchor = corner;
75+ if ((old_cursor - anchor).length_squared() <
76+ (old_cursor - corner).length_squared())
77+ {
78+ anchor = corner;
79+ }
80 }
81+
82+ left_resize = anchor.x != top_left.x;
83+ top_resize = anchor.y != top_left.y;
84 }
85
86- bool const left_resize = anchor.x != top_left.x;
87- bool const top_resize = anchor.y != top_left.y;
88 int const x_sign = left_resize? -1 : 1;
89 int const y_sign = top_resize? -1 : 1;
90
91- auto const delta = cursor-old_cursor;
92-
93- Size new_size{old_pos.size.width + x_sign*delta.dx, old_pos.size.height + y_sign*delta.dy};
94-
95+ auto delta = cursor-old_cursor;
96+
97+ auto new_width = old_pos.size.width + x_sign * delta.dx;
98+ auto new_height = old_pos.size.height + y_sign * delta.dy;
99+
100+ auto const min_width = std::max(window_info.min_width, Width{5});
101+ auto const min_height = std::max(window_info.min_height, Height{5});
102+
103+ if (new_width < min_width)
104+ {
105+ new_width = min_width;
106+ if (delta.dx > DeltaX{0})
107+ delta.dx = DeltaX{0};
108+ }
109+
110+ if (new_height < min_height)
111+ {
112+ new_height = min_height;
113+ if (delta.dy > DeltaY{0})
114+ delta.dy = DeltaY{0};
115+ }
116+
117+ Size new_size{new_width, new_height};
118 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;
119
120- auto& window_info = tools->info_for(window);
121-
122 apply_resize(window_info, new_pos, new_size);
123
124 return true;
125
126=== modified file 'miral-shell/canonical_window_manager.h'
127--- miral-shell/canonical_window_manager.h 2016-04-22 09:06:25 +0000
128+++ miral-shell/canonical_window_manager.h 2016-04-28 09:25:50 +0000
129@@ -88,7 +88,7 @@
130
131 void drag(Point cursor);
132 void click(Point cursor);
133- void resize(Point cursor);
134+ bool resize(Point cursor);
135 void toggle(MirSurfaceState state);
136
137 auto active_window() const -> miral::Window;
138@@ -108,6 +108,10 @@
139 using FullscreenSurfaces = std::set<miral::Window>;
140
141 FullscreenSurfaces fullscreen_surfaces;
142+
143+ bool resizing = false;
144+ bool left_resize = false;
145+ bool top_resize = false;
146 };
147
148 #endif /* MIRAL_SHELL_CANONICAL_WINDOW_MANAGER_H_ */

Subscribers

People subscribed via source and target branches