diff --git a/src/anbox/platform/sdl/window.cpp b/src/anbox/platform/sdl/window.cpp index 089d3c847943060223916ba049aad07e8bcd7692..7771a2c230805aa35081a17af82ac6c97283e461 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 403d3fcdad37dd93e4281588c8eabb994f94e885..543252b450074adf332d4280bb425fd002b662f4 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 7c3b282a2bc14da5abd74b8edd1de818884abc84..ef84e6df00701b2ce76736a8248d42b6d51546d7 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;