Mir
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_SHELL_CANONICAL_WINDOW_MANAGER_H_
20 #define MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_
21 
22 #include "basic_window_manager.h"
23 
25 
26 namespace mir
27 {
28 namespace shell
29 {
30 class DisplayLayout;
31 
33 {
34  int surfaces{0};
35 };
36 
38 {
40  std::shared_ptr<scene::Session> const& session,
41  std::shared_ptr<scene::Surface> const& surface,
42  scene::SurfaceCreationParameters const& params);
43 
44  bool can_be_active() const;
45 
46  bool can_morph_to(MirSurfaceType new_type) const;
47  bool must_have_parent() const;
48  bool must_not_have_parent() const;
49  bool is_visible() const;
50 
51  void constrain_resize(
52  std::shared_ptr<scene::Surface> const& surface,
53  geometry::Point& requested_pos,
54  geometry::Size& requested_size,
55  const bool left_resize,
56  const bool top_resize,
57  geometry::Rectangle const& bounds) const;
58 
62  std::weak_ptr<scene::Session> session;
63  std::weak_ptr<scene::Surface> parent;
64  std::vector<std::weak_ptr<scene::Surface>> children;
73 };
74 
75 // standard window management algorithm:
76 // o Switch apps: tap or click on the corresponding tile
77 // o Move window: Alt-leftmousebutton drag
78 // o Resize window: Alt-middle_button drag
79 // o Maximize/restore current window (to display size): Alt-F11
80 // o Maximize/restore current window (to display height): Shift-F11
81 // o Maximize/restore current window (to display width): Ctrl-F11
82 // o client requests to maximize, vertically maximize & restore
84 {
85 public:
89 
91  Tools* const tools,
92  std::shared_ptr<shell::DisplayLayout> const& display_layout);
93 
94  void click(geometry::Point cursor);
95 
97 
98  void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
99 
100  void resize(geometry::Point cursor);
101 
103  std::shared_ptr<scene::Session> const& session,
104  scene::SurfaceCreationParameters const& request_parameters)
106 
107  void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
108 
110  std::shared_ptr<scene::Session> const& session,
111  std::shared_ptr<scene::Surface> const& surface,
112  SurfaceSpecification const& modifications);
113 
114  void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
115 
116  int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
117 
118  void drag(geometry::Point cursor);
119 
120  bool handle_keyboard_event(MirKeyboardEvent const* event);
121 
122  bool handle_touch_event(MirTouchEvent const* event);
123 
124  bool handle_pointer_event(MirPointerEvent const* event);
125 
126  std::vector<std::shared_ptr<scene::Surface>> generate_decorations_for(
127  std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
128 
129 private:
130  static const int modifier_mask =
136 
137  void toggle(MirSurfaceState state);
138 
139  // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
140  // *window*,but Mir really only understands surfaces
141  void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
142  auto active_surface() const -> std::shared_ptr<scene::Surface>;
143 
144  bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
145  bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
146  void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
147  void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
148  void apply_resize(
149  std::shared_ptr<mir::scene::Surface> const& surface,
150  geometry::Point const& new_pos,
151  geometry::Size const& new_size) const;
152 
153  Tools* const tools;
154  std::shared_ptr<DisplayLayout> const display_layout;
155 
156  geometry::Rectangle display_area;
157  geometry::Point old_cursor{};
158  std::weak_ptr<scene::Surface> active_surface_;
159 };
160 
162 }
163 }
164 
165 #endif /* MIR_SHELL_CANONICAL_WINDOW_MANAGER_H_ */
Definition: size.h:30
geometry::Height min_height
Definition: canonical_window_manager.h:66
Definition: input_event.h:47
All things Mir.
Definition: atomic_callback.h:25
Interface to the layout of the display outputs.
Definition: display_layout.h:36
void constrain_resize(std::shared_ptr< scene::Surface > const &surface, geometry::Point &requested_pos, geometry::Size &requested_size, const bool left_resize, const bool top_resize, geometry::Rectangle const &bounds) const
Definition: canonical_window_manager.cpp:858
typename SessionTo< CanonicalSessionInfo >::type CanonicalSessionInfoMap
Definition: canonical_window_manager.h:87
void handle_delete_surface(std::shared_ptr< scene::Session > const &session, std::weak_ptr< scene::Surface > const &surface)
Definition: canonical_window_manager.cpp:492
The interface through which the policy instructs the controller. These functions assume that the Basi...
Definition: basic_window_manager.h:52
Definition: canonical_window_manager.h:32
std::vector< std::shared_ptr< scene::Surface > > generate_decorations_for(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface)
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
bool is_visible() const
Definition: canonical_window_manager.cpp:169
CanonicalWindowManagerPolicy(Tools *const tools, std::shared_ptr< shell::DisplayLayout > const &display_layout)
Definition: canonical_window_manager.cpp:183
mir::optional_value< geometry::DeltaY > height_inc
Definition: canonical_window_manager.h:70
MirSurfaceType type
Definition: canonical_window_manager.h:59
geometry::Width max_width
Definition: canonical_window_manager.h:67
int handle_set_state(std::shared_ptr< scene::Surface > const &surface, MirSurfaceState value)
Definition: canonical_window_manager.cpp:518
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
mir::optional_value< SurfaceAspectRatio > max_aspect
Definition: canonical_window_manager.h:72
STL namespace.
Definition: canonical_window_manager.h:83
Definition: input_event.h:58
bool handle_touch_event(MirTouchEvent const *event)
Definition: canonical_window_manager.cpp:684
void drag(geometry::Point cursor)
Definition: canonical_window_manager.cpp:603
geometry::Height max_height
Definition: canonical_window_manager.h:68
mir::optional_value< geometry::DeltaX > width_inc
Definition: canonical_window_manager.h:69
void handle_session_info_updated(CanonicalSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: canonical_window_manager.cpp:199
Definition: canonical_window_manager.h:37
CanonicalSurfaceInfo(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, scene::SurfaceCreationParameters const &params)
Definition: canonical_window_manager.cpp:76
bool can_be_active() const
Definition: canonical_window_manager.cpp:96
std::weak_ptr< scene::Surface > parent
Definition: canonical_window_manager.h:63
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
MirSurfaceState
Definition: common.h:64
mir::optional_value< SurfaceAspectRatio > min_aspect
Definition: canonical_window_manager.h:71
std::weak_ptr< scene::Session > session
Definition: canonical_window_manager.h:62
bool must_have_parent() const
Definition: canonical_window_manager.cpp:117
bool handle_pointer_event(MirPointerEvent const *event)
Definition: canonical_window_manager.cpp:727
bool can_morph_to(MirSurfaceType new_type) const
Definition: canonical_window_manager.cpp:122
A policy based window manager. This takes care of the management of any meta implementation held for ...
Definition: basic_window_manager.h:105
MirSurfaceType
Definition: common.h:48
void handle_displays_updated(CanonicalSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: canonical_window_manager.cpp:203
Definition: input_event.h:50
int surfaces
Definition: canonical_window_manager.h:34
geometry::Rectangle restore_rect
Definition: canonical_window_manager.h:61
void resize(geometry::Point cursor)
Definition: canonical_window_manager.cpp:208
std::map< std::weak_ptr< scene::Surface >, Info, std::owner_less< std::weak_ptr< scene::Surface >>> type
Definition: basic_window_manager.h:39
void click(geometry::Point cursor)
Definition: canonical_window_manager.cpp:191
bool must_not_have_parent() const
Definition: canonical_window_manager.cpp:164
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:44
Definition: surface_creation_parameters.h:42
Definition: rectangle.h:33
geometry::Width min_width
Definition: canonical_window_manager.h:65
bool handle_keyboard_event(MirKeyboardEvent const *event)
Definition: canonical_window_manager.cpp:610
void handle_new_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface)
Definition: canonical_window_manager.cpp:368
Definition: input_event.h:53
std::vector< std::weak_ptr< scene::Surface > > children
Definition: canonical_window_manager.h:64
Specification of surface properties requested by client.
Definition: surface_specification.h:50
auto handle_place_new_surface(std::shared_ptr< scene::Session > const &session, scene::SurfaceCreationParameters const &request_parameters) -> scene::SurfaceCreationParameters
Definition: canonical_window_manager.cpp:215
Definition: input_event.h:55
void handle_modify_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, SurfaceSpecification const &modifications)
Definition: canonical_window_manager.cpp:391
typename SurfaceTo< CanonicalSurfaceInfo >::type CanonicalSurfaceInfoMap
Definition: canonical_window_manager.h:88
MirSurfaceState state
Definition: canonical_window_manager.h:60
std::map< std::weak_ptr< scene::Session >, Info, std::owner_less< std::weak_ptr< scene::Session >>> type
Definition: basic_window_manager.h:45

Copyright © 2012-2015 Canonical Ltd.
Generated on Thu Oct 8 16:20:16 UTC 2015