Mir

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

Proposed by Alan Griffiths on 2017-09-15
Status: Superseded
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: 178 lines (+82/-19)
4 files modified
src/miral/CMakeLists.txt (+1/-0)
src/miral/window_info.cpp (+35/-11)
src/miral/window_info_defaults.h (+36/-0)
src/miral/window_management_trace.cpp (+10/-8)
To merge this branch: bzr merge lp:~alan-griffiths/mir/fix-1717061
Reviewer Review Type Date Requested Status
Mir development team 2017-09-15 Pending
Review via email: mp+330819@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.
lp:~alan-griffiths/mir/fix-1717061 updated on 2017-09-18
4254. By Alan Griffiths on 2017-09-15

Tidy whitespace

4255. By Alan Griffiths on 2017-09-15

Add Brandon's test case

4256. By Alan Griffiths on 2017-09-15

Clamp the minimum and maximum width and height

4257. By Alan Griffiths on 2017-09-15

Add to changelog

4258. By Alan Griffiths on 2017-09-18

merge :parent

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/miral/CMakeLists.txt'
2--- src/miral/CMakeLists.txt 2017-09-08 08:45:02 +0000
3+++ src/miral/CMakeLists.txt 2017-09-15 09:43:50 +0000
4@@ -61,6 +61,7 @@
5 window_manager_tools.cpp ${miral_include}/miral/window_manager_tools.h
6 ${miral_include}/miral/window_management_policy_addendum2.h
7 ${miral_include}/miral/window_management_policy_addendum3.h
8+ window_info_defaults.h
9 )
10
11 target_include_directories(mirclientcpp
12
13=== modified file 'src/miral/window_info.cpp'
14--- src/miral/window_info.cpp 2017-08-21 14:18:55 +0000
15+++ src/miral/window_info.cpp 2017-09-15 09:43:50 +0000
16@@ -17,6 +17,7 @@
17 */
18
19 #include "miral/window_info.h"
20+#include "window_info_defaults.h"
21
22 #include "both_versions.h"
23
24@@ -35,7 +36,30 @@
25 {
26 return optional_value.is_set() ? optional_value.value() : default_;
27 }
28-}
29+
30+unsigned clamp_dim(unsigned dim)
31+{
32+ return std::min<unsigned long>(std::numeric_limits<long>::max(), dim);
33+}
34+
35+// For our convenience when doing calculations we clamp the dimensions of the aspect ratio
36+// so they will fit into a long without overflow.
37+miral::WindowInfo::AspectRatio clamp(miral::WindowInfo::AspectRatio const& source)
38+{
39+ return {clamp_dim(source.width), clamp_dim(source.height)};
40+}
41+}
42+
43+miral::Width const miral::default_min_width{0};
44+miral::Height const miral::default_min_height{0};
45+miral::Width const miral::default_max_width{std::numeric_limits<int>::max()};
46+miral::Height const miral::default_max_height{std::numeric_limits<int>::max()};
47+miral::DeltaX const miral::default_width_inc{1};
48+miral::DeltaY const miral::default_height_inc{1};
49+miral::WindowInfo::AspectRatio const miral::default_min_aspect_ratio{
50+ clamp(WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()})};
51+miral::WindowInfo::AspectRatio const miral::default_max_aspect_ratio{
52+ clamp(WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U})};
53
54 struct miral::WindowInfo::Self
55 {
56@@ -71,16 +95,16 @@
57 type{optional_value_or_default(params.type(), mir_window_type_normal)},
58 state{optional_value_or_default(params.state(), mir_window_state_restored)},
59 restore_rect{params.top_left().value(), params.size().value()},
60- min_width{optional_value_or_default(params.min_width())},
61- min_height{optional_value_or_default(params.min_height())},
62- max_width{optional_value_or_default(params.max_width(), Width{std::numeric_limits<int>::max()})},
63- max_height{optional_value_or_default(params.max_height(), Height{std::numeric_limits<int>::max()})},
64+ min_width{optional_value_or_default(params.min_width(), miral::default_min_width)},
65+ min_height{optional_value_or_default(params.min_height(), miral::default_min_height)},
66+ max_width{optional_value_or_default(params.max_width(), miral::default_max_width)},
67+ max_height{optional_value_or_default(params.max_height(), miral::default_max_height)},
68 preferred_orientation{optional_value_or_default(params.preferred_orientation(), mir_orientation_mode_any)},
69 confine_pointer(optional_value_or_default(params.confine_pointer(), mir_pointer_unconfined)),
70- width_inc{optional_value_or_default(params.width_inc(), DeltaX{1})},
71- height_inc{optional_value_or_default(params.height_inc(), DeltaY{1})},
72- min_aspect(optional_value_or_default(params.min_aspect(), AspectRatio{0U, std::numeric_limits<unsigned>::max()})),
73- max_aspect(optional_value_or_default(params.max_aspect(), AspectRatio{std::numeric_limits<unsigned>::max(), 0U})),
74+ width_inc{optional_value_or_default(params.width_inc(), default_width_inc)},
75+ height_inc{optional_value_or_default(params.height_inc(), default_height_inc)},
76+ min_aspect(optional_value_or_default(params.min_aspect(), default_min_aspect_ratio)),
77+ max_aspect(optional_value_or_default(params.max_aspect(), default_max_aspect_ratio)),
78 shell_chrome(optional_value_or_default(params.shell_chrome(), mir_shell_chrome_normal))
79 {
80 if (params.output_id().is_set())
81@@ -520,7 +544,7 @@
82
83 void miral::WindowInfo::min_aspect(AspectRatio min_aspect)
84 {
85- self->min_aspect = min_aspect;
86+ self->min_aspect = clamp(min_aspect);
87 }
88
89 auto miral::WindowInfo::max_aspect() const -> AspectRatio
90@@ -530,7 +554,7 @@
91
92 void miral::WindowInfo::max_aspect(AspectRatio max_aspect)
93 {
94- self->max_aspect = max_aspect;
95+ self->max_aspect = clamp(max_aspect);
96 }
97
98 bool miral::WindowInfo::has_output_id() const
99
100=== added file 'src/miral/window_info_defaults.h'
101--- src/miral/window_info_defaults.h 1970-01-01 00:00:00 +0000
102+++ src/miral/window_info_defaults.h 2017-09-15 09:43:50 +0000
103@@ -0,0 +1,36 @@
104+/*
105+ * Copyright © 2017 Canonical Ltd.
106+ *
107+ * This program is free software: you can redistribute it and/or modify it
108+ * under the terms of the GNU General Public License version 2 or 3,
109+ * as published by the Free Software Foundation.
110+ *
111+ * This program is distributed in the hope that it will be useful,
112+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
113+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
114+ * GNU General Public License for more details.
115+ *
116+ * You should have received a copy of the GNU General Public License
117+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
118+ *
119+ * Authored by: Alan Griffiths <alan@octopull.co.uk>
120+ */
121+
122+#ifndef MIR_WINDOW_INFO_DEFAULTS_H
123+#define MIR_WINDOW_INFO_DEFAULTS_H
124+
125+#include "miral/window_info.h"
126+
127+namespace miral
128+{
129+Width extern const default_min_width;
130+Height extern const default_min_height;
131+Width extern const default_max_width;
132+Height extern const default_max_height;
133+DeltaX extern const default_width_inc;
134+DeltaY extern const default_height_inc;
135+WindowInfo::AspectRatio extern const default_min_aspect_ratio;
136+WindowInfo::AspectRatio extern const default_max_aspect_ratio;
137+}
138+
139+#endif //MIR_WINDOW_INFO_DEFAULTS_H
140
141=== modified file 'src/miral/window_management_trace.cpp'
142--- src/miral/window_management_trace.cpp 2017-08-21 14:18:55 +0000
143+++ src/miral/window_management_trace.cpp 2017-09-15 09:43:50 +0000
144@@ -17,6 +17,7 @@
145 */
146
147 #include "window_management_trace.h"
148+#include "window_info_defaults.h"
149
150 #include <miral/application_info.h>
151 #include <miral/window_info.h>
152@@ -133,18 +134,19 @@
153 APPEND(name);
154 APPEND(type);
155 APPEND(state);
156+ bout.append("size", info.window().size());
157 if (info.state() != mir_window_state_restored) APPEND(restore_rect);
158 if (std::shared_ptr<mir::scene::Surface> parent = info.parent())
159 bout.append("parent", parent->name());
160 bout.append("children", dump_of(info.children()));
161- if (info.min_width() != Width{0}) APPEND(min_width);
162- if (info.min_height() != Height{0}) APPEND(min_height);
163- if (info.max_width() != Width{std::numeric_limits<int>::max()}) APPEND(max_width);
164- if (info.max_height() != Height{std::numeric_limits<int>::max()}) APPEND(max_height);
165- if (info.width_inc() != DeltaX{1}) APPEND(width_inc);
166- if (info.height_inc() != DeltaY{1}) APPEND(height_inc);
167- if (info.min_aspect() != miral::WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()}) APPEND(min_aspect);
168- if (info.max_aspect() != miral::WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U}) APPEND(max_aspect);
169+ if (info.min_width() != miral::default_min_width) APPEND(min_width);
170+ if (info.min_height() != miral::default_min_height) APPEND(min_height);
171+ if (info.max_width() != miral::default_max_width) APPEND(max_width);
172+ if (info.max_height() != miral::default_max_height) APPEND(max_height);
173+ if (info.width_inc() != miral::default_width_inc) APPEND(width_inc);
174+ if (info.height_inc() != miral::default_height_inc) APPEND(height_inc);
175+ if (info.min_aspect() != miral::default_min_aspect_ratio) APPEND(min_aspect);
176+ if (info.max_aspect() != miral::default_max_aspect_ratio) APPEND(max_aspect);
177 APPEND(preferred_orientation);
178 APPEND(confine_pointer);
179

Subscribers

People subscribed via source and target branches