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_EXAMPLE_TILING_WINDOW_MANAGER_H_
20
#define MIR_EXAMPLE_TILING_WINDOW_MANAGER_H_
22
#include "server_example_basic_window_manager.h"
24
///\example server_example_tiling_window_manager.h
25
/// Demonstrate implementing a simple tiling algorithm
31
// simple tiling algorithm:
32
// o Switch apps: tap or click on the corresponding tile
33
// o Move window: Alt-leftmousebutton drag (three finger drag)
34
// o Resize window: Alt-middle_button drag (two finger drag)
35
// o Maximize/restore current window (to tile size): Alt-F11
36
// o Maximize/restore current window (to tile height): Shift-F11
37
// o Maximize/restore current window (to tile width): Ctrl-F11
38
// o client requests to maximize, vertically maximize & restore
39
class TilingWindowManagerPolicy : public WindowManagementPolicy
42
explicit TilingWindowManagerPolicy(WindowManagerTools* const tools);
44
void click(geometry::Point cursor);
46
void handle_session_info_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
48
void handle_displays_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
50
void resize(geometry::Point cursor);
52
auto handle_place_new_surface(
53
std::shared_ptr<scene::Session> const& session,
54
scene::SurfaceCreationParameters const& request_parameters)
55
-> scene::SurfaceCreationParameters;
57
void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
59
void handle_modify_surface(
60
std::shared_ptr<scene::Session> const& session,
61
std::shared_ptr<scene::Surface> const& surface,
62
shell::SurfaceSpecification const& modifications);
64
void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
66
int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
68
void drag(geometry::Point cursor);
70
bool handle_keyboard_event(MirKeyboardEvent const* event);
72
bool handle_touch_event(MirTouchEvent const* event);
74
bool handle_pointer_event(MirPointerEvent const* event);
76
void handle_raise_surface(
77
std::shared_ptr<scene::Session> const& session,
78
std::shared_ptr<scene::Surface> const& surface);
80
void generate_decorations_for(
81
std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface,
82
SurfaceInfoMap& surface_info,
83
std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const&, scene::SurfaceCreationParameters const&)> const& build);
86
static const int modifier_mask =
87
mir_input_event_modifier_alt |
88
mir_input_event_modifier_shift |
89
mir_input_event_modifier_sym |
90
mir_input_event_modifier_ctrl |
91
mir_input_event_modifier_meta;
93
void toggle(MirSurfaceState state);
95
std::shared_ptr<scene::Session> session_under(geometry::Point position);
98
SessionInfoMap& session_info,
99
geometry::Rectangles const& displays);
101
void update_surfaces(std::weak_ptr<scene::Session> const& session, geometry::Rectangle const& old_tile, geometry::Rectangle const& new_tile);
103
static void clip_to_tile(scene::SurfaceCreationParameters& parameters, geometry::Rectangle const& tile);
105
static void fit_to_new_tile(scene::Surface& surface, geometry::Rectangle const& old_tile, geometry::Rectangle const& new_tile);
107
void drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
109
static void resize(std::shared_ptr<scene::Surface> surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
111
static void constrained_move(std::shared_ptr<scene::Surface> const& surface, geometry::Displacement& movement, geometry::Rectangle const& bounds);
113
std::shared_ptr<scene::Surface> select_active_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
115
WindowManagerTools* const tools;
117
geometry::Point old_cursor{};
120
using TilingWindowManager = WindowManagerBuilder<TilingWindowManagerPolicy>;
124
#endif /* MIR_EXAMPLE_TILING_WINDOW_MANAGER_H_ */