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