From d9bb8c0a1702ed345ddacdc0179a43d1dc4722a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Wed, 20 Sep 2023 22:38:26 +0200 Subject: [PATCH] Automatically reflect new input context input direction when locale changes All platforms except Wayland fail to check for input direction change when the locale changes, and only emitLocaleChanged. We can simplify this for the platforms by checking if the new locale caused a change in input direction, and if so emit inputDirectionChanged on their behalf. Change-Id: I84d8df9392db5e716f5c277d0cc9e17e5a21783f Reviewed-by: Liang Qi --- src/gui/kernel/qplatforminputcontext.cpp | 12 ++++++++++++ src/gui/kernel/qplatforminputcontext.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/gui/kernel/qplatforminputcontext.cpp b/src/gui/kernel/qplatforminputcontext.cpp index 4cf7acea2e..9d3ee4acb6 100644 --- a/src/gui/kernel/qplatforminputcontext.cpp +++ b/src/gui/kernel/qplatforminputcontext.cpp @@ -47,6 +47,11 @@ QT_BEGIN_NAMESPACE QPlatformInputContext::QPlatformInputContext() : QObject(*(new QPlatformInputContextPrivate)) { + // Delay initialization of cached input direction + // until super class has finished constructing. + QMetaObject::invokeMethod(this, [this]{ + m_inputDirection = inputDirection(); + }, Qt::QueuedConnection); } /*! @@ -198,6 +203,9 @@ QLocale QPlatformInputContext::locale() const void QPlatformInputContext::emitLocaleChanged() { emit QGuiApplication::inputMethod()->localeChanged(); + + // Changing the locale might have updated the input direction + emitInputDirectionChanged(inputDirection()); } Qt::LayoutDirection QPlatformInputContext::inputDirection() const @@ -207,7 +215,11 @@ Qt::LayoutDirection QPlatformInputContext::inputDirection() const void QPlatformInputContext::emitInputDirectionChanged(Qt::LayoutDirection newDirection) { + if (newDirection == m_inputDirection) + return; + emit QGuiApplication::inputMethod()->inputDirectionChanged(newDirection); + m_inputDirection = newDirection; } /*! diff --git a/src/gui/kernel/qplatforminputcontext.h b/src/gui/kernel/qplatforminputcontext.h index 05d7497f9c..481f97a065 100644 --- a/src/gui/kernel/qplatforminputcontext.h +++ b/src/gui/kernel/qplatforminputcontext.h @@ -72,6 +72,8 @@ private: friend class QGuiApplication; friend class QGuiApplicationPrivate; friend class QInputMethod; + + Qt::LayoutDirection m_inputDirection; }; QT_END_NAMESPACE