1818
1919import java .awt .GraphicsConfiguration ;
2020import java .awt .Point ;
21+ import java .awt .Rectangle ;
2122import java .awt .Toolkit ;
2223import java .awt .Window ;
2324import java .awt .event .MouseEvent ;
@@ -78,7 +79,7 @@ static boolean isWMUtilsSupported( Window window ) {
7879 }
7980
8081 static boolean moveOrResizeWindow ( Window window , MouseEvent e , int direction ) {
81- Point pt = scale ( window , e .getLocationOnScreen () );
82+ Point pt = swingToX11Coordinates ( window , e .getLocationOnScreen () );
8283 return xMoveOrResizeWindow ( window , pt .x , pt .y , direction );
8384
8485/*
@@ -94,7 +95,7 @@ static boolean moveOrResizeWindow( Window window, MouseEvent e, int direction )
9495 }
9596
9697 static boolean showWindowMenu ( Window window , MouseEvent e ) {
97- Point pt = scale ( window , e .getLocationOnScreen () );
98+ Point pt = swingToX11Coordinates ( window , e .getLocationOnScreen () );
9899 return xShowWindowMenu ( window , pt .x , pt .y );
99100
100101/*
@@ -109,15 +110,29 @@ static boolean showWindowMenu( Window window, MouseEvent e ) {
109110*/
110111 }
111112
112- private static Point scale ( Window window , Point pt ) {
113+ private static Point swingToX11Coordinates ( Window window , Point pt ) {
113114 GraphicsConfiguration gc = window .getGraphicsConfiguration ();
114115 if ( gc == null )
115116 return pt ;
116117
117118 AffineTransform transform = gc .getDefaultTransform ();
118- int x = (int ) Math .round ( pt .x * transform .getScaleX () );
119- int y = (int ) Math .round ( pt .y * transform .getScaleY () );
120- return new Point ( x , y );
119+ if ( SystemInfo .isJetBrainsJVM && SystemInfo .isJava_17_orLater ) {
120+ // JetBrains Runtime 17+ uses different coordinate system for
121+ // scaled multi-screen environments than OpenJDK.
122+ // The origin of secondary screens is different to OpenJDK.
123+ // - JetBrains Runtime 17+ uses native screen resolution of primary screen
124+ // as origin for secondary screen.
125+ // - OpenJDK uses scaled bounds of primary screen
126+ // as origin for secondary screen.
127+ Rectangle bounds = gc .getBounds ();
128+ int x = (int ) Math .round ( (pt .x - bounds .x ) * transform .getScaleX () ) + bounds .x ;
129+ int y = (int ) Math .round ( (pt .y - bounds .y ) * transform .getScaleY () ) + bounds .y ;
130+ return new Point ( x , y );
131+ } else {
132+ int x = (int ) Math .round ( pt .x * transform .getScaleX () );
133+ int y = (int ) Math .round ( pt .y * transform .getScaleY () );
134+ return new Point ( x , y );
135+ }
121136 }
122137
123138 // X Window System
0 commit comments