zwp_pointer_gestures.cc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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/zwp_pointer_gestures.h"
  5. #include <pointer-gestures-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/pointer_gesture_pinch_delegate.h"
  10. #include "components/exo/surface.h"
  11. #include "components/exo/wayland/server_util.h"
  12. namespace exo {
  13. namespace wayland {
  14. namespace {
  15. ////////////////////////////////////////////////////////////////////////////////
  16. // pointer_gesture_swipe_v1 interface:
  17. void pointer_gestures_get_swipe_gesture(wl_client* client,
  18. wl_resource* resource,
  19. uint32_t id,
  20. wl_resource* pointer_resource) {
  21. NOTIMPLEMENTED();
  22. }
  23. ////////////////////////////////////////////////////////////////////////////////
  24. // pointer_gesture_pinch_v1 interface:
  25. class WaylandPointerGesturePinchDelegate : public PointerGesturePinchDelegate {
  26. public:
  27. WaylandPointerGesturePinchDelegate(wl_resource* resource, Pointer* pointer)
  28. : resource_(resource), pointer_(pointer) {
  29. pointer_->SetGesturePinchDelegate(this);
  30. }
  31. WaylandPointerGesturePinchDelegate(
  32. const WaylandPointerGesturePinchDelegate&) = delete;
  33. WaylandPointerGesturePinchDelegate& operator=(
  34. const WaylandPointerGesturePinchDelegate&) = delete;
  35. ~WaylandPointerGesturePinchDelegate() override {
  36. if (pointer_)
  37. pointer_->SetGesturePinchDelegate(nullptr);
  38. }
  39. void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; }
  40. void OnPointerPinchBegin(uint32_t unique_touch_event_id,
  41. base::TimeTicks time_stamp,
  42. Surface* surface) override {
  43. wl_resource* surface_resource = GetSurfaceResource(surface);
  44. DCHECK(surface_resource);
  45. zwp_pointer_gesture_pinch_v1_send_begin(resource_, unique_touch_event_id,
  46. TimeTicksToMilliseconds(time_stamp),
  47. surface_resource, 2);
  48. }
  49. void OnPointerPinchUpdate(base::TimeTicks time_stamp, float scale) override {
  50. zwp_pointer_gesture_pinch_v1_send_update(
  51. resource_, TimeTicksToMilliseconds(time_stamp), 0, 0,
  52. wl_fixed_from_double(scale), 0);
  53. }
  54. void OnPointerPinchEnd(uint32_t unique_touch_event_id,
  55. base::TimeTicks time_stamp) override {
  56. zwp_pointer_gesture_pinch_v1_send_end(resource_, unique_touch_event_id,
  57. TimeTicksToMilliseconds(time_stamp),
  58. 0);
  59. }
  60. private:
  61. wl_resource* const resource_;
  62. Pointer* pointer_;
  63. };
  64. void pointer_gesture_pinch_destroy(wl_client* client, wl_resource* resource) {
  65. wl_resource_destroy(resource);
  66. }
  67. const struct zwp_pointer_gesture_pinch_v1_interface
  68. pointer_gesture_pinch_implementation = {pointer_gesture_pinch_destroy};
  69. void pointer_gestures_get_pinch_gesture(wl_client* client,
  70. wl_resource* resource,
  71. uint32_t id,
  72. wl_resource* pointer_resource) {
  73. Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource);
  74. wl_resource* pointer_gesture_pinch_resource = wl_resource_create(
  75. client, &zwp_pointer_gesture_pinch_v1_interface, 1, id);
  76. SetImplementation(pointer_gesture_pinch_resource,
  77. &pointer_gesture_pinch_implementation,
  78. std::make_unique<WaylandPointerGesturePinchDelegate>(
  79. pointer_gesture_pinch_resource, pointer));
  80. }
  81. ////////////////////////////////////////////////////////////////////////////////
  82. // pointer_gestures_v1 interface:
  83. const struct zwp_pointer_gestures_v1_interface pointer_gestures_implementation =
  84. {pointer_gestures_get_swipe_gesture, pointer_gestures_get_pinch_gesture};
  85. } // namespace
  86. void bind_pointer_gestures(wl_client* client,
  87. void* data,
  88. uint32_t version,
  89. uint32_t id) {
  90. wl_resource* resource = wl_resource_create(
  91. client, &zwp_pointer_gestures_v1_interface, version, id);
  92. wl_resource_set_implementation(resource, &pointer_gestures_implementation,
  93. data, nullptr);
  94. }
  95. } // namespace wayland
  96. } // namespace exo