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
=== modified file 'miral-shell/canonical_window_manager.cpp'
--- miral-shell/canonical_window_manager.cpp 2016-04-22 09:06:25 +0000
+++ miral-shell/canonical_window_manager.cpp 2016-04-28 09:25:50 +0000
@@ -83,10 +83,11 @@
83 }83 }
84}84}
8585
86void CanonicalWindowManagerPolicy::resize(Point cursor)86bool CanonicalWindowManagerPolicy::resize(Point cursor)
87{87{
88 select_active_window(tools->window_at(old_cursor));88 if (!resizing)
89 resize(active_window(), cursor, old_cursor);89 select_active_window(tools->window_at(old_cursor));
90 return resize(active_window(), cursor, old_cursor);
90}91}
9192
9293
@@ -653,6 +654,7 @@
653 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};654 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
654655
655 bool consumes_event = false;656 bool consumes_event = false;
657 bool resize_event = false;
656658
657 if (action == mir_pointer_action_button_down)659 if (action == mir_pointer_action_button_down)
658 {660 {
@@ -669,7 +671,7 @@
669671
670 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))672 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))
671 {673 {
672 resize(cursor);674 resize_event = resize(cursor);
673 consumes_event = true;675 consumes_event = true;
674 }676 }
675 }677 }
@@ -692,6 +694,7 @@
692 }694 }
693 }695 }
694696
697 resizing = resize_event;
695 old_cursor = cursor;698 old_cursor = cursor;
696 return consumes_event;699 return consumes_event;
697}700}
@@ -782,39 +785,62 @@
782785
783bool CanonicalWindowManagerPolicy::resize(Window const& window, Point cursor, Point old_cursor)786bool CanonicalWindowManagerPolicy::resize(Window const& window, Point cursor, Point old_cursor)
784{787{
785 if (!window || !window.input_area_contains(old_cursor))788 if (!window)
786 return false;789 return false;
787790
791 auto& window_info = tools->info_for(window);
792
788 auto const top_left = window.top_left();793 auto const top_left = window.top_left();
789 Rectangle const old_pos{top_left, window.size()};794 Rectangle const old_pos{top_left, window.size()};
790795
791 auto anchor = top_left;796 if (!resizing)
792
793 for (auto const& corner : {
794 old_pos.top_right(),
795 old_pos.bottom_left(),
796 old_pos.bottom_right()})
797 {797 {
798 if ((old_cursor - anchor).length_squared() <798 auto anchor = old_pos.bottom_right();
799 (old_cursor - corner).length_squared())799
800 for (auto const& corner : {
801 old_pos.top_right(),
802 old_pos.bottom_left(),
803 top_left})
800 {804 {
801 anchor = corner;805 if ((old_cursor - anchor).length_squared() <
806 (old_cursor - corner).length_squared())
807 {
808 anchor = corner;
809 }
802 }810 }
811
812 left_resize = anchor.x != top_left.x;
813 top_resize = anchor.y != top_left.y;
803 }814 }
804815
805 bool const left_resize = anchor.x != top_left.x;
806 bool const top_resize = anchor.y != top_left.y;
807 int const x_sign = left_resize? -1 : 1;816 int const x_sign = left_resize? -1 : 1;
808 int const y_sign = top_resize? -1 : 1;817 int const y_sign = top_resize? -1 : 1;
809818
810 auto const delta = cursor-old_cursor;819 auto delta = cursor-old_cursor;
811820
812 Size new_size{old_pos.size.width + x_sign*delta.dx, old_pos.size.height + y_sign*delta.dy};821 auto new_width = old_pos.size.width + x_sign * delta.dx;
813822 auto new_height = old_pos.size.height + y_sign * delta.dy;
823
824 auto const min_width = std::max(window_info.min_width, Width{5});
825 auto const min_height = std::max(window_info.min_height, Height{5});
826
827 if (new_width < min_width)
828 {
829 new_width = min_width;
830 if (delta.dx > DeltaX{0})
831 delta.dx = DeltaX{0};
832 }
833
834 if (new_height < min_height)
835 {
836 new_height = min_height;
837 if (delta.dy > DeltaY{0})
838 delta.dy = DeltaY{0};
839 }
840
841 Size new_size{new_width, new_height};
814 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;842 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;
815843
816 auto& window_info = tools->info_for(window);
817
818 apply_resize(window_info, new_pos, new_size);844 apply_resize(window_info, new_pos, new_size);
819845
820 return true;846 return true;
821847
=== modified file 'miral-shell/canonical_window_manager.h'
--- miral-shell/canonical_window_manager.h 2016-04-22 09:06:25 +0000
+++ miral-shell/canonical_window_manager.h 2016-04-28 09:25:50 +0000
@@ -88,7 +88,7 @@
8888
89 void drag(Point cursor);89 void drag(Point cursor);
90 void click(Point cursor);90 void click(Point cursor);
91 void resize(Point cursor);91 bool resize(Point cursor);
92 void toggle(MirSurfaceState state);92 void toggle(MirSurfaceState state);
9393
94 auto active_window() const -> miral::Window;94 auto active_window() const -> miral::Window;
@@ -108,6 +108,10 @@
108 using FullscreenSurfaces = std::set<miral::Window>;108 using FullscreenSurfaces = std::set<miral::Window>;
109109
110 FullscreenSurfaces fullscreen_surfaces;110 FullscreenSurfaces fullscreen_surfaces;
111
112 bool resizing = false;
113 bool left_resize = false;
114 bool top_resize = false;
111};115};
112116
113#endif /* MIRAL_SHELL_CANONICAL_WINDOW_MANAGER_H_ */117#endif /* MIRAL_SHELL_CANONICAL_WINDOW_MANAGER_H_ */

Subscribers

People subscribed via source and target branches