Mir
window_spec.h
Go to the documentation of this file.
1/*
2 * Copyright © 2016-2017 Canonical Ltd.
3 *
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License version 2 or 3 as
6 * 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_CLIENT_WINDOW_SPEC_H
20#define MIR_CLIENT_WINDOW_SPEC_H
21
22#include <mir/client/window.h>
23
26#include <mir_toolkit/version.h>
28
29#include <memory>
30
31namespace mir
32{
33namespace client
34{
37{
38public:
39 explicit WindowSpec(MirWindowSpec* spec) : self{spec, deleter} {}
40
41 static auto for_normal_window(MirConnection* connection, int width, int height) -> WindowSpec
42 {
44 }
45
46 static auto for_menu(MirConnection* connection,
47 int width,
48 int height,
49 MirWindow* parent,
50 MirRectangle* rect,
52 {
53 auto spec = WindowSpec{mir_create_menu_window_spec(connection, width, height, parent, rect, edge)};
54 return spec;
55 }
56
57 static auto for_tip(MirConnection* connection,
58 int width,
59 int height,
60 MirWindow* parent,
61 MirRectangle* rect,
63 {
64 auto spec = WindowSpec{mir_create_tip_window_spec(connection, width, height, parent, rect, edge)};
65 return spec;
66 }
67
68 static auto for_dialog(MirConnection* connection,
69 int width,
70 int height)-> WindowSpec
71 {
72 auto spec = WindowSpec{mir_create_dialog_window_spec(connection, width, height)};
73 return spec;
74 }
75
76 static auto for_dialog(MirConnection* connection,
77 int width,
78 int height,
79 MirWindow* parent) -> WindowSpec
80 {
81 return for_dialog(connection, width, height).set_parent(parent);
82 }
83
84 static auto for_input_method(MirConnection* connection, int width, int height, MirWindow* parent)
85 {
87 .set_parent(parent);
88 return spec;
89 }
90
91 static auto for_satellite(MirConnection* connection, int width, int height, MirWindow* parent)
92 {
93 return WindowSpec{mir_create_satellite_window_spec(connection, width, height, parent)};
94 }
95
96 static auto for_gloss(MirConnection* connection, int width, int height)
97 {
99 }
100
101 static auto for_changes(MirConnection* connection) -> WindowSpec
102 {
103 return WindowSpec{mir_create_window_spec(connection)};
104 }
105
107 {
108 mir_window_spec_set_type(*this, type);
109 return *this;
110 }
111
113 {
115 return *this;
116 }
117
118 auto set_min_size(int min_width, int min_height) -> WindowSpec&
119 {
120 mir_window_spec_set_min_width(*this, min_width);
121 mir_window_spec_set_min_height(*this, min_height);
122 return *this;
123 }
124
125 auto set_max_size(int max_width, int max_height) -> WindowSpec&
126 {
127 mir_window_spec_set_max_width(*this, max_width);
128 mir_window_spec_set_max_height(*this, max_height);
129 return *this;
130 }
131
132 auto set_size_inc(int width_inc, int height_inc) -> WindowSpec&
133 {
134 mir_window_spec_set_width_increment(*this, width_inc);
135 mir_window_spec_set_height_increment(*this, height_inc);
136 return *this;
137 }
138
139 auto set_size(int width, int height) -> WindowSpec&
140 {
143 return *this;
144 }
145
146 auto set_name(char const* name) -> WindowSpec&
147 {
149 return *this;
150 }
151
152 auto set_event_handler(MirWindowEventCallback callback, void* context) -> WindowSpec&
153 {
154 mir_window_spec_set_event_handler(*this, callback, context);
155 return *this;
156 }
157
159 {
161 return *this;
162 }
163
164 auto set_placement(const MirRectangle* rect,
165 MirPlacementGravity rect_gravity,
166 MirPlacementGravity surface_gravity,
167 MirPlacementHints placement_hints,
168 int offset_dx,
169 int offset_dy) -> WindowSpec&
170 {
171 mir_window_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
172 return *this;
173 }
174
176 {
177 mir_window_spec_set_parent(*this, parent);
178 return *this;
179 }
180
182 {
183 mir_window_spec_set_state(*this, state);
184 return *this;
185 }
186
187 auto add_surface(MirRenderSurface* surface, int width, int height, int displacement_x, int displacement_y)
188 -> WindowSpec&
189 {
190 mir_window_spec_add_render_surface(*this, surface, width, height, displacement_x, displacement_y);
191 return *this;
192 }
193
194 template<typename Context>
195 void create_window(void (* callback)(MirWindow*, Context*), Context* context) const
196 {
197 mir_create_window(*this, reinterpret_cast<MirWindowCallback>(callback), context);
198 }
199
200 auto create_window() const -> Window
201 {
202 return Window{mir_create_window_sync(*this)};
203 }
204
205 void apply_to(MirWindow* window) const
206 {
207 mir_window_apply_spec(window, *this);
208 }
209
210 operator MirWindowSpec*() const { return self.get(); }
211
212private:
213 static void deleter(MirWindowSpec* spec) { mir_window_spec_release(spec); }
214 std::shared_ptr<MirWindowSpec> self;
215};
216
217// Provide a deleted overload to avoid double release "accidents".
218void mir_window_spec_release(WindowSpec const& spec) = delete;
219void mir_surface_spec_release(WindowSpec const& spec) = delete;
220}
221}
222
223#endif //MIRAL_TOOLKIT_WINDOW_SPEC_H_H
Handle class for MirWindow - provides automatic reference counting.
Definition: window.h:32
Handle class for MirWindowSpec - provides automatic reference counting, method chaining.
Definition: window_spec.h:37
static auto for_input_method(MirConnection *connection, int width, int height, MirWindow *parent)
Definition: window_spec.h:84
auto set_type(MirWindowType type) -> WindowSpec &
Definition: window_spec.h:106
auto add_surface(MirRenderSurface *surface, int width, int height, int displacement_x, int displacement_y) -> WindowSpec &
Definition: window_spec.h:187
auto set_size(int width, int height) -> WindowSpec &
Definition: window_spec.h:139
static auto for_dialog(MirConnection *connection, int width, int height, MirWindow *parent) -> WindowSpec
Definition: window_spec.h:76
static auto for_menu(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge) -> WindowSpec
Definition: window_spec.h:46
auto set_placement(const MirRectangle *rect, MirPlacementGravity rect_gravity, MirPlacementGravity surface_gravity, MirPlacementHints placement_hints, int offset_dx, int offset_dy) -> WindowSpec &
Definition: window_spec.h:164
static auto for_changes(MirConnection *connection) -> WindowSpec
Definition: window_spec.h:101
void create_window(void(*callback)(MirWindow *, Context *), Context *context) const
Definition: window_spec.h:195
auto set_parent(MirWindow *parent) -> WindowSpec &
Definition: window_spec.h:175
static auto for_satellite(MirConnection *connection, int width, int height, MirWindow *parent)
Definition: window_spec.h:91
auto set_fullscreen_on_output(uint32_t output_id) -> WindowSpec &
Definition: window_spec.h:158
auto set_max_size(int max_width, int max_height) -> WindowSpec &
Definition: window_spec.h:125
auto set_size_inc(int width_inc, int height_inc) -> WindowSpec &
Definition: window_spec.h:132
static auto for_tip(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge) -> WindowSpec
Definition: window_spec.h:57
auto create_window() const -> Window
Definition: window_spec.h:200
static auto for_gloss(MirConnection *connection, int width, int height)
Definition: window_spec.h:96
static auto for_dialog(MirConnection *connection, int width, int height) -> WindowSpec
Definition: window_spec.h:68
WindowSpec(MirWindowSpec *spec)
Definition: window_spec.h:39
auto set_name(char const *name) -> WindowSpec &
Definition: window_spec.h:146
auto set_min_size(int min_width, int min_height) -> WindowSpec &
Definition: window_spec.h:118
auto set_state(MirWindowState state) -> WindowSpec &
Definition: window_spec.h:181
void apply_to(MirWindow *window) const
Definition: window_spec.h:205
auto set_event_handler(MirWindowEventCallback callback, void *context) -> WindowSpec &
Definition: window_spec.h:152
static auto for_normal_window(MirConnection *connection, int width, int height) -> WindowSpec
Definition: window_spec.h:41
auto set_shell_chrome(MirShellChrome chrome) -> WindowSpec &
Definition: window_spec.h:112
int width
Definition: client_types.h:1
uint32_t output_id
The id of the output to place the surface in.
Definition: client_types.h:17
char const * name
Definition: client_types.h:0
int height
Definition: client_types.h:2
void mir_window_spec_set_type(MirWindowSpec *spec, MirWindowType type)
Update a window specification with a window type.
void mir_window_spec_set_max_height(MirWindowSpec *spec, unsigned max_height)
Set the maximum height, in pixels.
void mir_window_apply_spec(MirWindow *window, MirWindowSpec *spec)
Request changes to the specification of a window.
void(* MirWindowEventCallback)(MirWindow *window, MirEvent const *event, void *context)
Callback for handling of window events.
Definition: client_types.h:120
void mir_window_spec_set_width(MirWindowSpec *spec, unsigned width)
Set the requested width, in pixels.
struct MirSurface MirWindow
Definition: client_types.h:43
MirWindowSpec * mir_create_dialog_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a parentless dialog window.
MirWindowType
Definition: common.h:110
MirShellChrome
Shell chrome.
Definition: common.h:458
void mir_create_window(MirWindowSpec *requested_specification, MirWindowCallback callback, void *context)
Create a window from a given specification.
void mir_window_spec_set_state(MirWindowSpec *spec, MirWindowState state)
Set the requested state.
void mir_window_spec_add_render_surface(MirWindowSpec *spec, MirRenderSurface *render_surface, int logical_width, int logical_height, int displacement_x, int displacement_y) MIR_DEPRECATE_RENDERSURFACES_FOR_RENAME
Set the MirWindowSpec to display content contained in a render surface.
void mir_window_spec_set_shell_chrome(MirWindowSpec *spec, MirShellChrome style)
Ask the shell to customize "chrome" for this window.
MirWindowState
Definition: common.h:142
MirWindowSpec * mir_create_menu_window_spec(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge)
Create a window specification for a menu window.
MirWindowSpec * mir_create_window_spec(MirConnection *connection)
Create a window specification.
MirWindowSpec * mir_create_input_method_window_spec(MirConnection *connection, int width, int height)
Create a window specification for an input method window.
MirPlacementGravity
Reference point for aligning a surface relative to a rectangle.
Definition: common.h:318
void mir_window_spec_set_fullscreen_on_output(MirWindowSpec *spec, uint32_t output_id)
MirWindowSpec * mir_create_satellite_window_spec(MirConnection *connection, int width, int height, MirWindow *parent)
Create a window specification for a satellite window.
void mir_window_spec_set_event_handler(MirWindowSpec *spec, MirWindowEventCallback callback, void *context)
Set the event handler to be called when events arrive for a window.
struct MirSurfaceSpec MirWindowSpec
Definition: client_types.h:45
void mir_window_spec_set_height(MirWindowSpec *spec, unsigned height)
Set the requested height, in pixels.
MirEdgeAttachment
Definition: common.h:305
MirWindowSpec * mir_create_tip_window_spec(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge)
Create a window specification for a tip window.
void mir_window_spec_set_name(MirWindowSpec *spec, char const *name)
Set the requested name.
MirPlacementHints
Positioning hints for aligning a window relative to a rectangle.
Definition: common.h:373
MirWindowSpec * mir_create_normal_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a normal window.
void mir_window_spec_set_width_increment(MirWindowSpec *spec, unsigned width_inc)
Set the requested width increment, in pixels.
void mir_window_spec_set_min_width(MirWindowSpec *spec, unsigned min_width)
Set the minimum width, in pixels.
MirWindow * mir_create_window_sync(MirWindowSpec *requested_specification)
Create a window from a given specification and wait for the result.
void(* MirWindowCallback)(MirWindow *window, void *client_context)
Callback to be passed when calling window functions :
Definition: client_types.h:100
struct MirRenderSurface MirRenderSurface
Definition: client_types.h:57
struct MirConnection MirConnection
Definition: client_types.h:41
void mir_window_spec_set_min_height(MirWindowSpec *spec, unsigned min_height)
Set the minimum height, in pixels.
void mir_window_spec_set_height_increment(MirWindowSpec *spec, unsigned height_inc)
Set the requested height increment, in pixels Defines an arithmetic progression of sizes starting wit...
MirWindowSpec * mir_create_gloss_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a gloss window.
void mir_window_spec_set_parent(MirWindowSpec *spec, MirWindow *parent)
Set the requested parent.
void mir_window_spec_set_max_width(MirWindowSpec *spec, unsigned max_width)
Set the maximum width, in pixels.
void mir_window_spec_set_placement(MirWindowSpec *spec, const MirRectangle *rect, MirPlacementGravity rect_gravity, MirPlacementGravity window_gravity, MirPlacementHints placement_hints, int offset_dx, int offset_dy)
Set the window placement on the spec.
void mir_surface_spec_release(WindowSpec const &spec)=delete
void mir_window_spec_release(WindowSpec const &spec)=delete
Definition: splash_session.h:24
Definition: client_types.h:399

Copyright © 2012-2022 Canonical Ltd.
Generated on Sun Oct 9 06:13:38 UTC 2022
This documentation is licensed under the GPL version 2 or 3.