Mir
server_example_canonical_window_manager.h
Go to the documentation of this file.
1 /*
2  * Copyright © 2015 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 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_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_
20 #define MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_
21 
23 
25 
26 #include <atomic>
27 #include <set>
28 
30 // Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
31 
32 namespace mir
33 {
34 namespace shell { class DisplayLayout; }
35 namespace examples
36 {
37 // standard window management algorithm:
38 // o Switch apps: tap or click on the corresponding tile
39 // o Move window: Alt-leftmousebutton drag (three finger drag)
40 // o Resize window: Alt-middle_button drag (two finger drag)
41 // o Maximize/restore current window (to display size): Alt-F11
42 // o Maximize/restore current window (to display height): Shift-F11
43 // o Maximize/restore current window (to display width): Ctrl-F11
44 // o client requests to maximize, vertically maximize & restore
46 {
47 public:
48 
50  WindowManagerTools* const tools,
51  std::shared_ptr<shell::DisplayLayout> const& display_layout);
52 
53  void click(geometry::Point cursor);
54 
55  void handle_session_info_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
56 
57  void handle_displays_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays);
58 
59  void resize(geometry::Point cursor);
60 
61  auto handle_place_new_surface(
62  std::shared_ptr<scene::Session> const& session,
63  scene::SurfaceCreationParameters const& request_parameters)
65 
66  void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
67 
68  void handle_modify_surface(
69  std::shared_ptr<scene::Session> const& session,
70  std::shared_ptr<scene::Surface> const& surface,
71  shell::SurfaceSpecification const& modifications);
72 
73  void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
74 
75  int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirWindowState value);
76 
77  void drag(geometry::Point cursor);
78 
79  bool handle_keyboard_event(MirKeyboardEvent const* event);
80 
81  bool handle_touch_event(MirTouchEvent const* event);
82 
83  bool handle_pointer_event(MirPointerEvent const* event);
84 
85  void handle_raise_surface(
86  std::shared_ptr<scene::Session> const& session,
87  std::shared_ptr<scene::Surface> const& surface);
88 
89  void generate_decorations_for(
90  std::shared_ptr<scene::Session> const& session,
91  std::shared_ptr<scene::Surface> const& surface,
92  SurfaceInfoMap& surface_map,
93  std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const& session, scene::SurfaceCreationParameters const& params)> const& build);
94 
95 private:
96  static const int modifier_mask =
102 
103  void toggle(MirWindowState state);
104 
105  // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
106  // *window*,but Mir really only understands surfaces
107  void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
108  auto active_surface() const -> std::shared_ptr<scene::Surface>;
109 
110  bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
111  bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
112  void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
113  void apply_resize(
114  std::shared_ptr<mir::scene::Surface> const& surface,
115  std::shared_ptr<mir::scene::Surface> const& titlebar,
116  geometry::Point const& new_pos,
117  geometry::Size const& new_size) const;
118 
119  WindowManagerTools* const tools;
120  std::shared_ptr<shell::DisplayLayout> const display_layout;
121 
122  geometry::Rectangle display_area;
123  geometry::Point old_cursor{};
124  std::weak_ptr<scene::Surface> active_surface_;
125  using FullscreenSurfaces = std::set<std::weak_ptr<scene::Surface>, std::owner_less<std::weak_ptr<scene::Surface>>>;
126 
127  FullscreenSurfaces fullscreen_surfaces;
128 
129  bool resizing = false;
130  bool left_resize = false;
131  bool top_resize = false;
132 };
133 }
134 }
135 
136 #endif /* MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_ */
Definition: size.h:30
Definition: input_event.h:49
Definition: as_render_target.h:27
Interface to the layout of the display outputs.
Definition: display_layout.h:36
Definition: server_example_canonical_window_manager.h:45
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
Definition: server_example_basic_window_manager.h:80
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
Definition: input_event.h:60
typename WindowManagerTools::SessionInfoMap SessionInfoMap
Definition: server_example_basic_window_manager.h:83
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
typename WindowManagerTools::SurfaceInfoMap SurfaceInfoMap
Definition: server_example_basic_window_manager.h:84
Definition: input_event.h:52
Definition: displacement.h:32
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:41
Definition: surface_creation_parameters.h:41
Definition: rectangle.h:33
Definition: input_event.h:55
Specification of surface properties requested by client.
Definition: surface_specification.h:57
Definition: input_event.h:57
MirWindowState
Definition: common.h:139
The interface through which the policy instructs the controller. These functions assume that the Basi...
Definition: server_example_basic_window_manager.h:43

Copyright © 2012-2016 Canonical Ltd.
Generated on Wed Oct 11 22:26:23 UTC 2017