Index: components/exo/wayland/server.cc |
diff --git a/components/exo/wayland/server.cc b/components/exo/wayland/server.cc |
index 099429624c776812176b9109acb65ebd7e8fd236..e541591d3e903afb76ed5383054e4e9e57f4b1b2 100644 |
--- a/components/exo/wayland/server.cc |
+++ b/components/exo/wayland/server.cc |
@@ -15,6 +15,7 @@ |
#include <secure-output-unstable-v1-server-protocol.h> |
#include <stddef.h> |
#include <stdint.h> |
+#include <stylus-tools-unstable-v1-server-protocol.h> |
#include <stylus-unstable-v1-server-protocol.h> |
#include <stylus-unstable-v2-server-protocol.h> |
#include <viewporter-server-protocol.h> |
@@ -164,6 +165,10 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false); |
// to ignore the activation event originated by creation. |
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kIgnoreWindowActivated, true); |
+// A property key containing a boolean set to true if the stylus_tool |
+// object is associated with a window. |
+DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasStylusToolKey, false); |
+ |
wl_resource* GetSurfaceResource(Surface* surface) { |
return surface->GetProperty(kSurfaceResourceKey); |
} |
@@ -3839,6 +3844,87 @@ void bind_keyboard_configuration(wl_client* client, |
resource, &keyboard_configuration_implementation, data, nullptr); |
} |
+//////////////////////////////////////////////////////////////////////////////// |
+// stylus_tool interface: |
+ |
+class StylusTool : public SurfaceObserver { |
+ public: |
+ explicit StylusTool(Surface* surface) : surface_(surface) { |
+ surface_->AddSurfaceObserver(this); |
+ surface_->SetProperty(kSurfaceHasStylusToolKey, true); |
+ } |
+ ~StylusTool() override { |
+ if (surface_) { |
+ surface_->RemoveSurfaceObserver(this); |
+ surface_->SetProperty(kSurfaceHasStylusToolKey, false); |
+ } |
+ } |
+ |
+ void SetStylusOnly() { surface_->SetStylusOnly(); } |
+ |
+ // Overridden from SurfaceObserver: |
+ void OnSurfaceDestroying(Surface* surface) override { |
+ surface->RemoveSurfaceObserver(this); |
+ surface_ = nullptr; |
+ } |
+ |
+ private: |
+ Surface* surface_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(StylusTool); |
+}; |
+ |
+void stylus_tool_destroy(wl_client* client, wl_resource* resource) { |
+ wl_resource_destroy(resource); |
+} |
+ |
+void stylus_tool_set_stylus_only(wl_client* client, wl_resource* resource) { |
+ GetUserDataAs<StylusTool>(resource)->SetStylusOnly(); |
+} |
+ |
+const struct zcr_stylus_tool_v1_interface stylus_tool_implementation = { |
+ stylus_tool_destroy, stylus_tool_set_stylus_only}; |
+ |
+//////////////////////////////////////////////////////////////////////////////// |
+// stylus_tools interface: |
+ |
+void stylus_tools_destroy(wl_client* client, wl_resource* resource) { |
+ wl_resource_destroy(resource); |
+} |
+ |
+void stylus_tools_get_stylus_tool(wl_client* client, |
+ wl_resource* resource, |
+ uint32_t id, |
+ wl_resource* surface_resource) { |
+ Surface* surface = GetUserDataAs<Surface>(surface_resource); |
+ if (surface->GetProperty(kSurfaceHasStylusToolKey)) { |
+ wl_resource_post_error( |
+ resource, ZCR_STYLUS_TOOLS_V1_ERROR_STYLUS_TOOL_EXISTS, |
+ "a stylus_tool object for that surface already exists"); |
+ return; |
+ } |
+ |
+ wl_resource* stylus_tool_resource = |
+ wl_resource_create(client, &zcr_stylus_tool_v1_interface, 1, id); |
+ |
+ SetImplementation(stylus_tool_resource, &stylus_tool_implementation, |
+ base::MakeUnique<StylusTool>(surface)); |
+} |
+ |
+const struct zcr_stylus_tools_v1_interface stylus_tools_implementation = { |
+ stylus_tools_destroy, stylus_tools_get_stylus_tool}; |
+ |
+void bind_stylus_tools(wl_client* client, |
+ void* data, |
+ uint32_t version, |
+ uint32_t id) { |
+ wl_resource* resource = |
+ wl_resource_create(client, &zcr_stylus_tools_v1_interface, 1, id); |
+ |
+ wl_resource_set_implementation(resource, &stylus_tools_implementation, data, |
+ nullptr); |
+} |
+ |
} // namespace |
//////////////////////////////////////////////////////////////////////////////// |
@@ -3891,6 +3977,8 @@ Server::Server(Display* display) |
bind_stylus_v2); |
wl_global_create(wl_display_.get(), &zcr_keyboard_configuration_v1_interface, |
2, display_, bind_keyboard_configuration); |
+ wl_global_create(wl_display_.get(), &zcr_stylus_tools_v1_interface, 1, |
+ display_, bind_stylus_tools); |
} |
Server::~Server() {} |