Mir
basic_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_BASIC_WINDOW_MANAGER_H_
20 #define MIR_SHELL_BASIC_WINDOW_MANAGER_H_
21 
26 
27 #include <map>
28 #include <mutex>
29 
30 namespace mir
31 {
32 namespace shell
33 {
38 {
39 public:
40  using SurfaceInfoMap = std::map<std::weak_ptr<scene::Surface>, SurfaceInfo, std::owner_less<std::weak_ptr<scene::Surface>>>;
41  using SessionInfoMap = std::map<std::weak_ptr<scene::Session>, SessionInfo, std::owner_less<std::weak_ptr<scene::Session>>>;
42 
43  virtual auto find_session(std::function<bool(SessionInfo const& info)> const& predicate)
44  -> std::shared_ptr<scene::Session> = 0;
45 
46  virtual auto info_for(std::weak_ptr<scene::Session> const& session) const -> SessionInfo& = 0;
47 
48  virtual auto info_for(std::weak_ptr<scene::Surface> const& surface) const -> SurfaceInfo& = 0;
49 
50  virtual std::shared_ptr<scene::Session> focused_session() const = 0;
51 
52  virtual std::shared_ptr<scene::Surface> focused_surface() const = 0;
53 
54  virtual void focus_next_session() = 0;
55 
56  virtual void set_focus_to(
57  std::shared_ptr<scene::Session> const& focus,
58  std::shared_ptr<scene::Surface> const& surface) = 0;
59 
60  virtual auto surface_at(geometry::Point cursor) const -> std::shared_ptr<scene::Surface> = 0;
61 
62  virtual auto active_display() -> geometry::Rectangle const = 0;
63 
64  virtual void forget(std::weak_ptr<scene::Surface> const& surface) = 0;
65 
66  virtual void raise_tree(std::shared_ptr<scene::Surface> const& root) = 0;
67 
68  virtual ~WindowManagerTools() = default;
69  WindowManagerTools() = default;
70  WindowManagerTools(WindowManagerTools const&) = delete;
72 };
73 
75 {
76 public:
79 
80  virtual void handle_session_info_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays) = 0;
81 
82  virtual void handle_displays_updated(SessionInfoMap& session_info, geometry::Rectangles const& displays) = 0;
83 
84  virtual auto handle_place_new_surface(
85  std::shared_ptr<scene::Session> const& session,
86  scene::SurfaceCreationParameters const& request_parameters)
88 
89  virtual void handle_new_surface(std::shared_ptr<scene::Session> const& session, std::shared_ptr<scene::Surface> const& surface) = 0;
90 
91  virtual void handle_modify_surface(
92  std::shared_ptr<scene::Session> const& session,
93  std::shared_ptr<scene::Surface> const& surface,
94  shell::SurfaceSpecification const& modifications) = 0;
95 
96  virtual void handle_delete_surface(std::shared_ptr<scene::Session> const& session, std::weak_ptr<scene::Surface> const& surface) = 0;
97 
98  virtual int handle_set_state(std::shared_ptr<scene::Surface> const& surface, MirSurfaceState value) = 0;
99 
100  virtual bool handle_keyboard_event(MirKeyboardEvent const* event) = 0;
101 
102  virtual bool handle_touch_event(MirTouchEvent const* event) = 0;
103 
104  virtual bool handle_pointer_event(MirPointerEvent const* event) = 0;
105 
106  virtual void handle_raise_surface(
107  std::shared_ptr<scene::Session> const& session,
108  std::shared_ptr<scene::Surface> const& surface) = 0;
109 
110  virtual ~WindowManagementPolicy() = default;
111  WindowManagementPolicy() = default;
114 };
115 
119  protected WindowManagerTools
120 {
121 protected:
123  shell::FocusController* focus_controller,
124  std::unique_ptr<WindowManagementPolicy> policy);
125 
126 public:
127  using typename WindowManagerTools::SurfaceInfoMap;
128  using typename WindowManagerTools::SessionInfoMap;
129 
130  void add_session(std::shared_ptr<scene::Session> const& session) override;
131 
132  void remove_session(std::shared_ptr<scene::Session> const& session) override;
133 
134  auto add_surface(
135  std::shared_ptr<scene::Session> const& session,
136  scene::SurfaceCreationParameters const& params,
137  std::function<frontend::SurfaceId(std::shared_ptr<scene::Session> const& session, scene::SurfaceCreationParameters const& params)> const& build)
138  -> frontend::SurfaceId override;
139 
140  void modify_surface(
141  std::shared_ptr<scene::Session> const& session,
142  std::shared_ptr<scene::Surface> const& surface,
143  shell::SurfaceSpecification const& modifications) override;
144 
145  void remove_surface(
146  std::shared_ptr<scene::Session> const& session,
147  std::weak_ptr<scene::Surface> const& surface) override;
148 
149  void forget(std::weak_ptr<scene::Surface> const& surface) override;
150 
151  void add_display(geometry::Rectangle const& area) override;
152 
153  void remove_display(geometry::Rectangle const& area) override;
154 
155  bool handle_keyboard_event(MirKeyboardEvent const* event) override;
156 
157  bool handle_touch_event(MirTouchEvent const* event) override;
158 
159  bool handle_pointer_event(MirPointerEvent const* event) override;
160 
161  void handle_raise_surface(
162  std::shared_ptr<scene::Session> const& session,
163  std::shared_ptr<scene::Surface> const& surface,
164  uint64_t timestamp) override;
165 
166  int set_surface_attribute(
167  std::shared_ptr<scene::Session> const& /*session*/,
168  std::shared_ptr<scene::Surface> const& surface,
169  MirSurfaceAttrib attrib,
170  int value) override;
171 
172  auto find_session(std::function<bool(SessionInfo const& info)> const& predicate)
173  -> std::shared_ptr<scene::Session> override;
174 
175  auto info_for(std::weak_ptr<scene::Session> const& session) const -> SessionInfo& override;
176 
177  auto info_for(std::weak_ptr<scene::Surface> const& surface) const -> SurfaceInfo& override;
178 
179  std::shared_ptr<scene::Session> focused_session() const override;
180 
181  std::shared_ptr<scene::Surface> focused_surface() const override;
182 
183  void focus_next_session() override;
184 
185  void set_focus_to(
186  std::shared_ptr<scene::Session> const& focus,
187  std::shared_ptr<scene::Surface> const& surface) override;
188 
189  auto surface_at(geometry::Point cursor) const -> std::shared_ptr<scene::Surface> override;
190 
191  auto active_display() -> geometry::Rectangle const override;
192 
193  void raise_tree(std::shared_ptr<scene::Surface> const& root) override;
194 
195 private:
196  shell::FocusController* const focus_controller;
197  std::unique_ptr<WindowManagementPolicy> const policy;
198 
199  std::mutex mutex;
200  SessionInfoMap session_info;
201  SurfaceInfoMap surface_info;
202  geometry::Rectangles displays;
203  geometry::Point cursor;
204  uint64_t last_input_event_timestamp{0};
205 
206  void update_event_timestamp(MirKeyboardEvent const* kev);
207  void update_event_timestamp(MirPointerEvent const* pev);
208  void update_event_timestamp(MirTouchEvent const* tev);
209 };
210 
214 template<typename WMPolicy>
216 {
217 public:
218 
219  template <typename... PolicyArgs>
221  shell::FocusController* focus_controller,
222  PolicyArgs&&... policy_args) :
224  focus_controller,
225  build_policy(std::forward<PolicyArgs>(policy_args)...))
226  {
227  }
228 
229 private:
230  template <typename... PolicyArgs>
231  auto build_policy(PolicyArgs&&... policy_args)
232  -> std::unique_ptr<WMPolicy>
233  {
234  return std::unique_ptr<WMPolicy>(
235  new WMPolicy(this, std::forward<PolicyArgs>(policy_args)...));
236  }
237 };
238 }
239 }
240 
241 #endif /* MIR_SHELL_BASIC_WINDOW_MANAGER_H_ */
The interface through which the policy instructs the controller. These functions assume that the Basi...
Definition: basic_window_manager.h:37
All things Mir.
Definition: atomic_callback.h:25
typename WindowManagerTools::SessionInfoMap SessionInfoMap
Definition: basic_window_manager.h:77
virtual ~WindowManagerTools()=default
interface to provide window management logic
Definition: window_manager.h:37
std::map< std::weak_ptr< scene::Session >, SessionInfo, std::owner_less< std::weak_ptr< scene::Session >>> SessionInfoMap
Definition: basic_window_manager.h:41
A collection of rectangles (with possible duplicates).
Definition: rectangles.h:34
Definition: point.h:30
virtual std::shared_ptr< scene::Session > focused_session() const =0
virtual void focus_next_session()=0
virtual auto info_for(std::weak_ptr< scene::Session > const &session) const -> SessionInfo &=0
struct MirPointerEvent MirPointerEvent
An event type describing a change in pointer device state.
Definition: pointer_event.h:35
Definition: event_private.h:51
STL namespace.
Definition: focus_controller.h:38
std::map< std::weak_ptr< scene::Session >, SessionInfo, std::owner_less< std::weak_ptr< scene::Session >>> SessionInfoMap
Definition: basic_window_manager.h:41
virtual auto find_session(std::function< bool(SessionInfo const &info)> const &predicate) -> std::shared_ptr< scene::Session >=0
virtual void forget(std::weak_ptr< scene::Surface > const &surface)=0
virtual std::shared_ptr< scene::Surface > focused_surface() const =0
virtual void raise_tree(std::shared_ptr< scene::Surface > const &root)=0
std::map< std::weak_ptr< scene::Surface >, SurfaceInfo, std::owner_less< std::weak_ptr< scene::Surface >>> SurfaceInfoMap
Definition: basic_window_manager.h:40
struct MirTouchEvent MirTouchEvent
An event type describing a change in touch device state.
Definition: touch_event.h:33
MirSurfaceState
Definition: common.h:64
WindowManagerTools & operator=(WindowManagerTools const &)=delete
virtual auto surface_at(geometry::Point cursor) const -> std::shared_ptr< scene::Surface >=0
Definition: basic_window_manager.h:74
Definition: window_management_info.h:33
virtual void set_focus_to(std::shared_ptr< scene::Session > const &focus, std::shared_ptr< scene::Surface > const &surface)=0
A policy based window manager. This takes care of the management of any meta implementation held for ...
Definition: basic_window_manager.h:118
MirSurfaceAttrib
Attributes of a surface that the client and server/shell may wish to get or set over the wire...
Definition: common.h:34
A policy based window manager. This exists to initialize BasicWindowManager and the WMPolicy (in an a...
Definition: basic_window_manager.h:215
Definition: window_management_info.h:92
std::map< std::weak_ptr< scene::Surface >, SurfaceInfo, std::owner_less< std::weak_ptr< scene::Surface >>> SurfaceInfoMap
Definition: basic_window_manager.h:40
typename WindowManagerTools::SurfaceInfoMap SurfaceInfoMap
Definition: basic_window_manager.h:78
Definition: surface_creation_parameters.h:41
virtual auto active_display() -> geometry::Rectangle const =0
Definition: rectangle.h:33
Specification of surface properties requested by client.
Definition: surface_specification.h:49
WindowManagerConstructor(shell::FocusController *focus_controller, PolicyArgs &&...policy_args)
Definition: basic_window_manager.h:220

Copyright © 2012-2015 Canonical Ltd.
Generated on Wed Mar 30 00:29:56 UTC 2016