mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-6814 Wayland: support sun.java2d.uiScale property
(cherry picked from commit 2d420bfd59)
This commit is contained in:
@@ -297,6 +297,12 @@ public class PopupFactory {
|
||||
(EmbeddedFrame.getAppletIfAncestorOf(owner) != null)) {
|
||||
((HeavyWeightPopup)popup).setCacheEnabled(false);
|
||||
}
|
||||
|
||||
if (isPopupPositionedRelatively()) {
|
||||
// Or else there are positioning artifacts when moving between monitors
|
||||
// with a different scale and -Dsun.java2d.uiScale=N was specified.
|
||||
((HeavyWeightPopup)popup).setCacheEnabled(false);
|
||||
}
|
||||
return popup;
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -39,7 +39,26 @@ import sun.util.logging.PlatformLogger;
|
||||
import sun.util.logging.PlatformLogger.Level;
|
||||
|
||||
import javax.swing.SwingUtilities;
|
||||
import java.awt.*;
|
||||
import java.awt.AWTEvent;
|
||||
import java.awt.AWTException;
|
||||
import java.awt.BufferCapabilities;
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Container;
|
||||
import java.awt.Cursor;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.FontMetrics;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Image;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.ComponentEvent;
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.InputEvent;
|
||||
@@ -103,6 +122,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
int width; // protected by dataLock
|
||||
int height; // protected by dataLock
|
||||
int wlBufferScale; // protected by dataLock
|
||||
double effectiveScale; // protected by dataLock
|
||||
|
||||
static {
|
||||
initIDs();
|
||||
@@ -118,7 +138,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
width = size.width;
|
||||
height = size.height;
|
||||
final WLGraphicsConfig config = (WLGraphicsConfig)target.getGraphicsConfiguration();
|
||||
wlBufferScale = config.getScale();
|
||||
wlBufferScale = config.getWlScale();
|
||||
effectiveScale = config.getEffectiveScale();
|
||||
surfaceData = config.createSurfaceData(this);
|
||||
nativePtr = nativeCreateFrame();
|
||||
paintArea = new WLRepaintArea();
|
||||
@@ -241,8 +262,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
if (v) {
|
||||
String title = getTitle();
|
||||
boolean isWlPopup = targetIsWlPopup();
|
||||
int thisWidth = getWidth();
|
||||
int thisHeight = getHeight();
|
||||
int thisWidth = javaUnitsToSurfaceUnits(getWidth());
|
||||
int thisHeight = javaUnitsToSurfaceUnits(getHeight());
|
||||
boolean isModal = targetIsModal();
|
||||
|
||||
int state = (target instanceof Frame frame)
|
||||
@@ -260,13 +281,13 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
final Point toplevelLocation = toplevel == null
|
||||
? new Point(popupParent.getX(), popupParent.getY())
|
||||
: SwingUtilities.convertPoint(popupParent, 0, 0, toplevel);
|
||||
final int parentX = toplevelLocation.x;
|
||||
final int parentY = toplevelLocation.y;
|
||||
final int parentX = javaUnitsToSurfaceUnits(toplevelLocation.x);
|
||||
final int parentY = javaUnitsToSurfaceUnits(toplevelLocation.y);
|
||||
|
||||
// Offset must be relative to the top-left corner of the "parent".
|
||||
final Point offsetFromParent = popup.getLocation();
|
||||
final int offsetX = offsetFromParent.x;
|
||||
final int offsetY = offsetFromParent.y;
|
||||
final int offsetX = javaUnitsToSurfaceUnits(offsetFromParent.x);
|
||||
final int offsetY = javaUnitsToSurfaceUnits(offsetFromParent.y);
|
||||
|
||||
if (popupLog.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
popupLog.fine("New popup: " + popup);
|
||||
@@ -280,9 +301,11 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
thisWidth, thisHeight,
|
||||
parentX + offsetX, parentY + offsetY);
|
||||
} else {
|
||||
int xNative = javaUnitsToSurfaceUnits(target.getX());
|
||||
int yNative = javaUnitsToSurfaceUnits(target.getY());
|
||||
nativeCreateWLSurface(nativePtr,
|
||||
getParentNativePtr(target),
|
||||
target.getX(), target.getY(),
|
||||
xNative, yNative,
|
||||
isModal, isMaximized, isMinimized,
|
||||
title, WLToolkit.getApplicationID());
|
||||
}
|
||||
@@ -322,12 +345,17 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
|| dialog.getModalityType() == Dialog.ModalityType.TOOLKIT_MODAL);
|
||||
}
|
||||
|
||||
void updateSurfaceData() {
|
||||
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).revalidate(
|
||||
getBufferWidth(), getBufferHeight(), getBufferScale());
|
||||
updateWindowGeometry();
|
||||
}
|
||||
|
||||
void configureWLSurface() {
|
||||
if (log.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
log.fine(String.format("%s is configured to %dx%d with %dx scale", this, getBufferWidth(), getBufferHeight(), getBufferScale()));
|
||||
}
|
||||
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).revalidate(
|
||||
getBufferWidth(), getBufferHeight(), getBufferScale());
|
||||
updateSurfaceData();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -421,7 +449,9 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
// the location will be updated in notifyConfigured() following
|
||||
// the xdg_popup::repositioned event
|
||||
} else {
|
||||
performLocked(() -> WLRobotPeer.setLocationOfWLSurface(getWLSurface(nativePtr), newX, newY));
|
||||
int newXNative = javaUnitsToSurfaceUnits(newX);
|
||||
int newYNative = javaUnitsToSurfaceUnits(newY);
|
||||
performLocked(() -> WLRobotPeer.setLocationOfWLSurface(getWLSurface(nativePtr), newXNative, newYNative));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -436,9 +466,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
log.fine(String.format("%s is resizing its buffer to %dx%d with %dx scale",
|
||||
this, getBufferWidth(), getBufferHeight(), getBufferScale()));
|
||||
}
|
||||
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).revalidate(
|
||||
getBufferWidth(), getBufferHeight(), getBufferScale());
|
||||
updateWindowGeometry();
|
||||
updateSurfaceData();
|
||||
layout();
|
||||
|
||||
WLToolkit.postEvent(new ComponentEvent(getTarget(), ComponentEvent.COMPONENT_RESIZED));
|
||||
@@ -467,8 +495,10 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
final Point toplevelLocation = toplevel == null
|
||||
? new Point(popupParent.getX(), popupParent.getY())
|
||||
: SwingUtilities.convertPoint(popupParent, 0, 0, toplevel);
|
||||
final int parentX = toplevelLocation.x;
|
||||
final int parentY = toplevelLocation.y;
|
||||
final int parentX = javaUnitsToSurfaceUnits(toplevelLocation.x);
|
||||
final int parentY = javaUnitsToSurfaceUnits(toplevelLocation.y);
|
||||
int newXNative = javaUnitsToSurfaceUnits(newX);
|
||||
int newYNative = javaUnitsToSurfaceUnits(newY);
|
||||
if (popupLog.isLoggable(Level.FINE)) {
|
||||
popupLog.fine("Repositioning popup: " + popup);
|
||||
popupLog.fine("\tparent:" + popupParent);
|
||||
@@ -476,7 +506,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
popupLog.fine("\toffset of anchor from toplevel: " + toplevelLocation);
|
||||
popupLog.fine("\toffset from anchor: " + newX + ", " + newY);
|
||||
}
|
||||
nativeRepositionWLPopup(nativePtr, thisWidth, thisHeight, parentX + newX, parentY + newY);
|
||||
nativeRepositionWLPopup(nativePtr, thisWidth, thisHeight, parentX + newXNative, parentY + newYNative);
|
||||
} );
|
||||
}
|
||||
|
||||
@@ -499,16 +529,16 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
}
|
||||
|
||||
private int toBufferUnits(int x) {
|
||||
return x * getBufferScale();
|
||||
}
|
||||
|
||||
public int getBufferWidth() {
|
||||
return toBufferUnits(getWidth());
|
||||
synchronized (dataLock) {
|
||||
return (int)(width * effectiveScale);
|
||||
}
|
||||
}
|
||||
|
||||
public int getBufferHeight() {
|
||||
return toBufferUnits(getHeight());
|
||||
synchronized (dataLock) {
|
||||
return (int)(height * effectiveScale);
|
||||
}
|
||||
}
|
||||
|
||||
public Rectangle getBufferBounds() {
|
||||
@@ -523,10 +553,14 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
// user's perspective. Client-side decorations often have invisible
|
||||
// portions like drop-shadows which should be ignored for the
|
||||
// purposes of aligning, placing and constraining windows"
|
||||
final Rectangle visibleBounds = getVisibleBounds();
|
||||
Rectangle nativeVisibleBounds = getVisibleBounds();
|
||||
nativeVisibleBounds.x = javaUnitsToSurfaceUnits(nativeVisibleBounds.x);
|
||||
nativeVisibleBounds.y = javaUnitsToSurfaceUnits(nativeVisibleBounds.y);
|
||||
nativeVisibleBounds.width = javaUnitsToSurfaceUnits(nativeVisibleBounds.width);
|
||||
nativeVisibleBounds.height = javaUnitsToSurfaceUnits(nativeVisibleBounds.height);
|
||||
performLocked(() -> nativeSetWindowGeometry(nativePtr,
|
||||
visibleBounds.x, visibleBounds.y,
|
||||
visibleBounds.width, visibleBounds.height));
|
||||
nativeVisibleBounds.x, nativeVisibleBounds.y,
|
||||
nativeVisibleBounds.width, nativeVisibleBounds.height));
|
||||
}
|
||||
|
||||
public void coalescePaintEvent(PaintEvent e) {
|
||||
@@ -690,17 +724,23 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
}
|
||||
|
||||
void setMinimumSizeTo(Dimension minSize) {
|
||||
Dimension constrainedSize = constrainSize(minSize);
|
||||
performLocked(() -> nativeSetMinimumSize(nativePtr, constrainedSize.width, constrainedSize.height));
|
||||
Dimension nativeSize = constrainSize(minSize);
|
||||
nativeSize.width = javaUnitsToSurfaceUnits(nativeSize.width);
|
||||
nativeSize.height = javaUnitsToSurfaceUnits(nativeSize.height);
|
||||
performLocked(() -> nativeSetMinimumSize(nativePtr, nativeSize.width, nativeSize.height));
|
||||
}
|
||||
|
||||
void setMaximumSizeTo(Dimension maxSize) {
|
||||
Dimension constrainedSize = constrainSize(maxSize);
|
||||
performLocked(() -> nativeSetMaximumSize(nativePtr, constrainedSize.width, constrainedSize.height));
|
||||
Dimension nativeSize = constrainSize(maxSize);
|
||||
nativeSize.width = javaUnitsToSurfaceUnits(nativeSize.width);
|
||||
nativeSize.height = javaUnitsToSurfaceUnits(nativeSize.height);
|
||||
performLocked(() -> nativeSetMaximumSize(nativePtr, nativeSize.width, nativeSize.height));
|
||||
}
|
||||
|
||||
void showWindowMenu(int x, int y) {
|
||||
performLocked(() -> nativeShowWindowMenu(nativePtr, x, y));
|
||||
int xNative = javaUnitsToSurfaceUnits(x);
|
||||
int yNative = javaUnitsToSurfaceUnits(y);
|
||||
performLocked(() -> nativeShowWindowMenu(nativePtr, xNative, yNative));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -781,7 +821,7 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
WLComponentPeer peer = inputState.getPeer();
|
||||
if (peer == null) return;
|
||||
Cursor cursor = peer.getCursor(inputState.getPointerX(), inputState.getPointerY());
|
||||
setCursor(cursor, getGraphicsDevice() != null ? getGraphicsDevice().getScale() : 1);
|
||||
setCursor(cursor, getGraphicsDevice() != null ? getGraphicsDevice().getWlScale() : 1);
|
||||
}
|
||||
|
||||
Cursor getCursor(int x, int y) {
|
||||
@@ -892,17 +932,16 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
|
||||
@Override
|
||||
public boolean updateGraphicsData(GraphicsConfiguration gc) {
|
||||
final int newScale = ((WLGraphicsConfig)gc).getScale();
|
||||
final int newWlScale = ((WLGraphicsConfig)gc).getWlScale();
|
||||
|
||||
synchronized (dataLock) {
|
||||
if (newScale != wlBufferScale) {
|
||||
wlBufferScale = newScale;
|
||||
if (newWlScale != wlBufferScale) {
|
||||
wlBufferScale = newWlScale;
|
||||
effectiveScale = ((WLGraphicsConfig)gc).getEffectiveScale();
|
||||
if (log.isLoggable(PlatformLogger.Level.FINE)) {
|
||||
log.fine(String.format("%s is updating buffer to %dx%d with %dx scale", this, getBufferWidth(), getBufferHeight(), wlBufferScale));
|
||||
}
|
||||
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).revalidate(
|
||||
getBufferWidth(), getBufferHeight(), wlBufferScale);
|
||||
|
||||
updateSurfaceData();
|
||||
postPaintEvent();
|
||||
}
|
||||
}
|
||||
@@ -1124,7 +1163,37 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
performLocked(() -> nativeStartResize(nativePtr, edges));
|
||||
}
|
||||
|
||||
void notifyConfigured(int newX, int newY, int newWidth, int newHeight, boolean active, boolean maximized) {
|
||||
/**
|
||||
* Converts a value in the Wayland surface-local coordinate system
|
||||
* into the Java coordinate system.
|
||||
*/
|
||||
int surfaceUnitsToJavaUnits(int value) {
|
||||
if (!WLGraphicsEnvironment.isDebugScaleEnabled()) {
|
||||
return value;
|
||||
} else {
|
||||
synchronized (dataLock) {
|
||||
return (int)(value * wlBufferScale / effectiveScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts a value in the Java coordinate system into the Wayland
|
||||
* surface-local coordinate system.
|
||||
*/
|
||||
int javaUnitsToSurfaceUnits(int value) {
|
||||
if (!WLGraphicsEnvironment.isDebugScaleEnabled()) {
|
||||
return value;
|
||||
} else {
|
||||
synchronized (dataLock) {
|
||||
return (int)(value * effectiveScale / wlBufferScale);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void notifyConfigured(int newXNative, int newYNative, int newWidthNative, int newHeightNative, boolean active, boolean maximized) {
|
||||
int newWidth = surfaceUnitsToJavaUnits(newWidthNative);
|
||||
int newHeight = surfaceUnitsToJavaUnits(newHeightNative);
|
||||
final long wlSurfacePtr = getWLSurface(nativePtr);
|
||||
if (!surfaceAssigned) {
|
||||
SurfaceData.convertTo(WLSurfaceDataExt.class, surfaceData).assignSurface(wlSurfacePtr);
|
||||
@@ -1137,6 +1206,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
boolean isWlPopup = targetIsWlPopup();
|
||||
|
||||
if (isWlPopup) { // Only popups provide (relative) location
|
||||
int newX = surfaceUnitsToJavaUnits(newXNative);
|
||||
int newY = surfaceUnitsToJavaUnits(newYNative);
|
||||
setLocationTo(newX, newY);
|
||||
}
|
||||
|
||||
@@ -1204,8 +1275,8 @@ public class WLComponentPeer implements ComponentPeer {
|
||||
// Wayland's output and are removed as soon as we have left.
|
||||
synchronized (devices) {
|
||||
for (WLGraphicsDevice gd : devices) {
|
||||
if (gd.getScale() > scale) {
|
||||
scale = gd.getScale();
|
||||
if (gd.getWlScale() > scale) {
|
||||
scale = gd.getWlScale();
|
||||
theDevice = gd;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -108,8 +108,8 @@ public abstract class WLDecoratedPeer extends WLWindowPeer {
|
||||
}
|
||||
|
||||
@Override
|
||||
void notifyConfigured(int newX, int newY, int newWidth, int newHeight, boolean active, boolean maximized) {
|
||||
super.notifyConfigured(newX, newY, newWidth, newHeight, active, maximized);
|
||||
void notifyConfigured(int newX, int newY, int newWidthNative, int newHeightNative, boolean active, boolean maximized) {
|
||||
super.notifyConfigured(newX, newY, newWidthNative, newHeightNative, active, maximized);
|
||||
decoration.setActive(active);
|
||||
}
|
||||
|
||||
|
||||
@@ -133,11 +133,11 @@ public class WLFramePeer extends WLDecoratedPeer implements FramePeer {
|
||||
}
|
||||
|
||||
@Override
|
||||
void notifyConfigured(int newX, int newY, int newWidth, int newHeight, boolean active, boolean maximized) {
|
||||
void notifyConfigured(int newXNative, int newYNative, int newWidthNative, int newHeightNative, boolean active, boolean maximized) {
|
||||
int widthBefore = getWidth();
|
||||
int heightBefore = getHeight();
|
||||
|
||||
super.notifyConfigured(newX, newY, newWidth, newHeight, active, maximized);
|
||||
|
||||
super.notifyConfigured(newXNative, newYNative, newWidthNative, newHeightNative, active, maximized);
|
||||
|
||||
synchronized (getStateLock()) {
|
||||
int oldState = state;
|
||||
@@ -147,7 +147,7 @@ public class WLFramePeer extends WLDecoratedPeer implements FramePeer {
|
||||
if (maximized) {
|
||||
widthBeforeMaximized = widthBefore;
|
||||
heightBeforeMaximized = heightBefore;
|
||||
} else if (newWidth == 0 && newHeight == 0 && widthBeforeMaximized > 0 && heightBeforeMaximized > 0) {
|
||||
} else if (newWidthNative == 0 && newHeightNative == 0 && widthBeforeMaximized > 0 && heightBeforeMaximized > 0) {
|
||||
performUnlocked(() -> target.setSize(widthBeforeMaximized, heightBeforeMaximized));
|
||||
}
|
||||
WLToolkit.postEvent(new WindowEvent(getFrame(), WindowEvent.WINDOW_STATE_CHANGED, oldState, state));
|
||||
|
||||
@@ -39,17 +39,19 @@ public abstract class WLGraphicsConfig extends GraphicsConfiguration {
|
||||
private final WLGraphicsDevice device;
|
||||
private final int width;
|
||||
private final int height;
|
||||
private final int scale;
|
||||
private final int wlScale; // as reported by Wayland
|
||||
private final double effectiveScale; // as enforced by Java
|
||||
|
||||
protected WLGraphicsConfig(WLGraphicsDevice device, int width, int height, int scale) {
|
||||
protected WLGraphicsConfig(WLGraphicsDevice device, int width, int height, int wlScale) {
|
||||
this.device = device;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.scale = scale;
|
||||
this.wlScale = wlScale;
|
||||
this.effectiveScale = WLGraphicsEnvironment.effectiveScaleFrom(wlScale);
|
||||
}
|
||||
|
||||
boolean differsFrom(int width, int height, int scale) {
|
||||
return width != this.width || height != this.height || scale != this.scale;
|
||||
return width != this.width || height != this.height || scale != this.wlScale;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -67,7 +69,7 @@ public abstract class WLGraphicsConfig extends GraphicsConfiguration {
|
||||
|
||||
@Override
|
||||
public AffineTransform getDefaultTransform() {
|
||||
double scale = getScale();
|
||||
double scale = effectiveScale;
|
||||
return AffineTransform.getScaleInstance(scale, scale);
|
||||
}
|
||||
|
||||
@@ -83,8 +85,19 @@ public abstract class WLGraphicsConfig extends GraphicsConfiguration {
|
||||
return new Rectangle(width, height);
|
||||
}
|
||||
|
||||
public int getScale() {
|
||||
return scale;
|
||||
/**
|
||||
* Returns the preferred Wayland buffer scale for this display configuration.
|
||||
*/
|
||||
public int getWlScale() {
|
||||
return wlScale;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the effective scale, which can differ from the buffer scale
|
||||
* if overridden with the sun.java2d.uiScale system property.
|
||||
*/
|
||||
public double getEffectiveScale() {
|
||||
return effectiveScale;
|
||||
}
|
||||
|
||||
public abstract SurfaceType getSurfaceType();
|
||||
@@ -92,6 +105,6 @@ public abstract class WLGraphicsConfig extends GraphicsConfiguration {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%dx%d %dx scale", width, height, scale);
|
||||
return String.format("%dx%d %dx scale", width, height, wlScale);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +121,7 @@ public class WLGraphicsDevice extends GraphicsDevice {
|
||||
this.x = similarDevice.x;
|
||||
this.y = similarDevice.y;
|
||||
|
||||
int newScale = similarDevice.getScale();
|
||||
int newScale = similarDevice.getWlScale();
|
||||
Rectangle newBounds = similarDevice.defaultConfig.getBounds();
|
||||
updateConfiguration(similarDevice.name, newBounds.width, newBounds.height, newScale);
|
||||
}
|
||||
@@ -183,8 +183,8 @@ public class WLGraphicsDevice extends GraphicsDevice {
|
||||
return defaultConfig;
|
||||
}
|
||||
|
||||
int getScale() {
|
||||
return defaultConfig.getScale();
|
||||
int getWlScale() {
|
||||
return defaultConfig.getWlScale();
|
||||
}
|
||||
|
||||
int getResolution() {
|
||||
|
||||
@@ -49,6 +49,7 @@ public class WLGraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
private static boolean verboseVulkanStatus = false;
|
||||
private static boolean vulkanRequested = false;
|
||||
private static int vulkanRequestedDeviceNumber = -1;
|
||||
private static final boolean debugScaleEnabled;
|
||||
@SuppressWarnings("removal")
|
||||
private static String vulkanOption =
|
||||
AccessController.doPrivileged(
|
||||
@@ -85,6 +86,8 @@ public class WLGraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
log.fine("Vulkan rendering enabled: " + (vulkanEnabled?"YES":"NO"));
|
||||
}
|
||||
|
||||
debugScaleEnabled = SunGraphicsEnvironment.isUIScaleEnabled() && SunGraphicsEnvironment.getDebugScale() >= 1;
|
||||
|
||||
// Make sure the toolkit is loaded because otherwise this GE is going to be empty
|
||||
WLToolkit.isInitialized();
|
||||
}
|
||||
@@ -148,6 +151,7 @@ public class WLGraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
if (gd.getID() == wlID) {
|
||||
newOutput = false;
|
||||
if (gd.isSameDeviceAs(wlID, x, y)) {
|
||||
// These coordinates and the size are not scaled.
|
||||
gd.updateConfiguration(humanID, width, height, scale);
|
||||
} else {
|
||||
final WLGraphicsDevice updatedDevice = WLGraphicsDevice.createWithConfiguration(wlID, humanID,
|
||||
@@ -255,4 +259,12 @@ public class WLGraphicsEnvironment extends SunGraphicsEnvironment {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static double effectiveScaleFrom(int displayScale) {
|
||||
return debugScaleEnabled ? SunGraphicsEnvironment.getDebugScale() : displayScale;
|
||||
}
|
||||
|
||||
static boolean isDebugScaleEnabled() {
|
||||
return debugScaleEnabled;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -215,11 +215,23 @@ record WLInputState(WLPointerEvent eventWithSurface,
|
||||
}
|
||||
|
||||
public int getPointerX() {
|
||||
return eventWithCoordinates != null ? eventWithCoordinates.getSurfaceX() : 0;
|
||||
int x = eventWithCoordinates != null ? eventWithCoordinates.getSurfaceX() : 0;
|
||||
if (!WLGraphicsEnvironment.isDebugScaleEnabled()) {
|
||||
return x;
|
||||
} else {
|
||||
WLComponentPeer peer = getPeer();
|
||||
return peer == null ? x : peer.surfaceUnitsToJavaUnits(x);
|
||||
}
|
||||
}
|
||||
|
||||
public int getPointerY() {
|
||||
return eventWithCoordinates != null ? eventWithCoordinates.getSurfaceY() : 0;
|
||||
int y = eventWithCoordinates != null ? eventWithCoordinates.getSurfaceY() : 0;
|
||||
if (!WLGraphicsEnvironment.isDebugScaleEnabled()) {
|
||||
return y;
|
||||
} else {
|
||||
WLComponentPeer peer = getPeer();
|
||||
return peer == null ? y : peer.surfaceUnitsToJavaUnits(y);
|
||||
}
|
||||
}
|
||||
|
||||
public WLComponentPeer getPeer() {
|
||||
@@ -233,8 +245,8 @@ record WLInputState(WLPointerEvent eventWithSurface,
|
||||
*/
|
||||
public boolean isPointerOverPeer() {
|
||||
if (isPointerOverSurface && eventWithCoordinates != null) {
|
||||
int x = eventWithCoordinates.getSurfaceX();
|
||||
int y = eventWithCoordinates.getSurfaceY();
|
||||
int x = getPointerX();
|
||||
int y = getPointerY();
|
||||
WLComponentPeer peer = getPeer();
|
||||
if (peer != null) {
|
||||
return x >= 0
|
||||
|
||||
@@ -25,7 +25,15 @@
|
||||
package sun.awt.wl;
|
||||
|
||||
import sun.awt.AWTAccessor;
|
||||
import java.awt.*;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Font;
|
||||
import java.awt.GraphicsConfiguration;
|
||||
import java.awt.Insets;
|
||||
import java.awt.SystemColor;
|
||||
import java.awt.Window;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.peer.ComponentPeer;
|
||||
import java.awt.peer.WindowPeer;
|
||||
@@ -141,6 +149,13 @@ public class WLWindowPeer extends WLComponentPeer implements WindowPeer {
|
||||
if (maxSize != null) super.setMaximumSizeTo(maxSize);
|
||||
}
|
||||
|
||||
@Override
|
||||
void updateSurfaceData() {
|
||||
updateMinimumSize();
|
||||
updateMaximumSize();
|
||||
super.updateSurfaceData();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateIconImages() {
|
||||
// No support for this from Wayland, icon is a desktop integration feature.
|
||||
|
||||
@@ -60,7 +60,7 @@ public abstract class WLVKSurfaceData extends VKSurfaceData implements WLSurface
|
||||
final int backgroundRGB = peer.getBackground() != null
|
||||
? peer.getBackground().getRGB()
|
||||
: 0;
|
||||
int scale = ((WLGraphicsConfig)peer.getGraphicsConfiguration()).getScale();
|
||||
int scale = ((WLGraphicsConfig)peer.getGraphicsConfiguration()).getWlScale();
|
||||
initOps(peer.getBufferWidth(), peer.getBufferHeight(), scale, backgroundRGB);
|
||||
}
|
||||
|
||||
|
||||
@@ -75,7 +75,7 @@ public class WLSMSurfaceData extends SurfaceData implements WLSurfaceDataExt {
|
||||
}
|
||||
ColorModel cm = graphicsConfig.getColorModel();
|
||||
SurfaceType surfaceType = graphicsConfig.getSurfaceType();
|
||||
return new WLSMSurfaceData(peer, surfaceType, cm, graphicsConfig.getScale(), graphicsConfig.getWlShmFormat());
|
||||
return new WLSMSurfaceData(peer, surfaceType, cm, graphicsConfig.getWlScale(), graphicsConfig.getWlShmFormat());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -1059,9 +1059,15 @@ WLSBM_SizeChangeTo(WLSurfaceBufferManager * manager, jint width, jint height, ji
|
||||
}
|
||||
|
||||
MUTEX_LOCK(manager->drawLock);
|
||||
MUTEX_LOCK(manager->showLock);
|
||||
const bool change_needed =
|
||||
manager->bufferForDraw.width != width
|
||||
|| manager->bufferForDraw.height != height
|
||||
|| manager->scale != scale;
|
||||
manager->scale = scale;
|
||||
MUTEX_UNLOCK(manager->showLock);
|
||||
|
||||
const bool size_changed = manager->bufferForDraw.width != width || manager->bufferForDraw.height != height;
|
||||
if (size_changed) {
|
||||
if (change_needed) {
|
||||
DrawBufferDestroy(manager);
|
||||
|
||||
manager->bufferForDraw.width = width;
|
||||
@@ -1072,12 +1078,6 @@ WLSBM_SizeChangeTo(WLSurfaceBufferManager * manager, jint width, jint height, ji
|
||||
WLBufferTrace(manager, "WLSBM_SizeChangeTo %dx%d", width, height);
|
||||
}
|
||||
|
||||
MUTEX_LOCK(manager->showLock);
|
||||
if (manager->scale != scale) {
|
||||
manager->scale = scale;
|
||||
}
|
||||
MUTEX_UNLOCK(manager->showLock);
|
||||
|
||||
MUTEX_UNLOCK(manager->drawLock);
|
||||
}
|
||||
|
||||
|
||||
@@ -638,7 +638,8 @@ JNIEXPORT void JNICALL Java_sun_awt_wl_WLComponentPeer_nativeSetWindowGeometry
|
||||
struct WLFrame *frame = jlong_to_ptr(ptr);
|
||||
if (frame->xdg_surface) {
|
||||
xdg_surface_set_window_geometry(frame->xdg_surface, x, y, width, height);
|
||||
wlFlushToServer(env);
|
||||
// Do not flush here as this update needs to be committed together with the change
|
||||
// of the buffer's size and scale, if any.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -648,7 +649,8 @@ JNIEXPORT void JNICALL Java_sun_awt_wl_WLComponentPeer_nativeSetMinimumSize
|
||||
struct WLFrame *frame = jlong_to_ptr(ptr);
|
||||
if (frame->toplevel) {
|
||||
xdg_toplevel_set_min_size(frame->xdg_toplevel, width, height);
|
||||
wlFlushToServer(env);
|
||||
// Do not flush here as this update needs to be committed together with the change
|
||||
// of the buffer's size and scale, if any.
|
||||
}
|
||||
}
|
||||
|
||||
@@ -658,7 +660,8 @@ JNIEXPORT void JNICALL Java_sun_awt_wl_WLComponentPeer_nativeSetMaximumSize
|
||||
struct WLFrame *frame = jlong_to_ptr(ptr);
|
||||
if (frame->toplevel) {
|
||||
xdg_toplevel_set_max_size(frame->xdg_toplevel, width, height);
|
||||
wlFlushToServer(env);
|
||||
// Do not flush here as this update needs to be committed together with the change
|
||||
// of the buffer's size and scale, if any.
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user