From 08f3d01a4ec0f649db7af0fbdbf25cab9f516429 Mon Sep 17 00:00:00 2001 From: night_xiaoye <2260737534@qq.com> Date: Wed, 10 Jun 2020 14:38:56 +0800 Subject: [PATCH] window: [fix bug]open app in horizontal screen, but window is in vertical state. Some app opens in horizontal screen, but window on anbox side is in vertical state, As the result, bottom of the window has black area. To solve this problem, we adjust window on anbox side when app opens in horizontal screen state. But, when window adjusted by user, app follows this adjustment and send this adjustment to anbox at the second time. So change of this commit has no effect after window is adjusted by user or 15s timeout. --- src/anbox/platform/sdl/window.cpp | 54 ++++++++++++++++++++++++++++++- src/anbox/platform/sdl/window.h | 4 +++ src/anbox/wm/window.h | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) diff --git a/src/anbox/platform/sdl/window.cpp b/src/anbox/platform/sdl/window.cpp index 089d3c84..7771a2c2 100755 --- a/src/anbox/platform/sdl/window.cpp +++ b/src/anbox/platform/sdl/window.cpp @@ -114,7 +114,8 @@ Window::Window(const std::shared_ptr &renderer, struct timeval now = (struct timeval) { 0 }; gettimeofday(&now, NULL); - lastClickTime = USEC_PER_SEC * (now.tv_sec) + now.tv_usec; + last_update_time = USEC_PER_SEC * (now.tv_sec) + now.tv_usec; + lastClickTime = last_update_time; SDL_ShowWindow(window_); } @@ -157,10 +158,19 @@ SDL_HitTestResult Window::on_window_hit(SDL_Window *window, const SDL_Point *pt, else break; + if (!platform_window->initialized.load()) { + INFO("window initialized by resize"); + platform_window->initialized = true; + } return result; } if (pt->y < top_drag_area_height) { + if (!platform_window->initialized.load()) { + INFO("window initialized by click top"); + platform_window->initialized = true; + } + if (pt->x > 0 && pt->x < button_area_width) { std::shared_ptr observer_temp = platform_window->observer_; if (observer_temp) { @@ -270,6 +280,48 @@ EGLNativeWindowType Window::native_handle() const { return native_window_; } Window::Id Window::id() const { return id_; } std::uint32_t Window::window_id() const { return SDL_GetWindowID(window_); } + +void Window::update_state(const wm::WindowState::List &states) { + if (!initialized.load() && !states.empty()) { + int w = 0; + int h = 0; + int x = 0; + int y = 0; + SDL_GetWindowSize(window_, &w, &h); + SDL_GetWindowPosition(window_, &x, &y); + + graphics::Rect rect; + int area = w * h; + for (auto ws : states) + { + int temp = ws.frame().width() * ws.frame().height(); + if (temp >= area) { + rect = ws.frame(); + } + } + + if (w == rect.width() && + h == rect.height() && + x == rect.left() && + y == rect.top()) { + return; + } + + struct timeval now = (struct timeval) { 0 }; + gettimeofday(&now, NULL); + long long current_time = USEC_PER_SEC * (now.tv_sec) + now.tv_usec; + if (current_time - last_update_time >= APP_START_MAX_TIME) { + INFO("window initialized by timeout"); + initialized = true; + return; + } + + last_update_time = current_time; + SDL_SetWindowSize(window_, rect.width(), rect.height()); + SDL_SetWindowPosition(window_, rect.left(), rect.top()); + update_frame(rect); + } +} } // namespace sdl } // namespace platform } // namespace anbox diff --git a/src/anbox/platform/sdl/window.h b/src/anbox/platform/sdl/window.h index 403d3fcd..543252b4 100755 --- a/src/anbox/platform/sdl/window.h +++ b/src/anbox/platform/sdl/window.h @@ -70,6 +70,8 @@ class Window : public std::enable_shared_from_this, public wm::Window { void process_event(const SDL_Event &event); bool check_min_state() {return SDL_GetWindowFlags(window_) & SDL_WINDOW_MINIMIZED;} + + void update_state(const wm::WindowState::List &states) override; bool check_db_clicked(int x, int y); EGLNativeWindowType native_handle() const override; @@ -82,6 +84,8 @@ class Window : public std::enable_shared_from_this, public wm::Window { void close(); void switch_window_state(); + std::atomic initialized{false}; + long long last_update_time{ 0 }; Id id_; std::shared_ptr observer_; EGLNativeDisplayType native_display_; diff --git a/src/anbox/wm/window.h b/src/anbox/wm/window.h index 7c3b282a..ef84e6df 100644 --- a/src/anbox/wm/window.h +++ b/src/anbox/wm/window.h @@ -51,7 +51,7 @@ class Window { bool attach(); void release(); - void update_state(const WindowState::List &states); + virtual void update_state(const WindowState::List &states); void update_frame(const graphics::Rect &frame); virtual EGLNativeWindowType native_handle() const; -- GitLab