From 47b346ad74fd190325899f63b3f70826e306e734 Mon Sep 17 00:00:00 2001 From: yu_qinfei <878919698@qq.com> Date: Tue, 4 Aug 2020 19:30:31 +0800 Subject: [PATCH] launch:click the desktop icon to restore the minimized application after an app is minimized, the app icon does not respond when you click the app icon on the Desktop --- external/libSDL/SDL_fix_Restore.patch | 38 ++++++++++++++++++++++++++ src/anbox/bridge/android_api_stub.cpp | 9 +++++- src/anbox/bridge/android_api_stub.h | 5 ++++ src/anbox/cmds/session_manager.cpp | 1 + src/anbox/platform/base_platform.h | 1 + src/anbox/platform/null/platform.cpp | 4 +++ src/anbox/platform/null/platform.h | 1 + src/anbox/platform/sdl/platform.cpp | 14 ++++++++++ src/anbox/platform/sdl/platform.h | 1 + src/anbox/platform/sdl/window.cpp | 9 ++++++ src/anbox/platform/sdl/window.h | 2 ++ src/anbox/wm/manager.h | 1 + src/anbox/wm/multi_window_manager.cpp | 9 ++++++ src/anbox/wm/multi_window_manager.h | 1 + src/anbox/wm/single_window_manager.cpp | 5 ++++ src/anbox/wm/single_window_manager.h | 1 + 16 files changed, 101 insertions(+), 1 deletion(-) create mode 100644 external/libSDL/SDL_fix_Restore.patch diff --git a/external/libSDL/SDL_fix_Restore.patch b/external/libSDL/SDL_fix_Restore.patch new file mode 100644 index 00000000..e2cc5ea6 --- /dev/null +++ b/external/libSDL/SDL_fix_Restore.patch @@ -0,0 +1,38 @@ +diff --git a/src/events/SDL_windowevents.c b/src/events/SDL_windowevents.c +index 1670841..18e2135 100644 +--- a/src/events/SDL_windowevents.c ++++ b/src/events/SDL_windowevents.c +@@ -127,7 +127,6 @@ SDL_SendWindowEvent(SDL_Window * window, Uint8 windowevent, int data1, + if (window->flags & SDL_WINDOW_MINIMIZED) { + return 0; + } +- window->flags &= ~SDL_WINDOW_MAXIMIZED; + window->flags |= SDL_WINDOW_MINIMIZED; + SDL_OnWindowMinimized(window); + break; +diff --git a/src/video/x11/SDL_x11window.c b/src/video/x11/SDL_x11window.c +index 0a254b0..e87ff2f 100644 +--- a/src/video/x11/SDL_x11window.c ++++ b/src/video/x11/SDL_x11window.c +@@ -28,6 +28,7 @@ + #include "../SDL_pixels_c.h" + #include "../../events/SDL_keyboard_c.h" + #include "../../events/SDL_mouse_c.h" ++#include + + #include "SDL_x11video.h" + #include "SDL_x11mouse.h" +@@ -1166,7 +1167,12 @@ X11_MinimizeWindow(_THIS, SDL_Window * window) + void + X11_RestoreWindow(_THIS, SDL_Window * window) + { +- SetWindowMaximized(_this, window, SDL_FALSE); ++ if ((window->flags & SDL_WINDOW_MAXIMIZED) && (window->flags & SDL_WINDOW_MINIMIZED)) { ++ SetWindowMaximized(_this, window, SDL_TRUE); ++ } else { ++ SetWindowMaximized(_this, window, SDL_FALSE); ++ } ++ window->flags &= ~SDL_WINDOW_MINIMIZED; + X11_ShowWindow(_this, window); + SetWindowActive(_this, window); + } diff --git a/src/anbox/bridge/android_api_stub.cpp b/src/anbox/bridge/android_api_stub.cpp index b81ebe5e..eb67e97d 100644 --- a/src/anbox/bridge/android_api_stub.cpp +++ b/src/anbox/bridge/android_api_stub.cpp @@ -15,13 +15,13 @@ * */ +#include "anbox/platform/base_platform.h" #include "anbox/bridge/android_api_stub.h" #include "anbox/system_configuration.h" #include "anbox/logger.h" #include "anbox/rpc/channel.h" #include "anbox/utils.h" #include "anbox/wm/stack.h" - #include "anbox_bridge.pb.h" #include "anbox_rpc.pb.h" @@ -106,6 +106,9 @@ void AndroidApiStub::launch(const android::Intent &intent, *c = category; } + std::string package_name = intent.package; + platform_->restore_app(package_name); + channel_->call_method( "launch_application", &message, c->response.get(), google::protobuf::NewCallback(this, &AndroidApiStub::application_launched, @@ -223,5 +226,9 @@ void AndroidApiStub::task_resized(Request *request) { (void)request; resize_task_handle_.result_received(); } + +void AndroidApiStub::set_platform(const std::shared_ptr&base_platform) { + platform_ = base_platform; +} } // namespace bridge } // namespace anbox diff --git a/src/anbox/bridge/android_api_stub.h b/src/anbox/bridge/android_api_stub.h index d95fd7bd..3cf38526 100644 --- a/src/anbox/bridge/android_api_stub.h +++ b/src/anbox/bridge/android_api_stub.h @@ -34,6 +34,9 @@ class Void; namespace rpc { class Channel; } // namespace rpc +namespace platform { +class Platform; +} // namespace platform namespace bridge { class AndroidApiStub : public anbox::application::Manager { public: @@ -48,6 +51,7 @@ class AndroidApiStub : public anbox::application::Manager { void resize_task(const std::int32_t &id, const anbox::graphics::Rect &rect, const std::int32_t &resize_mode); + void set_platform(const std::shared_ptr&base_platform); void launch(const android::Intent &intent, const graphics::Rect &launch_bounds = graphics::Rect::Invalid, const wm::Stack::Id &stack = wm::Stack::Id::Default) override; @@ -70,6 +74,7 @@ class AndroidApiStub : public anbox::application::Manager { void task_resized(Request *request); mutable std::mutex mutex_; + std::shared_ptr platform_; std::shared_ptr channel_; common::WaitHandle launch_wait_handle_; common::WaitHandle set_focused_task_handle_; diff --git a/src/anbox/cmds/session_manager.cpp b/src/anbox/cmds/session_manager.cpp index 92d2b69f..d9c76efc 100644 --- a/src/anbox/cmds/session_manager.cpp +++ b/src/anbox/cmds/session_manager.cpp @@ -197,6 +197,7 @@ anbox::cmds::SessionManager::SessionManager() platform->set_window_manager(window_manager); platform->set_renderer(gl_server->renderer()); window_manager->setup(); + android_api_stub->set_platform(platform); auto app_manager = std::static_pointer_cast(android_api_stub); if (!using_single_window) { diff --git a/src/anbox/platform/base_platform.h b/src/anbox/platform/base_platform.h index d07a9283..244bafee 100644 --- a/src/anbox/platform/base_platform.h +++ b/src/anbox/platform/base_platform.h @@ -73,6 +73,7 @@ class BasePlatform { virtual void set_renderer(const std::shared_ptr &renderer) = 0; virtual void set_window_manager(const std::shared_ptr &window_manager) = 0; + virtual bool restore_app(const std::string &package_name) = 0; virtual bool supports_multi_window() const = 0; virtual int get_user_window_event() const = 0; virtual std::string ime_socket_file() const = 0; diff --git a/src/anbox/platform/null/platform.cpp b/src/anbox/platform/null/platform.cpp index b7d7badb..41b04654 100644 --- a/src/anbox/platform/null/platform.cpp +++ b/src/anbox/platform/null/platform.cpp @@ -79,6 +79,10 @@ int NullPlatform::get_user_window_event() const { return -1; } +bool NullPlatform::restore_app(const std::string &package_name) { + (void)package_name; +} + std::string NullPlatform::ime_socket_file() const { ERROR("Not implemented"); return ""; diff --git a/src/anbox/platform/null/platform.h b/src/anbox/platform/null/platform.h index c80ed90b..7e53c726 100644 --- a/src/anbox/platform/null/platform.h +++ b/src/anbox/platform/null/platform.h @@ -39,6 +39,7 @@ class NullPlatform : public BasePlatform { bool supports_multi_window() const override; int get_user_window_event() const override; std::string ime_socket_file() const override; + bool restore_app(const std::string &package_name) override; }; } // namespace wm } // namespace anbox diff --git a/src/anbox/platform/sdl/platform.cpp b/src/anbox/platform/sdl/platform.cpp index 05128a17..ee3951b7 100644 --- a/src/anbox/platform/sdl/platform.cpp +++ b/src/anbox/platform/sdl/platform.cpp @@ -650,6 +650,20 @@ int Platform::get_user_window_event() const { } return user_window_event; } + +bool Platform::restore_app(const std::string &package_name) { + auto title = window_manager_->get_title(package_name); + for (auto &iter : windows_) { + if (auto w = iter.second.lock()) { + if (w->title() == title) { + w->restore_window(); + DEBUG("ready to restore window"); + return true; + } + } + } + return false; +} } // namespace sdl } // namespace platform } // namespace anbox diff --git a/src/anbox/platform/sdl/platform.h b/src/anbox/platform/sdl/platform.h index 6294d590..d84c4dff 100644 --- a/src/anbox/platform/sdl/platform.h +++ b/src/anbox/platform/sdl/platform.h @@ -52,6 +52,7 @@ class Platform : public std::enable_shared_from_this, const anbox::graphics::Rect &frame, const std::string &title) override; + bool restore_app(const std::string &package_name) override; void input_key_event(const SDL_Scancode &scan_code, std::int32_t down_or_up) override; void window_deleted(const Window::Id &id) override; void window_wants_focus(const Window::Id &id) override; diff --git a/src/anbox/platform/sdl/window.cpp b/src/anbox/platform/sdl/window.cpp index e945faa3..aeac67da 100755 --- a/src/anbox/platform/sdl/window.cpp +++ b/src/anbox/platform/sdl/window.cpp @@ -369,6 +369,15 @@ void Window::update_state(const wm::WindowState::List &states) { update_frame(rect); } } + +void Window::restore_window() { + SDL_ShowWindow(window_); + SDL_RaiseWindow(window_); + auto flags = SDL_GetWindowFlags(window_); + if (flags & SDL_WINDOW_MINIMIZED) { + SDL_RestoreWindow(window_); + } +} } // namespace sdl } // namespace platform } // namespace anbox diff --git a/src/anbox/platform/sdl/window.h b/src/anbox/platform/sdl/window.h index c424276b..6a6d9043 100755 --- a/src/anbox/platform/sdl/window.h +++ b/src/anbox/platform/sdl/window.h @@ -77,6 +77,8 @@ class Window : public std::enable_shared_from_this, public wm::Window { void update_state(const wm::WindowState::List &states) override; bool check_db_clicked(int x, int y); + + void restore_window(); Id id() const; std::uint32_t window_id() const; Uint32 GetWindowFlags(){return SDL_GetWindowFlags(window_);} diff --git a/src/anbox/wm/manager.h b/src/anbox/wm/manager.h index 3f91df5c..133539c4 100644 --- a/src/anbox/wm/manager.h +++ b/src/anbox/wm/manager.h @@ -42,6 +42,7 @@ class Manager { virtual void insert_task(const Task::Id &task, std::shared_ptr pt) = 0; virtual void erase_task(const Task::Id &task) = 0; + virtual std::string get_title(const std::string &package_name) = 0; // FIXME only applies for the multi-window case virtual std::shared_ptr find_window_for_task(const Task::Id &task) = 0; }; diff --git a/src/anbox/wm/multi_window_manager.cpp b/src/anbox/wm/multi_window_manager.cpp index 8a5322ad..013c6ec1 100755 --- a/src/anbox/wm/multi_window_manager.cpp +++ b/src/anbox/wm/multi_window_manager.cpp @@ -141,5 +141,14 @@ void MultiWindowManager::erase_task(const Task::Id &task) { windows_.erase(it); } } + +std::string MultiWindowManager::get_title(const std::string &package_name) { + auto app = app_db_->find_by_package(package_name); + if (app.valid()) { + return app.name; + } else { + return package_name; + } +} } // namespace wm } // namespace anbox diff --git a/src/anbox/wm/multi_window_manager.h b/src/anbox/wm/multi_window_manager.h index 20c26bce..4bbb0dcd 100755 --- a/src/anbox/wm/multi_window_manager.h +++ b/src/anbox/wm/multi_window_manager.h @@ -54,6 +54,7 @@ class MultiWindowManager : public Manager { void insert_task(const Task::Id &task, std::shared_ptr pt) override; void erase_task(const Task::Id &task) override; + std::string get_title(const std::string &package_name) override; private: std::mutex mutex_; std::weak_ptr platform_; diff --git a/src/anbox/wm/single_window_manager.cpp b/src/anbox/wm/single_window_manager.cpp index c9b46409..1e644abe 100644 --- a/src/anbox/wm/single_window_manager.cpp +++ b/src/anbox/wm/single_window_manager.cpp @@ -84,5 +84,10 @@ void SingleWindowManager::insert_task(const Task::Id &task, std::shared_ptr pt) override; void erase_task(const Task::Id &task) override; + std::string get_title(const std::string &package_name) override; private: std::weak_ptr platform_; -- GitLab