Mir

Merge lp:~alan-griffiths/mir/fix-1447886 into lp:mir

Proposed by Alan Griffiths
Status: Merged
Approved by: Alan Griffiths
Approved revision: no longer in the source branch.
Merged at revision: 3488
Proposed branch: lp:~alan-griffiths/mir/fix-1447886
Merge into: lp:mir
Diff against target: 264 lines (+98/-38)
4 files modified
examples/server_example_canonical_window_manager.cpp (+45/-19)
examples/server_example_canonical_window_manager.h (+4/-0)
src/include/server/mir/shell/canonical_window_manager.h (+4/-0)
src/server/shell/canonical_window_manager.cpp (+45/-19)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1447886
Reviewer Review Type Date Requested Status
Daniel van Vugt Approve
Cemil Azizoglu (community) Approve
Mir CI Bot continuous-integration Approve
Review via email: mp+293223@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
Mir CI Bot (mir-ci-bot) wrote :

PASSED: Continuous integration, rev:3483
https://mir-jenkins.ubuntu.com/job/mir-ci/910/
Executed test runs:
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-mir/956
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/997
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=vivid+overlay/988
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/988
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/966
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=vivid+overlay/966/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/966
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/966/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/966
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=android,release=vivid+overlay/966/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/966
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=android,release=vivid+overlay/966/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/966
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/966/artifact/output/*zip*/output.zip

Click here to trigger a rebuild:
https://mir-jenkins.ubuntu.com/job/mir-ci/910/rebuild

review: Approve (continuous-integration)
Revision history for this message
Cemil Azizoglu (cemil-azizoglu) wrote :

lgtm

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

Feels like an improvement. I don't want to be a blocker on this for too long, but things worth noting:

New bug: Dragging a corner past the window's minimum size and back again results in the cursor losing its original position within the window. The cursor keeping the same relative position within the window for the duration of the resize feels most professional and least frustrating. Just try it in Compiz/Unity7 to get a feel for what should happen. Admittedly mir_proving_server has the same bug right now.

Old bug: I just noticed you're dividing the window into quarters instead of thirds. So grabbing a window from the middle of an edge incorrectly resizes two axes instead of one. See Compiz/Unity or mir_proving_server for examples of what should happen. This one would represent a regression for mir_proving_server, but also isn't the bug being fixed here. Just a recommended prerequisite before abolishing DefaultWindowManager.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'examples/server_example_canonical_window_manager.cpp'
--- examples/server_example_canonical_window_manager.cpp 2016-04-15 03:41:28 +0000
+++ examples/server_example_canonical_window_manager.cpp 2016-04-28 09:10:37 +0000
@@ -90,7 +90,7 @@
9090
91void me::CanonicalWindowManagerPolicyCopy::resize(Point cursor)91void me::CanonicalWindowManagerPolicyCopy::resize(Point cursor)
92{92{
93 select_active_surface(tools->surface_at(old_cursor));93 if (!resizing) select_active_surface(tools->surface_at(old_cursor));
94 resize(active_surface(), cursor, old_cursor, display_area);94 resize(active_surface(), cursor, old_cursor, display_area);
95}95}
9696
@@ -733,6 +733,7 @@
733 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};733 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
734734
735 bool consumes_event = false;735 bool consumes_event = false;
736 bool resize_event = false;
736737
737 if (action == mir_pointer_action_button_down)738 if (action == mir_pointer_action_button_down)
738 {739 {
@@ -750,6 +751,7 @@
750 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))751 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))
751 {752 {
752 resize(cursor);753 resize(cursor);
754 resize_event = active_surface_.lock().get();
753 consumes_event = true;755 consumes_event = true;
754 }756 }
755 }757 }
@@ -768,6 +770,7 @@
768 }770 }
769 }771 }
770772
773 resizing = resize_event;
771 old_cursor = cursor;774 old_cursor = cursor;
772 return consumes_event;775 return consumes_event;
773}776}
@@ -852,40 +855,63 @@
852855
853bool me::CanonicalWindowManagerPolicyCopy::resize(std::shared_ptr<ms::Surface> const& surface, Point cursor, Point old_cursor, Rectangle bounds)856bool me::CanonicalWindowManagerPolicyCopy::resize(std::shared_ptr<ms::Surface> const& surface, Point cursor, Point old_cursor, Rectangle bounds)
854{857{
855 if (!surface || !surface->input_area_contains(old_cursor))858 if (!surface)
856 return false;859 return false;
857860
861 auto const& surface_info = tools->info_for(surface);
862
858 auto const top_left = surface->top_left();863 auto const top_left = surface->top_left();
859 Rectangle const old_pos{top_left, surface->size()};864 Rectangle const old_pos{top_left, surface->size()};
860865
861 auto anchor = top_left;866 if (!resizing)
862
863 for (auto const& corner : {
864 old_pos.top_right(),
865 old_pos.bottom_left(),
866 old_pos.bottom_right()})
867 {867 {
868 if ((old_cursor - anchor).length_squared() <868 auto anchor = old_pos.bottom_right();
869 (old_cursor - corner).length_squared())869
870 for (auto const& corner : {
871 old_pos.top_right(),
872 old_pos.bottom_left(),
873 top_left})
870 {874 {
871 anchor = corner;875 if ((old_cursor - anchor).length_squared() <
876 (old_cursor - corner).length_squared())
877 {
878 anchor = corner;
879 }
872 }880 }
881
882 left_resize = anchor.x != top_left.x;
883 top_resize = anchor.y != top_left.y;
873 }884 }
874885
875 bool const left_resize = anchor.x != top_left.x;
876 bool const top_resize = anchor.y != top_left.y;
877 int const x_sign = left_resize? -1 : 1;886 int const x_sign = left_resize? -1 : 1;
878 int const y_sign = top_resize? -1 : 1;887 int const y_sign = top_resize? -1 : 1;
879888
880 auto const delta = cursor-old_cursor;889 auto delta = cursor-old_cursor;
881890
882 Size new_size{old_pos.size.width + x_sign*delta.dx, old_pos.size.height + y_sign*delta.dy};891 auto new_width = old_pos.size.width + x_sign * delta.dx;
883892 auto new_height = old_pos.size.height + y_sign * delta.dy;
893
894 auto const min_width = std::max(surface_info.min_width, Width{5});
895 auto const min_height = std::max(surface_info.min_height, Height{5});
896
897 if (new_width < min_width)
898 {
899 new_width = min_width;
900 if (delta.dx > DeltaX{0})
901 delta.dx = DeltaX{0};
902 }
903
904 if (new_height < min_height)
905 {
906 new_height = min_height;
907 if (delta.dy > DeltaY{0})
908 delta.dy = DeltaY{0};
909 }
910
911 Size new_size{new_width, new_height};
884 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;912 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;
885913
886914
887 auto const& surface_info = tools->info_for(surface);
888
889 surface_info.constrain_resize(surface, new_pos, new_size, left_resize, top_resize, bounds);915 surface_info.constrain_resize(surface, new_pos, new_size, left_resize, top_resize, bounds);
890916
891 apply_resize(surface, surface_info.titlebar, new_pos, new_size);917 apply_resize(surface, surface_info.titlebar, new_pos, new_size);
892918
=== modified file 'examples/server_example_canonical_window_manager.h'
--- examples/server_example_canonical_window_manager.h 2016-04-15 03:41:28 +0000
+++ examples/server_example_canonical_window_manager.h 2016-04-28 09:10:37 +0000
@@ -125,6 +125,10 @@
125 using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;125 using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;
126126
127 FullscreenSurfaces fullscreen_surfaces;127 FullscreenSurfaces fullscreen_surfaces;
128
129 bool resizing = false;
130 bool left_resize = false;
131 bool top_resize = false;
128};132};
129}133}
130}134}
131135
=== modified file 'src/include/server/mir/shell/canonical_window_manager.h'
--- src/include/server/mir/shell/canonical_window_manager.h 2016-03-23 06:39:56 +0000
+++ src/include/server/mir/shell/canonical_window_manager.h 2016-04-28 09:10:37 +0000
@@ -110,6 +110,10 @@
110 using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;110 using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;
111111
112 FullscreenSurfaces fullscreen_surfaces;112 FullscreenSurfaces fullscreen_surfaces;
113
114 bool resizing = false;
115 bool left_resize = false;
116 bool top_resize = false;
113};117};
114118
115using CanonicalWindowManager = WindowManagerConstructor<CanonicalWindowManagerPolicy>;119using CanonicalWindowManager = WindowManagerConstructor<CanonicalWindowManagerPolicy>;
116120
=== modified file 'src/server/shell/canonical_window_manager.cpp'
--- src/server/shell/canonical_window_manager.cpp 2016-04-05 11:59:12 +0000
+++ src/server/shell/canonical_window_manager.cpp 2016-04-28 09:10:37 +0000
@@ -113,7 +113,7 @@
113113
114void msh::CanonicalWindowManagerPolicy::resize(Point cursor)114void msh::CanonicalWindowManagerPolicy::resize(Point cursor)
115{115{
116 select_active_surface(tools->surface_at(old_cursor));116 if (!resizing) select_active_surface(tools->surface_at(old_cursor));
117 resize(active_surface(), cursor, old_cursor, display_area);117 resize(active_surface(), cursor, old_cursor, display_area);
118 old_cursor = cursor;118 old_cursor = cursor;
119}119}
@@ -703,6 +703,7 @@
703 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};703 mir_pointer_event_axis_value(event, mir_pointer_axis_y)};
704704
705 bool consumes_event = false;705 bool consumes_event = false;
706 bool resize_event = false;
706707
707 if (action == mir_pointer_action_button_down)708 if (action == mir_pointer_action_button_down)
708 {709 {
@@ -720,10 +721,12 @@
720 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))721 if (mir_pointer_event_button_state(event, mir_pointer_button_tertiary))
721 {722 {
722 resize(cursor);723 resize(cursor);
724 resize_event = active_surface_.lock().get();
723 consumes_event = true;725 consumes_event = true;
724 }726 }
725 }727 }
726728
729 resizing = resize_event;
727 old_cursor = cursor;730 old_cursor = cursor;
728 return consumes_event;731 return consumes_event;
729}732}
@@ -786,40 +789,63 @@
786789
787bool msh::CanonicalWindowManagerPolicy::resize(std::shared_ptr<ms::Surface> const& surface, Point cursor, Point old_cursor, Rectangle bounds)790bool msh::CanonicalWindowManagerPolicy::resize(std::shared_ptr<ms::Surface> const& surface, Point cursor, Point old_cursor, Rectangle bounds)
788{791{
789 if (!surface || !surface->input_area_contains(old_cursor))792 if (!surface)
790 return false;793 return false;
791794
795 auto const& surface_info = tools->info_for(surface);
796
792 auto const top_left = surface->top_left();797 auto const top_left = surface->top_left();
793 Rectangle const old_pos{top_left, surface->size()};798 Rectangle const old_pos{top_left, surface->size()};
794799
795 auto anchor = top_left;800 if (!resizing)
796
797 for (auto const& corner : {
798 old_pos.top_right(),
799 old_pos.bottom_left(),
800 old_pos.bottom_right()})
801 {801 {
802 if ((old_cursor - anchor).length_squared() <802 auto anchor = old_pos.bottom_right();
803 (old_cursor - corner).length_squared())803
804 for (auto const& corner : {
805 old_pos.top_right(),
806 old_pos.bottom_left(),
807 top_left})
804 {808 {
805 anchor = corner;809 if ((old_cursor - anchor).length_squared() <
810 (old_cursor - corner).length_squared())
811 {
812 anchor = corner;
813 }
806 }814 }
815
816 left_resize = anchor.x != top_left.x;
817 top_resize = anchor.y != top_left.y;
807 }818 }
808819
809 bool const left_resize = anchor.x != top_left.x;
810 bool const top_resize = anchor.y != top_left.y;
811 int const x_sign = left_resize? -1 : 1;820 int const x_sign = left_resize? -1 : 1;
812 int const y_sign = top_resize? -1 : 1;821 int const y_sign = top_resize? -1 : 1;
813822
814 auto const delta = cursor-old_cursor;823 auto delta = cursor-old_cursor;
815824
816 Size new_size{old_pos.size.width + x_sign*delta.dx, old_pos.size.height + y_sign*delta.dy};825 auto new_width = old_pos.size.width + x_sign * delta.dx;
817826 auto new_height = old_pos.size.height + y_sign * delta.dy;
827
828 auto const min_width = std::max(surface_info.min_width, Width{5});
829 auto const min_height = std::max(surface_info.min_height, Height{5});
830
831 if (new_width < min_width)
832 {
833 new_width = min_width;
834 if (delta.dx > DeltaX{0})
835 delta.dx = DeltaX{0};
836 }
837
838 if (new_height < min_height)
839 {
840 new_height = min_height;
841 if (delta.dy > DeltaY{0})
842 delta.dy = DeltaY{0};
843 }
844
845 Size new_size{new_width, new_height};
818 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;846 Point new_pos = top_left + left_resize*delta.dx + top_resize*delta.dy;
819847
820848
821 auto const& surface_info = tools->info_for(surface);
822
823 surface_info.constrain_resize(surface, new_pos, new_size, left_resize, top_resize, bounds);849 surface_info.constrain_resize(surface, new_pos, new_size, left_resize, top_resize, bounds);
824850
825 apply_resize(surface, new_pos, new_size);851 apply_resize(surface, new_pos, new_size);

Subscribers

People subscribed via source and target branches