Mir

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

Proposed by Alan Griffiths
Status: Merged
Merged at revision: 4255
Proposed branch: lp:~alan-griffiths/mir/fix-1717061
Merge into: lp:mir
Prerequisite: lp:~alan-griffiths/mir/fix-FTBFS-on-artful-clang
Diff against target: 316 lines (+160/-23)
7 files modified
debian/changelog (+2/-0)
src/miral/CMakeLists.txt (+1/-0)
src/miral/window_info.cpp (+49/-15)
src/miral/window_info_defaults.h (+36/-0)
src/miral/window_management_trace.cpp (+10/-8)
tests/miral/CMakeLists.txt (+1/-0)
tests/miral/window_info.cpp (+61/-0)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1717061
Reviewer Review Type Date Requested Status
Mir CI Bot continuous-integration Needs Fixing
Gerry Boland (community) Approve
Review via email: mp+330820@code.launchpad.net

Commit message

Clamp the window aspect ratio dimensions (to avoid ldiv0) and define default window settings in one place. (LP: #1717061)

To post a comment you must log in.
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:4254
https://mir-jenkins.ubuntu.com/job/mir-ci/3662/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/5011/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5240
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5228
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5228
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5228
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5054/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5054/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5054/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5054/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5054/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5054/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5054/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5054
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5054/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:4256
https://mir-jenkins.ubuntu.com/job/mir-ci/3663/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/5012/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5241
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5229
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5229
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5229
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5055
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5055/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5055/console
    ABORTED: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5055/console
    ABORTED: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5055/console
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5055/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5055
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5055/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5055
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5055/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5055/console

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Gerry Boland (gerboland) wrote :

+unsigned clamp_dim(unsigned dim)
+{
+ return std::min<unsigned long>(std::numeric_limits<long>::max(), dim);
+}

Why max "long" - the signedness of it confuses me. What is this clamping "dim" to?

If sizeof(unsigned) < sizeof(long), this always returns "dim", so the only interesting case is if sizeof(unsigned) == sizeof(long), where this clamps dim in the bottom 1/2 of the unsigned ints. Intended?

review: Needs Information
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

> +unsigned clamp_dim(unsigned dim)
> +{
> + return std::min<unsigned long>(std::numeric_limits<long>::max(), dim);
> +}
>
> Why max "long" - the signedness of it confuses me. What is this clamping "dim"
> to?
>
> If sizeof(unsigned) < sizeof(long), this always returns "dim", so the only
> interesting case is if sizeof(unsigned) == sizeof(long), where this clamps dim
> in the bottom 1/2 of the unsigned ints. Intended?

That was the intent, yes. To clamp dim to the shared range of long and unsigned int.

Revision history for this message
Gerry Boland (gerboland) wrote :

So you want bottom 1/2 only to ensure the sign bit is always positive. Ok

review: Approve
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Continuous integration, rev:4258
https://mir-jenkins.ubuntu.com/job/mir-ci/3666/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/5017/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5249
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5237
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5237
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5237
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5060/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5060/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5060/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5060/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5060/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5060/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5060/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5060
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5060/artifact/output/*zip*/output.zip

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

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/1424/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/5020/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1555/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5253
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5241
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5241
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5241
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5063/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5063/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5063/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5063/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5063/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5063/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5063/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5063
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5063/artifact/output/*zip*/output.zip

review: Needs Fixing (continuous-integration)
Revision history for this message
Mir CI Bot (mir-ci-bot) wrote :

FAILED: Autolanding.
More details in the following jenkins job:
https://mir-jenkins.ubuntu.com/job/mir-autolanding/1425/
Executed test runs:
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-mir/5022/console
    None: https://mir-jenkins.ubuntu.com/job/generic-land-mp/1556/console
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-0-fetch/5255
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=artful/5243
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=xenial/5243
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-1-sourcepkg/release=zesty/5243
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=artful/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=clang,platform=mesa,release=zesty/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=artful/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=xenial/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=amd64,compiler=gcc,platform=mesa,release=zesty/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=artful/5065/artifact/output/*zip*/output.zip
    SUCCESS: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5065
        deb: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=cross-armhf,compiler=gcc,platform=mesa,release=zesty/5065/artifact/output/*zip*/output.zip
    FAILURE: https://mir-jenkins.ubuntu.com/job/build-2-binpkg-mir/arch=i386,compiler=gcc,platform=mesa,release=xenial/5065/console

review: Needs Fixing (continuous-integration)
Revision history for this message
Alan Griffiths (alan-griffiths) wrote :

Landing by hand

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'debian/changelog'
--- debian/changelog 2017-09-14 09:27:21 +0000
+++ debian/changelog 2017-09-18 08:45:41 +0000
@@ -47,6 +47,8 @@
47 . [miral-shell] Don't allow splashscreen to be occluded (LP: #1705973)47 . [miral-shell] Don't allow splashscreen to be occluded (LP: #1705973)
48 . [miral-shell] Update maximized windows on display changes (LP: #1705695)48 . [miral-shell] Update maximized windows on display changes (LP: #1705695)
49 . Make racy DragAndDrop test reliable. (LP: #1704780)49 . Make racy DragAndDrop test reliable. (LP: #1704780)
50 . [libmiral] Define default window settings in one place and clamp the
51 actual values to avoid ldiv0. (LP: #1717061)
5052
51 -- Alan Griffiths <alan.griffiths@canonical.com> Thu, 10 Aug 2017 11:54:30 +000053 -- Alan Griffiths <alan.griffiths@canonical.com> Thu, 10 Aug 2017 11:54:30 +0000
5254
5355
=== modified file 'src/miral/CMakeLists.txt'
--- src/miral/CMakeLists.txt 2017-09-08 08:45:02 +0000
+++ src/miral/CMakeLists.txt 2017-09-18 08:45:41 +0000
@@ -61,6 +61,7 @@
61 window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h61 window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h
62 ${miral_include}/miral/window_management_policy_addendum2.h62 ${miral_include}/miral/window_management_policy_addendum2.h
63 ${miral_include}/miral/window_management_policy_addendum3.h63 ${miral_include}/miral/window_management_policy_addendum3.h
64 window_info_defaults.h
64)65)
6566
66target_include_directories(mirclientcpp67target_include_directories(mirclientcpp
6768
=== modified file 'src/miral/window_info.cpp'
--- src/miral/window_info.cpp 2017-08-21 14:18:55 +0000
+++ src/miral/window_info.cpp 2017-09-18 08:45:41 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "miral/window_info.h"19#include "miral/window_info.h"
20#include "window_info_defaults.h"
2021
21#include "both_versions.h"22#include "both_versions.h"
2223
@@ -35,7 +36,40 @@
35{36{
36 return optional_value.is_set() ? optional_value.value() : default_;37 return optional_value.is_set() ? optional_value.value() : default_;
37}38}
38}39
40unsigned clamp_dim(unsigned dim)
41{
42 return std::min<unsigned long>(std::numeric_limits<long>::max(), dim);
43}
44
45// For our convenience when doing calculations we clamp the dimensions of the aspect ratio
46// so they will fit into a long without overflow.
47miral::WindowInfo::AspectRatio clamp(miral::WindowInfo::AspectRatio const& source)
48{
49 return {clamp_dim(source.width), clamp_dim(source.height)};
50}
51
52miral::Width clamp(miral::Width const& source)
53{
54 return std::min(miral::default_max_width, std::max(miral::default_min_width, source));
55}
56
57miral::Height clamp(miral::Height const& source)
58{
59 return std::min(miral::default_max_height, std::max(miral::default_min_height, source));
60}
61}
62
63miral::Width const miral::default_min_width{0};
64miral::Height const miral::default_min_height{0};
65miral::Width const miral::default_max_width{std::numeric_limits<int>::max()};
66miral::Height const miral::default_max_height{std::numeric_limits<int>::max()};
67miral::DeltaX const miral::default_width_inc{1};
68miral::DeltaY const miral::default_height_inc{1};
69miral::WindowInfo::AspectRatio const miral::default_min_aspect_ratio{
70 clamp(WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()})};
71miral::WindowInfo::AspectRatio const miral::default_max_aspect_ratio{
72 clamp(WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U})};
3973
40struct miral::WindowInfo::Self74struct miral::WindowInfo::Self
41{75{
@@ -71,16 +105,16 @@
71 type{optional_value_or_default(params.type(), mir_window_type_normal)},105 type{optional_value_or_default(params.type(), mir_window_type_normal)},
72 state{optional_value_or_default(params.state(), mir_window_state_restored)},106 state{optional_value_or_default(params.state(), mir_window_state_restored)},
73 restore_rect{params.top_left().value(), params.size().value()},107 restore_rect{params.top_left().value(), params.size().value()},
74 min_width{optional_value_or_default(params.min_width())},108 min_width{optional_value_or_default(params.min_width(), miral::default_min_width)},
75 min_height{optional_value_or_default(params.min_height())},109 min_height{optional_value_or_default(params.min_height(), miral::default_min_height)},
76 max_width{optional_value_or_default(params.max_width(), Width{std::numeric_limits<int>::max()})},110 max_width{optional_value_or_default(params.max_width(), miral::default_max_width)},
77 max_height{optional_value_or_default(params.max_height(), Height{std::numeric_limits<int>::max()})},111 max_height{optional_value_or_default(params.max_height(), miral::default_max_height)},
78 preferred_orientation{optional_value_or_default(params.preferred_orientation(), mir_orientation_mode_any)},112 preferred_orientation{optional_value_or_default(params.preferred_orientation(), mir_orientation_mode_any)},
79 confine_pointer(optional_value_or_default(params.confine_pointer(), mir_pointer_unconfined)),113 confine_pointer(optional_value_or_default(params.confine_pointer(), mir_pointer_unconfined)),
80 width_inc{optional_value_or_default(params.width_inc(), DeltaX{1})},114 width_inc{optional_value_or_default(params.width_inc(), default_width_inc)},
81 height_inc{optional_value_or_default(params.height_inc(), DeltaY{1})},115 height_inc{optional_value_or_default(params.height_inc(), default_height_inc)},
82 min_aspect(optional_value_or_default(params.min_aspect(), AspectRatio{0U, std::numeric_limits<unsigned>::max()})),116 min_aspect(optional_value_or_default(params.min_aspect(), default_min_aspect_ratio)),
83 max_aspect(optional_value_or_default(params.max_aspect(), AspectRatio{std::numeric_limits<unsigned>::max(), 0U})),117 max_aspect(optional_value_or_default(params.max_aspect(), default_max_aspect_ratio)),
84 shell_chrome(optional_value_or_default(params.shell_chrome(), mir_shell_chrome_normal))118 shell_chrome(optional_value_or_default(params.shell_chrome(), mir_shell_chrome_normal))
85{119{
86 if (params.output_id().is_set())120 if (params.output_id().is_set())
@@ -450,7 +484,7 @@
450484
451void miral::WindowInfo::min_width(mir::geometry::Width min_width)485void miral::WindowInfo::min_width(mir::geometry::Width min_width)
452{486{
453 self->min_width = min_width;487 self->min_width = clamp(min_width);
454}488}
455489
456auto miral::WindowInfo::min_height() const -> mir::geometry::Height490auto miral::WindowInfo::min_height() const -> mir::geometry::Height
@@ -460,7 +494,7 @@
460494
461void miral::WindowInfo::min_height(mir::geometry::Height min_height)495void miral::WindowInfo::min_height(mir::geometry::Height min_height)
462{496{
463 self->min_height = min_height;497 self->min_height = clamp(min_height);
464}498}
465499
466auto miral::WindowInfo::max_width() const -> mir::geometry::Width500auto miral::WindowInfo::max_width() const -> mir::geometry::Width
@@ -470,7 +504,7 @@
470504
471void miral::WindowInfo::max_width(mir::geometry::Width max_width)505void miral::WindowInfo::max_width(mir::geometry::Width max_width)
472{506{
473 self->max_width = max_width;507 self->max_width = clamp(max_width);
474}508}
475509
476auto miral::WindowInfo::max_height() const -> mir::geometry::Height510auto miral::WindowInfo::max_height() const -> mir::geometry::Height
@@ -480,7 +514,7 @@
480514
481void miral::WindowInfo::max_height(mir::geometry::Height max_height)515void miral::WindowInfo::max_height(mir::geometry::Height max_height)
482{516{
483 self->max_height = max_height;517 self->max_height = clamp(max_height);
484}518}
485519
486auto miral::WindowInfo::userdata() const -> std::shared_ptr<void>520auto miral::WindowInfo::userdata() const -> std::shared_ptr<void>
@@ -520,7 +554,7 @@
520554
521void miral::WindowInfo::min_aspect(AspectRatio min_aspect)555void miral::WindowInfo::min_aspect(AspectRatio min_aspect)
522{556{
523 self->min_aspect = min_aspect;557 self->min_aspect = clamp(min_aspect);
524}558}
525559
526auto miral::WindowInfo::max_aspect() const -> AspectRatio560auto miral::WindowInfo::max_aspect() const -> AspectRatio
@@ -530,7 +564,7 @@
530564
531void miral::WindowInfo::max_aspect(AspectRatio max_aspect)565void miral::WindowInfo::max_aspect(AspectRatio max_aspect)
532{566{
533 self->max_aspect = max_aspect;567 self->max_aspect = clamp(max_aspect);
534}568}
535569
536bool miral::WindowInfo::has_output_id() const570bool miral::WindowInfo::has_output_id() const
537571
=== added file 'src/miral/window_info_defaults.h'
--- src/miral/window_info_defaults.h 1970-01-01 00:00:00 +0000
+++ src/miral/window_info_defaults.h 2017-09-18 08:45:41 +0000
@@ -0,0 +1,36 @@
1/*
2 * Copyright © 2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3,
6 * as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Alan Griffiths <alan@octopull.co.uk>
17 */
18
19#ifndef MIR_WINDOW_INFO_DEFAULTS_H
20#define MIR_WINDOW_INFO_DEFAULTS_H
21
22#include "miral/window_info.h"
23
24namespace miral
25{
26Width extern const default_min_width;
27Height extern const default_min_height;
28Width extern const default_max_width;
29Height extern const default_max_height;
30DeltaX extern const default_width_inc;
31DeltaY extern const default_height_inc;
32WindowInfo::AspectRatio extern const default_min_aspect_ratio;
33WindowInfo::AspectRatio extern const default_max_aspect_ratio;
34}
35
36#endif //MIR_WINDOW_INFO_DEFAULTS_H
037
=== modified file 'src/miral/window_management_trace.cpp'
--- src/miral/window_management_trace.cpp 2017-08-21 14:18:55 +0000
+++ src/miral/window_management_trace.cpp 2017-09-18 08:45:41 +0000
@@ -17,6 +17,7 @@
17 */17 */
1818
19#include "window_management_trace.h"19#include "window_management_trace.h"
20#include "window_info_defaults.h"
2021
21#include <miral/application_info.h>22#include <miral/application_info.h>
22#include <miral/window_info.h>23#include <miral/window_info.h>
@@ -133,18 +134,19 @@
133 APPEND(name);134 APPEND(name);
134 APPEND(type);135 APPEND(type);
135 APPEND(state);136 APPEND(state);
137 bout.append("size", info.window().size());
136 if (info.state() != mir_window_state_restored) APPEND(restore_rect);138 if (info.state() != mir_window_state_restored) APPEND(restore_rect);
137 if (std::shared_ptr<mir::scene::Surface> parent = info.parent())139 if (std::shared_ptr<mir::scene::Surface> parent = info.parent())
138 bout.append("parent", parent->name());140 bout.append("parent", parent->name());
139 bout.append("children", dump_of(info.children()));141 bout.append("children", dump_of(info.children()));
140 if (info.min_width() != Width{0}) APPEND(min_width);142 if (info.min_width() != miral::default_min_width) APPEND(min_width);
141 if (info.min_height() != Height{0}) APPEND(min_height);143 if (info.min_height() != miral::default_min_height) APPEND(min_height);
142 if (info.max_width() != Width{std::numeric_limits<int>::max()}) APPEND(max_width);144 if (info.max_width() != miral::default_max_width) APPEND(max_width);
143 if (info.max_height() != Height{std::numeric_limits<int>::max()}) APPEND(max_height);145 if (info.max_height() != miral::default_max_height) APPEND(max_height);
144 if (info.width_inc() != DeltaX{1}) APPEND(width_inc);146 if (info.width_inc() != miral::default_width_inc) APPEND(width_inc);
145 if (info.height_inc() != DeltaY{1}) APPEND(height_inc);147 if (info.height_inc() != miral::default_height_inc) APPEND(height_inc);
146 if (info.min_aspect() != miral::WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()}) APPEND(min_aspect);148 if (info.min_aspect() != miral::default_min_aspect_ratio) APPEND(min_aspect);
147 if (info.max_aspect() != miral::WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U}) APPEND(max_aspect);149 if (info.max_aspect() != miral::default_max_aspect_ratio) APPEND(max_aspect);
148 APPEND(preferred_orientation);150 APPEND(preferred_orientation);
149 APPEND(confine_pointer);151 APPEND(confine_pointer);
150152
151153
=== modified file 'tests/miral/CMakeLists.txt'
--- tests/miral/CMakeLists.txt 2017-09-14 09:22:16 +0000
+++ tests/miral/CMakeLists.txt 2017-09-18 08:45:41 +0000
@@ -40,6 +40,7 @@
40 workspaces.cpp40 workspaces.cpp
41 drag_and_drop.cpp41 drag_and_drop.cpp
42 client_mediated_gestures.cpp42 client_mediated_gestures.cpp
43 window_info.cpp
43)44)
4445
45target_link_libraries(miral-test46target_link_libraries(miral-test
4647
=== added file 'tests/miral/window_info.cpp'
--- tests/miral/window_info.cpp 1970-01-01 00:00:00 +0000
+++ tests/miral/window_info.cpp 2017-09-18 08:45:41 +0000
@@ -0,0 +1,61 @@
1/*
2 * Copyright © 2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify it
5 * under the terms of the GNU General Public License version 2 or 3 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *
16 * Authored by: Brandon Schaefer <brandon.schaefer@canonical.com>
17 */
18
19#include <miral/window_info.h>
20
21#include "mir_test_framework/process.h"
22
23#include <gtest/gtest.h>
24#include <gmock/gmock.h>
25
26using namespace miral;
27namespace mtf = mir_test_framework;
28
29namespace
30{
31static int a_successful_exit_function()
32{
33 return EXIT_SUCCESS;
34}
35}
36
37// Test for crash http://paste.ubuntu.com/25523431/
38TEST(WindowInfo, negative_window_size_does_not_divide_by_zero)
39{
40 auto p = mtf::fork_and_run_in_a_different_process(
41 [] {
42 Window window;
43 WindowSpecification params;
44
45 Point p{0, 0};
46 Size s{-300, -300};
47
48 params.name() = "";
49 params.top_left() = p;
50 params.size() = s;
51
52 WindowInfo info(window, params);
53
54 info.min_width(s.width);
55 info.min_height(s.height);
56
57 info.constrain_resize(p, s);
58 }, a_successful_exit_function);
59
60 EXPECT_TRUE(p->wait_for_termination().succeeded());
61}

Subscribers

People subscribed via source and target branches