mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-9310 Wayland: Gtk-WARNING in swing app
This commit is contained in:
@@ -76,8 +76,10 @@ public class GtkFrameDecoration extends FullFrameDecorationHelper {
|
||||
@Override
|
||||
public void paint(Graphics g) {
|
||||
// Determine buttons' bounds, etc.
|
||||
nativePrePaint(nativePtr, peer.getWidth());
|
||||
super.paint(g);
|
||||
nativePrePaint(nativePtr, peer.getWidth(), peer.getHeight());
|
||||
if (peer.getWidth() >= titleBarMinWidth && peer.getHeight() >= titleBarHeight) {
|
||||
super.paint(g);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,6 +87,9 @@ public class GtkFrameDecoration extends FullFrameDecorationHelper {
|
||||
int width = peer.getWidth();
|
||||
int height = titleBarHeight;
|
||||
|
||||
assert width >= titleBarMinWidth;
|
||||
assert peer.getHeight() >= titleBarHeight;
|
||||
|
||||
double scale = ((WLGraphicsConfig) peer.getGraphicsConfiguration()).getEffectiveScale();
|
||||
g2d.setBackground(new Color(0, true));
|
||||
g2d.clearRect(0, 0, width, height);
|
||||
@@ -217,5 +222,5 @@ public class GtkFrameDecoration extends FullFrameDecorationHelper {
|
||||
String title, int buttonsState);
|
||||
private native int nativeGetIntProperty(long nativePtr, String name);
|
||||
private native void nativeNotifyConfigured(long nativePtr, boolean active, boolean maximized, boolean fullscreen);
|
||||
private native void nativePrePaint(long nativePtr, int width);
|
||||
private native void nativePrePaint(long nativePtr, int width, int height);
|
||||
}
|
||||
|
||||
@@ -30,14 +30,12 @@ import sun.awt.AWTAccessor;
|
||||
import sun.awt.AWTAccessor.ComponentAccessor;
|
||||
import sun.awt.PaintEventDispatcher;
|
||||
import sun.awt.SunToolkit;
|
||||
import sun.awt.SurfacePixelGrabber;
|
||||
import sun.awt.event.IgnorePaintEvent;
|
||||
import sun.awt.image.SunVolatileImage;
|
||||
import sun.java2d.SunGraphics2D;
|
||||
import sun.java2d.SunGraphicsEnvironment;
|
||||
import sun.java2d.SurfaceData;
|
||||
import sun.java2d.pipe.Region;
|
||||
import sun.java2d.vulkan.VKSurfaceData;
|
||||
import sun.java2d.wl.WLSurfaceDataExt;
|
||||
import sun.java2d.wl.WLSurfaceSizeListener;
|
||||
import sun.util.logging.PlatformLogger;
|
||||
@@ -90,8 +88,8 @@ public class WLComponentPeer implements ComponentPeer, WLSurfaceSizeListener {
|
||||
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.wl.focus.WLComponentPeer");
|
||||
private static final PlatformLogger popupLog = PlatformLogger.getLogger("sun.awt.wl.popup.WLComponentPeer");
|
||||
|
||||
private static final int MINIMUM_WIDTH = 1;
|
||||
private static final int MINIMUM_HEIGHT = 1;
|
||||
protected static final int MINIMUM_WIDTH = 1;
|
||||
protected static final int MINIMUM_HEIGHT = 1;
|
||||
|
||||
private final Object stateLock = new Object();
|
||||
|
||||
@@ -859,8 +857,10 @@ public class WLComponentPeer implements ComponentPeer, WLSurfaceSizeListener {
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
int shadowSize = (int) Math.ceil(shadow.getSize() * 4);
|
||||
return new Dimension(shadowSize, shadowSize);
|
||||
int shadowSize = shadow != null ? (int) Math.ceil(shadow.getSize() * 4) : 0;
|
||||
return shadowSize == 0
|
||||
? new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT)
|
||||
: new Dimension(shadowSize, shadowSize);
|
||||
}
|
||||
|
||||
void showWindowMenu(long serial, int x, int y) {
|
||||
@@ -1756,9 +1756,12 @@ public class WLComponentPeer implements ComponentPeer, WLSurfaceSizeListener {
|
||||
|
||||
private Dimension constrainSize(int width, int height) {
|
||||
Dimension maxBounds = getMaxBufferBounds();
|
||||
Dimension minSize = getMinimumSize();
|
||||
minSize.width = Math.max(MINIMUM_WIDTH, minSize.width);
|
||||
minSize.height = Math.max(MINIMUM_HEIGHT, minSize.height);
|
||||
return new Dimension(
|
||||
Math.max(Math.min(width, maxBounds.width), MINIMUM_WIDTH),
|
||||
Math.max(Math.min(height, maxBounds.height), MINIMUM_HEIGHT));
|
||||
Math.max(Math.min(width, maxBounds.width), minSize.width),
|
||||
Math.max(Math.min(height, maxBounds.height), minSize.height));
|
||||
}
|
||||
|
||||
private Dimension constrainSize(Dimension bounds) {
|
||||
|
||||
@@ -134,10 +134,11 @@ public abstract class WLDecoratedPeer extends WLWindowPeer {
|
||||
@Override
|
||||
public Dimension getMinimumSize() {
|
||||
final Dimension parentMinimumSize = super.getMinimumSize();
|
||||
final Dimension decorMinimumSize = getDecoration().getMinimumSize();
|
||||
var d = getDecoration();
|
||||
final Dimension decorMinimumSize = d != null ? d.getMinimumSize() : new Dimension(0, 0);
|
||||
final Dimension frameMinimumSize
|
||||
= (decorMinimumSize.getWidth() == 0 && decorMinimumSize.getHeight() == 0)
|
||||
? new Dimension(1, 1)
|
||||
? new Dimension(MINIMUM_WIDTH, MINIMUM_HEIGHT)
|
||||
: decorMinimumSize;
|
||||
return new Rectangle(parentMinimumSize)
|
||||
.union(new Rectangle(frameMinimumSize))
|
||||
|
||||
@@ -684,7 +684,7 @@ JNIEXPORT void JNICALL Java_sun_awt_wl_GtkFrameDecoration_nativePaintTitleBar
|
||||
}
|
||||
|
||||
JNIEXPORT void JNICALL Java_sun_awt_wl_GtkFrameDecoration_nativePrePaint(JNIEnv *env, jobject obj,
|
||||
jlong ptr, jint width) {
|
||||
jlong ptr, jint width, jint height) {
|
||||
assert (ptr != 0);
|
||||
GtkFrameDecorationDescr* decor = jlong_to_ptr(ptr);
|
||||
|
||||
@@ -714,6 +714,12 @@ JNIEXPORT void JNICALL Java_sun_awt_wl_GtkFrameDecoration_nativePrePaint(JNIEnv
|
||||
(*env)->SetIntField(env, obj, TitleBarHeightFID, pref_height);
|
||||
(*env)->SetIntField(env, obj, TitleBarMinWidthFID, min_width);
|
||||
|
||||
if (width < min_width || height < pref_height) {
|
||||
// Avoid gtk warnings in case of insufficient space
|
||||
p_gdk_threads_leave();
|
||||
return;
|
||||
}
|
||||
|
||||
GtkAllocation ha = {0, 0, width, pref_height};
|
||||
p_gtk_widget_size_allocate(decor->titlebar, &ha);
|
||||
|
||||
|
||||
65
test/jdk/jb/javax/swing/wayland/WLFrameMinSize.java
Normal file
65
test/jdk/jb/javax/swing/wayland/WLFrameMinSize.java
Normal file
@@ -0,0 +1,65 @@
|
||||
/*
|
||||
* Copyright 2025 JetBrains s.r.o.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License version 2 only, as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This code is distributed in the hope that it will be useful, but WITHOUT
|
||||
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
||||
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* version 2 for more details (a copy is included in the LICENSE file that
|
||||
* accompanied this code).
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License version
|
||||
* 2 along with this work; if not, write to the Free Software Foundation,
|
||||
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
*
|
||||
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
||||
* or visit www.oracle.com if you need additional information or have any
|
||||
* questions.
|
||||
*/
|
||||
|
||||
import jdk.test.lib.process.OutputAnalyzer;
|
||||
import jdk.test.lib.process.ProcessTools;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
/**
|
||||
* @test
|
||||
* @summary Verifies that a small window does not generate GTK warnings in Wayland
|
||||
* @requires os.family == "linux"
|
||||
* @key headful
|
||||
* @library /test/lib
|
||||
* @run main WLFrameMinSize
|
||||
*/
|
||||
public class WLFrameMinSize {
|
||||
private static JFrame frame;
|
||||
public static void main(String[] args) throws Exception {
|
||||
if (args.length > 0 && args[0].equals("--test")) {
|
||||
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
frame = new JFrame("WLFrameMinSize");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.getContentPane().add(new JLabel("a"));
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
});
|
||||
Thread.sleep(2000);
|
||||
javax.swing.SwingUtilities.invokeAndWait(new Runnable() {
|
||||
public void run() {
|
||||
frame.dispose();
|
||||
}
|
||||
});
|
||||
} else {
|
||||
ProcessBuilder pb = ProcessTools.createTestJavaProcessBuilder(
|
||||
WLFrameMinSize.class.getName(),
|
||||
"--test");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldNotContain("Gtk-WARNING");
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user