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 2 or 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_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_
20
#define MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_
22
#include "server_example_basic_window_manager.h"
24
#include "mir/geometry/displacement.h"
29
///\example server_example_canonical_window_manager.h
30
// Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
34
namespace shell { class DisplayLayout; }
37
class GraphicBufferAllocator;
41
// standard window management algorithm:
42
// o Switch apps: tap or click on the corresponding tile
43
// o Move window: Alt-leftmousebutton drag (three finger drag)
44
// o Resize window: Alt-middle_button drag (two finger drag)
45
// o Maximize/restore current window (to display size): Alt-F11
46
// o Maximize/restore current window (to display height): Shift-F11
47
// o Maximize/restore current window (to display width): Ctrl-F11
48
// o client requests to maximize, vertically maximize & restore
49
class CanonicalWindowManagerPolicyCopy : public WindowManagementPolicy
53
explicit CanonicalWindowManagerPolicyCopy(
54
WindowManagerTools* const tools,
55
std::shared_ptr<shell::DisplayLayout> const& display_layout,
56
std::shared_ptr<graphics::GraphicBufferAllocator> const& allocator);
58
void click(geometry::Point cursor);
60
void handle_session_info_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
62
void handle_displays_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
64
void resize(geometry::Point cursor);
66
auto handle_place_new_surface(
67
std::shared_ptr<scene::Session> const& session,
68
scene::SurfaceCreationParameters const& request_parameters)
69
-> scene::SurfaceCreationParameters;
71
void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
73
void handle_modify_surface(
74
std::shared_ptr<scene::Session> const& session,
75
std::shared_ptr<scene::Surface> const& surface,
76
shell::SurfaceSpecification const& modifications);
78
void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
80
int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirWindowState value);
82
void drag(geometry::Point cursor);
84
bool handle_keyboard_event(MirKeyboardEvent const* event);
86
bool handle_touch_event(MirTouchEvent const* event);
88
bool handle_pointer_event(MirPointerEvent const* event);
90
void handle_raise_surface(
91
std::shared_ptr<scene::Session> const& session,
92
std::shared_ptr<scene::Surface> const& surface);
94
void generate_decorations_for(
95
std::shared_ptr<scene::Session> const& session,
96
std::shared_ptr<scene::Surface> const& surface,
97
SurfaceInfoMap& surface_map,
98
std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const& session, scene::SurfaceCreationParameters const& params)> const& build);
101
static const int modifier_mask =
102
mir_input_event_modifier_alt |
103
mir_input_event_modifier_shift |
104
mir_input_event_modifier_sym |
105
mir_input_event_modifier_ctrl |
106
mir_input_event_modifier_meta;
108
void toggle(MirWindowState state);
110
// "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
111
// *window*,but Mir really only understands surfaces
112
void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
113
auto active_surface() const -> std::shared_ptr<scene::Surface>;
115
bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
116
bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
117
void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
119
std::shared_ptr<mir::scene::Surface> const& surface,
120
std::shared_ptr<mir::scene::Surface> const& titlebar,
121
geometry::Point const& new_pos,
122
geometry::Size const& new_size) const;
124
WindowManagerTools* const tools;
125
std::shared_ptr<shell::DisplayLayout> const display_layout;
126
std::shared_ptr<graphics::GraphicBufferAllocator> const allocator;
128
geometry::Rectangle display_area;
129
geometry::Point old_cursor{};
130
std::weak_ptr<scene::Surface> active_surface_;
131
using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;
133
FullscreenSurfaces fullscreen_surfaces;
135
bool resizing = false;
136
bool left_resize = false;
137
bool top_resize = false;
142
#endif /* MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_ */