vcl/inc/qt5/Qt5Frame.hxx | 4 ++++ vcl/inc/qt5/Qt5Instance.hxx | 1 + vcl/qt5/Qt5Frame.cxx | 11 ++++++++--- vcl/qt5/Qt5Instance.cxx | 16 ++++++++++++++++ 4 files changed, 29 insertions(+), 3 deletions(-)
New commits: commit 9d96088c2832b681ae079b29cbc977231674ad52 Author: Jan-Marek Glogowski <glo...@fbihome.de> AuthorDate: Sun Nov 22 14:53:14 2020 +0100 Commit: Jan-Marek Glogowski <glo...@fbihome.de> CommitDate: Sun Nov 22 17:01:07 2020 +0100 Qt5 report input method language This is in the spirit of tdf#108151, based on the information Qt provides for the IM setting. I don't know how correct it is, especially looking at Caolans comment 3 in that bug report regarding the assumed validity of GtkIMContextInfo. OTOH it seems to work well enough for my simple tests. Some BG info: while the QInputMethod object is a global one, it's "bound" to the focused window. So you'll get change events, when you change the input window, with the correct IM settings for the new one, be it a real window or just the menu bar. To prevent unneeded flushes of buffers and language lookup, this caches the current IM language of a window. The language is not affected just by changing keyboard mappings, which the bug reporter requested! It just works with a configured input method, like fcitx or ibus (which can have keyboard mappings too, which work correctly). Change-Id: Ia9133edf4d1ce77d29adbfe57c180db15db0a560 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/106354 Tested-by: Jenkins Reviewed-by: Jan-Marek Glogowski <glo...@fbihome.de> diff --git a/vcl/inc/qt5/Qt5Frame.hxx b/vcl/inc/qt5/Qt5Frame.hxx index 54a721e03730..c07fda54ec40 100644 --- a/vcl/inc/qt5/Qt5Frame.hxx +++ b/vcl/inc/qt5/Qt5Frame.hxx @@ -109,6 +109,8 @@ class VCLPLUG_QT5_PUBLIC Qt5Frame : public QObject, public SalFrame ScreenSaverInhibitor m_ScreenSaverInhibitor; #endif + LanguageType m_nInputLanguage; + void SetDefaultPos(); Size CalcDefaultSize(); void SetDefaultSize(); @@ -211,6 +213,8 @@ public: virtual void SetApplicationID(const OUString&) override; inline bool CallCallback(SalEvent nEvent, const void* pEvent) const; + + void setInputLanguage(LanguageType); }; inline bool Qt5Frame::CallCallback(SalEvent nEvent, const void* pEvent) const diff --git a/vcl/inc/qt5/Qt5Instance.hxx b/vcl/inc/qt5/Qt5Instance.hxx index d73a59de51c1..cd9c51826a90 100644 --- a/vcl/inc/qt5/Qt5Instance.hxx +++ b/vcl/inc/qt5/Qt5Instance.hxx @@ -73,6 +73,7 @@ class VCLPLUG_QT5_PUBLIC Qt5Instance : public QObject, private Q_SLOTS: bool ImplYield(bool bWait, bool bHandleAllCurrentEvents); static void deleteObjectLater(QObject* pObject); + static void localeChanged(); Q_SIGNALS: bool ImplYieldSignal(bool bWait, bool bHandleAllCurrentEvents); diff --git a/vcl/qt5/Qt5Frame.cxx b/vcl/qt5/Qt5Frame.cxx index 06984b983a79..ad541db4f70c 100644 --- a/vcl/qt5/Qt5Frame.cxx +++ b/vcl/qt5/Qt5Frame.cxx @@ -116,6 +116,7 @@ Qt5Frame::Qt5Frame(Qt5Frame* pParent, SalFrameStyleFlags nStyle, bool bUseCairo) , m_bDefaultPos(true) , m_bFullScreen(false) , m_bFullScreenSpanAll(false) + , m_nInputLanguage(LANGUAGE_DONTKNOW) { Qt5Instance* pInst = static_cast<Qt5Instance*>(GetSalData()->m_pInstance); pInst->insertFrame(this); @@ -995,10 +996,14 @@ bool Qt5Frame::MapUnicodeToKeyCode(sal_Unicode /*aUnicode*/, LanguageType /*aLan return false; } -LanguageType Qt5Frame::GetInputLanguage() +LanguageType Qt5Frame::GetInputLanguage() { return m_nInputLanguage; } + +void Qt5Frame::setInputLanguage(LanguageType nInputLanguage) { - // fallback - return LANGUAGE_DONTKNOW; + if (nInputLanguage == m_nInputLanguage) + return; + m_nInputLanguage = nInputLanguage; + CallCallback(SalEvent::InputLanguageChange, nullptr); } static Color toColor(const QColor& rColor) diff --git a/vcl/qt5/Qt5Instance.cxx b/vcl/qt5/Qt5Instance.cxx index ca1f914dd707..97eff04fe77a 100644 --- a/vcl/qt5/Qt5Instance.cxx +++ b/vcl/qt5/Qt5Instance.cxx @@ -229,6 +229,9 @@ Qt5Instance::Qt5Instance(std::unique_ptr<QApplication>& pQApp, bool bUseCairo) connect(dispatcher, &QAbstractEventDispatcher::awake, this, [this]() { m_bSleeping = false; }); connect(dispatcher, &QAbstractEventDispatcher::aboutToBlock, this, [this]() { m_bSleeping = true; }); + + connect(QGuiApplication::inputMethod(), &QInputMethod::localeChanged, this, + &Qt5Instance::localeChanged); } Qt5Instance::~Qt5Instance() @@ -248,6 +251,19 @@ void Qt5Instance::AfterAppInit() : Qt::LeftToRight); } +void Qt5Instance::localeChanged() +{ + SolarMutexGuard aGuard; + const vcl::Window* pFocusWindow = Application::GetFocusWindow(); + SalFrame* const pFocusFrame = pFocusWindow ? pFocusWindow->ImplGetFrame() : nullptr; + if (!pFocusFrame) + return; + + const LanguageTag aTag( + toOUString(QGuiApplication::inputMethod()->locale().name().replace("_", "-"))); + static_cast<Qt5Frame*>(pFocusFrame)->setInputLanguage(aTag.getLanguageType()); +} + void Qt5Instance::deleteObjectLater(QObject* pObject) { pObject->deleteLater(); } SalFrame* Qt5Instance::CreateChildFrame(SystemParentData* /*pParent*/, SalFrameStyleFlags nStyle) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits