File ibus-mozc-candidate-window-qt-virtual-coordinate.patch of Package mozc
diff --git a/src/renderer/qt/qt_window_manager.cc b/src/renderer/qt/qt_window_manager.cc
index 0aceecce6..5c8662b1f 100644
--- a/src/renderer/qt/qt_window_manager.cc
+++ b/src/renderer/qt/qt_window_manager.cc
@@ -32,9 +32,9 @@
#include <algorithm>
#include <string>
+#include "absl/strings/str_cat.h"
#include "base/logging.h"
#include "protocol/candidates.pb.h"
-#include "absl/strings/str_cat.h"
#include "renderer/renderer_style_handler.h"
#include "renderer/window_util.h"
@@ -341,16 +341,53 @@ void FillCandidates(const commands::Candidates &candidates,
}
} // namespace
+struct VirtualRect {
+ const QScreen* screen;
+ const Rect rect;
+
+ VirtualRect(const QScreen* screen, const Rect rect): screen(screen), rect(rect) {}
+};
+
+Rect TranslateToVirtualRectWithScreen(const QScreen *screen, const Rect& native_rect) {
+ const double device_pixel_ratio = screen->devicePixelRatio();
+ // screen_left, screen_top have the save value in both virtual and native coordinate
+ const int screen_left = screen->geometry().x();
+ const int screen_top = screen->geometry().y();
+ const int vx = (native_rect.Left() - screen_left) / device_pixel_ratio + screen_left;
+ const int vy = (native_rect.Top() - screen_top) / device_pixel_ratio + screen_top;
+
+ return Rect(vx, vy, native_rect.Width() / device_pixel_ratio, native_rect.Height() / device_pixel_ratio);
+}
+
+VirtualRect TranslateToVirtualRect(const Rect& native_rect) {
+ for (const QScreen *screen: QGuiApplication::screens()) {
+ Rect rect = TranslateToVirtualRectWithScreen(screen, native_rect);
+ const QRect screen_rect = screen->geometry();
+
+ // Use (top left) to locate a screen
+ if (screen_rect.contains(rect.Left(), rect.Top())) {
+ return VirtualRect(screen, rect);
+ }
+ }
+
+ // fall back to primary screen
+ const QScreen *screen = QGuiApplication::primaryScreen();
+ Rect point = TranslateToVirtualRectWithScreen(screen, native_rect);
+ return VirtualRect(screen, point);
+}
+
Point QtWindowManager::GetWindowPosition(
const commands::RendererCommand &command, const Size &win_size) {
- const Rect preedit_rect = GetRect(command.preedit_rectangle());
- const Point win_pos = Point(preedit_rect.Left(), preedit_rect.Bottom());
- const Rect monitor_rect = GetMonitorRect(win_pos.x, win_pos.y);
+
+ const Rect native_preedit_rect = GetRect(command.preedit_rectangle());
+ const VirtualRect preedit_rect = TranslateToVirtualRect(native_preedit_rect);
+ const Point win_pos = Point(preedit_rect.rect.Left(), preedit_rect.rect.Bottom());
+ const Rect monitor_rect = GetRect(preedit_rect.screen->geometry());
const Point offset_to_column1(kColumn0Width, 0);
const Rect adjusted_win_geometry =
WindowUtil::GetWindowRectForMainWindowFromTargetPointAndPreedit(
- win_pos, preedit_rect, win_size, offset_to_column1, monitor_rect,
+ win_pos, preedit_rect.rect, win_size, offset_to_column1, monitor_rect,
/* vertical */ false); // Only support horizontal window yet.
return adjusted_win_geometry.origin;
}