[graphics/drawy/gsoc2026] src/widgets/controller: fix: handle switching apps while preedit is active

Laurent Montel <[email protected]>
Newsgroups gmane.comp.kde.cvs
Message-ID <[email protected]>
Git commit 4f9698ecc45c06b8cf86abff975df6094eb01e14 by Laurent Montel, on behalf of Abdelhadi Wael.
Committed on 06/08/2026 at 18:09.
Pushed by mlaurent into branch 'gsoc2026'.

fix: handle switching apps while preedit is active

M  +12   -1    src/widgets/controller/controller.cpp
M  +1    -0    src/widgets/controller/controller.hpp

https://invent.kde.org/graphics/drawy/-/commit/4f9698ecc45c06b8cf86abff975df6094eb01e14

diff --git a/src/widgets/controller/controller.cpp b/src/widgets/controller/controller.cpp
index 9f5850ad..62f45dc8 100644
--- a/src/widgets/controller/controller.cpp
+++ b/src/widgets/controller/controller.cpp
@@ -12,7 +12,6 @@
 #include "command/commandhistory.hpp"
 #include "command/insertitemcommand.hpp"
 #include "common/constants.hpp"
-#include "common/renderitems.hpp"
 #include "components/toolbar.hpp"
 #include "context/applicationcontext.hpp"
 #include "context/coordinatetransformer.hpp"
@@ -34,6 +33,7 @@ Controller::Controller(ApplicationContext *context, QObject *parent)
     , m_zoomTimer{new QTimer{this}}
 {
     connect(m_zoomTimer, &QTimer::timeout, this, &Controller::renderZoom);
+    connect(qApp, &QGuiApplication::applicationStateChanged, this, &Controller::applicationStateChanged);
 }
 
 Controller::~Controller()
@@ -418,6 +418,17 @@ void Controller::drop()
     m_context->renderingContext()->markForUpdate();
 }
 
+void Controller::applicationStateChanged(const Qt::ApplicationState state)
+{
+    if (state == Qt::ApplicationInactive || state == Qt::ApplicationSuspended) {
+        QGuiApplication::inputMethod()->reset();
+
+        const QList<QInputMethodEvent::Attribute> attributes;
+        QInputMethodEvent event(QString(), attributes);
+        inputMethodInvoked(&event);
+    }
+}
+
 void Controller::renderZoom()
 {
     if (m_zoomDelta == 0) {
diff --git a/src/widgets/controller/controller.hpp b/src/widgets/controller/controller.hpp
index 8b95e27f..7746a3db 100644
--- a/src/widgets/controller/controller.hpp
+++ b/src/widgets/controller/controller.hpp
@@ -36,6 +36,7 @@ public:
     void dragMove(QDragMoveEvent *event);
     void dragLeave();
     void drop();
+    void applicationStateChanged(Qt::ApplicationState state);
 
 private:
     void renderZoom();
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.