Bug 152519 - SurroundingText is not working in kf5 VCL
Summary: SurroundingText is not working in kf5 VCL
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: LibreOffice (show other bugs)
Version:
(earliest affected)
7.4.2.3 release
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: KDE, KF5
  Show dependency treegraph
 
Reported: 2022-12-15 13:25 UTC by trmdi
Modified: 2022-12-23 16:18 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments
working in Kate (5.44 MB, video/x-matroska)
2022-12-19 16:20 UTC, trmdi
Details

Note You need to log in before you can comment on or make changes to this bug.
Description trmdi 2022-12-15 13:25:54 UTC
Description:
SurroundingText capability is used by some input method like fcitx, ibus...
It's broken in kf5 vcl but still works in the gtk mode.

Steps to Reproduce:
1. Install fcitx5-unikey and run it
2. With fcitx5-unikey, in Libre Writer, type: g[space][backspace]ias

Actual Results:
gía

Expected Results:
giá


Reproducible: Always


User Profile Reset: No

Additional Info:
.
Comment 1 Michael Weghorn 2022-12-19 13:20:02 UTC
(In reply to trmdi from comment #0)
> Steps to Reproduce:
> 1. Install fcitx5-unikey and run it

Can you please explain in more detail what "run it" means, i.e. how to (set it up if necessary and) run it?

I have installed package "fcitx5-unikey" in Debian testing, but I don't see any obvious executable to just run in the 'dpkg -L fcitx5-unikey' output, so maybe this needs to be set up and run in a certain way with the fcitx framework that I know little about? A step-by-step description to do so would be very helpful here.
Comment 2 Phoenix 2022-12-19 14:32:06 UTC
1) Install fcitx5-unikey
2) Open Fcitx5 and find and add Unikey to current input
3) Run im-config, choose fcitx5, and set fcitx5 to auto start
4) Log out and log in, Ctrl + Space switch im to Unikey and type in LibreOffice
Fcitx5 similar ibus
Comment 3 Michael Weghorn 2022-12-19 15:19:17 UTC
Thanks, I can reproduce the described difference between the gtk3 VCL plugin on the one side and kf5 or qt6 on the other side.

However, this doesn't look LibreOffice-specific to me, since I can reproduce the same with other Gtk/Qt-based applications:

* When I type "g[space][backspace]ias" in gedit (based on gtk), this results in "giá".

* When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get "gía".

Therefore, I tend to think that this is probably rather an issue in either Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of LibreOffice and would suggest to report that there instead.

Closing as NOTOURBUG for now due to these observations, but this can of course be reopened if other findings suggest that something actually needs to be done on LO side.


Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: gtk3
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: kf5 (cairo+xcb)
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded

Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: qt6 (qfont+xcb)
Locale: en-GB (en_GB.UTF-8); UI: en-US
Calc: threaded
Comment 4 Michael Weghorn 2022-12-19 15:25:48 UTC
(In reply to Michael Weghorn from comment #3)
> Therefore, I tend to think that this is probably rather an issue in either
> Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of
> LibreOffice and would suggest to report that there instead.

i.e., probably here: https://github.com/fcitx/fcitx5-qt/issues (or https://bugreports.qt.io for the Qt case)
Comment 5 trmdi 2022-12-19 16:03:15 UTC
(In reply to Michael Weghorn from comment #3)
> Thanks, I can reproduce the described difference between the gtk3 VCL plugin
> on the one side and kf5 or qt6 on the other side.
> 
> However, this doesn't look LibreOffice-specific to me, since I can reproduce
> the same with other Gtk/Qt-based applications:
> 
> * When I type "g[space][backspace]ias" in gedit (based on gtk), this results
> in "giá".
> 
> * When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get
> "gía".
> 
> Therefore, I tend to think that this is probably rather an issue in either
> Qt or the fcitx Qt integration (package "libfcitx5-qt1"?) instead of
> LibreOffice and would suggest to report that there instead.
> 
> Closing as NOTOURBUG for now due to these observations, but this can of
> course be reopened if other findings suggest that something actually needs
> to be done on LO side.
> 
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: gtk3
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: kf5 (cairo+xcb)
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded
> 
> Version: 7.6.0.0.alpha0+ (X86_64) / LibreOffice Community
> Build ID: d640bfe7767292c8a89de57d378dd752a8ec8342
> CPU threads: 12; OS: Linux 6.0; UI render: default; VCL: qt6 (qfont+xcb)
> Locale: en-GB (en_GB.UTF-8); UI: en-US
> Calc: threaded

Konsole doesn't support that, but Kate does.
The SurroundingText capability need support from the app. So I opened this request here to get the support from LibreOffice's kf5 vcl.
Comment 6 trmdi 2022-12-19 16:06:18 UTC
> When I type "g[space][backspace]ias" in kate or Konsole (Qt-based), I get "gía".

Probably something's wrong with your setup. It does support that here on my openSUSE Tumbleweed, Kate 22.12.0
Comment 7 trmdi 2022-12-19 16:20:34 UTC
Created attachment 184243 [details]
working in Kate
Comment 8 Xuetian Weng 2022-12-20 00:59:39 UTC
The issue for libreoffice is that, although it implements the surrounding support.
Like: https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L893

It doesn't seem to notify input method about surrounding changes, which is usually done with QWidget::updateMicroFocus(), or call QGuiApplication::inputMethod()->update(FLAGS).

```
void QWidget::updateMicroFocus()
{
    // updating everything since this is currently called for any kind of state change
    if (this == QGuiApplication::focusObject())
        QGuiApplication::inputMethod()->update(Qt::ImQueryAll);
}
```

I can only find libreoffice's qt implementation notifies about cursor rectangle change at 
https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L628
Comment 9 Xuetian Weng 2022-12-20 01:35:51 UTC
While it is possible to implement a polling like logic. Retrieving surrounding text is an expensive query, so I'd prefer libreoffice to notify the change instead of letting input method poll it.

Also, the implementation itself seems not working properly. Even if I tried to hack fcitx5-qt to poll the surrounding text by explicitly query the object, it return value for inputMethodQuery(Qt::ImSurroundingText) is still QVariant(Invalid).

So despite of adding qApp->inputMethod()->update(Qt::ImSurroundingText | Qt::ImCursorPosition | Qt::ImAnchorPosition) to a proper place maybe also check if this lcl_retrieveSurrounding actually works.
https://github.com/LibreOffice/core/blob/d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L897

Gtk counterpart seems to use a different approach for retrieving surrounding
https://github.com/LibreOffice/core/blob/83485052e6cac574754191c59371dbc41383b810/vcl/unx/gtk3/gtkframe.cxx#L5824
Comment 10 Michael Weghorn 2022-12-23 16:18:00 UTC
(In reply to trmdi from comment #6)
> Probably something's wrong with your setup. It does support that here on my
> openSUSE Tumbleweed, Kate 22.12.0

Indeed, was apparently some problem with my setup, since I was using the same Kate version. It works now.

Interestingly, I explicitly have to unset GTK_IM_MODULE (or set it to an empty string) because GTK_IM_MODULE=fcitx breaks the LO Writer use case with gtk3 (still works with Calc or gedit, though...).

(In reply to Xuetian Weng from comment #9)
> While it is possible to implement a polling like logic. Retrieving
> surrounding text is an expensive query, so I'd prefer libreoffice to notify
> the change instead of letting input method poll it.
> 
> Also, the implementation itself seems not working properly. Even if I tried
> to hack fcitx5-qt to poll the surrounding text by explicitly query the
> object, it return value for inputMethodQuery(Qt::ImSurroundingText) is still
> QVariant(Invalid).
> 
> So despite of adding qApp->inputMethod()->update(Qt::ImSurroundingText |
> Qt::ImCursorPosition | Qt::ImAnchorPosition) to a proper place maybe also
> check if this lcl_retrieveSurrounding actually works.
> https://github.com/LibreOffice/core/blob/
> d57836db76fcf3133e6eb54d264c774911015e08/vcl/qt5/QtWidget.cxx#L897
> 
> Gtk counterpart seems to use a different approach for retrieving surrounding
> https://github.com/LibreOffice/core/blob/
> 83485052e6cac574754191c59371dbc41383b810/vcl/unx/gtk3/gtkframe.cxx#L5824

Thank you so much, this is extremely helpful!

I have experimented a bit locally and have had a first quick-and-dirty version that somewhat works (but breaks other things), but needs more work for a proper solution.