1
1
/*
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.
3
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
4
*
5
5
* This code is free software; you can redistribute it and/or modify it
27
27
28
28
import java .awt .Component ;
29
29
import java .awt .Cursor ;
30
+ import java .awt .Toolkit ;
30
31
import java .awt .Window ;
31
32
32
33
import java .awt .datatransfer .DataFlavor ;
@@ -392,6 +393,40 @@ private boolean updateSourceAction(int state) {
392
393
return true ;
393
394
}
394
395
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
+
395
430
/**
396
431
* Returns the client window under the specified root subwindow.
397
432
*/
@@ -400,6 +435,10 @@ private static long findClientWindow(long window) {
400
435
return window ;
401
436
}
402
437
438
+ if (isXWaylandDndAwareWindow (window )) {
439
+ return window ;
440
+ }
441
+
403
442
Set <Long > children = XlibUtil .getChildWindows (window );
404
443
for (Long child : children ) {
405
444
long win = findClientWindow (child );
0 commit comments