Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

8280994: [XWayland] Drag and Drop does not work in java -> wayland app direction #14266

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/java.desktop/share/classes/sun/awt/SunToolkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -1883,6 +1883,11 @@ public boolean isNativeGTKAvailable() {
return false;
}

/**
* Checks if the system is running Linux with the Wayland server.
*
* @return true if running on Wayland, false otherwise
*/
public boolean isRunningOnWayland() {
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2015, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
Expand Down Expand Up @@ -27,6 +27,7 @@

import java.awt.Component;
import java.awt.Cursor;
import java.awt.Toolkit;
import java.awt.Window;

import java.awt.datatransfer.DataFlavor;
Expand Down Expand Up @@ -392,6 +393,40 @@ private boolean updateSourceAction(int state) {
return true;
}

/**
* Our X11 code expects the drop target window to be a top level window
* and to have the XA_WM_STATE property.
* This is not true when performing drag and drop from XWayland
* to a native Wayland application.
* In this case XWayland creates a dummy window with only one property,
* XdndAware.
*
* @param window to test
* @return true if window has XdndAware property when running under Wayland
*/
private static boolean isXWaylandDndAwareWindow(long window) {
Toolkit toolkit = Toolkit.getDefaultToolkit();
if (!(toolkit instanceof SunToolkit)
|| !((SunToolkit) toolkit).isRunningOnWayland()) {
azvegint marked this conversation as resolved.
Show resolved Hide resolved
return false;
}

WindowPropertyGetter wpg =
new WindowPropertyGetter(window, XDnDConstants.XA_XdndAware, 0, 1,
false, XConstants.AnyPropertyType);

try {
int status =
wpg.execute(XErrorHandler.IgnoreBadWindowHandler.getInstance());

return status == XConstants.Success
&& wpg.getData() != 0
&& wpg.getActualType() == XAtom.XA_ATOM;
} finally {
wpg.dispose();
}
}

/**
* Returns the client window under the specified root subwindow.
*/
Expand All @@ -400,6 +435,10 @@ private static long findClientWindow(long window) {
return window;
}

if (isXWaylandDndAwareWindow(window)) {
return window;
}

Set<Long> children = XlibUtil.getChildWindows(window);
for (Long child : children) {
long win = findClientWindow(child);
Expand Down