Skip to content

Commit 83b621c

Browse files
committed
Linux with JetBrains Runtime: fixed mouse "jumping" to other position when moving window on scaled secondary screen, if using FlatLaf window decorations (issue #1103)
1 parent b147628 commit 83b621c

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ FlatLaf Change Log
99
shown. (issue #1100)
1010
- macOS: Fixed missing close/iconify/maximize buttons on inactive window, if
1111
system appearance is dark, but application appearance is light. (issue #1032)
12+
- Linux with JetBrains Runtime: Fixed mouse "jumping" to other position when
13+
moving window on scaled secondary screen, if using FlatLaf window decorations.
14+
(issue #1103)
1215

1316

1417
## 3.7.1

flatlaf-core/src/main/java/com/formdev/flatlaf/ui/FlatNativeLinuxLibrary.java

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import java.awt.GraphicsConfiguration;
2020
import java.awt.Point;
21+
import java.awt.Rectangle;
2122
import java.awt.Toolkit;
2223
import java.awt.Window;
2324
import 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

Comments
 (0)