From c70866a9956ae5ab2612e10637e7427c0ae29245 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 19 Jul 2024 17:42:08 +0200 Subject: [PATCH] Fix child native window focus. --- Telegram/SourceFiles/iv/iv_controller.cpp | 15 ++++++++------- .../ui/chat/attach/attach_bot_webview.cpp | 13 ++++++------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/iv/iv_controller.cpp b/Telegram/SourceFiles/iv/iv_controller.cpp index e72298f6c..b3fb82a0d 100644 --- a/Telegram/SourceFiles/iv/iv_controller.cpp +++ b/Telegram/SourceFiles/iv/iv_controller.cpp @@ -9,6 +9,7 @@ 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" @@ -35,6 +36,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include #include #include +#include #include #include #include @@ -280,14 +282,13 @@ void Controller::createWindow() { _window = std::make_unique(); const auto window = _window.get(); - window->windowActiveValue( - ) | rpl::map([=] { + base::qt_signal_producer( + qApp, + &QGuiApplication::focusWindowChanged + ) | rpl::filter([=](QWindow *focused) { 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([=] { + return _webview && handle && (focused == handle); + }) | 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 6a50d2590..a8dee5f76 100644 --- a/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp +++ b/Telegram/SourceFiles/ui/chat/attach/attach_bot_webview.cpp @@ -741,17 +741,16 @@ postEvent: function(eventType, eventData) { setupProgressGeometry(); - _widget->windowActiveValue( - ) | rpl::map([=] { + base::qt_signal_producer( + qApp, + &QGuiApplication::focusWindowChanged + ) | rpl::filter([=](QWindow *focused) { 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([=] { + && (focused == handle); + }) | rpl::start_with_next([=] { _webview->window.focus(); }, _webview->lifetime);