2
* Copyright © 2016 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 2 or 3 as
6
* 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 MIRAL_WINDOW_MANAGEMENT_POLICY_H
20
#define MIRAL_WINDOW_MANAGEMENT_POLICY_H
22
#include <mir/geometry/displacement.h>
23
#include <mir/geometry/rectangles.h>
24
#include <mir_toolkit/event.h>
29
class WindowSpecification;
30
struct ApplicationInfo;
33
using namespace mir::geometry;
35
/// The interface through which the window management policy is determined.
36
class WindowManagementPolicy
39
/// before any related calls begin
40
virtual void advise_begin();
42
/// after any related calls end
43
virtual void advise_end();
45
/** Customize initial window placement
47
* @param app_info the application requesting a new window
48
* @param requested_specification the requested specification (updated with default placement)
49
* @return the customized specification
51
virtual auto place_new_window(
52
ApplicationInfo const& app_info,
53
WindowSpecification const& requested_specification) -> WindowSpecification = 0;
55
/** @name handle events originating from the client
56
* The policy is expected to update the model as appropriate
58
/** notification that the first buffer has been posted
60
* @param window_info the window
62
virtual void handle_window_ready(WindowInfo& window_info) = 0;
64
/** request from client to modify the window specification.
65
* \note the request has already been validated against the type definition
67
* @param window_info the window
68
* @param modifications the requested changes
70
virtual void handle_modify_window(WindowInfo& window_info, WindowSpecification const& modifications) = 0;
72
/** request from client to raise the window
73
* \note the request has already been validated against the requesting event
75
* @param window_info the window
77
virtual void handle_raise_window(WindowInfo& window_info) = 0;
80
/** @name handle events originating from user
81
* The policy is expected to interpret (and optionally consume) the event
83
/** keyboard event handler
85
* @param event the event
86
* @return whether the policy has consumed the event
88
virtual bool handle_keyboard_event(MirKeyboardEvent const* event) = 0;
90
/** touch event handler
92
* @param event the event
93
* @return whether the policy has consumed the event
95
virtual bool handle_touch_event(MirTouchEvent const* event) = 0;
97
/** pointer event handler
99
* @param event the event
100
* @return whether the policy has consumed the event
102
virtual bool handle_pointer_event(MirPointerEvent const* event) = 0;
105
/** @name notification of WM events that the policy may need to track.
106
* \note if the policy updates a Window object directly (as opposed to using tools)
107
* no notification is generated.
109
/** Notification that a new application has connected
111
* @param application the application
113
virtual void advise_new_app(ApplicationInfo& application);
115
/** Notification that an application has disconnected
117
* @param application the application
119
virtual void advise_delete_app(ApplicationInfo const& application);
121
/** Notification that a window has been created
123
* @param window_info the window
125
virtual void advise_new_window(WindowInfo const& window_info);
127
/** Notification that a window has lost focus
129
* @param window_info the window
131
virtual void advise_focus_lost(WindowInfo const& window_info);
133
/** Notification that a window has gained focus
135
* @param window_info the window
137
virtual void advise_focus_gained(WindowInfo const& window_info);
139
/** Notification that a window is about to change state
141
* @param window_info the window
142
* @param state the new state
144
virtual void advise_state_change(WindowInfo const& window_info, MirWindowState state);
146
/** Notification that a window is about to move
148
* @param window_info the window
149
* @param top_left the new position
151
virtual void advise_move_to(WindowInfo const& window_info, Point top_left);
153
/** Notification that a window is about to resize
155
* @param window_info the window
156
* @param new_size the new size
158
virtual void advise_resize(WindowInfo const& window_info, Size const& new_size);
160
/** Notification that a window is about to be destroyed
162
* @param window_info the window
164
virtual void advise_delete_window(WindowInfo const& window_info);
166
/** Notification that windows are being raised to the top.
167
* These windows are ordered with parents before children,
168
* and form a single tree rooted at the first element.
170
* @param windows the windows
171
* \note The relative Z-order of these windows will be maintained, they will be raised en bloc.
173
virtual void advise_raise(std::vector<Window> const& windows);
176
/** Confirm (and optionally adjust) the motion of a child window when the parent is moved.
178
* @param window_info the window
179
* @param movement the movement of the parent
181
* @return the confirmed placement of the window
183
virtual auto confirm_inherited_move(WindowInfo const& window_info, Displacement movement) -> Rectangle = 0;
185
virtual ~WindowManagementPolicy() = default;
186
WindowManagementPolicy() = default;
187
WindowManagementPolicy(WindowManagementPolicy const&) = delete;
188
WindowManagementPolicy& operator=(WindowManagementPolicy const&) = delete;
191
class WindowManagerTools;
194
#endif //MIRAL_WINDOW_MANAGEMENT_POLICY_H