Debian Codegraph @

thirdparty/linuxbsd_headers/libdecor-0/libdecor.h

raw symbols SCIP
1 /*
2 * Copyright © 2017-2018 Red Hat Inc.
3 * Copyright © 2018 Jonas Ådahl
4 * Copyright © 2019 Christian Rauch
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining
7 * a copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sublicense, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial
16 * portions of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
21 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
22 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
23 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * SOFTWARE.
26 */
27
28 #ifndef LIBDECOR_H
29 #define LIBDECOR_H
30
31 #include <stdbool.h>
32 #include <wayland-client.h>
33
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37
38 #if defined(__GNUC__) && __GNUC__ >= 4
39 #define LIBDECOR_EXPORT __attribute__ ((visibility("default")))
40 #else
41 #define LIBDECOR_EXPORT
42 #endif
43
44 struct xdg_toplevel;
45
46 /** \class libdecor
47 *
48 * \brief A libdecor context instance.
49 */
50 struct libdecor;
51
52 /** \class libdecor_frame
53 *
54 * \brief A frame used for decorating a Wayland surface.
55 */
56 struct libdecor_frame;
57
58 /** \class libdecor_configuration
59 *
60 * \brief An object representing a toplevel window configuration.
61 */
62 struct libdecor_configuration;
63
64 /** \class libdecor_state
65 *
66 * \brief An object corresponding to a configured content state.
67 */
68 struct libdecor_state;
69
70 enum libdecor_error {
71 LIBDECOR_ERROR_COMPOSITOR_INCOMPATIBLE,
72 LIBDECOR_ERROR_INVALID_FRAME_CONFIGURATION,
73 };
74
75 enum libdecor_window_state {
76 LIBDECOR_WINDOW_STATE_NONE = 0,
77 LIBDECOR_WINDOW_STATE_ACTIVE = 1 << 0,
78 LIBDECOR_WINDOW_STATE_MAXIMIZED = 1 << 1,
79 LIBDECOR_WINDOW_STATE_FULLSCREEN = 1 << 2,
80 LIBDECOR_WINDOW_STATE_TILED_LEFT = 1 << 3,
81 LIBDECOR_WINDOW_STATE_TILED_RIGHT = 1 << 4,
82 LIBDECOR_WINDOW_STATE_TILED_TOP = 1 << 5,
83 LIBDECOR_WINDOW_STATE_TILED_BOTTOM = 1 << 6,
84 LIBDECOR_WINDOW_STATE_SUSPENDED = 1 << 7,
85 };
86
87 enum libdecor_resize_edge {
88 LIBDECOR_RESIZE_EDGE_NONE,
89 LIBDECOR_RESIZE_EDGE_TOP,
90 LIBDECOR_RESIZE_EDGE_BOTTOM,
91 LIBDECOR_RESIZE_EDGE_LEFT,
92 LIBDECOR_RESIZE_EDGE_TOP_LEFT,
93 LIBDECOR_RESIZE_EDGE_BOTTOM_LEFT,
94 LIBDECOR_RESIZE_EDGE_RIGHT,
95 LIBDECOR_RESIZE_EDGE_TOP_RIGHT,
96 LIBDECOR_RESIZE_EDGE_BOTTOM_RIGHT,
97 };
98
99 enum libdecor_capabilities {
100 LIBDECOR_ACTION_MOVE = 1 << 0,
101 LIBDECOR_ACTION_RESIZE = 1 << 1,
102 LIBDECOR_ACTION_MINIMIZE = 1 << 2,
103 LIBDECOR_ACTION_FULLSCREEN = 1 << 3,
104 LIBDECOR_ACTION_CLOSE = 1 << 4,
105 };
106
107 struct libdecor_interface {
108 /**
109 * An error event
110 */
111 void (* error)(struct libdecor *context,
112 enum libdecor_error error,
113 const char *message);
114
115 /* Reserved */
116 void (* reserved0)(void);
117 void (* reserved1)(void);
118 void (* reserved2)(void);
119 void (* reserved3)(void);
120 void (* reserved4)(void);
121 void (* reserved5)(void);
122 void (* reserved6)(void);
123 void (* reserved7)(void);
124 void (* reserved8)(void);
125 void (* reserved9)(void);
126 };
127
128 /**
129 * Interface for integrating a Wayland surface with libdecor.
130 */
131 struct libdecor_frame_interface {
132 /**
133 * A new configuration was received. An application should respond to
134 * this by creating a suitable libdecor_state, and apply it using
135 * libdecor_frame_commit.
136 */
137 void (* configure)(struct libdecor_frame *frame,
138 struct libdecor_configuration *configuration,
139 void *user_data);
140
141 /**
142 * The window was requested to be closed by the compositor.
143 */
144 void (* close)(struct libdecor_frame *frame,
145 void *user_data);
146
147 /**
148 * The window decoration asked to have the main surface to be
149 * committed. This is required when the decoration is implemented using
150 * synchronous subsurfaces.
151 */
152 void (* commit)(struct libdecor_frame *frame,
153 void *user_data);
154
155 /**
156 * Any mapped popup that has a grab on the given seat should be
157 * dismissed.
158 */
159 void (* dismiss_popup)(struct libdecor_frame *frame,
160 const char *seat_name,
161 void *user_data);
162
163 /* Reserved */
164 void (* reserved0)(void);
165 void (* reserved1)(void);
166 void (* reserved2)(void);
167 void (* reserved3)(void);
168 void (* reserved4)(void);
169 void (* reserved5)(void);
170 void (* reserved6)(void);
171 void (* reserved7)(void);
172 void (* reserved8)(void);
173 void (* reserved9)(void);
174 };
175
176 /**
177 * Remove a reference to the libdecor instance. When the reference count
178 * reaches zero, it is freed.
179 */
180 void
181 libdecor_unref(struct libdecor *context);
182
183 /**
184 * Create a new libdecor context for the given wl_display.
185 */
186 struct libdecor *
187 libdecor_new(struct wl_display *display,
188 struct libdecor_interface *iface);
189
190 /**
191 * Get the file descriptor used by libdecor. This is similar to
192 * wl_display_get_fd(), thus should be polled, and when data is available,
193 * libdecor_dispatch() should be called.
194 */
195 int
196 libdecor_get_fd(struct libdecor *context);
197
198 /**
199 * Dispatch events. This function should be called when data is available on
200 * the file descriptor returned by libdecor_get_fd(). If timeout is zero, this
201 * function will never block.
202 */
203 int
204 libdecor_dispatch(struct libdecor *context,
205 int timeout);
206
207 /**
208 * Decorate the given content wl_surface.
209 *
210 * This will create an xdg_surface and an xdg_toplevel, and integrate it
211 * properly with the windowing system, including creating appropriate
212 * decorations when needed, as well as handle windowing integration events such
213 * as resizing, moving, maximizing, etc.
214 *
215 * The passed wl_surface should only contain actual application content,
216 * without any window decoration.
217 */
218 struct libdecor_frame *
219 libdecor_decorate(struct libdecor *context,
220 struct wl_surface *surface,
221 struct libdecor_frame_interface *iface,
222 void *user_data);
223
224 /**
225 * Add a reference to the frame object.
226 */
227 void
228 libdecor_frame_ref(struct libdecor_frame *frame);
229
230 /**
231 * Remove a reference to the frame object. When the reference count reaches
232 * zero, the frame object is destroyed.
233 */
234 void
235 libdecor_frame_unref(struct libdecor_frame *frame);
236
237 /**
238 * Set the visibility of the frame.
239 *
240 * If an application wants to be borderless, it can set the frame visibility to
241 * false.
242 */
243 void
244 libdecor_frame_set_visibility(struct libdecor_frame *frame,
245 bool visible);
246
247 /**
248 * Get the visibility of the frame.
249 */
250 bool
251 libdecor_frame_is_visible(struct libdecor_frame *frame);
252
253
254 /**
255 * Set the parent of the window.
256 *
257 * This can be used to stack multiple toplevel windows above or under each
258 * other.
259 */
260 void
261 libdecor_frame_set_parent(struct libdecor_frame *frame,
262 struct libdecor_frame *parent);
263
264 /**
265 * Set the title of the window.
266 */
267 void
268 libdecor_frame_set_title(struct libdecor_frame *frame,
269 const char *title);
270
271 /**
272 * Get the title of the window.
273 */
274 const char *
275 libdecor_frame_get_title(struct libdecor_frame *frame);
276
277 /**
278 * Set the application ID of the window.
279 */
280 void
281 libdecor_frame_set_app_id(struct libdecor_frame *frame,
282 const char *app_id);
283
284 /**
285 * Set new capabilities of the window.
286 *
287 * This determines whether e.g. a window decoration should show a maximize
288 * button, etc.
289 *
290 * Setting a capability does not implicitly unset any other.
291 */
292 void
293 libdecor_frame_set_capabilities(struct libdecor_frame *frame,
294 enum libdecor_capabilities capabilities);
295
296 /**
297 * Unset capabilities of the window.
298 *
299 * The opposite of libdecor_frame_set_capabilities.
300 */
301 void
302 libdecor_frame_unset_capabilities(struct libdecor_frame *frame,
303 enum libdecor_capabilities capabilities);
304
305 /**
306 * Check whether the window has any of the given capabilities.
307 */
308 bool
309 libdecor_frame_has_capability(struct libdecor_frame *frame,
310 enum libdecor_capabilities capability);
311
312 /**
313 * Show the window menu.
314 */
315 void
316 libdecor_frame_show_window_menu(struct libdecor_frame *frame,
317 struct wl_seat *wl_seat,
318 uint32_t serial,
319 int x,
320 int y);
321
322 /**
323 * Issue a popup grab on the window. Call this when a xdg_popup is mapped, so
324 * that it can be properly dismissed by the decorations.
325 */
326 void
327 libdecor_frame_popup_grab(struct libdecor_frame *frame,
328 const char *seat_name);
329
330 /**
331 * Release the popup grab. Call this when you unmap a popup.
332 */
333 void
334 libdecor_frame_popup_ungrab(struct libdecor_frame *frame,
335 const char *seat_name);
336
337 /**
338 * Translate content surface local coordinates to toplevel window local
339 * coordinates.
340 *
341 * This can be used to translate surface coordinates to coordinates useful for
342 * e.g. showing the window menu, or positioning a popup.
343 */
344 void
345 libdecor_frame_translate_coordinate(struct libdecor_frame *frame,
346 int surface_x,
347 int surface_y,
348 int *frame_x,
349 int *frame_y);
350
351 /**
352 * Set the min content size.
353 *
354 * This translates roughly to xdg_toplevel_set_min_size().
355 */
356 void
357 libdecor_frame_set_min_content_size(struct libdecor_frame *frame,
358 int content_width,
359 int content_height);
360
361 /**
362 * Set the max content size.
363 *
364 * This translates roughly to xdg_toplevel_set_max_size().
365 */
366 void
367 libdecor_frame_set_max_content_size(struct libdecor_frame *frame,
368 int content_width,
369 int content_height);
370
371 /**
372 * Get the min content size.
373 */
374 void
375 libdecor_frame_get_min_content_size(const struct libdecor_frame *frame,
376 int *content_width,
377 int *content_height);
378
379 /**
380 * Get the max content size.
381 */
382 void
383 libdecor_frame_get_max_content_size(const struct libdecor_frame *frame,
384 int *content_width,
385 int *content_height);
386
387 /**
388 * Initiate an interactive resize.
389 *
390 * This roughly translates to xdg_toplevel_resize().
391 */
392 void
393 libdecor_frame_resize(struct libdecor_frame *frame,
394 struct wl_seat *wl_seat,
395 uint32_t serial,
396 enum libdecor_resize_edge edge);
397
398 /**
399 * Initiate an interactive move.
400 *
401 * This roughly translates to xdg_toplevel_move().
402 */
403 void
404 libdecor_frame_move(struct libdecor_frame *frame,
405 struct wl_seat *wl_seat,
406 uint32_t serial);
407
408 /**
409 * Commit a new window state. This can be called on application driven resizes
410 * when the window is floating, or in response to received configurations, i.e.
411 * from e.g. interactive resizes or state changes.
412 */
413 void
414 libdecor_frame_commit(struct libdecor_frame *frame,
415 struct libdecor_state *state,
416 struct libdecor_configuration *configuration);
417
418 /**
419 * Minimize the window.
420 *
421 * Roughly translates to xdg_toplevel_set_minimized().
422 */
423 void
424 libdecor_frame_set_minimized(struct libdecor_frame *frame);
425
426 /**
427 * Maximize the window.
428 *
429 * Roughly translates to xdg_toplevel_set_maximized().
430 */
431 void
432 libdecor_frame_set_maximized(struct libdecor_frame *frame);
433
434 /**
435 * Unmaximize the window.
436 *
437 * Roughly translates to xdg_toplevel_unset_maximized().
438 */
439 void
440 libdecor_frame_unset_maximized(struct libdecor_frame *frame);
441
442 /**
443 * Fullscreen the window.
444 *
445 * Roughly translates to xdg_toplevel_set_fullscreen().
446 */
447 void
448 libdecor_frame_set_fullscreen(struct libdecor_frame *frame,
449 struct wl_output *output);
450
451 /**
452 * Unfullscreen the window.
453 *
454 * Roughly translates to xdg_toplevel_unset_unfullscreen().
455 */
456 void
457 libdecor_frame_unset_fullscreen(struct libdecor_frame *frame);
458
459 /**
460 * Return true if the window is floating.
461 *
462 * A window is floating when it's not maximized, tiled, fullscreen, or in any
463 * similar way with a fixed size and state.
464 * Note that this function uses the "applied" configuration. If this function
465 * is used in the 'configure' callback, the provided configuration has to be
466 * applied via 'libdecor_frame_commit' first, before it will reflect the current
467 * window state from the provided configuration.
468 */
469 bool
470 libdecor_frame_is_floating(struct libdecor_frame *frame);
471
472 /**
473 * Close the window.
474 *
475 * Roughly translates to xdg_toplevel_close().
476 */
477 void
478 libdecor_frame_close(struct libdecor_frame *frame);
479
480 /**
481 * Map the window.
482 *
483 * This will eventually result in the initial configure event.
484 */
485 void
486 libdecor_frame_map(struct libdecor_frame *frame);
487
488 /**
489 * Get the associated xdg_surface for content wl_surface.
490 */
491 struct xdg_surface *
492 libdecor_frame_get_xdg_surface(struct libdecor_frame *frame);
493
494 /**
495 * Get the associated xdg_toplevel for the content wl_surface.
496 */
497 struct xdg_toplevel *
498 libdecor_frame_get_xdg_toplevel(struct libdecor_frame *frame);
499
500 /**
501 * Create a new content surface state.
502 */
503 struct libdecor_state *
504 libdecor_state_new(int width,
505 int height);
506
507 /**
508 * Free a content surface state.
509 */
510 void
511 libdecor_state_free(struct libdecor_state *state);
512
513 /**
514 * Get the expected size of the content for this configuration.
515 *
516 * If the configuration doesn't contain a size, false is returned.
517 */
518 bool
519 libdecor_configuration_get_content_size(struct libdecor_configuration *configuration,
520 struct libdecor_frame *frame,
521 int *width,
522 int *height);
523
524 /**
525 * Get the window state for this configuration.
526 *
527 * If the configuration doesn't contain any associated window state, false is
528 * returned, and the application should assume the window state remains
529 * unchanged.
530 */
531 bool
532 libdecor_configuration_get_window_state(struct libdecor_configuration *configuration,
533 enum libdecor_window_state *window_state);
534
535 #ifdef __cplusplus
536 }
537 #endif
538
539 #endif /* LIBDECOR_H */