zxdg_output_manager.cc 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. // Copyright 2021 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4. #include "components/exo/wayland/zxdg_output_manager.h"
  5. #include <xdg-output-unstable-v1-server-protocol.h>
  6. #include "components/exo/wayland/server_util.h"
  7. #include "components/exo/wayland/wayland_display_observer.h"
  8. namespace exo {
  9. namespace wayland {
  10. ////////////////////////////////////////////////////////////////////////////////
  11. // zxdg_output_v1_interface
  12. void xdg_output_destroy(wl_client* client, wl_resource* resource) {
  13. WaylandDisplayHandler* handler =
  14. GetUserDataAs<WaylandDisplayHandler>(resource);
  15. if (handler)
  16. handler->UnsetXdgOutputResource();
  17. wl_resource_destroy(resource);
  18. }
  19. const struct zxdg_output_v1_interface xdg_output_implementation = {
  20. xdg_output_destroy};
  21. ////////////////////////////////////////////////////////////////////////////////
  22. // zxdg_output_manager_v1_interface
  23. void xdg_output_manager_destroy(wl_client* client, wl_resource* resource) {
  24. wl_resource_destroy(resource);
  25. }
  26. void xdg_output_manager_get_xdg_output(wl_client* client,
  27. wl_resource* manager,
  28. uint32_t id,
  29. wl_resource* output_resource) {
  30. uint32_t version = wl_resource_get_version(manager);
  31. wl_resource* resource =
  32. wl_resource_create(client, &zxdg_output_v1_interface, version, id);
  33. if (!resource) {
  34. wl_client_post_no_memory(client);
  35. return;
  36. }
  37. WaylandDisplayHandler* handler =
  38. GetUserDataAs<WaylandDisplayHandler>(output_resource);
  39. if (handler) {
  40. wl_resource_set_implementation(resource, &xdg_output_implementation,
  41. handler, nullptr);
  42. handler->OnXdgOutputCreated(resource);
  43. }
  44. }
  45. const struct zxdg_output_manager_v1_interface
  46. xdg_output_manager_implementation = {xdg_output_manager_destroy,
  47. xdg_output_manager_get_xdg_output};
  48. void bind_zxdg_output_manager(wl_client* client,
  49. void* data,
  50. uint32_t version,
  51. uint32_t id) {
  52. wl_resource* resource = wl_resource_create(
  53. client, &zxdg_output_manager_v1_interface, version, id);
  54. if (!resource) {
  55. wl_client_post_no_memory(client);
  56. return;
  57. }
  58. wl_resource_set_implementation(resource, &xdg_output_manager_implementation,
  59. data, nullptr);
  60. }
  61. } // namespace wayland
  62. } // namespace exo