Skip to content

Commit

Permalink
Better handling of multiple monitors when converting IM coords
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Fox committed Jan 4, 2024
1 parent 6ce899f commit 3a59921
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@

import javafx.event.EventType;
import javafx.geometry.Point2D;
import javafx.geometry.Rectangle2D;
import javafx.scene.input.InputMethodEvent;
import javafx.scene.input.InputMethodHighlight;
import javafx.scene.input.InputMethodTextRun;
Expand Down Expand Up @@ -669,12 +670,19 @@ protected void onChanged(ListChangeListener.Change<InputMethodTextRun> c) {
@Override
public double[] getInputMethodCandidatePos(int offset) {
Point2D p2d = scene.inputMethodRequests.getTextLocation(offset);
final Screen s = Screen.getMainScreen();
float pScaleX = (s == null) ? 1.0f : s.getPlatformScaleX();
float pScaleY = (s == null) ? 1.0f : s.getPlatformScaleY();
double[] ret = new double[2];
ret[0] = p2d.getX() * pScaleX;
ret[1] = p2d.getY() * pScaleY;
ret[0] = p2d.getX();
ret[1] = p2d.getY();

for (Screen scr : Screen.getScreens()) {
Rectangle2D bounds = new Rectangle2D(scr.getX(), scr.getY(), scr.getWidth(), scr.getHeight());
if (bounds.contains(p2d)) {
ret[0] = scr.toPlatformX((float) p2d.getX());
ret[1] = scr.toPlatformY((float) p2d.getY());
break;
}
}

return ret;
}

Expand Down

0 comments on commit 3a59921

Please sign in to comment.