Bug 140207 - Qt's ImCursorRectangle is not correctly take device scale factor into account
Summary: Qt's ImCursorRectangle is not correctly take device scale factor into account
Status: RESOLVED FIXED
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: UI (show other bugs)
Version:
(earliest affected)
7.1.0.3 release
Hardware: All All
: medium normal
Assignee: Jan-Marek Glogowski
URL:
Whiteboard: target:7.2.0 target:7.1.2 target:7.0.5
Keywords:
Depends on:
Blocks: KDE, KF5
  Show dependency treegraph
 
Reported: 2021-02-06 08:37 UTC by Xuetian Weng
Modified: 2021-02-16 13:07 UTC (History)
1 user (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Xuetian Weng 2021-02-06 08:37:27 UTC
For regular Qt application, the ImCursorRectangle value returned by inputMethodQuery is scaled with the corresponding QWindow's device scale factor.

But libreoffice returns the non-scaled value which confuses the input method and send the non-native coordinates.

To be more concrete, this is how the coordinates being transformed by fcitx: (fcitx is expected to receive the native pixel value from application)

https://github.com/fcitx/fcitx5-qt/blob/cb48a057e1bcb0961a9eaaf12dda73f164b98b0c/qt5/platforminputcontext/qfcitxplatforminputcontext.cpp#L413

As you can see, the coordinates is up-scaled based on the input window's device pixel ratio then sent to input method server. But libreoffice set the non-scale value here, which makes it scaled wrongly in this code.

In this case, Libreoffice need to be fixed to behave consistently with other Qt application on this value (dividing the value by window scale).
Comment 1 Michael Weghorn 2021-02-15 06:41:39 UTC
(In reply to Xuetian Weng from comment #0)
> For regular Qt application, the ImCursorRectangle value returned by
> inputMethodQuery is scaled with the corresponding QWindow's device scale
> factor.
> 
> But libreoffice returns the non-scaled value which confuses the input method
> and send the non-native coordinates.
> 
> To be more concrete, this is how the coordinates being transformed by fcitx:
> (fcitx is expected to receive the native pixel value from application)
> 
> https://github.com/fcitx/fcitx5-qt/blob/
> cb48a057e1bcb0961a9eaaf12dda73f164b98b0c/qt5/platforminputcontext/
> qfcitxplatforminputcontext.cpp#L413
> 
> As you can see, the coordinates is up-scaled based on the input window's
> device pixel ratio then sent to input method server. But libreoffice set the
> non-scale value here, which makes it scaled wrongly in this code.

Thanks for your report and explanation on what's happening. Can you give specific steps on how one can reproduce that something behaves in a wrong way (description of steps to take, expected vs. actual behaviour)?

In case you already know how to fix the issue: We're happy to review and accept patches. :-)
https://wiki.documentfoundation.org/Development/GetInvolved
Comment 2 Jan-Marek Glogowski 2021-02-15 17:18:18 UTC
There is now https://gerrit.libreoffice.org/c/core/+/110945

I first tried to do some mapToParent stuff from the linked fcitx code. But actually we literally just need to "dividing the value by window scale".

Easy to reproduce, if you have a complex input, like Pinyin and start LO with QT_SCALE_FACTOR=1.5, activate IM and the input methods window is positioned wrong.

Also the terminology with "native" pixels caught me wrong :-)
Comment 3 Commit Notification 2021-02-15 19:45:10 UTC
Jan-Marek Glogowski committed a patch related to this issue.
It has been pushed to "master":

https://git.libreoffice.org/core/commit/41cffc379259fec626a282ca243a9750d96d1c63

tdf#140207 Qt downscale the ExtTextInputPos

It will be available in 7.2.0.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 4 Commit Notification 2021-02-16 06:38:32 UTC
Jan-Marek Glogowski committed a patch related to this issue.
It has been pushed to "libreoffice-7-1":

https://git.libreoffice.org/core/commit/61bf6b4d90aa1d37009b397e44fe39c9c5b06afd

tdf#140207 Qt downscale the ExtTextInputPos

It will be available in 7.1.2.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.
Comment 5 Commit Notification 2021-02-16 13:07:04 UTC
Jan-Marek Glogowski committed a patch related to this issue.
It has been pushed to "libreoffice-7-0":

https://git.libreoffice.org/core/commit/cb566a1806563f779690d79479ad5ba1ccef0460

tdf#140207 Qt downscale the ExtTextInputPos

It will be available in 7.0.5.

The patch should be included in the daily builds available at
https://dev-builds.libreoffice.org/daily/ in the next 24-48 hours. More
information about daily builds can be found at:
https://wiki.documentfoundation.org/Testing_Daily_Builds

Affected users are encouraged to test the fix and report feedback.