Skip to content

Commit 5ad9e24

Browse files
committed
8280994: [XWayland] Drag and Drop does not work in java -> wayland app direction
Backport-of: 73352b68c4e19929305ce430cb74ca850b752d22
1 parent 1242055 commit 5ad9e24

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

src/java.desktop/share/classes/sun/awt/SunToolkit.java

+5
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,11 @@ public boolean isNativeGTKAvailable() {
18831883
return false;
18841884
}
18851885

1886+
/**
1887+
* Checks if the system is running Linux with the Wayland server.
1888+
*
1889+
* @return true if running on Wayland, false otherwise
1890+
*/
18861891
public boolean isRunningOnWayland() {
18871892
return false;
18881893
}

src/java.desktop/unix/classes/sun/awt/X11/XDragSourceContextPeer.java

+40-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -27,6 +27,7 @@
2727

2828
import java.awt.Component;
2929
import java.awt.Cursor;
30+
import java.awt.Toolkit;
3031
import java.awt.Window;
3132

3233
import java.awt.datatransfer.DataFlavor;
@@ -392,6 +393,40 @@ private boolean updateSourceAction(int state) {
392393
return true;
393394
}
394395

396+
/**
397+
* Our X11 code expects the drop target window to be a top level window
398+
* and to have the XA_WM_STATE property.
399+
* This is not true when performing drag and drop from XWayland
400+
* to a native Wayland application.
401+
* In this case XWayland creates a dummy window with only one property,
402+
* XdndAware.
403+
*
404+
* @param window to test
405+
* @return true if window has XdndAware property when running under Wayland
406+
*/
407+
private static boolean isXWaylandDndAwareWindow(long window) {
408+
Toolkit toolkit = Toolkit.getDefaultToolkit();
409+
if (!(toolkit instanceof SunToolkit)
410+
|| !((SunToolkit) toolkit).isRunningOnWayland()) {
411+
return false;
412+
}
413+
414+
WindowPropertyGetter wpg =
415+
new WindowPropertyGetter(window, XDnDConstants.XA_XdndAware, 0, 1,
416+
false, XConstants.AnyPropertyType);
417+
418+
try {
419+
int status =
420+
wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());
421+
422+
return status == XConstants.Success
423+
&& wpg.getData() != 0
424+
&& wpg.getActualType() == XAtom.XA_ATOM;
425+
} finally {
426+
wpg.dispose();
427+
}
428+
}
429+
395430
/**
396431
* Returns the client window under the specified root subwindow.
397432
*/
@@ -400,6 +435,10 @@ private static long findClientWindow(long window) {
400435
return window;
401436
}
402437

438+
if (isXWaylandDndAwareWindow(window)) {
439+
return window;
440+
}
441+
403442
Set<Long> children = XlibUtil.getChildWindows(window);
404443
for (Long child : children) {
405444
long win = findClientWindow(child);

0 commit comments

Comments
 (0)