1 From 413898c43c8f66a7d49fe8bb74a85ce67733bc86 Mon Sep 17 00:00:00 2001
2 From: Scott Murray <scott.murray@konsulko.com>
3 Date: Thu, 1 Jun 2023 14:34:03 -0400
4 Subject: [PATCH] Add optional agl_shell plugin
6 Add an optional agl_shell static plugin to expose the activate_app
7 call from the agl-shell Wayland protocol that is used when running
8 against the AGL compositor. This provides a way for a homescreen
9 application to activate other application surfaces to switch between
10 multiple applications as is needed for the AGL demo.
12 Upstream-Status: Pending
14 Signed-off-by: Scott Murray <scott.murray@konsulko.com>
15 [Updated to work with upstream OSS 0223 release]
16 Signed-off-by: Marius Vlad <marius.vlad@collabora.com>
19 cmake/plugins.cmake | 5 ++
20 shell/engine.cc | 6 ++
21 shell/engine.h | 10 +++
22 shell/platform_channel.cc | 6 ++
23 shell/static_plugins/agl_shell/agl_shell.cc | 77 +++++++++++++++++++++
24 shell/static_plugins/agl_shell/agl_shell.h | 31 +++++++++
25 shell/wayland/display.cc | 7 ++
26 shell/wayland/display.h | 8 +++
27 shell/wayland/window.h | 2 +
28 9 files changed, 152 insertions(+)
29 create mode 100644 shell/static_plugins/agl_shell/agl_shell.cc
30 create mode 100644 shell/static_plugins/agl_shell/agl_shell.h
32 diff --git a/cmake/plugins.cmake b/cmake/plugins.cmake
33 index b720dca..20a55d7 100644
34 --- a/cmake/plugins.cmake
35 +++ b/cmake/plugins.cmake
36 @@ -123,4 +123,9 @@ if (BUILD_PLUGIN_SECURE_STORAGE)
40 +option(BUILD_PLUGIN_AGL_SHELL "Includes AGL Shell Wayland Protocol Plugin" OFF)
41 +if (BUILD_PLUGIN_AGL_SHELL)
42 + ENABLE_PLUGIN(agl_shell)
45 message(STATUS "Plugin Config .......... ${PLUGINS}")
46 diff --git a/shell/engine.cc b/shell/engine.cc
47 index d20b6ba..a0e38e9 100644
50 @@ -614,3 +614,9 @@ MAYBE_UNUSED TextInput* Engine::GetTextInput() const {
55 +#if ENABLE_PLUGIN_AGL_SHELL
56 +std::shared_ptr<Display> Engine::GetDisplay() const {
57 + return m_egl_window->GetDisplay();
60 diff --git a/shell/engine.h b/shell/engine.h
61 index 94808dc..3a06f51 100644
64 @@ -60,6 +60,12 @@ class KeyEvent;
68 +#if ENABLE_PLUGIN_AGL_SHELL
77 @@ -445,6 +451,10 @@ class Engine {
78 MAYBE_UNUSED NODISCARD KeyEvent* GetKeyEvent() const;
81 +#if ENABLE_PLUGIN_AGL_SHELL
82 + std::shared_ptr<Display> GetDisplay() const;
86 * @brief Get backend of view
88 diff --git a/shell/platform_channel.cc b/shell/platform_channel.cc
89 index b72156a..81d7cb5 100644
90 --- a/shell/platform_channel.cc
91 +++ b/shell/platform_channel.cc
93 #ifdef ENABLE_PLUGIN_SECURE_STORAGE
94 #include "static_plugins/secure_storage/secure_storage.h"
96 +#ifdef ENABLE_PLUGIN_AGL_SHELL
97 +#include "static_plugins/agl_shell/agl_shell.h"
100 PlatformChannel* PlatformChannel::singleton = nullptr;
102 @@ -122,4 +125,7 @@ PlatformChannel::PlatformChannel() {
103 RegisterCallback(SecureStorage::kChannelName,
104 &SecureStorage::OnPlatformMessage);
106 +#ifdef ENABLE_PLUGIN_AGL_SHELL
107 + RegisterCallback(AglShell::kChannelName, &AglShell::OnPlatformMessage);
110 diff --git a/shell/static_plugins/agl_shell/agl_shell.cc b/shell/static_plugins/agl_shell/agl_shell.cc
112 index 0000000..e6160a5
114 +++ b/shell/static_plugins/agl_shell/agl_shell.cc
116 +// Copyright 2020 Toyota Connected North America
117 +// Copyright 2022 Konsulko Group
119 +// Licensed under the Apache License, Version 2.0 (the "License");
120 +// you may not use this file except in compliance with the License.
121 +// You may obtain a copy of the License at
123 +// http://www.apache.org/licenses/LICENSE-2.0
125 +// Unless required by applicable law or agreed to in writing, software
126 +// distributed under the License is distributed on an "AS IS" BASIS,
127 +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
128 +// See the License for the specific language governing permissions and
129 +// limitations under the License.
131 +#include "agl_shell.h"
133 +#include <flutter/fml/logging.h>
134 +#include <flutter/standard_method_codec.h>
137 +#include "wayland/display.h"
141 +void AglShell::OnPlatformMessage(const FlutterPlatformMessage* message,
143 + std::unique_ptr<std::vector<uint8_t>> result;
144 + auto engine = reinterpret_cast<Engine*>(userdata);
145 + auto& codec = flutter::StandardMethodCodec::GetInstance();
146 + auto obj = codec.DecodeMethodCall(message->message, message->message_size);
148 + auto method = obj->method_name();
149 + if (method == kMethodActivateApp) {
150 + if (obj->arguments()->IsNull()) {
151 + result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
155 + auto args = std::get_if<flutter::EncodableMap>(obj->arguments());
157 + result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
161 + std::string app_id;
162 + auto it = args->find(flutter::EncodableValue("app_id"));
163 + if (it != args->end()) {
164 + app_id = std::get<std::string>(it->second);
168 + it = args->find(flutter::EncodableValue("index"));
169 + if (it != args->end()) {
170 + index = std::get<int32_t>(it->second);
173 + if (app_id.empty() || index < 0) {
174 + result = codec.EncodeErrorEnvelope("argument_error", "Invalid Arguments");
178 + auto display = engine->GetDisplay();
180 + display->AglShellDoActivate(app_id, index);
182 + auto val = flutter::EncodableValue(true);
183 + result = codec.EncodeSuccessEnvelope(&val);
185 + FML_DLOG(INFO) << "AglShell: " << method << " is unhandled";
186 + result = codec.EncodeErrorEnvelope("unhandled_method", "Unhandled Method");
190 + engine->SendPlatformMessageResponse(message->response_handle, result->data(),
193 diff --git a/shell/static_plugins/agl_shell/agl_shell.h b/shell/static_plugins/agl_shell/agl_shell.h
195 index 0000000..698e44c
197 +++ b/shell/static_plugins/agl_shell/agl_shell.h
200 + * Copyright 2020 Toyota Connected North America
201 + * Copyright 2022 Konsulko Group
203 + * Licensed under the Apache License, Version 2.0 (the "License");
204 + * you may not use this file except in compliance with the License.
205 + * You may obtain a copy of the License at
207 + * http://www.apache.org/licenses/LICENSE-2.0
209 + * Unless required by applicable law or agreed to in writing, software
210 + * distributed under the License is distributed on an "AS IS" BASIS,
211 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
212 + * See the License for the specific language governing permissions and
213 + * limitations under the License.
218 +#include <shell/platform/embedder/embedder.h>
222 + static constexpr char kChannelName[] = "flutter/agl_shell";
224 + static void OnPlatformMessage(const FlutterPlatformMessage* message,
228 + static constexpr char kMethodActivateApp[] = "activate_app";
230 diff --git a/shell/wayland/display.cc b/shell/wayland/display.cc
231 index 434dd05..99aa5ff 100644
232 --- a/shell/wayland/display.cc
233 +++ b/shell/wayland/display.cc
234 @@ -869,6 +869,13 @@ void Display::AglShellDoSetupActivationArea(uint32_t x,
238 +void Display::AglShellDoActivate(const std::string& app_id, size_t index) {
240 + agl_shell_activate_app(m_agl.shell, app_id.c_str(),
241 + m_all_outputs[index]->output);
245 void Display::SetEngine(wl_surface* surface, Engine* engine) {
246 m_active_engine = engine;
247 m_active_surface = surface;
248 diff --git a/shell/wayland/display.h b/shell/wayland/display.h
249 index 06b0f8b..ef6ea3f 100644
250 --- a/shell/wayland/display.h
251 +++ b/shell/wayland/display.h
252 @@ -150,6 +150,14 @@ class Display {
254 void AglShellDoReady() const;
257 + * @brief AglShellDoActivate:
260 + * wayland, agl-shell
262 + void AglShellDoActivate(const std::string& app_id, size_t index);
265 * @brief AglShell: Set up an activation area where to display the client's
267 diff --git a/shell/wayland/window.h b/shell/wayland/window.h
268 index d5e3c77..677dbdc 100644
269 --- a/shell/wayland/window.h
270 +++ b/shell/wayland/window.h
271 @@ -129,6 +129,8 @@ class WaylandWindow {
272 return std::pair<int32_t, int32_t>{m_geometry.width, m_geometry.height};
275 + std::shared_ptr<Display> GetDisplay() { return m_display; }
279 std::shared_ptr<Display> m_display;