Skip to content

Commit

Permalink
JBR-5095 Incorrect initial window's location under GNOME
Browse files Browse the repository at this point in the history
(cherry picked from commit 6995ce4)

with fix for JBR-5189 Can't exit fullscreen mode on ubuntu 22.10

(cherry picked from commit b933660)
  • Loading branch information
JB-Dmitry committed Dec 8, 2023
1 parent 80b6e4b commit f4ea24e
Show file tree
Hide file tree
Showing 4 changed files with 146 additions and 17 deletions.
18 changes: 5 additions & 13 deletions src/java.desktop/unix/classes/sun/awt/X11/XDecoratedPeer.java
Original file line number Diff line number Diff line change
Expand Up @@ -344,19 +344,11 @@ public void handlePropertyNotify(XEvent xev) {
|| ev.get_atom() == XWM.XA_NET_FRAME_EXTENTS.getAtom())
{
if (XWM.getWMID() != XWM.UNITY_COMPIZ_WM) {
if ((XWM.getWMID() == XWM.MUTTER_WM && !isTargetUndecorated() && isVisible())
|| getMWMDecorTitleProperty().isPresent()) {
// Insets might have changed "in-flight" if that property
// is present, so we need to get the actual values of
// insets from the WM and propagate them through all the
// proper channels.
wm_set_insets = null;
Insets in = getWMSetInsets(XAtom.get(ev.get_atom()));
if (in != null && !in.equals(dimensions.getInsets())) {
handleCorrectInsets(in);
}
} else {
getWMSetInsets(XAtom.get(ev.get_atom()));
wm_set_insets = null;
Insets in = getWMSetInsets(XAtom.get(ev.get_atom()));
if (isReparented() && (!isMapped() || getMWMDecorTitleProperty().isPresent()) &&
in != null && !in.equals(dimensions.getInsets())) {
handleCorrectInsets(in);
}
} else {
if (!isReparented()) {
Expand Down
4 changes: 0 additions & 4 deletions src/java.desktop/unix/classes/sun/awt/X11/XWM.java
Original file line number Diff line number Diff line change
Expand Up @@ -1419,9 +1419,6 @@ Insets guessInsets(XDecoratedPeer window) {
case UNITY_COMPIZ_WM:
res = new Insets(28, 1, 1, 1);
break;
case MUTTER_WM:
res = new Insets(37, 0, 0, 0);
break;
case MOTIF_WM:
case OPENLOOK_WM:
default:
Expand All @@ -1433,7 +1430,6 @@ Insets guessInsets(XDecoratedPeer window) {
}
return res;
}

/*
* Some buggy WMs ignore window gravity when processing
* ConfigureRequest and position window as if the gravity is Static.
Expand Down
71 changes: 71 additions & 0 deletions test/jdk/jb/java/awt/Window/RestoreFromFullScreen.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* Copyright 2023 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 java.awt.*;
import javax.swing.*;

/**
* @test
* @summary Regression test for JBR-5189 Can't exit fullscreen mode on ubuntu 22.10
* @key headful
*/

public class RestoreFromFullScreen {
private static final int INITIAL_WIDTH = 400;
private static final int INITIAL_HEIGHT = 300;

private static JFrame frame;

public static void main(String[] args) throws Exception {
try {
SwingUtilities.invokeAndWait(RestoreFromFullScreen::initUI);
Thread.sleep(1000);
SwingUtilities.invokeAndWait(() -> frame.getGraphicsConfiguration().getDevice().setFullScreenWindow(frame));
Thread.sleep(1000);
SwingUtilities.invokeAndWait(() -> {
if (frame.getWidth() <= INITIAL_WIDTH || frame.getHeight() <= INITIAL_HEIGHT) {
throw new RuntimeException("Full screen transition hasn't happened");
}
frame.getGraphicsConfiguration().getDevice().setFullScreenWindow(null);
});
Thread.sleep(1000);
SwingUtilities.invokeAndWait(() -> {
if (frame.getWidth() != INITIAL_WIDTH || frame.getHeight() != INITIAL_HEIGHT) {
throw new RuntimeException("Restoring of the original size hasn't happened");
}
});
} finally {
SwingUtilities.invokeAndWait(RestoreFromFullScreen::disposeUI);
}
}

private static void initUI() {
frame = new JFrame("RestoreFromFullScreen");
frame.setBounds(200, 200, INITIAL_WIDTH, INITIAL_HEIGHT);
frame.setVisible(true);
}

private static void disposeUI() {
if (frame != null) frame.dispose();
}
}
70 changes: 70 additions & 0 deletions test/jdk/jb/java/awt/Window/WindowInitialPosition.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*
* Copyright 2022 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 javax.swing.*;
import java.awt.*;

/**
* @test
* @summary Regression test for JBR-5095 Incorrect initial window's location under GNOME
* @key headful
*/

public class WindowInitialPosition {
private static JFrame frame;
private static Point location;
private static Point locationOnScreen;

public static void main(String[] args) throws Exception {
try {
SwingUtilities.invokeAndWait(WindowInitialPosition::initUI);
Thread.sleep(1000);
SwingUtilities.invokeAndWait(WindowInitialPosition::fetchLocation);
Point expectedLocation = new Point(200, 200);
if (!expectedLocation.equals(location)) {
throw new RuntimeException("Frame reports unexpected location: " + location);
}
if (!expectedLocation.equals(locationOnScreen)) {
throw new RuntimeException("Frame reports unexpected locationOnScreen: " + locationOnScreen);
}
}
finally {
SwingUtilities.invokeAndWait(WindowInitialPosition::disposeUI);
}
}

private static void initUI() {
frame = new JFrame("WindowInitialPosition");
frame.setBounds(200, 200, 200, 200);
frame.setVisible(true);
}

private static void disposeUI() {
if (frame != null) frame.dispose();
}

private static void fetchLocation() {
location = frame.getLocation();
locationOnScreen = frame.getLocationOnScreen();
}
}

0 comments on commit f4ea24e

Please sign in to comment.