JBR-5971 Wayland: support WindowMove JBR API

Updated the XToolkit implementation to match API changes required for
WLToolkit
This commit is contained in:
Maxim Kartashev
2023-08-29 10:45:25 +04:00
committed by jbrbot
parent 12a5f08441
commit badbe7e6b1
3 changed files with 54 additions and 1 deletions

View File

@@ -57,7 +57,7 @@ public class JBRApiModule {
.clientProxy("com.jetbrains.desktop.ConstrainableGraphics2D", "com.jetbrains.GraphicsUtils$ConstrainableGraphics2D")
.service("com.jetbrains.WindowDecorations", "java.awt.Window$WindowDecorations")
.proxy("com.jetbrains.WindowDecorations$CustomTitleBar", "java.awt.Window$CustomTitleBar")
.service("com.jetbrains.WindowMove", "sun.awt.X11.XWindowPeer$WindowMoveService")
.service("com.jetbrains.WindowMove", "java.awt.Window$WindowMoveService")
;
}
}

View File

@@ -59,6 +59,7 @@ import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.HashMap;
import java.util.Objects;
import java.util.ResourceBundle;
import java.util.Set;
import java.util.Vector;
@@ -4256,6 +4257,48 @@ public class Window extends Container implements Accessible {
}
}
private interface WindowMovePeer {
void startMovingWindowTogetherWithMouse(Window window, int mouseButton);
}
private interface WindowMovePeerX11 extends WindowMovePeer {
WindowMovePeerX11 INSTANCE = (WindowMovePeerX11) JBRApi.internalServiceBuilder(MethodHandles.lookup())
.withStatic("startMovingWindowTogetherWithMouse",
"startMovingWindowTogetherWithMouse",
"sun.awt.X11.XWindowPeer")
.build();
}
private static class WindowMoveService {
WindowMovePeer windowMovePeer;
WindowMoveService() {
var toolkit = Toolkit.getDefaultToolkit();
var ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
if (toolkit == null || ge == null) {
throw new JBRApi.ServiceNotAvailableException("Supported only with a Toolkit present");
}
if (!objectIsInstanceOf(toolkit, "sun.awt.X11.XToolkit")
|| !objectIsInstanceOf(ge, "sun.awt.X11GraphicsEnvironment")) {
throw new JBRApi.ServiceNotAvailableException("Supported only with XToolkit and X11GraphicsEnvironment");
}
// This will throw if the service is not supported by the underlying WM
windowMovePeer = WindowMovePeerX11.INSTANCE;
}
boolean objectIsInstanceOf(Object o, String className) {
Objects.requireNonNull(o);
return o.getClass().getName().equals(className);
}
void startMovingTogetherWithMouse(Window window, int mouseButton) {
Objects.requireNonNull(window);
windowMovePeer.startMovingWindowTogetherWithMouse(window, mouseButton);
}
}
// ************************** JBR stuff *******************************
private volatile boolean ignoreMouseEvents;

View File

@@ -2603,6 +2603,16 @@ class XWindowPeer extends XPanelPeer implements WindowPeer,
XWM.getWM().startMovingWindowTogetherWithMouse(getParentTopLevel().getWindow(), getLastButtonPressAbsLocation(), mouseButton);
}
private static void startMovingWindowTogetherWithMouse(Window window, int mouseButton) {
final AWTAccessor.ComponentAccessor acc = AWTAccessor.getComponentAccessor();
ComponentPeer peer = acc.getPeer(window);
if (peer instanceof XWindowPeer xWindowPeer) {
xWindowPeer.startMovingTogetherWithMouse(mouseButton);
} else {
throw new IllegalArgumentException("AWT window must have XWindowPeer as its peer");
}
}
private static class WindowMoveService {
WindowMoveService() {
final var toolkit = Toolkit.getDefaultToolkit();