[LyX/2.5.x] Synchronise the return of GuiInputMethod::inputMethodQuery()
Koji Yokota
yokota at lyx.org
Sat Jul 4 04:31:07 UTC 2026
commit 1a09c517cc23cfb3f73e0d37736015f167d5a6ca
Author: Koji Yokota <yokota at lyx.org>
Date: Fri May 8 09:17:07 2026 +0900
Synchronise the return of GuiInputMethod::inputMethodQuery()
---
src/frontends/qt/GuiInputMethod.cpp | 49 ++++++++++++++++++-------------------
src/frontends/qt/GuiInputMethod.h | 3 +--
src/frontends/qt/GuiWorkArea.cpp | 21 +---------------
src/frontends/qt/GuiWorkArea.h | 1 -
4 files changed, 26 insertions(+), 48 deletions(-)
diff --git a/src/frontends/qt/GuiInputMethod.cpp b/src/frontends/qt/GuiInputMethod.cpp
index 7850876c73..27da8d6841 100644
--- a/src/frontends/qt/GuiInputMethod.cpp
+++ b/src/frontends/qt/GuiInputMethod.cpp
@@ -906,13 +906,12 @@ int GuiInputMethod::shiftFromCaretToSegmentHead()
/* *
* * Input Method Query
* */
-void GuiInputMethod::processQuery(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 " +
@@ -924,8 +923,8 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
if (d->im_state_.enabled_)
LYXERR(Debug::DEBUG, msg << "true");
else
- LYXERR(Debug::DEBUG, msg << "false");
- Q_EMIT queryProcessed(d->im_state_.enabled_);
+ LYXERR(Debug::KEY, msg << "\"false\"");
+ return d->im_state_.enabled_;
break;
}
// this is the CJK-specific composition window position and
@@ -945,12 +944,12 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
LYXERR(Debug::DEBUG, 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::DEBUG, msg << d->cur_->selectionAsString(false));
- Q_EMIT queryProcessed(toqstr(d->cur_->selectionAsString(false)));
+ LYXERR(Debug::KEY, msg << d->cur_->selectionAsString(false));
+ return toqstr(d->cur_->selectionAsString(false));
break;
}
// plain text around the input area, for example the current paragraph
@@ -958,9 +957,9 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
if (d->im_state_.surrounding_text_.empty())
LYXERR(Debug::DEBUG, msg << "\"\"");
else
- LYXERR(Debug::DEBUG, msg <<
- d->im_state_.surrounding_text_.substr(0, 20) << "...");
- Q_EMIT queryProcessed(toqstr(d->im_state_.surrounding_text_));
+ LYXERR(Debug::KEY, msg << "\"" <<
+ d->im_state_.surrounding_text_.substr(0, 20) << "...\"");
+ return toqstr(d->im_state_.surrounding_text_);
break;
}
// logical position of the cursor within the entire document
@@ -968,8 +967,8 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
// FIXME: position should be set only when there was a non-virtual
// change in the document
setAbsolutePosition(*d->cur_);
- LYXERR(Debug::DEBUG, msg << std::dec << d->abs_pos_);
- Q_EMIT queryProcessed((qlonglong)d->abs_pos_);
+ LYXERR(Debug::KEY, msg << std::dec << d->abs_pos_);
+ return (qlonglong)d->abs_pos_;
break;
}
// plain text before the cursor
@@ -980,7 +979,7 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
else
LYXERR(Debug::DEBUG, msg << "…" << d->im_state_.text_before_);
QVariant str(toqstr(d->im_state_.text_before_));
- Q_EMIT queryProcessed(str);
+ return str;
break;
}
// plain text after the cursor
@@ -991,21 +990,21 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
else
LYXERR(Debug::DEBUG, msg << d->im_state_.text_after_);
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::DEBUG, msg << std::dec << d->cur_->pos());
- Q_EMIT queryProcessed((qlonglong)d->cur_->pos());
+ LYXERR(Debug::KEY, msg << std::dec << d->cur_->pos());
+ return (qlonglong)d->cur_->pos();
break;
}
// position of the selection anchor
case Qt::ImAnchorPosition: {
updatePosAndSurroundingText();
- LYXERR(Debug::DEBUG, msg << std::dec << (unsigned int)d->anchor_pos_);
- Q_EMIT queryProcessed(QVariant((unsigned int)d->anchor_pos_));
+ LYXERR(Debug::KEY, msg << std::dec << (unsigned int)d->anchor_pos_);
+ return QVariant((unsigned int)d->anchor_pos_);
break;
}
case Qt::ImInputItemClipRectangle: {
@@ -1016,7 +1015,7 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
LYXERR(Debug::DEBUG, 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
@@ -1024,15 +1023,15 @@ void GuiInputMethod::processQuery(Qt::InputMethodQuery query)
LYXERR(Debug::DEBUG, 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;
}
//
case Qt::ImPreferredLanguage: {
QLocale locale(toqstr(d->cur_->getFont().language()->code()));
QString lang = locale.languageToString(locale.language());
- LYXERR(Debug::DEBUG, msg << lang);
- Q_EMIT queryProcessed(lang);
+ LYXERR(Debug::KEY, msg << lang);
+ return lang;
break;
}
// Qt::ImAnchorRectangle holds the selection rectangle in preedit.
@@ -1043,14 +1042,14 @@ void GuiInputMethod::processQuery(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::DEBUG, "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 d052e82ed3..3868738adc 100644
--- a/src/frontends/qt/GuiInputMethod.h
+++ b/src/frontends/qt/GuiInputMethod.h
@@ -116,7 +116,6 @@ public:
bool canWrapAnywhere(pos_type const) override;
Q_SIGNALS:
void preeditProcessed(QInputMethodEvent* ev);
- void queryProcessed(QVariant response);
void inputMethodStateChanged(Qt::InputMethodQueries);
void cursorPositionChanged();
@@ -124,7 +123,7 @@ public Q_SLOTS:
/// Process incoming preedit string
void processPreedit(QInputMethodEvent* ev);
/// Process incoming input method query
- void processQuery(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 16edf513c2..0e0f194820 100644
--- a/src/frontends/qt/GuiWorkArea.cpp
+++ b/src/frontends/qt/GuiWorkArea.cpp
@@ -189,8 +189,6 @@ void GuiWorkArea::init()
d->im_, &GuiInputMethod::processPreedit);
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,
@@ -1352,18 +1350,7 @@ void GuiWorkArea::inputMethodEvent(QInputMethodEvent * ev)
QVariant GuiWorkArea::inputMethodQuery(Qt::InputMethodQuery query) const
{
- // ask a query
- d->im_->processQuery(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);
}
@@ -1412,12 +1399,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 1ac5b07643..47271cc4b0 100644
--- a/src/frontends/qt/GuiWorkArea.h
+++ b/src/frontends/qt/GuiWorkArea.h
@@ -138,7 +138,6 @@ private Q_SLOTS:
void fixVerticalScrollBar();
void flagPreedit(QInputMethodEvent* ev);
- void receiveIMQueryResponse(QVariant);
private:
/// Update window titles of all users.
More information about the lyx-cvs
mailing list