From 917d1841c1ce1a6ca8afb78c14e891f4034d16a7 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 12 Jul 2024 15:07:08 +0200 Subject: [PATCH] Try better webview focusing. --- Telegram/SourceFiles/iv/iv_controller.cpp | 15 ++++++------- .../ui/chat/attach/attach_bot_webview.cpp | 21 +++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/Telegram/SourceFiles/iv/iv_controller.cpp b/Telegram/SourceFiles/iv/iv_controller.cpp index 4161fe876..e72298f6c 100644 --- a/Telegram/SourceFiles/iv/iv_controller.cpp +++ b/Telegram/SourceFiles/iv/iv_controller.cpp @@ -9,7 +9,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/platform/base_platform_info.h" #include "base/invoke_queued.h" -#include "base/qt_signal_producer.h" #include "base/qthelp_url.h" #include "iv/iv_data.h" #include "lang/lang_keys.h" @@ -281,12 +280,14 @@ void Controller::createWindow() { _window = std::make_unique(); const auto window = _window.get(); - base::qt_signal_producer( - window->window()->windowHandle(), - &QWindow::activeChanged - ) | rpl::filter([=] { - return _webview && window->window()->windowHandle()->isActive(); - }) | rpl::start_with_next([=] { + window->windowActiveValue( + ) | rpl::map([=] { + const auto handle = window->window()->windowHandle(); + return (_shareFocus || _webview) && handle && handle->isActive(); + }) | rpl::distinct_until_changed( + ) | rpl::filter( + rpl::mappers::_1 + ) | rpl::start_with_next([=] { setInnerFocus(); }, window->lifetime()); diff --git a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp index d367e3382..cbc27c0b8 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -739,15 +739,18 @@ postEvent: function(eventType, eventData) { setupProgressGeometry(); - base::qt_signal_producer( - _widget->window()->windowHandle(), - &QWindow::activeChanged - ) | rpl::filter([=] { - return _webview && _widget->window()->windowHandle()->isActive(); - }) | rpl::start_with_next([=] { - if (_webview && !_webview->window.widget()->isHidden()) { - _webview->window.focus(); - } + _widget->windowActiveValue( + ) | rpl::map([=] { + const auto handle = _widget->window()->windowHandle(); + return _webview + && !_webview->window.widget()->isHidden() + && handle + && handle->isActive(); + }) | rpl::distinct_until_changed( + ) | rpl::filter( + rpl::mappers::_1 + ) | rpl::start_with_next([=] { + _webview->window.focus(); }, _webview->lifetime); return true;