libdecor.h 13 KB

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