Mir

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

Proposed by Alan Griffiths
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 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.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/miral/CMakeLists.txt'
--- src/miral/CMakeLists.txt 2017-09-08 08:45:02 +0000
+++ src/miral/CMakeLists.txt 2017-09-15 09:43:50 +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-15 09:43:50 +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,30 @@
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}
52
53miral::Width const miral::default_min_width{0};
54miral::Height const miral::default_min_height{0};
55miral::Width const miral::default_max_width{std::numeric_limits<int>::max()};
56miral::Height const miral::default_max_height{std::numeric_limits<int>::max()};
57miral::DeltaX const miral::default_width_inc{1};
58miral::DeltaY const miral::default_height_inc{1};
59miral::WindowInfo::AspectRatio const miral::default_min_aspect_ratio{
60 clamp(WindowInfo::AspectRatio{0U, std::numeric_limits<unsigned>::max()})};
61miral::WindowInfo::AspectRatio const miral::default_max_aspect_ratio{
62 clamp(WindowInfo::AspectRatio{std::numeric_limits<unsigned>::max(), 0U})};
3963
40struct miral::WindowInfo::Self64struct miral::WindowInfo::Self
41{65{
@@ -71,16 +95,16 @@
71 type{optional_value_or_default(params.type(), mir_window_type_normal)},95 type{optional_value_or_default(params.type(), mir_window_type_normal)},
72 state{optional_value_or_default(params.state(), mir_window_state_restored)},96 state{optional_value_or_default(params.state(), mir_window_state_restored)},
73 restore_rect{params.top_left().value(), params.size().value()},97 restore_rect{params.top_left().value(), params.size().value()},
74 min_width{optional_value_or_default(params.min_width())},98 min_width{optional_value_or_default(params.min_width(), miral::default_min_width)},
75 min_height{optional_value_or_default(params.min_height())},99 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()})},100 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()})},101 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)},102 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)),103 confine_pointer(optional_value_or_default(params.confine_pointer(), mir_pointer_unconfined)),
80 width_inc{optional_value_or_default(params.width_inc(), DeltaX{1})},104 width_inc{optional_value_or_default(params.width_inc(), default_width_inc)},
81 height_inc{optional_value_or_default(params.height_inc(), DeltaY{1})},105 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()})),106 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})),107 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))108 shell_chrome(optional_value_or_default(params.shell_chrome(), mir_shell_chrome_normal))
85{109{
86 if (params.output_id().is_set())110 if (params.output_id().is_set())
@@ -520,7 +544,7 @@
520544
521void miral::WindowInfo::min_aspect(AspectRatio min_aspect)545void miral::WindowInfo::min_aspect(AspectRatio min_aspect)
522{546{
523 self->min_aspect = min_aspect;547 self->min_aspect = clamp(min_aspect);
524}548}
525549
526auto miral::WindowInfo::max_aspect() const -> AspectRatio550auto miral::WindowInfo::max_aspect() const -> AspectRatio
@@ -530,7 +554,7 @@
530554
531void miral::WindowInfo::max_aspect(AspectRatio max_aspect)555void miral::WindowInfo::max_aspect(AspectRatio max_aspect)
532{556{
533 self->max_aspect = max_aspect;557 self->max_aspect = clamp(max_aspect);
534}558}
535559
536bool miral::WindowInfo::has_output_id() const560bool miral::WindowInfo::has_output_id() const
537561
=== 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-15 09:43:50 +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-15 09:43:50 +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

Subscribers

People subscribed via source and target branches