Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mozc Renderer: Windows are not placed under the cursor with HiDPI display #823

Closed
ftake opened this issue Oct 17, 2023 · 2 comments
Closed

Comments

@ftake
Copy link
Contributor

ftake commented Oct 17, 2023

Description

Qt6 does not support AA_EnableHighDpiScaling as mentioned in compiler warnings.

renderer/qt/qt_server.cc:109:34: warning: 'Qt::AA_EnableHighDpiScaling' is deprecated: High-DPI scaling is always enabled.
This attribute no longer has any effect. [-Wdeprecated-declarations]
 109 |   QApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

It now always uses virtual pixels. However, IBus only knows about device pixels and it sends a preedit rect in device pixel coordinates. Thus, a candidate window is usually placed bottom-right of the appropriate place.

Steps to reproduce

Steps to reproduce the behavior:

  1. Set display DPI to 120
  2. Open gEdit, type some keys
  3. The suggestion window and candidate window is not shown in a correct place

Screenshots

Screenshot_20231017_222954

Version or commit-id

Mozc-2.29.5220.102+24.11.oss

Environment

  • OS: openSUSE Leap 15.5,
  • IMF (for Linux): IBus 1.5.25
  • Related Applications
    • Qt 6.4.2
    • KDE Plasma 5.27.4.1-bp155.1.7

Investigations

  • Whether this issue happens on both Ibus and other IMF (e.g. Fcitx, uim).
    • N/A
  • Whether this issue happens on other IMEs (e.g. Anthy, SKK).
    • N/A
  • What applications this issue happens on (e.g. Chromium, gedit).
    • gEdit, VSCode
  • What applications this issue does not happen on (e.g. Chromium, gedit).
  • (optional) What versions or commit-ids this issue did not happen on
    (e.g. Mozc-2.28.4960.100+24.11.oss).
    • list of versions or commit-ids, or no-investigation.

Additional context

@yukawa
Copy link
Collaborator

yukawa commented Oct 17, 2023

I cannot find any function that converts device pixels to virtual.

I think what you need to do is just dividing the virtual screen coordinates with device pixel ratio, as explained the Qt document you linked.

For example, creating a QWindow or QWidget, and setting its size to 200x200 will cover 200x200 display pixels on a normal density display (with a device pixel ratio of 1.0), but will cover 400x400 pixels on a high density display (with a device pixel ratio of 2.0).

The device pixel ratio mentioned here can be obtained with QScreen::devicePixelRatio(), and Given that X11 doesn't support user-configurable per-monitor DPI, I guess you can simply use primary display's device pixel ratio.

const auto dpr = QGuiApplication::primaryScreen()->devicePixelRatio();

Can you confirm that 1) QGuiApplication::primaryScreen()->devicePixelRatio() is higher than 1.0 in your environment and 2) dividing the screen coordinates provided by IBus with QGuiApplication::primaryScreen()->devicePixelRatio() gives us the virtual screen coordinates that Qt relies on?

@ftake
Copy link
Contributor Author

ftake commented Nov 5, 2023

  1. QGuiApplication::primaryScreen()->devicePixelRatio() is higher than 1.0 in your environment

It is 1.25

  1. dividing the screen coordinates provided by IBus with QGuiApplication::primaryScreen()->devicePixelRatio() gives us the virtual screen coordinates that Qt relies on?

Unfortunately, no because the virtual coordinates of two displays are not continuous even if they are physically continuous, and the point of virtual top-left is the same as physical.

Screenshot_20231105_235809

It seems that we can convert physical coordinate (x, y) to virtual by checking ((x - left) / ratio, (y - top) / ratio)) < (width, height) for each screen.

ftake added a commit to ftake/mozc that referenced this issue Feb 12, 2024
…s window position on HiDPI displays

Qt6 applications use virtual coordinates. Since IBus use the device pixel coordinate system to represent a position of a pre-edit area, mozc_renderer converts it to the virtual coordinate.
ftake added a commit to ftake/mozc that referenced this issue Mar 3, 2024
…s window position on HiDPI displays

Qt6 applications use virtual coordinates. Since IBus use the device pixel coordinate system to represent a position of a pre-edit area, mozc_renderer converts it to the virtual coordinate.
ftake added a commit to ftake/mozc that referenced this issue Mar 9, 2024
…s window position on HiDPI displays

Qt6 applications use virtual coordinates. Since IBus uses the device-pixel native coordinate system to represent a position of a pre-edit area, mozc_renderer converts it to the virtual coordinate.
ftake added a commit to ftake/mozc that referenced this issue Mar 9, 2024
…s window position on HiDPI displays

Qt6 applications use virtual coordinates. Since IBus uses the device-pixel native coordinate system to represent a position of a pre-edit area, mozc_renderer converts it to the virtual coordinate.
ftake added a commit to ftake/mozc that referenced this issue Mar 14, 2024
…s window position on HiDPI displays

Qt6 applications use virtual coordinates. Since IBus uses the device-pixel native coordinate system to represent a position of a pre-edit area, mozc_renderer converts it to the virtual coordinate.
hiroyuki-komatsu pushed a commit that referenced this issue Mar 16, 2024
A follow up to 37424fc for #823

Let's explicitly include <cmath> for std::floor.

#codehealth

PiperOrigin-RevId: 616338439
hiroyuki-komatsu added a commit that referenced this issue Apr 6, 2024
Features
* Supported the conversion from "なう" to date/time (i.e. 2024/12/31 23:59)
* Supported loading user dictionary files exported from Gboard
* Fixed voiced Katakana conversion from ゑ (ヸ → ヹ)
* Improved the about dialog with the dark mode (#897)
* Linux: Improved the candidate UI with HiDPI displays (#823)

Build
* Updated the Protobuf version: v25.0 → v26.1
* Updated the Abseil version: 20230802.1 → 20240116.1
* Updated the Qt version: 6.6.2 → 6.7.0

Code
* Performed code refactoring

PiperOrigin-RevId: 622060710
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants