2
* Copyright © 2015 Canonical Ltd.
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 3,
6
* as published by the Free Software Foundation.
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.
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/>.
16
* Authored By: Alan Griffiths <alan@octopull.co.uk>
19
#ifndef MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_
20
#define MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_
22
#include "basic_window_manager.h"
24
#include "mir/geometry/displacement.h"
32
struct CanonicalSessionInfo
37
struct CanonicalSurfaceInfo
40
std::shared_ptr<scene::Session> const& session,
41
std::shared_ptr<scene::Surface> const& surface,
42
scene::SurfaceCreationParameters const& params);
44
MirSurfaceState state;
45
geometry::Rectangle restore_rect;
46
std::weak_ptr<scene::Session> session;
47
std::weak_ptr<scene::Surface> parent;
48
std::vector<std::weak_ptr<scene::Surface>> children;
49
optional_value<geometry::Width> min_width;
50
optional_value<geometry::Height> min_height;
51
optional_value<geometry::Width> max_width;
52
optional_value<geometry::Height> max_height;
53
mir::optional_value<geometry::DeltaX> width_inc;
54
mir::optional_value<geometry::DeltaY> height_inc;
55
mir::optional_value<SurfaceAspectRatio> min_aspect;
56
mir::optional_value<SurfaceAspectRatio> max_aspect;
59
// standard window management algorithm:
60
// o Switch apps: tap or click on the corresponding tile
61
// o Move window: Alt-leftmousebutton drag
62
// o Resize window: Alt-middle_button drag
63
// o Maximize/restore current window (to display size): Alt-F11
64
// o Maximize/restore current window (to display height): Shift-F11
65
// o Maximize/restore current window (to display width): Ctrl-F11
66
// o client requests to maximize, vertically maximize & restore
67
class CanonicalWindowManagerPolicy
70
using Tools = BasicWindowManagerTools<CanonicalSessionInfo, CanonicalSurfaceInfo>;
71
using CanonicalSessionInfoMap = typename SessionTo<CanonicalSessionInfo>::type;
73
explicit CanonicalWindowManagerPolicy(
75
std::shared_ptr<shell::DisplayLayout> const& display_layout);
77
void click(geometry::Point cursor);
79
void handle_session_info_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
81
void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
83
void resize(geometry::Point cursor);
85
auto handle_place_new_surface(
86
std::shared_ptr<scene::Session> const& session,
87
scene::SurfaceCreationParameters const& request_parameters)
88
-> scene::SurfaceCreationParameters;
90
void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
92
void handle_modify_surface(
93
std::shared_ptr<scene::Session> const& session,
94
std::shared_ptr<scene::Surface> const& surface,
95
SurfaceSpecification const& modifications);
97
void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
99
int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
101
void drag(geometry::Point cursor);
103
bool handle_keyboard_event(MirKeyboardEvent const* event);
105
bool handle_touch_event(MirTouchEvent const* event);
107
bool handle_pointer_event(MirPointerEvent const* event);
109
std::vector<std::shared_ptr<scene::Surface>> generate_decorations_for(
110
std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
113
static const int modifier_mask =
114
mir_input_event_modifier_alt |
115
mir_input_event_modifier_shift |
116
mir_input_event_modifier_sym |
117
mir_input_event_modifier_ctrl |
118
mir_input_event_modifier_meta;
120
void toggle(MirSurfaceState state);
122
// "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
123
// *window*,but Mir really only understands surfaces
124
void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
125
auto active_surface() const -> std::shared_ptr<scene::Surface>;
127
bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
128
bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
129
void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
130
void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
131
bool constrained_resize(
132
std::shared_ptr<scene::Surface> const& surface,
133
geometry::Point const& requested_pos,
134
geometry::Size const& requested_size,
135
const bool left_resize,
136
const bool top_resize,
137
geometry::Rectangle const& bounds);
140
std::shared_ptr<DisplayLayout> const display_layout;
142
geometry::Rectangle display_area;
143
geometry::Point old_cursor{};
144
std::weak_ptr<scene::Surface> active_surface_;
147
using CanonicalWindowManager = BasicWindowManager<CanonicalWindowManagerPolicy, CanonicalSessionInfo, CanonicalSurfaceInfo>;
151
#endif /* MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_ */