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 
29 // Based on "Mir and Unity: Surfaces, input, and displays (v0.3)"
30 
31 namespace mir
32 {
33 namespace shell { class DisplayLayout; }
34 namespace examples
35 {
37 {
38  int surfaces{0};
39 };
40 
42 {
44  std::shared_ptr<scene::Session> const& session,
45  std::shared_ptr<scene::Surface> const& surface,
46  scene::SurfaceCreationParameters const& params);
47 
48  bool can_be_active() const;
49 
50  bool can_morph_to(MirSurfaceType new_type) const;
51  bool must_have_parent() const;
52  bool must_not_have_parent() const;
53  bool is_visible() const;
54 
55  void constrain_resize(
56  std::shared_ptr<scene::Surface> const& surface,
57  geometry::Point& requested_pos,
58  geometry::Size& requested_size,
59  const bool left_resize,
60  const bool top_resize,
61  geometry::Rectangle const& bounds) const;
62 
66  std::weak_ptr<scene::Session> session;
67  std::weak_ptr<scene::Surface> parent;
68  std::vector<std::weak_ptr<scene::Surface>> children;
69  std::shared_ptr<scene::Surface> titlebar;
71  bool is_titlebar = false;
80 
81  void init_titlebar(std::shared_ptr<scene::Surface> const& surface);
82  void paint_titlebar(int intensity);
83 
84 private:
85 
86  struct PaintingImpl;
87 
88  std::shared_ptr<PaintingImpl> painting_impl;
89 };
90 
91 // standard window management algorithm:
92 // o Switch apps: tap or click on the corresponding tile
93 // o Move window: Alt-leftmousebutton drag
94 // o Resize window: Alt-middle_button drag
95 // o Maximize/restore current window (to display size): Alt-F11
96 // o Maximize/restore current window (to display height): Shift-F11
97 // o Maximize/restore current window (to display width): Ctrl-F11
98 // o client requests to maximize, vertically maximize & restore
100 {
101 public:
105 
107  Tools* const tools,
108  std::shared_ptr<shell::DisplayLayout> const& display_layout);
109 
110  void click(geometry::Point cursor);
111 
112  void handle_session_info_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
113 
114  void handle_displays_updated(CanonicalSessionInfoMap& session_info, geometry::Rectangles const& displays);
115 
116  void resize(geometry::Point cursor);
117 
119  std::shared_ptr<scene::Session> const& session,
120  scene::SurfaceCreationParameters const& request_parameters)
122 
123  void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface);
124 
126  std::shared_ptr<scene::Session> const& session,
127  std::shared_ptr<scene::Surface> const& surface,
128  shell::SurfaceSpecification const& modifications);
129 
130  void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface);
131 
132  int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value);
133 
134  void drag(geometry::Point cursor);
135 
136  bool handle_keyboard_event(MirKeyboardEvent const* event);
137 
138  bool handle_touch_event(MirTouchEvent const* event);
139 
140  bool handle_pointer_event(MirPointerEvent const* event);
141 
143  std::shared_ptr<scene::Session> const& session,
144  std::shared_ptr<scene::Surface> const& surface,
145  CanonicalSurfaceInfoMap& surface_map,
146  std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const& session, scene::SurfaceCreationParameters const& params)> const& build);
147 
148 private:
149  static const int modifier_mask =
155 
156  void toggle(MirSurfaceState state);
157 
158  // "Mir and Unity: Surfaces, input, and displays (v0.3)" talks about active
159  // *window*,but Mir really only understands surfaces
160  void select_active_surface(std::shared_ptr<scene::Surface> const& surface);
161  auto active_surface() const -> std::shared_ptr<scene::Surface>;
162 
163  bool resize(std::shared_ptr<scene::Surface> const& surface, geometry::Point cursor, geometry::Point old_cursor, geometry::Rectangle bounds);
164  bool drag(std::shared_ptr<scene::Surface> surface, geometry::Point to, geometry::Point from, geometry::Rectangle bounds);
165  void move_tree(std::shared_ptr<scene::Surface> const& root, geometry::Displacement movement) const;
166  void raise_tree(std::shared_ptr<scene::Surface> const& root) const;
167  void apply_resize(
168  std::shared_ptr<mir::scene::Surface> const& surface,
169  std::shared_ptr<mir::scene::Surface> const& titlebar,
170  geometry::Point const& new_pos,
171  geometry::Size const& new_size) const;
172 
173  Tools* const tools;
174  std::shared_ptr<shell::DisplayLayout> const display_layout;
175 
176  geometry::Rectangle display_area;
177  geometry::Point old_cursor{};
178  std::weak_ptr<scene::Surface> active_surface_;
179 };
180 }
181 }
182 
183 #endif /* MIR_EXAMPLE_CANONICAL_WINDOW_MANAGER_H_ */
Definition: size.h:30
void click(geometry::Point cursor)
Definition: server_example_canonical_window_manager.cpp:206
Definition: input_event.h:47
All things Mir.
Definition: atomic_callback.h:25
std::vector< std::weak_ptr< scene::Surface > > children
Definition: server_example_canonical_window_manager.h:68
CanonicalWindowManagerPolicyCopy(Tools *const tools, std::shared_ptr< shell::DisplayLayout > const &display_layout)
Definition: server_example_canonical_window_manager.cpp:198
Definition: server_example_canonical_window_manager.h:99
Definition: server_example_canonical_window_manager.h:36
CanonicalSurfaceInfoCopy(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, scene::SurfaceCreationParameters const &params)
Definition: server_example_canonical_window_manager.cpp:73
void handle_displays_updated(CanonicalSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: server_example_canonical_window_manager.cpp:218
bool handle_keyboard_event(MirKeyboardEvent const *event)
Definition: server_example_canonical_window_manager.cpp:720
void paint_titlebar(int intensity)
Definition: server_example_canonical_window_manager.cpp:406
void handle_modify_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, shell::SurfaceSpecification const &modifications)
Definition: server_example_canonical_window_manager.cpp:477
std::map< std::weak_ptr< scene::Surface >, Info, std::owner_less< std::weak_ptr< scene::Surface >>> type
Definition: server_example_basic_window_manager.h:44
void init_titlebar(std::shared_ptr< scene::Surface > const &surface)
Definition: server_example_canonical_window_manager.cpp:401
void drag(geometry::Point cursor)
Definition: server_example_canonical_window_manager.cpp:713
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
mir::optional_value< shell::SurfaceAspectRatio > min_aspect
Definition: server_example_canonical_window_manager.h:78
void resize(geometry::Point cursor)
Definition: server_example_canonical_window_manager.cpp:223
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
auto handle_place_new_surface(std::shared_ptr< scene::Session > const &session, scene::SurfaceCreationParameters const &request_parameters) -> scene::SurfaceCreationParameters
Definition: server_example_canonical_window_manager.cpp:230
STL namespace.
bool must_not_have_parent() const
Definition: server_example_canonical_window_manager.cpp:171
geometry::Width min_width
Definition: server_example_canonical_window_manager.h:72
Definition: input_event.h:58
std::map< std::weak_ptr< scene::Session >, Info, std::owner_less< std::weak_ptr< scene::Session >>> type
Definition: server_example_basic_window_manager.h:50
void handle_session_info_updated(CanonicalSessionInfoMap &session_info, geometry::Rectangles const &displays)
Definition: server_example_canonical_window_manager.cpp:214
bool handle_pointer_event(MirPointerEvent const *event)
Definition: server_example_canonical_window_manager.cpp:837
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: server_example_canonical_window_manager.cpp:1004
mir::optional_value< geometry::DeltaY > height_inc
Definition: server_example_canonical_window_manager.h:77
typename SessionTo< CanonicalSessionInfoCopy >::type CanonicalSessionInfoMap
Definition: server_example_canonical_window_manager.h:103
bool can_be_active() const
Definition: server_example_canonical_window_manager.cpp:93
geometry::Height max_height
Definition: server_example_canonical_window_manager.h:75
bool is_visible() const
Definition: server_example_canonical_window_manager.cpp:184
bool can_morph_to(MirSurfaceType new_type) const
Definition: server_example_canonical_window_manager.cpp:129
std::weak_ptr< scene::Surface > parent
Definition: server_example_canonical_window_manager.h:67
The interface through which the policy instructs the controller. These functions assume that the Basi...
Definition: server_example_basic_window_manager.h:58
int handle_set_state(std::shared_ptr< scene::Surface > const &surface, MirSurfaceState value)
Definition: server_example_canonical_window_manager.cpp:612
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
MirSurfaceState
Definition: common.h:64
void generate_decorations_for(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface, CanonicalSurfaceInfoMap &surface_map, std::function< frontend::SurfaceId(std::shared_ptr< scene::Session > const &session, scene::SurfaceCreationParameters const &params)> const &build)
Definition: server_example_canonical_window_manager.cpp:421
Definition: server_example_canonical_window_manager.h:41
std::weak_ptr< scene::Session > session
Definition: server_example_canonical_window_manager.h:66
frontend::SurfaceId titlebar_id
Definition: server_example_canonical_window_manager.h:70
MirSurfaceType
Definition: common.h:48
typename SurfaceTo< CanonicalSurfaceInfoCopy >::type CanonicalSurfaceInfoMap
Definition: server_example_canonical_window_manager.h:104
Definition: input_event.h:50
bool is_titlebar
Definition: server_example_canonical_window_manager.h:71
MirSurfaceType type
Definition: server_example_canonical_window_manager.h:63
int surfaces
Definition: server_example_canonical_window_manager.h:38
mir::optional_value< shell::SurfaceAspectRatio > max_aspect
Definition: server_example_canonical_window_manager.h:79
mir::optional_value< geometry::DeltaX > width_inc
Definition: server_example_canonical_window_manager.h:76
struct MirKeyboardEvent MirKeyboardEvent
An event type describing a change in keyboard state.
Definition: keyboard_event.h:44
Definition: surface_creation_parameters.h:42
geometry::Height min_height
Definition: server_example_canonical_window_manager.h:73
Definition: rectangle.h:33
geometry::Width max_width
Definition: server_example_canonical_window_manager.h:74
void handle_delete_surface(std::shared_ptr< scene::Session > const &session, std::weak_ptr< scene::Surface > const &surface)
Definition: server_example_canonical_window_manager.cpp:580
Definition: input_event.h:53
Specification of surface properties requested by client.
Definition: surface_specification.h:50
void handle_new_surface(std::shared_ptr< scene::Session > const &session, std::shared_ptr< scene::Surface > const &surface)
Definition: server_example_canonical_window_manager.cpp:454
Definition: input_event.h:55
bool must_have_parent() const
Definition: server_example_canonical_window_manager.cpp:114
geometry::Rectangle restore_rect
Definition: server_example_canonical_window_manager.h:65
std::shared_ptr< scene::Surface > titlebar
Definition: server_example_canonical_window_manager.h:69
bool handle_touch_event(MirTouchEvent const *event)
Definition: server_example_canonical_window_manager.cpp:794
MirSurfaceState state
Definition: server_example_canonical_window_manager.h:64

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