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 
25 #include <mir_toolkit/mir_window.h>
26 #include <mir_toolkit/version.h>
28 
29 #include <memory>
30 
31 namespace mir
32 {
33 namespace client
34 {
37 {
38 public:
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 #if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
94  return WindowSpec{mir_create_satellite_window_spec(connection, width, height, parent)};
95 #else
96  // There's no mir_create_satellite_window_spec()
97  auto spec = WindowSpec{mir_create_window_spec(connection)}
98  .set_size(width, height)
99  .set_type(mir_window_type_satellite)
100  .set_parent(parent);
101 
102  mir_window_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); // Required protobuf field for create_window()
103  mir_window_spec_set_pixel_format(spec, mir_pixel_format_invalid); // Required protobuf field for create_window()
104  return spec;
105 #endif
106  }
107 
108  static auto for_gloss(MirConnection* connection, int width, int height)
109  {
110 #if MIR_CLIENT_API_VERSION >= MIR_VERSION_NUMBER(0, 27, 0)
111  return WindowSpec{mir_create_gloss_window_spec(connection, width, height)};
112 #else
113  // There's no mir_create_gloss_window_spec()
114  auto spec = WindowSpec{mir_create_window_spec(connection)}
115  .set_size(width, height)
116  .set_type(mir_window_type_gloss);
117 
118  mir_window_spec_set_buffer_usage(spec, mir_buffer_usage_hardware); // Required protobuf field for create_window()
119  mir_window_spec_set_pixel_format(spec, mir_pixel_format_invalid); // Required protobuf field for create_window()
120  return spec;
121 #endif
122  }
123 
124  static auto for_changes(MirConnection* connection) -> WindowSpec
125  {
126  return WindowSpec{mir_create_window_spec(connection)};
127  }
128 
130  {
131  mir_window_spec_set_type(*this, type);
132  return *this;
133  }
134 
136  {
137  mir_window_spec_set_shell_chrome(*this, chrome);
138  return *this;
139  }
140 
141  auto set_min_size(int min_width, int min_height) -> WindowSpec&
142  {
143  mir_window_spec_set_min_width(*this, min_width);
144  mir_window_spec_set_min_height(*this, min_height);
145  return *this;
146  }
147 
148  auto set_max_size(int max_width, int max_height) -> WindowSpec&
149  {
150  mir_window_spec_set_max_width(*this, max_width);
151  mir_window_spec_set_max_height(*this, max_height);
152  return *this;
153  }
154 
155  auto set_size_inc(int width_inc, int height_inc) -> WindowSpec&
156  {
157  mir_window_spec_set_width_increment(*this, width_inc);
158  mir_window_spec_set_height_increment(*this, height_inc);
159  return *this;
160  }
161 
162  auto set_size(int width, int height) -> WindowSpec&
163  {
166  return *this;
167  }
168 
169  auto set_name(char const* name) -> WindowSpec&
170  {
172  return *this;
173  }
174 
175  auto set_event_handler(MirWindowEventCallback callback, void* context) -> WindowSpec&
176  {
177  mir_window_spec_set_event_handler(*this, callback, context);
178  return *this;
179  }
180 
182  {
184  return *this;
185  }
186 
187  auto set_placement(const MirRectangle* rect,
188  MirPlacementGravity rect_gravity,
189  MirPlacementGravity surface_gravity,
190  MirPlacementHints placement_hints,
191  int offset_dx,
192  int offset_dy) -> WindowSpec&
193  {
194  mir_window_spec_set_placement(*this, rect, rect_gravity, surface_gravity, placement_hints, offset_dx, offset_dy);
195  return *this;
196  }
197 
198  auto set_parent(MirWindow* parent) -> WindowSpec&
199  {
200  mir_window_spec_set_parent(*this, parent);
201  return *this;
202  }
203 
205  {
206  mir_window_spec_set_state(*this, state);
207  return *this;
208  }
209 
210  auto add_surface(MirRenderSurface* surface, int width, int height, int displacement_x, int displacement_y)
211  -> WindowSpec&
212  {
213 #if MIR_CLIENT_API_VERSION < MIR_VERSION_NUMBER(0, 27, 0)
214 #pragma GCC diagnostic push
215 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
216 #endif
217  mir_window_spec_add_render_surface(*this, surface, width, height, displacement_x, displacement_y);
218 #if MIR_CLIENT_API_VERSION < MIR_VERSION_NUMBER(0, 27, 0)
219 #pragma GCC diagnostic pop
220 #endif
221  return *this;
222  }
223 
224  template<typename Context>
225  void create_window(void (* callback)(MirWindow*, Context*), Context* context) const
226  {
227  mir_create_window(*this, reinterpret_cast<MirWindowCallback>(callback), context);
228  }
229 
230  auto create_window() const -> Window
231  {
232  return Window{mir_create_window_sync(*this)};
233  }
234 
235  void apply_to(MirWindow* window) const
236  {
237  mir_window_apply_spec(window, *this);
238  }
239 
240  operator MirWindowSpec*() const { return self.get(); }
241 
242 private:
243  static void deleter(MirWindowSpec* spec) { mir_window_spec_release(spec); }
244  std::shared_ptr<MirWindowSpec> self;
245 };
246 
247 // Provide a deleted overload to avoid double release "accidents".
248 void mir_window_spec_release(WindowSpec const& spec) = delete;
249 void mir_surface_spec_release(WindowSpec const& spec) = delete;
250 }
251 }
252 
253 #endif //MIRAL_TOOLKIT_WINDOW_SPEC_H_H
AutoUnblockThread is a helper thread class that can gracefully shutdown at destruction time...
Definition: blob.h:26
static auto for_input_method(MirConnection *connection, int width, int height, MirWindow *parent)
Definition: window_spec.h:84
void mir_window_spec_set_min_width(MirWindowSpec *spec, unsigned min_width)
Set the minimum width, in pixels.
struct MirSurface MirWindow
Definition: client_types.h:43
static auto for_satellite(MirConnection *connection, int width, int height, MirWindow *parent)
Definition: window_spec.h:91
void mir_create_window(MirWindowSpec *requested_specification, MirWindowCallback callback, void *context)
Create a window from a given specification.
static auto for_dialog(MirConnection *connection, int width, int height, MirWindow *parent) -> WindowSpec
Definition: window_spec.h:76
void mir_window_spec_set_min_height(MirWindowSpec *spec, unsigned min_height)
Set the minimum height, in pixels.
void mir_window_spec_set_width_increment(MirWindowSpec *spec, unsigned width_inc)
Set the requested width increment, in pixels.
MirPlacementHints
Positioning hints for aligning a window relative to a rectangle.
Definition: common.h:369
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.
void mir_window_spec_set_width(MirWindowSpec *spec, unsigned width)
Set the requested width, in pixels.
auto set_state(MirWindowState state) -> WindowSpec &
Definition: window_spec.h:204
auto set_type(MirWindowType type) -> WindowSpec &
Definition: window_spec.h:129
void create_window(void(*callback)(MirWindow *, Context *), Context *context) const
Definition: window_spec.h:225
MirWindowSpec * mir_create_satellite_window_spec(MirConnection *connection, int width, int height, MirWindow *parent)
Create a window specification for a satellite window.
Definition: common.h:243
void mir_window_spec_set_max_width(MirWindowSpec *spec, unsigned max_width)
Set the maximum width, in pixels.
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.
int height
Definition: client_types.h:179
void mir_window_spec_set_fullscreen_on_output(MirWindowSpec *spec, uint32_t output_id)
auto set_max_size(int max_width, int max_height) -> WindowSpec &
Definition: window_spec.h:148
MirWindowSpec * mir_create_window_spec(MirConnection *connection)
Create a window specification.
auto set_event_handler(MirWindowEventCallback callback, void *context) -> WindowSpec &
Definition: window_spec.h:175
auto set_min_size(int min_width, int min_height) -> WindowSpec &
Definition: window_spec.h:141
void mir_window_spec_set_max_height(MirWindowSpec *spec, unsigned max_height)
Set the maximum height, in pixels.
MirWindowSpec * mir_create_normal_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a normal window.
static auto for_changes(MirConnection *connection) -> WindowSpec
Definition: window_spec.h:124
MirWindow * mir_create_window_sync(MirWindowSpec *requested_specification)
Create a window from a given specification and wait for the result.
Handle class for MirWindow - provides automatic reference counting.
Definition: window.h:31
auto set_parent(MirWindow *parent) -> WindowSpec &
Definition: window_spec.h:198
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:187
static auto for_tip(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge) -> WindowSpec
Definition: window_spec.h:57
void mir_window_spec_set_height(MirWindowSpec *spec, unsigned height)
Set the requested height, in pixels.
MirWindowSpec * mir_create_input_method_window_spec(MirConnection *connection, int width, int height)
Create a window specification for an input method window.
void mir_window_apply_spec(MirWindow *window, MirWindowSpec *spec)
Request changes to the specification of a window.
auto set_shell_chrome(MirShellChrome chrome) -> WindowSpec &
Definition: window_spec.h:135
auto add_surface(MirRenderSurface *surface, int width, int height, int displacement_x, int displacement_y) -> WindowSpec &
Definition: window_spec.h:210
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.
void mir_window_spec_set_type(MirWindowSpec *spec, MirWindowType type)
Update a window specification with a window type.
struct MirConnection MirConnection
Definition: client_types.h:41
MirWindowType
Definition: common.h:109
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...
void mir_window_spec_set_state(MirWindowSpec *spec, MirWindowState state)
Set the requested state.
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.
struct MirSurfaceSpec MirWindowSpec
Definition: client_types.h:45
MirWindowSpec * mir_create_dialog_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a parentless dialog window.
static auto for_menu(MirConnection *connection, int width, int height, MirWindow *parent, MirRectangle *rect, MirEdgeAttachment edge) -> WindowSpec
Definition: window_spec.h:46
auto set_size(int width, int height) -> WindowSpec &
Definition: window_spec.h:162
auto set_name(char const *name) -> WindowSpec &
Definition: window_spec.h:169
Handle class for MirWindowSpec - provides automatic reference counting, method chaining.
Definition: window_spec.h:36
void mir_window_spec_release(WindowSpec const &spec)=delete
void apply_to(MirWindow *window) const
Definition: window_spec.h:235
MirShellChrome
Shell chrome.
Definition: common.h:454
Definition: common.h:114
auto create_window() const -> Window
Definition: window_spec.h:230
static auto for_normal_window(MirConnection *connection, int width, int height) -> WindowSpec
Definition: window_spec.h:41
void(* MirWindowEventCallback)(MirWindow *window, MirEvent const *event, void *context)
Callback for handling of window events.
Definition: client_types.h:120
mir_buffer_usage_hardware
Definition: client_types.h:177
void mir_window_spec_set_buffer_usage(MirWindowSpec *spec, MirBufferUsage usage) MIR_FOR_REMOVAL_IN_VERSION_1("No longer applicable
char const * name
Definition: client_types.h:177
WindowSpec(MirWindowSpec *spec)
Definition: window_spec.h:39
void mir_window_spec_set_pixel_format(MirWindowSpec *spec, MirPixelFormat format) MIR_FOR_REMOVAL_IN_VERSION_1("Use mir_connection_allocate_buffer/mir_render_surface_get_buffer_stream instead")
Set the requested pixel format.
Definition: client_types.h:398
void mir_window_spec_set_parent(MirWindowSpec *spec, MirWindow *parent)
Set the requested parent.
void mir_window_spec_set_shell_chrome(MirWindowSpec *spec, MirShellChrome style)
Ask the shell to customize "chrome" for this window.
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.
uint32_t output_id
The id of the output to place the surface in.
Definition: client_types.h:194
void mir_surface_spec_release(WindowSpec const &spec)=delete
static auto for_dialog(MirConnection *connection, int width, int height) -> WindowSpec
Definition: window_spec.h:68
MirWindowState
Definition: common.h:139
int width
Definition: client_types.h:178
void mir_window_spec_set_name(MirWindowSpec *spec, char const *name)
Set the requested name.
AKA "toolbox"/"toolbar".
Definition: common.h:118
auto set_fullscreen_on_output(uint32_t output_id) -> WindowSpec &
Definition: window_spec.h:181
struct MirRenderSurface MirRenderSurface
Definition: client_types.h:57
MirWindowSpec * mir_create_gloss_window_spec(MirConnection *connection, int width, int height)
Create a window specification for a gloss window.
MirPlacementGravity
Reference point for aligning a surface relative to a rectangle.
Definition: common.h:314
auto set_size_inc(int width_inc, int height_inc) -> WindowSpec &
Definition: window_spec.h:155
MirEdgeAttachment
Definition: common.h:301
static auto for_gloss(MirConnection *connection, int width, int height)
Definition: window_spec.h:108

Copyright © 2012-2018 Canonical Ltd.
Generated on Thu Mar 15 13:04:52 UTC 2018