zcr_cursor_shapes.cc 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. // Copyright 2018 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/zcr_cursor_shapes.h"
  5. #include <cursor-shapes-unstable-v1-server-protocol.h>
  6. #include <wayland-server-core.h>
  7. #include <wayland-server-protocol-core.h>
  8. #include "components/exo/pointer.h"
  9. #include "components/exo/wayland/server_util.h"
  10. #include "ui/base/cursor/mojom/cursor_type.mojom-shared.h"
  11. namespace exo {
  12. namespace wayland {
  13. namespace {
  14. ////////////////////////////////////////////////////////////////////////////////
  15. // cursor_shapes interface:
  16. static ui::mojom::CursorType GetCursorType(int32_t cursor_shape) {
  17. switch (cursor_shape) {
  18. #define ADD_CASE(wayland, chrome) \
  19. case ZCR_CURSOR_SHAPES_V1_CURSOR_SHAPE_TYPE_##wayland: \
  20. return ui::mojom::CursorType::chrome
  21. ADD_CASE(POINTER, kPointer);
  22. ADD_CASE(CROSS, kCross);
  23. ADD_CASE(HAND, kHand);
  24. ADD_CASE(IBEAM, kIBeam);
  25. ADD_CASE(WAIT, kWait);
  26. ADD_CASE(HELP, kHelp);
  27. ADD_CASE(EAST_RESIZE, kEastResize);
  28. ADD_CASE(NORTH_RESIZE, kNorthResize);
  29. ADD_CASE(NORTH_EAST_RESIZE, kNorthEastResize);
  30. ADD_CASE(NORTH_WEST_RESIZE, kNorthWestResize);
  31. ADD_CASE(SOUTH_RESIZE, kSouthResize);
  32. ADD_CASE(SOUTH_EAST_RESIZE, kSouthEastResize);
  33. ADD_CASE(SOUTH_WEST_RESIZE, kSouthWestResize);
  34. ADD_CASE(WEST_RESIZE, kWestResize);
  35. ADD_CASE(NORTH_SOUTH_RESIZE, kNorthSouthResize);
  36. ADD_CASE(EAST_WEST_RESIZE, kEastWestResize);
  37. ADD_CASE(NORTH_EAST_SOUTH_WEST_RESIZE, kNorthEastSouthWestResize);
  38. ADD_CASE(NORTH_WEST_SOUTH_EAST_RESIZE, kNorthWestSouthEastResize);
  39. ADD_CASE(COLUMN_RESIZE, kColumnResize);
  40. ADD_CASE(ROW_RESIZE, kRowResize);
  41. ADD_CASE(MIDDLE_PANNING, kMiddlePanning);
  42. ADD_CASE(EAST_PANNING, kEastPanning);
  43. ADD_CASE(NORTH_PANNING, kNorthPanning);
  44. ADD_CASE(NORTH_EAST_PANNING, kNorthEastPanning);
  45. ADD_CASE(NORTH_WEST_PANNING, kNorthWestPanning);
  46. ADD_CASE(SOUTH_PANNING, kSouthPanning);
  47. ADD_CASE(SOUTH_EAST_PANNING, kSouthEastPanning);
  48. ADD_CASE(SOUTH_WEST_PANNING, kSouthWestPanning);
  49. ADD_CASE(WEST_PANNING, kWestPanning);
  50. ADD_CASE(MOVE, kMove);
  51. ADD_CASE(VERTICAL_TEXT, kVerticalText);
  52. ADD_CASE(CELL, kCell);
  53. ADD_CASE(CONTEXT_MENU, kContextMenu);
  54. ADD_CASE(ALIAS, kAlias);
  55. ADD_CASE(PROGRESS, kProgress);
  56. ADD_CASE(NO_DROP, kNoDrop);
  57. ADD_CASE(COPY, kCopy);
  58. ADD_CASE(NONE, kNone);
  59. ADD_CASE(NOT_ALLOWED, kNotAllowed);
  60. ADD_CASE(ZOOM_IN, kZoomIn);
  61. ADD_CASE(ZOOM_OUT, kZoomOut);
  62. ADD_CASE(GRAB, kGrab);
  63. ADD_CASE(GRABBING, kGrabbing);
  64. ADD_CASE(DND_NONE, kDndNone);
  65. ADD_CASE(DND_MOVE, kDndMove);
  66. ADD_CASE(DND_COPY, kDndCopy);
  67. ADD_CASE(DND_LINK, kDndLink);
  68. #undef ADD_CASE
  69. default:
  70. return ui::mojom::CursorType::kNull;
  71. }
  72. }
  73. void cursor_shapes_set_cursor_shape(wl_client* client,
  74. wl_resource* resource,
  75. wl_resource* pointer_resource,
  76. int32_t shape) {
  77. ui::mojom::CursorType cursor_type = GetCursorType(shape);
  78. if (cursor_type == ui::mojom::CursorType::kNull) {
  79. wl_resource_post_error(resource, ZCR_CURSOR_SHAPES_V1_ERROR_INVALID_SHAPE,
  80. "Unrecognized shape %d", shape);
  81. return;
  82. }
  83. Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource);
  84. pointer->SetCursorType(cursor_type);
  85. }
  86. const struct zcr_cursor_shapes_v1_interface cursor_shapes_implementation = {
  87. cursor_shapes_set_cursor_shape};
  88. } // namespace
  89. void bind_cursor_shapes(wl_client* client,
  90. void* data,
  91. uint32_t version,
  92. uint32_t id) {
  93. wl_resource* resource =
  94. wl_resource_create(client, &zcr_cursor_shapes_v1_interface, version, id);
  95. wl_resource_set_implementation(resource, &cursor_shapes_implementation, data,
  96. nullptr);
  97. }
  98. } // namespace wayland
  99. } // namespace exo