| Index: components/exo/wayland/server.cc
|
| diff --git a/components/exo/wayland/server.cc b/components/exo/wayland/server.cc
|
| index 3ef44e26282a37b0b7e43390de97f75b241e4917..4f45afd69677a91119271f9db59f05c472a02a73 100644
|
| --- a/components/exo/wayland/server.cc
|
| +++ b/components/exo/wayland/server.cc
|
| @@ -14,6 +14,7 @@
|
|
|
| // Note: core wayland headers need to be included before protocol headers.
|
| #include <alpha-compositing-unstable-v1-server-protocol.h> // NOLINT
|
| +#include <gamepads-unstable-v1-server-protocol.h> // NOLINT
|
| #include <remote-shell-unstable-v1-server-protocol.h> // NOLINT
|
| #include <secure-output-unstable-v1-server-protocol.h> // NOLINT
|
| #include <xdg-shell-unstable-v5-server-protocol.h> // NOLINT
|
| @@ -40,6 +41,8 @@
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "components/exo/buffer.h"
|
| #include "components/exo/display.h"
|
| +#include "components/exo/gamepads.h"
|
| +#include "components/exo/gamepads_delegate.h"
|
| #include "components/exo/keyboard.h"
|
| #include "components/exo/keyboard_delegate.h"
|
| #include "components/exo/pointer.h"
|
| @@ -122,6 +125,10 @@ uint32_t TimeTicksToMilliseconds(base::TimeTicks ticks) {
|
| return (ticks - base::TimeTicks()).InMilliseconds();
|
| }
|
|
|
| +uint32_t NowInMilliseconds() {
|
| + return TimeTicksToMilliseconds(base::TimeTicks::Now());
|
| +}
|
| +
|
| // A property key containing the surface resource that is associated with
|
| // window. If unset, no surface resource is associated with window.
|
| DEFINE_SURFACE_PROPERTY_KEY(wl_resource*, kSurfaceResourceKey, nullptr);
|
| @@ -2663,6 +2670,70 @@ void bind_alpha_compositing(wl_client* client,
|
| data, nullptr);
|
| }
|
|
|
| +////////////////////////////////////////////////////////////////////////////////
|
| +// zwp_gamepads_v1:
|
| +
|
| +// Gamepads delegate class that forwards gamepad events to the client resource.
|
| +class WaylandGamepadsDelegate : public GamepadsDelegate {
|
| + public:
|
| + explicit WaylandGamepadsDelegate(wl_resource* gamepads_resource)
|
| + : gamepads_resource_(gamepads_resource) {}
|
| +
|
| + // Overridden from GamepadsDelegate:
|
| + void OnGamepadsDestroying(Gamepads* gamepads) override { delete this; }
|
| +
|
| + void OnConnected(int id) override {
|
| + zwp_gamepads_v1_send_connected(gamepads_resource_, id);
|
| + wl_client_flush(client());
|
| + }
|
| + void OnDisconnected(int id) override {
|
| + zwp_gamepads_v1_send_disconnected(gamepads_resource_, id);
|
| + wl_client_flush(client());
|
| + }
|
| + void OnAxis(int id, int axis, double value) override {
|
| + zwp_gamepads_v1_send_axis(gamepads_resource_, NowInMilliseconds(), id,
|
| + axis, wl_fixed_from_double(value));
|
| + }
|
| + void OnButton(int id, int button, bool pressed, double value) override {
|
| + zwp_gamepads_v1_send_button(gamepads_resource_, NowInMilliseconds(), id,
|
| + button, pressed, wl_fixed_from_double(value));
|
| + }
|
| + void OnFrame(int id) override {
|
| + zwp_gamepads_v1_send_frame(gamepads_resource_, NowInMilliseconds(), id);
|
| + wl_client_flush(client());
|
| + }
|
| +
|
| + private:
|
| + // The client who own this gamepads instance.
|
| + wl_client* client() const {
|
| + return wl_resource_get_client(gamepads_resource_);
|
| + }
|
| +
|
| + // The gamepads resource associated with the gamepads.
|
| + wl_resource* const gamepads_resource_;
|
| +
|
| + DISALLOW_COPY_AND_ASSIGN(WaylandGamepadsDelegate);
|
| +};
|
| +
|
| +void gamepads_destroy(wl_client* client, wl_resource* resource) {
|
| + wl_resource_destroy(resource);
|
| +}
|
| +
|
| +const struct zwp_gamepads_v1_interface gamepads_implementation = {
|
| + gamepads_destroy};
|
| +
|
| +void bind_gamepads(wl_client* client,
|
| + void* data,
|
| + uint32_t version,
|
| + uint32_t id) {
|
| + wl_resource* resource =
|
| + wl_resource_create(client, &zwp_gamepads_v1_interface, version, id);
|
| +
|
| + auto gamepads = new Gamepads(new WaylandGamepadsDelegate(resource));
|
| + SetImplementation(resource, &gamepads_implementation,
|
| + base::WrapUnique(gamepads));
|
| +}
|
| +
|
| } // namespace
|
|
|
| ////////////////////////////////////////////////////////////////////////////////
|
| @@ -2701,6 +2772,8 @@ Server::Server(Display* display)
|
| display_, bind_alpha_compositing);
|
| wl_global_create(wl_display_.get(), &zwp_remote_shell_v1_interface,
|
| remote_shell_version, display_, bind_remote_shell);
|
| + wl_global_create(wl_display_.get(), &zwp_gamepads_v1_interface, 1, display_,
|
| + bind_gamepads);
|
| }
|
|
|
| Server::~Server() {}
|
|
|