logo

inaban

Distrustful Wayland Compositor (inspired by XMonad and dwm) git clone https://hacktivis.me/git/inaban.git

xdg-decoration.c (1925B)


  1. // SPDX-FileCopyrightText: 2019-2022 inaban Authors <https://hacktivis.me/git/inaban>
  2. // SPDX-License-Identifier: BSD-3-Clause
  3. #include "inaban.h"
  4. #include <stdlib.h> // free()
  5. struct inaban_xdg_decoration
  6. {
  7. struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration;
  8. struct inaban_server *server;
  9. struct wl_listener destroy;
  10. struct wl_listener request_mode;
  11. };
  12. static void
  13. xdg_decoration_handle_destroy(struct wl_listener *listener, void *data)
  14. {
  15. (void)data;
  16. struct inaban_xdg_decoration *xdg_decoration = wl_container_of(listener, xdg_decoration, destroy);
  17. wl_list_remove(&xdg_decoration->destroy.link);
  18. wl_list_remove(&xdg_decoration->request_mode.link);
  19. free(xdg_decoration);
  20. }
  21. static void
  22. xdg_decoration_handle_request_mode(struct wl_listener *listener, void *data)
  23. {
  24. (void)data;
  25. struct inaban_xdg_decoration *xdg_decoration =
  26. wl_container_of(listener, xdg_decoration, request_mode);
  27. wlr_xdg_toplevel_decoration_v1_set_mode(xdg_decoration->wlr_decoration,
  28. WLR_XDG_TOPLEVEL_DECORATION_V1_MODE_SERVER_SIDE);
  29. }
  30. void
  31. handle_xdg_toplevel_decoration(struct wl_listener *listener, void *data)
  32. {
  33. struct inaban_server *server = wl_container_of(listener, server, xdg_toplevel_decoration);
  34. struct wlr_xdg_toplevel_decoration_v1 *wlr_decoration = data;
  35. struct inaban_xdg_decoration *xdg_decoration = calloc(1, sizeof(struct inaban_xdg_decoration));
  36. if(!xdg_decoration)
  37. {
  38. return;
  39. }
  40. xdg_decoration->wlr_decoration = wlr_decoration;
  41. xdg_decoration->server = server;
  42. xdg_decoration->destroy.notify = xdg_decoration_handle_destroy;
  43. wl_signal_add(&wlr_decoration->events.destroy, &xdg_decoration->destroy);
  44. xdg_decoration->request_mode.notify = xdg_decoration_handle_request_mode;
  45. wl_signal_add(&wlr_decoration->events.request_mode, &xdg_decoration->request_mode);
  46. xdg_decoration_handle_request_mode(&xdg_decoration->request_mode, wlr_decoration);
  47. }