Commit ad8550cc authored by Shawn Gallea's avatar Shawn Gallea Committed by Commit Bot

EXO: Refactor pointer_gestures interface

Move pointer_gestures interface out of server.cc
This CL only moves code around.

Bug: 896710
Test: Built on ChromeOS
Change-Id: I5f33889794bc1ff3645f6bb0006fd9b8c87de5df
Reviewed-on: https://chromium-review.googlesource.com/c/1324146
Commit-Queue: Daniel Nicoara <dnicoara@chromium.org>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609392}
parent 7ff5615f
......@@ -63,6 +63,8 @@ source_set("wayland") {
"zcr_stylus_tools.h",
"zwp_input_timestamps_manager.cc",
"zwp_input_timestamps_manager.h",
"zwp_pointer_gestures.cc",
"zwp_pointer_gestures.h",
"zwp_text_input_manager.cc",
"zwp_text_input_manager.h",
"zxdg_shell.cc",
......
......@@ -109,6 +109,7 @@
#include "components/exo/wayland/zcr_remote_shell.h"
#include "components/exo/wayland/zcr_stylus_tools.h"
#include "components/exo/wayland/zwp_input_timestamps_manager.h"
#include "components/exo/wayland/zwp_pointer_gestures.h"
#include "components/exo/wayland/zwp_text_input_manager.h"
#include "components/exo/wayland/zxdg_shell.h"
#include "components/exo/wm_helper.h"
......@@ -2207,95 +2208,6 @@ void bind_stylus_v2(wl_client* client,
nullptr);
}
////////////////////////////////////////////////////////////////////////////////
// pointer_gesture_swipe_v1 interface:
void pointer_gestures_get_swipe_gesture(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* pointer_resource) {
NOTIMPLEMENTED();
}
////////////////////////////////////////////////////////////////////////////////
// pointer_gesture_pinch_v1 interface:
class WaylandPointerGesturePinchDelegate : public PointerGesturePinchDelegate {
public:
WaylandPointerGesturePinchDelegate(wl_resource* resource, Pointer* pointer)
: resource_(resource), pointer_(pointer) {
pointer_->SetGesturePinchDelegate(this);
}
~WaylandPointerGesturePinchDelegate() override {
if (pointer_)
pointer_->SetGesturePinchDelegate(nullptr);
}
void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; }
void OnPointerPinchBegin(uint32_t unique_touch_event_id,
base::TimeTicks time_stamp,
Surface* surface) override {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
zwp_pointer_gesture_pinch_v1_send_begin(resource_, unique_touch_event_id,
TimeTicksToMilliseconds(time_stamp),
surface_resource, 2);
}
void OnPointerPinchUpdate(base::TimeTicks time_stamp, float scale) override {
zwp_pointer_gesture_pinch_v1_send_update(
resource_, TimeTicksToMilliseconds(time_stamp), 0, 0,
wl_fixed_from_double(scale), 0);
}
void OnPointerPinchEnd(uint32_t unique_touch_event_id,
base::TimeTicks time_stamp) override {
zwp_pointer_gesture_pinch_v1_send_end(resource_, unique_touch_event_id,
TimeTicksToMilliseconds(time_stamp),
0);
}
private:
wl_resource* const resource_;
Pointer* pointer_;
DISALLOW_COPY_AND_ASSIGN(WaylandPointerGesturePinchDelegate);
};
void pointer_gesture_pinch_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct zwp_pointer_gesture_pinch_v1_interface
pointer_gesture_pinch_implementation = {pointer_gesture_pinch_destroy};
void pointer_gestures_get_pinch_gesture(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* pointer_resource) {
Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource);
wl_resource* pointer_gesture_pinch_resource = wl_resource_create(
client, &zwp_pointer_gesture_pinch_v1_interface, 1, id);
SetImplementation(pointer_gesture_pinch_resource,
&pointer_gesture_pinch_implementation,
std::make_unique<WaylandPointerGesturePinchDelegate>(
pointer_gesture_pinch_resource, pointer));
}
////////////////////////////////////////////////////////////////////////////////
// pointer_gestures_v1 interface:
const struct zwp_pointer_gestures_v1_interface pointer_gestures_implementation =
{pointer_gestures_get_swipe_gesture, pointer_gestures_get_pinch_gesture};
void bind_pointer_gestures(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zwp_pointer_gestures_v1_interface, version, id);
wl_resource_set_implementation(resource, &pointer_gestures_implementation,
data, nullptr);
}
} // namespace
////////////////////////////////////////////////////////////////////////////////
......
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/exo/wayland/zwp_pointer_gestures.h"
#include <pointer-gestures-unstable-v1-server-protocol.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/pointer.h"
#include "components/exo/pointer_gesture_pinch_delegate.h"
#include "components/exo/surface.h"
#include "components/exo/wayland/server_util.h"
namespace exo {
namespace wayland {
namespace {
////////////////////////////////////////////////////////////////////////////////
// pointer_gesture_swipe_v1 interface:
void pointer_gestures_get_swipe_gesture(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* pointer_resource) {
NOTIMPLEMENTED();
}
////////////////////////////////////////////////////////////////////////////////
// pointer_gesture_pinch_v1 interface:
class WaylandPointerGesturePinchDelegate : public PointerGesturePinchDelegate {
public:
WaylandPointerGesturePinchDelegate(wl_resource* resource, Pointer* pointer)
: resource_(resource), pointer_(pointer) {
pointer_->SetGesturePinchDelegate(this);
}
~WaylandPointerGesturePinchDelegate() override {
if (pointer_)
pointer_->SetGesturePinchDelegate(nullptr);
}
void OnPointerDestroying(Pointer* pointer) override { pointer_ = nullptr; }
void OnPointerPinchBegin(uint32_t unique_touch_event_id,
base::TimeTicks time_stamp,
Surface* surface) override {
wl_resource* surface_resource = GetSurfaceResource(surface);
DCHECK(surface_resource);
zwp_pointer_gesture_pinch_v1_send_begin(resource_, unique_touch_event_id,
TimeTicksToMilliseconds(time_stamp),
surface_resource, 2);
}
void OnPointerPinchUpdate(base::TimeTicks time_stamp, float scale) override {
zwp_pointer_gesture_pinch_v1_send_update(
resource_, TimeTicksToMilliseconds(time_stamp), 0, 0,
wl_fixed_from_double(scale), 0);
}
void OnPointerPinchEnd(uint32_t unique_touch_event_id,
base::TimeTicks time_stamp) override {
zwp_pointer_gesture_pinch_v1_send_end(resource_, unique_touch_event_id,
TimeTicksToMilliseconds(time_stamp),
0);
}
private:
wl_resource* const resource_;
Pointer* pointer_;
DISALLOW_COPY_AND_ASSIGN(WaylandPointerGesturePinchDelegate);
};
void pointer_gesture_pinch_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
const struct zwp_pointer_gesture_pinch_v1_interface
pointer_gesture_pinch_implementation = {pointer_gesture_pinch_destroy};
void pointer_gestures_get_pinch_gesture(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* pointer_resource) {
Pointer* pointer = GetUserDataAs<Pointer>(pointer_resource);
wl_resource* pointer_gesture_pinch_resource = wl_resource_create(
client, &zwp_pointer_gesture_pinch_v1_interface, 1, id);
SetImplementation(pointer_gesture_pinch_resource,
&pointer_gesture_pinch_implementation,
std::make_unique<WaylandPointerGesturePinchDelegate>(
pointer_gesture_pinch_resource, pointer));
}
////////////////////////////////////////////////////////////////////////////////
// pointer_gestures_v1 interface:
const struct zwp_pointer_gestures_v1_interface pointer_gestures_implementation =
{pointer_gestures_get_swipe_gesture, pointer_gestures_get_pinch_gesture};
} // namespace
void bind_pointer_gestures(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zwp_pointer_gestures_v1_interface, version, id);
wl_resource_set_implementation(resource, &pointer_gestures_implementation,
data, nullptr);
}
} // namespace wayland
} // namespace exo
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_EXO_WAYLAND_ZWP_POINTER_GESTURES_H_
#define COMPONENTS_EXO_WAYLAND_ZWP_POINTER_GESTURES_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_pointer_gestures(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZWP_POINTER_GESTURES_H_
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment