mirror of
https://github.com/JetBrains/JetBrainsRuntime.git
synced 2025-12-06 09:29:38 +01:00
JBR-5971 Wayland: support WindowMove JBR API
Updated the XToolkit implementation to match API changes required for WLToolkit
This commit is contained in:
@@ -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")
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user