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;
55
// standard window management algorithm:
56
// o Switch apps: tap or click on the corresponding tile
57
// o Move window: Alt-leftmousebutton drag
58
// o Resize window: Alt-middle_button drag
59
// o Maximize/restore current window (to display size): Alt-F11
60
// o Maximize/restore current window (to display height): Shift-F11
61
// o Maximize/restore current window (to display width): Ctrl-F11
62
// o client requests to maximize, vertically maximize & restore
63
class CanonicalWindowManagerPolicy
66
using Tools = BasicWindowManagerTools<CanonicalSessionInfo, CanonicalSurfaceInfo>;
67
using CanonicalSessionInfoMap = typename SessionTo<CanonicalSessionInfo>::type;
69
explicit CanonicalWindowManagerPolicy(
71
std::shared_ptr<shell::DisplayLayout> const& display_layout);
73
void click(geometry::Point cursor);
75
void handle_session_info_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
77
void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
79
void resize(geometry::Point cursor);
81
auto handle_place_new_surface(
82
std::shared_ptr<scene::Session> const& session,
83
scene::SurfaceCreationParameters const& request_parameters)
84
-> scene::SurfaceCreationParameters;
86
void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
88
void handle_modify_surface(
89
std::shared_ptr<scene::Session> const& session,
90
std::shared_ptr<scene::Surface> const& surface,
91
SurfaceSpecification const& modifications);
93
void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
95
int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
97
void drag(geometry::Point cursor);
99
bool handle_keyboard_event(MirKeyboardEvent const* event);
101
bool handle_touch_event(MirTouchEvent const* event);
103
bool handle_pointer_event(MirPointerEvent const* event);
105
std::vector<std::shared_ptr<scene::Surface>> generate_decorations_for(
106
std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
109
static const int modifier_mask =
110
mir_input_event_modifier_alt |
111
mir_input_event_modifier_shift |
112
mir_input_event_modifier_sym |
113
mir_input_event_modifier_ctrl |
114
mir_input_event_modifier_meta;
116
void toggle(MirSurfaceState state);
118
// "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
119
// *window*,but Mir really only understands surfaces
120
void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
121
auto active_surface() const -> std::shared_ptr<scene::Surface>;
123
bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
124
bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
125
void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
126
void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
127
bool constrained_resize(
128
std::shared_ptr<scene::Surface> const& surface,
129
geometry::Point new_pos,
130
geometry::Size new_size,
131
const bool left_resize,
132
const bool top_resize,
133
geometry::Rectangle const& bounds);
136
std::shared_ptr<DisplayLayout> const display_layout;
138
geometry::Rectangle display_area;
139
geometry::Point old_cursor{};
140
std::weak_ptr<scene::Surface> active_surface_;
143
using CanonicalWindowManager = BasicWindowManager<CanonicalWindowManagerPolicy, CanonicalSessionInfo, CanonicalSurfaceInfo>;
147
#endif /* MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_ */