commit 2a40e522575f3bac3491e48cacc8ad18a8d5c4a5
Author: Koji Yokota <[email protected]>
Date:   Fri May 8 09:17:07 2026 +0900

    Synchronise the return of GuiInputMethod::inputMethodQuery()
---
 src/frontends/qt/GuiInputMethod.cpp | 33 ++++++++++++++++-----------------
 src/frontends/qt/GuiInputMethod.h   |  3 +--
 src/frontends/qt/GuiWorkArea.cpp    | 21 +--------------------
 src/frontends/qt/GuiWorkArea.h      |  1 -
 4 files changed, 18 insertions(+), 40 deletions(-)

diff --git a/src/frontends/qt/GuiInputMethod.cpp 
b/src/frontends/qt/GuiInputMethod.cpp
index e28ca2fdda..d3aae50069 100644
--- a/src/frontends/qt/GuiInputMethod.cpp
+++ b/src/frontends/qt/GuiInputMethod.cpp
@@ -904,13 +904,12 @@ int GuiInputMethod::shiftFromCaretToSegmentHead()
 /* *
  * *        Input Method Query
  * */
-void GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
+QVariant GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
 {
        // input method is not ready yet
        if (d->buffer_view_->inputMethod() == nullptr) {
                QVariant null_answer;
-               Q_EMIT queryProcessed(null_answer);
-               return;
+               return null_answer;
        }
 
        docstring msg = "Responded to query " +
@@ -922,7 +921,7 @@ void GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery 
query)
                        LYXERR(Debug::KEY, msg << "\"true\"");
                else
                        LYXERR(Debug::KEY, msg << "\"false\"");
-               Q_EMIT queryProcessed(d->im_state_.enabled_);
+               return d->im_state_.enabled_;
                break;
        }
        // this is the CJK-specific composition window position and
@@ -942,12 +941,12 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
 
                LYXERR(Debug::KEY, msg << " x:" << rect->x() << " y:" << 
rect->y()
                       << " w:" << rect->width() << " h:" << rect->height());
-               Q_EMIT queryProcessed(*rect);
+               return *rect;
                break;
        }
        case Qt::ImCurrentSelection: {
                LYXERR(Debug::KEY, msg << d->cur_->selectionAsString(false));
-               Q_EMIT 
queryProcessed(toqstr(d->cur_->selectionAsString(false)));
+               return toqstr(d->cur_->selectionAsString(false));
                break;
        }
        // plain text around the input area, for example the current paragraph
@@ -960,7 +959,7 @@ void GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery 
query)
                else
                        LYXERR(Debug::KEY, msg << "\"" <<
                               d->im_state_.surrounding_text_.substr(0, 20) << 
"...\"");
-               Q_EMIT queryProcessed(toqstr(d->im_state_.surrounding_text_));
+               return toqstr(d->im_state_.surrounding_text_);
                break;
        }
        // logical position of the cursor within the entire document
@@ -969,7 +968,7 @@ void GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery 
query)
                // change in the document
                setAbsolutePosition(*d->cur_);
                LYXERR(Debug::KEY, msg << std::dec << d->abs_pos_);
-               Q_EMIT queryProcessed((qlonglong)d->abs_pos_);
+               return (qlonglong)d->abs_pos_;
                break;
        }
        // plain text before the cursor
@@ -983,7 +982,7 @@ void GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery 
query)
                        LYXERR(Debug::KEY, msg << "\"..." <<
                               d->im_state_.text_before_.substr(0, 20) << "\"");
                QVariant str(toqstr(d->im_state_.text_before_));
-               Q_EMIT queryProcessed(str);
+               return str;
                break;
        }
        // plain text after the cursor
@@ -997,21 +996,21 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
                        LYXERR(Debug::KEY, msg << "\"..." <<
                               d->im_state_.text_after_.substr(0, 20) << "\"");
                QVariant str(toqstr(d->im_state_.text_after_));
-               Q_EMIT queryProcessed(str);
+               return str;
                break;
        }
        // logical position of the cursor within the text surrounding the input 
area
        case Qt::ImCursorPosition: {
                updatePosAndSurroundingText();
                LYXERR(Debug::KEY, msg << std::dec << d->cur_->pos());
-               Q_EMIT queryProcessed((qlonglong)d->cur_->pos());
+               return (qlonglong)d->cur_->pos();
                break;
        }
        // position of the selection anchor
        case Qt::ImAnchorPosition: {
                updatePosAndSurroundingText();
                LYXERR(Debug::KEY, msg << std::dec << (unsigned 
int)d->anchor_pos_);
-               Q_EMIT queryProcessed(QVariant((unsigned int)d->anchor_pos_));
+               return QVariant((unsigned int)d->anchor_pos_);
                break;
        }
        case Qt::ImInputItemClipRectangle: {
@@ -1022,7 +1021,7 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
                LYXERR(Debug::KEY, msg << "(x,y,w,h) = " <<
                       viewport.x() << ", " << viewport.y() << ", " <<
                       viewport.width() << ", " << viewport.height() << ")");
-               Q_EMIT queryProcessed(viewport);
+               return viewport;
                break;
        }
        // hints for input method on expected input
@@ -1030,7 +1029,7 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
                LYXERR(Debug::KEY, msg << "0x" << std::hex
                                         << d->work_area_->inputMethodHints()
                                         << std::dec);
-               Q_EMIT 
queryProcessed((qlonglong)d->work_area_->inputMethodHints());
+               return (qlonglong)d->work_area_->inputMethodHints();
                break;
        }
        //
@@ -1038,7 +1037,7 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
                QLocale locale(toqstr(d->cur_->getFont().language()->code()));
                QString lang = locale.languageToString(locale.language());
                LYXERR(Debug::KEY, msg << lang);
-               Q_EMIT queryProcessed(lang);
+               return lang;
                break;
        }
        // Qt::ImAnchorRectangle holds the selection rectangle in preedit.
@@ -1049,14 +1048,14 @@ void 
GuiInputMethod::inputMethodQuery(Qt::InputMethodQuery query)
                       << " y:" << d->im_state_.anchor_rect_.y()
                       << " w:" << d->im_state_.anchor_rect_.width()
                       << " h:" << d->im_state_.anchor_rect_.height());
-               Q_EMIT queryProcessed(d->im_state_.anchor_rect_);
+               return d->im_state_.anchor_rect_;
                break;
        }
        default: {
                QVariant null;
                LYXERR(Debug::KEY, "Unsupported query by LyX came in: " <<
                       inputMethodQueryFlagsAsString(query));
-               Q_EMIT queryProcessed(null);
+               return null;
        }
        }
 }
diff --git a/src/frontends/qt/GuiInputMethod.h 
b/src/frontends/qt/GuiInputMethod.h
index 87e5e3d8f9..66cdeea033 100644
--- a/src/frontends/qt/GuiInputMethod.h
+++ b/src/frontends/qt/GuiInputMethod.h
@@ -121,14 +121,13 @@ public:
        bool canWrapAnywhere(pos_type const) override;
 Q_SIGNALS:
        void preeditProcessed(QInputMethodEvent* ev);
-       void queryProcessed(QVariant response);
        void inputMethodStateChanged(Qt::InputMethodQueries);
 
 public Q_SLOTS:
        /// Process incoming preedit string
        void inputMethodEvent(QInputMethodEvent* ev);
        /// Process incoming input method query
-       void inputMethodQuery(Qt::InputMethodQuery query);
+       QVariant inputMethodQuery(Qt::InputMethodQuery query);
        /// Turn off IM in math mode and command phase and turn it on otherwise
        void toggleInputMethodAcceptance() override;
        /// Enable the input method
diff --git a/src/frontends/qt/GuiWorkArea.cpp b/src/frontends/qt/GuiWorkArea.cpp
index 4b36d1b73c..fe937f8860 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -188,8 +188,6 @@ void GuiWorkArea::init()
        connect(&d->caret_timeout_, SIGNAL(timeout()), this, 
SLOT(toggleCaret()));
        connect(d->im_, &GuiInputMethod::preeditProcessed,
                this, &GuiWorkArea::flagPreedit);
-       connect(d->im_, &GuiInputMethod::queryProcessed,
-               this, &GuiWorkArea::receiveIMQueryResponse);
        connect(guiApp, &GuiApplication::keyCommandStateSet,
                        this, &GuiWorkArea::onKeyCommandStateSet);
        connect(this, &GuiWorkArea::keyCommandStateSet,
@@ -1396,18 +1394,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * 
ev)
 
 QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
 {
-       // ask a query
-       d->im_->inputMethodQuery(query);
-
-       // wait for the response and return
-       clock_t start = clock();
-       while (!d->im_query_responded_) {
-               // time out in one second
-               if ((clock() - start)/CLOCKS_PER_SEC >= 1) break;
-       }
-       d->im_query_responded_ = false;
-
-       return d->im_query_response_;
+       return d->im_->inputMethodQuery(query);
 }
 
 
@@ -1456,12 +1443,6 @@ void GuiWorkArea::flagPreedit(QInputMethodEvent* ev)
 }
 
 
-void GuiWorkArea::receiveIMQueryResponse(QVariant response) {
-       d->im_query_response_ = response;
-       // notify the response
-       d->im_query_responded_ = true;
-}
-
 GuiCompleter & GuiWorkArea::completer()
 {
        return *d->completer_;
diff --git a/src/frontends/qt/GuiWorkArea.h b/src/frontends/qt/GuiWorkArea.h
index e007135246..d9bca99ceb 100644
--- a/src/frontends/qt/GuiWorkArea.h
+++ b/src/frontends/qt/GuiWorkArea.h
@@ -136,7 +136,6 @@ private Q_SLOTS:
        void fixVerticalScrollBar();
 
        void flagPreedit(QInputMethodEvent* ev);
-       void receiveIMQueryResponse(QVariant);
 
 private:
        /// Update window titles of all users.
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to