summaryrefslogtreecommitdiffstats
path: root/src/gui/kernel/qplatforminputcontext.cpp
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-09-20 22:38:26 +0200
committerTor Arne Vestbø <tor.arne.vestbo@qt.io>2023-10-06 15:48:45 +0200
commitd9bb8c0a1702ed345ddacdc0179a43d1dc4722a7 (patch)
treeb09a7c502d478a3715e82b9141f52213c73bae32 /src/gui/kernel/qplatforminputcontext.cpp
parent84d0ebabaab38a900b74bb0f384f46f3c9a400d2 (diff)
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 <liang.qi@qt.io>
Diffstat (limited to 'src/gui/kernel/qplatforminputcontext.cpp')
-rw-r--r--src/gui/kernel/qplatforminputcontext.cpp12
1 files changed, 12 insertions, 0 deletions
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;
}
/*!