Synchronize clipboard bi-directional with the android container
This commit is contained in:
parent
5512f79941
commit
db3499fd89
16 changed files with 213 additions and 4 deletions
|
|
@ -17,9 +17,10 @@
|
|||
|
||||
#include "anbox/bridge/platform_api_skeleton.h"
|
||||
#include "anbox/application/launcher_storage.h"
|
||||
#include "anbox/logger.h"
|
||||
#include "anbox/platform/policy.h"
|
||||
#include "anbox/wm/manager.h"
|
||||
#include "anbox/wm/window_state.h"
|
||||
#include "anbox/logger.h"
|
||||
|
||||
#include "anbox_bridge.pb.h"
|
||||
|
||||
|
|
@ -27,14 +28,40 @@ namespace anbox {
|
|||
namespace bridge {
|
||||
PlatformApiSkeleton::PlatformApiSkeleton(
|
||||
const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<platform::Policy> &platform_policy,
|
||||
const std::shared_ptr<wm::Manager> &window_manager,
|
||||
const std::shared_ptr<application::LauncherStorage> &launcher_storage)
|
||||
: pending_calls_(pending_calls),
|
||||
platform_policy_(platform_policy),
|
||||
window_manager_(window_manager),
|
||||
launcher_storage_(launcher_storage) {}
|
||||
|
||||
PlatformApiSkeleton::~PlatformApiSkeleton() {}
|
||||
|
||||
|
||||
void PlatformApiSkeleton::set_clipboard_data(anbox::protobuf::bridge::ClipboardData const *request,
|
||||
anbox::protobuf::rpc::Void *response,
|
||||
google::protobuf::Closure *done) {
|
||||
(void)response;
|
||||
|
||||
if (request->has_text())
|
||||
platform_policy_->set_clipboard_data(platform::Policy::ClipboardData{request->text()});
|
||||
|
||||
done->Run();
|
||||
}
|
||||
|
||||
void PlatformApiSkeleton::get_clipboard_data(anbox::protobuf::rpc::Void const *request,
|
||||
anbox::protobuf::bridge::ClipboardData *response,
|
||||
google::protobuf::Closure *done) {
|
||||
(void)request;
|
||||
|
||||
auto data = platform_policy_->get_clipboard_data();
|
||||
if (!data.text.empty())
|
||||
response->set_text(data.text);
|
||||
|
||||
done->Run();
|
||||
}
|
||||
|
||||
void PlatformApiSkeleton::handle_boot_finished_event(
|
||||
const anbox::protobuf::bridge::BootFinishedEvent &event) {
|
||||
(void)event;
|
||||
|
|
|
|||
|
|
@ -32,11 +32,15 @@ namespace rpc {
|
|||
class Void;
|
||||
} // namespace rpc
|
||||
namespace bridge {
|
||||
class ClipboardData;
|
||||
class BootFinishedEvent;
|
||||
class WindowStateUpdateEvent;
|
||||
class ApplicationListUpdateEvent;
|
||||
} // namespace bridge
|
||||
} // namespace protobuf
|
||||
namespace platform {
|
||||
class Policy;
|
||||
} // namespace platform
|
||||
namespace rpc {
|
||||
class PendingCallCache;
|
||||
} // namespace rpc
|
||||
|
|
@ -51,10 +55,18 @@ class PlatformApiSkeleton {
|
|||
public:
|
||||
PlatformApiSkeleton(
|
||||
const std::shared_ptr<rpc::PendingCallCache> &pending_calls,
|
||||
const std::shared_ptr<platform::Policy> &platform_policy,
|
||||
const std::shared_ptr<wm::Manager> &window_manager,
|
||||
const std::shared_ptr<application::LauncherStorage> &launcher_storage);
|
||||
virtual ~PlatformApiSkeleton();
|
||||
|
||||
void set_clipboard_data(anbox::protobuf::bridge::ClipboardData const *request,
|
||||
anbox::protobuf::rpc::Void *response,
|
||||
google::protobuf::Closure *done);
|
||||
void get_clipboard_data(anbox::protobuf::rpc::Void const *request,
|
||||
anbox::protobuf::bridge::ClipboardData *response,
|
||||
google::protobuf::Closure *done);
|
||||
|
||||
void handle_boot_finished_event(
|
||||
const anbox::protobuf::bridge::BootFinishedEvent &event);
|
||||
void handle_window_state_update_event(
|
||||
|
|
@ -66,6 +78,7 @@ class PlatformApiSkeleton {
|
|||
|
||||
private:
|
||||
std::shared_ptr<rpc::PendingCallCache> pending_calls_;
|
||||
std::shared_ptr<platform::Policy> platform_policy_;
|
||||
std::shared_ptr<wm::Manager> window_manager_;
|
||||
std::shared_ptr<application::LauncherStorage> launcher_storage_;
|
||||
std::function<void()> boot_finished_handler_;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,12 @@ PlatformMessageProcessor::PlatformMessageProcessor(
|
|||
|
||||
PlatformMessageProcessor::~PlatformMessageProcessor() {}
|
||||
|
||||
void PlatformMessageProcessor::dispatch(rpc::Invocation const &invocation) {}
|
||||
void PlatformMessageProcessor::dispatch(rpc::Invocation const &invocation) {
|
||||
if (invocation.method_name() == "set_clipboard_data")
|
||||
invoke(this, server_.get(), &PlatformApiSkeleton::set_clipboard_data, invocation);
|
||||
else if (invocation.method_name() == "get_clipboard_data")
|
||||
invoke(this, server_.get(), &PlatformApiSkeleton::get_clipboard_data, invocation);
|
||||
}
|
||||
|
||||
void PlatformMessageProcessor::process_event_sequence(
|
||||
const std::string &raw_events) {
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ anbox::cmds::Run::Run(const BusFactory &bus_factory)
|
|||
android_api_stub->set_rpc_channel(rpc_channel);
|
||||
|
||||
auto server = std::make_shared<bridge::PlatformApiSkeleton>(
|
||||
pending_calls, window_manager, launcher_storage);
|
||||
pending_calls, policy, window_manager, launcher_storage);
|
||||
server->register_boot_finished_handler(
|
||||
[&]() { DEBUG("Android successfully booted"); });
|
||||
return std::make_shared<bridge::PlatformMessageProcessor>(
|
||||
|
|
|
|||
|
|
@ -37,6 +37,16 @@ std::shared_ptr<wm::Window> DefaultPolicy::create_window(
|
|||
return std::make_shared<::NullWindow>(task, frame);
|
||||
}
|
||||
|
||||
void DefaultPolicy::set_clipboard_data(const ClipboardData &data) {
|
||||
(void)data;
|
||||
ERROR("Not implemented");
|
||||
}
|
||||
|
||||
DefaultPolicy::ClipboardData DefaultPolicy::get_clipboard_data() {
|
||||
ERROR("Not implemented");
|
||||
return ClipboardData{};
|
||||
}
|
||||
|
||||
std::shared_ptr<audio::Sink> DefaultPolicy::create_audio_sink() {
|
||||
ERROR("Not implemented");
|
||||
return nullptr;
|
||||
|
|
|
|||
|
|
@ -28,6 +28,8 @@ class DefaultPolicy : public Policy {
|
|||
std::shared_ptr<wm::Window> create_window(
|
||||
const anbox::wm::Task::Id &task,
|
||||
const anbox::graphics::Rect &frame) override;
|
||||
void set_clipboard_data(const ClipboardData &data) override;
|
||||
ClipboardData get_clipboard_data() override;
|
||||
std::shared_ptr<audio::Sink> create_audio_sink() override;
|
||||
std::shared_ptr<audio::Source> create_audio_source() override;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -39,6 +39,13 @@ class Policy {
|
|||
virtual std::shared_ptr<wm::Window> create_window(
|
||||
const anbox::wm::Task::Id &task, const anbox::graphics::Rect &frame) = 0;
|
||||
|
||||
struct ClipboardData {
|
||||
std::string text;
|
||||
};
|
||||
|
||||
virtual void set_clipboard_data(const ClipboardData &data) = 0;
|
||||
virtual ClipboardData get_clipboard_data() = 0;
|
||||
|
||||
virtual std::shared_ptr<audio::Sink> create_audio_sink() = 0;
|
||||
virtual std::shared_ptr<audio::Source> create_audio_source() = 0;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -50,6 +50,13 @@ message ResizeTask {
|
|||
required Rect rect = 3;
|
||||
}
|
||||
|
||||
message ClipboardData {
|
||||
optional string text = 1;
|
||||
|
||||
optional string error = 127;
|
||||
optional StructuredError structured_error = 128;
|
||||
}
|
||||
|
||||
message BootFinishedEvent {
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -265,6 +265,25 @@ DisplayManager::DisplayInfo PlatformPolicy::display_info() const {
|
|||
return display_info_;
|
||||
}
|
||||
|
||||
void PlatformPolicy::set_clipboard_data(const ClipboardData &data) {
|
||||
if (data.text.empty())
|
||||
return;
|
||||
SDL_SetClipboardText(data.text.c_str());
|
||||
}
|
||||
|
||||
PlatformPolicy::ClipboardData PlatformPolicy::get_clipboard_data() {
|
||||
if (!SDL_HasClipboardText())
|
||||
return ClipboardData{};
|
||||
|
||||
auto text = SDL_GetClipboardText();
|
||||
if (!text)
|
||||
return ClipboardData{};
|
||||
|
||||
auto data = ClipboardData{text};
|
||||
SDL_free(text);
|
||||
return data;
|
||||
}
|
||||
|
||||
std::shared_ptr<audio::Sink> PlatformPolicy::create_audio_sink() {
|
||||
return std::make_shared<AudioSink>();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -63,6 +63,9 @@ class PlatformPolicy : public std::enable_shared_from_this<PlatformPolicy>,
|
|||
|
||||
void set_renderer(const std::shared_ptr<Renderer> &renderer);
|
||||
|
||||
void set_clipboard_data(const ClipboardData &data) override;
|
||||
ClipboardData get_clipboard_data() override;
|
||||
|
||||
std::shared_ptr<audio::Sink> create_audio_sink() override;
|
||||
std::shared_ptr<audio::Source> create_audio_source() override;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue