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

EXO: Refactored stylus_tools interface

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

Bug: 896710
Test: Built on ChromeOS
Change-Id: Ie891710ea8df139f49ae350cd40ec9f083870460
Reviewed-on: https://chromium-review.googlesource.com/c/1324141
Commit-Queue: Shawn Gallea <sagallea@google.com>
Reviewed-by: default avatarDaniele Castagna <dcastagna@chromium.org>
Reviewed-by: default avatarDaniel Nicoara <dnicoara@chromium.org>
Cr-Commit-Position: refs/heads/master@{#609003}
parent 95ada4bb
...@@ -59,6 +59,8 @@ source_set("wayland") { ...@@ -59,6 +59,8 @@ source_set("wayland") {
"zcr_notification_shell.h", "zcr_notification_shell.h",
"zcr_remote_shell.cc", "zcr_remote_shell.cc",
"zcr_remote_shell.h", "zcr_remote_shell.h",
"zcr_stylus_tools.cc",
"zcr_stylus_tools.h",
"zwp_input_timestamps_manager.cc", "zwp_input_timestamps_manager.cc",
"zwp_input_timestamps_manager.h", "zwp_input_timestamps_manager.h",
"zwp_text_input_manager.cc", "zwp_text_input_manager.cc",
......
...@@ -107,6 +107,7 @@ ...@@ -107,6 +107,7 @@
#include "components/exo/wayland/zcr_keyboard_extension.h" #include "components/exo/wayland/zcr_keyboard_extension.h"
#include "components/exo/wayland/zcr_notification_shell.h" #include "components/exo/wayland/zcr_notification_shell.h"
#include "components/exo/wayland/zcr_remote_shell.h" #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_input_timestamps_manager.h"
#include "components/exo/wayland/zwp_text_input_manager.h" #include "components/exo/wayland/zwp_text_input_manager.h"
#include "components/exo/wayland/zxdg_shell.h" #include "components/exo/wayland/zxdg_shell.h"
...@@ -232,10 +233,6 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false); ...@@ -232,10 +233,6 @@ DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasSecurityKey, false);
// associated with surface object. // associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasBlendingKey, false);
// A property key containing a boolean set to true if the stylus_tool
// object is associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasStylusToolKey, false);
// A property key containing a boolean set to true if na aura surface object is // A property key containing a boolean set to true if na aura surface object is
// associated with surface object. // associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasAuraSurfaceKey, false); DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasAuraSurfaceKey, false);
...@@ -2299,87 +2296,6 @@ void bind_pointer_gestures(wl_client* client, ...@@ -2299,87 +2296,6 @@ void bind_pointer_gestures(wl_client* client,
data, nullptr); 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,
std::make_unique<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 } // 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/zcr_stylus_tools.h"
#include <stylus-tools-unstable-v1-server-protocol.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/surface.h"
#include "components/exo/surface_observer.h"
#include "components/exo/wayland/server_util.h"
namespace exo {
namespace wayland {
namespace {
// A property key containing a boolean set to true if the stylus_tool
// object is associated with surface object.
DEFINE_UI_CLASS_PROPERTY_KEY(bool, kSurfaceHasStylusToolKey, false);
////////////////////////////////////////////////////////////////////////////////
// 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,
std::make_unique<StylusTool>(surface));
}
const struct zcr_stylus_tools_v1_interface stylus_tools_implementation = {
stylus_tools_destroy, stylus_tools_get_stylus_tool};
} // namespace
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 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_ZCR_STYLUS_TOOLS_H_
#define COMPONENTS_EXO_WAYLAND_ZCR_STYLUS_TOOLS_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_stylus_tools(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZCR_STYLUS_TOOLS_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