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

EXO: Refactored keyboard extension interface

Move keyboard extension out of server.cc
This CL only moves code around.

Bug: 896710
Test: Built on ChromeOS
Change-Id: I15ea4ac7f9c5cabf9470d0478cd91a409c0b5e6a
Reviewed-on: https://chromium-review.googlesource.com/c/1320028
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@{#608439}
parent 896bb87a
...@@ -43,6 +43,8 @@ source_set("wayland") { ...@@ -43,6 +43,8 @@ source_set("wayland") {
"wayland_pointer_delegate.h", "wayland_pointer_delegate.h",
"wayland_touch_delegate.cc", "wayland_touch_delegate.cc",
"wayland_touch_delegate.h", "wayland_touch_delegate.h",
"zcr_keyboard_extension.cc",
"zcr_keyboard_extension.h",
"zcr_notification_shell.cc", "zcr_notification_shell.cc",
"zcr_notification_shell.h", "zcr_notification_shell.h",
"zwp_input_timestamps_manager.cc", "zwp_input_timestamps_manager.cc",
......
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include "components/exo/wayland/wayland_keyboard_delegate.h" #include "components/exo/wayland/wayland_keyboard_delegate.h"
#include "components/exo/wayland/wayland_pointer_delegate.h" #include "components/exo/wayland/wayland_pointer_delegate.h"
#include "components/exo/wayland/wayland_touch_delegate.h" #include "components/exo/wayland/wayland_touch_delegate.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/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"
...@@ -4604,94 +4605,6 @@ void bind_stylus_tools(wl_client* client, ...@@ -4604,94 +4605,6 @@ void bind_stylus_tools(wl_client* client,
nullptr); nullptr);
} }
////////////////////////////////////////////////////////////////////////////////
// extended_keyboard interface:
class WaylandExtendedKeyboardImpl : public KeyboardObserver {
public:
explicit WaylandExtendedKeyboardImpl(Keyboard* keyboard)
: keyboard_(keyboard) {
keyboard_->AddObserver(this);
keyboard_->SetNeedKeyboardKeyAcks(true);
}
~WaylandExtendedKeyboardImpl() override {
if (keyboard_) {
keyboard_->RemoveObserver(this);
keyboard_->SetNeedKeyboardKeyAcks(false);
}
}
// Overridden from KeyboardObserver:
void OnKeyboardDestroying(Keyboard* keyboard) override {
DCHECK(keyboard_ == keyboard);
keyboard_ = nullptr;
}
void AckKeyboardKey(uint32_t serial, bool handled) {
if (keyboard_)
keyboard_->AckKeyboardKey(serial, handled);
}
private:
Keyboard* keyboard_;
DISALLOW_COPY_AND_ASSIGN(WaylandExtendedKeyboardImpl);
};
void extended_keyboard_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void extended_keyboard_ack_key(wl_client* client,
wl_resource* resource,
uint32_t serial,
uint32_t handled_state) {
GetUserDataAs<WaylandExtendedKeyboardImpl>(resource)->AckKeyboardKey(
serial, handled_state == ZCR_EXTENDED_KEYBOARD_V1_HANDLED_STATE_HANDLED);
}
const struct zcr_extended_keyboard_v1_interface
extended_keyboard_implementation = {extended_keyboard_destroy,
extended_keyboard_ack_key};
////////////////////////////////////////////////////////////////////////////////
// keyboard_extension interface:
void keyboard_extension_get_extended_keyboard(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* keyboard_resource) {
Keyboard* keyboard = GetUserDataAs<Keyboard>(keyboard_resource);
if (keyboard->AreKeyboardKeyAcksNeeded()) {
wl_resource_post_error(
resource, ZCR_KEYBOARD_EXTENSION_V1_ERROR_EXTENDED_KEYBOARD_EXISTS,
"keyboard has already been associated with a extended_keyboard object");
return;
}
wl_resource* extended_keyboard_resource =
wl_resource_create(client, &zcr_extended_keyboard_v1_interface, 1, id);
SetImplementation(extended_keyboard_resource,
&extended_keyboard_implementation,
std::make_unique<WaylandExtendedKeyboardImpl>(keyboard));
}
const struct zcr_keyboard_extension_v1_interface
keyboard_extension_implementation = {
keyboard_extension_get_extended_keyboard};
void bind_keyboard_extension(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zcr_keyboard_extension_v1_interface, version, id);
wl_resource_set_implementation(resource, &keyboard_extension_implementation,
data, nullptr);
}
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
// cursor_shapes interface: // cursor_shapes interface:
......
// 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_keyboard_extension.h"
#include <keyboard-extension-unstable-v1-server-protocol.h>
#include <wayland-server-core.h>
#include <wayland-server-protocol-core.h>
#include "components/exo/keyboard.h"
#include "components/exo/keyboard_observer.h"
#include "components/exo/wayland/server_util.h"
namespace exo {
namespace wayland {
namespace {
////////////////////////////////////////////////////////////////////////////////
// extended_keyboard interface:
class WaylandExtendedKeyboardImpl : public KeyboardObserver {
public:
explicit WaylandExtendedKeyboardImpl(Keyboard* keyboard)
: keyboard_(keyboard) {
keyboard_->AddObserver(this);
keyboard_->SetNeedKeyboardKeyAcks(true);
}
~WaylandExtendedKeyboardImpl() override {
if (keyboard_) {
keyboard_->RemoveObserver(this);
keyboard_->SetNeedKeyboardKeyAcks(false);
}
}
// Overridden from KeyboardObserver:
void OnKeyboardDestroying(Keyboard* keyboard) override {
DCHECK(keyboard_ == keyboard);
keyboard_ = nullptr;
}
void AckKeyboardKey(uint32_t serial, bool handled) {
if (keyboard_)
keyboard_->AckKeyboardKey(serial, handled);
}
private:
Keyboard* keyboard_;
DISALLOW_COPY_AND_ASSIGN(WaylandExtendedKeyboardImpl);
};
void extended_keyboard_destroy(wl_client* client, wl_resource* resource) {
wl_resource_destroy(resource);
}
void extended_keyboard_ack_key(wl_client* client,
wl_resource* resource,
uint32_t serial,
uint32_t handled_state) {
GetUserDataAs<WaylandExtendedKeyboardImpl>(resource)->AckKeyboardKey(
serial, handled_state == ZCR_EXTENDED_KEYBOARD_V1_HANDLED_STATE_HANDLED);
}
const struct zcr_extended_keyboard_v1_interface
extended_keyboard_implementation = {extended_keyboard_destroy,
extended_keyboard_ack_key};
////////////////////////////////////////////////////////////////////////////////
// keyboard_extension interface:
void keyboard_extension_get_extended_keyboard(wl_client* client,
wl_resource* resource,
uint32_t id,
wl_resource* keyboard_resource) {
Keyboard* keyboard = GetUserDataAs<Keyboard>(keyboard_resource);
if (keyboard->AreKeyboardKeyAcksNeeded()) {
wl_resource_post_error(
resource, ZCR_KEYBOARD_EXTENSION_V1_ERROR_EXTENDED_KEYBOARD_EXISTS,
"keyboard has already been associated with a extended_keyboard object");
return;
}
wl_resource* extended_keyboard_resource =
wl_resource_create(client, &zcr_extended_keyboard_v1_interface, 1, id);
SetImplementation(extended_keyboard_resource,
&extended_keyboard_implementation,
std::make_unique<WaylandExtendedKeyboardImpl>(keyboard));
}
const struct zcr_keyboard_extension_v1_interface
keyboard_extension_implementation = {
keyboard_extension_get_extended_keyboard};
} // namespace
void bind_keyboard_extension(wl_client* client,
void* data,
uint32_t version,
uint32_t id) {
wl_resource* resource = wl_resource_create(
client, &zcr_keyboard_extension_v1_interface, version, id);
wl_resource_set_implementation(resource, &keyboard_extension_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_KEYBOARD_EXTENSION_H_
#define COMPONENTS_EXO_WAYLAND_ZCR_KEYBOARD_EXTENSION_H_
#include <stdint.h>
struct wl_client;
namespace exo {
namespace wayland {
void bind_keyboard_extension(wl_client* client,
void* data,
uint32_t version,
uint32_t id);
} // namespace wayland
} // namespace exo
#endif // COMPONENTS_EXO_WAYLAND_ZCR_KEYBOARD_EXTENSION_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