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

Wayland qt kde clipboard fix #863

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

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,9 @@ boolean setData(Clipboard owner, Object[] data, Transfer[] dataTypes, int clipbo
System.arraycopy(entries, 0, tmp, 0, entries.length);
tmp[entries.length] = entry;
entries = tmp;
TransferData tdata = new TransferData();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change is non-functional. Why it was added?

Copy link
Contributor Author

@the-snowwhite the-snowwhite Nov 10, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These 3 lines where needed to get Eclipse to present text/plain;uft-8 data to the clipboard.
Otherwise the javaToNative function in Texttreanfer.java was'nt called.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This I confirmed by the eclipse debugger

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is wrong - have you asked why does the rest of clipboard data works but only new type would need that? I would assume you've missed something else.

The javaToNative is called from org.eclipse.swt.dnd.ClipboardProxy.getFunc(long, long, long, long)

tdata.type = typeIds[j];
transfer.javaToNative(data[i], tdata);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*******************************************************************************/
package org.eclipse.swt.dnd;

import java.nio.charset.*;

import org.eclipse.swt.internal.*;
import org.eclipse.swt.internal.gtk.*;

Expand Down Expand Up @@ -42,9 +44,11 @@ public class TextTransfer extends ByteArrayTransfer {
private static final String COMPOUND_TEXT = "COMPOUND_TEXT"; //$NON-NLS-1$
private static final String UTF8_STRING = "UTF8_STRING"; //$NON-NLS-1$
private static final String STRING = "STRING"; //$NON-NLS-1$
private static final String TEXT_PLAIN_UTF8 = "text/plain;charset=utf-8"; //RFC-1341
private static final int COMPOUND_TEXT_ID = GTK.GTK4 ? 0 : registerType(COMPOUND_TEXT);
private static final int UTF8_STRING_ID = GTK.GTK4 ? 0 : registerType(UTF8_STRING);
private static final int STRING_ID = GTK.GTK4 ? 0 : registerType(STRING);
private static final int TEXT_PLAIN_UTF8_ID = GTK.GTK4 ? 0 : registerType(TEXT_PLAIN_UTF8);

private TextTransfer() {}

Expand Down Expand Up @@ -107,8 +111,29 @@ public void javaToNative (Object object, TransferData transferData) {
transferData.pValue = string_target;
transferData.result = 1;
}
if (transferData.type == TEXT_PLAIN_UTF8_ID) {
// Convert the text into RFC-1341 format
byte[] rfc1341Data = encodeTextAsRFC1341(string);
transferData.format = 8; // Format for UTF-8
transferData.length = rfc1341Data.length;
transferData.pValue = OS.g_malloc(rfc1341Data.length);
if (transferData.pValue != 0) {
C.memmove(transferData.pValue, rfc1341Data, rfc1341Data.length);
transferData.result = 1;
}
}
}

// New method to encode text as RFC-1341
private byte[] encodeTextAsRFC1341(String text) {
// Implement encoding logic here, e.g., adding MIME headers and encoding text
// This is a simplified example; actual encoding depends on RFC-1341 standards
// String rfc1341Text = "Content-Type: " + TEXTPLAINUTF8 + "\r\n\r\n" + text;
String rfc1341Text = text;
return rfc1341Text.getBytes(StandardCharsets.UTF_8);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see #875 (comment)

I have my doubts what this method does.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the method should be named convertToUTF8, as RFC 1341 is the standard that talks about the formatting if "MIME types" (i.e. the maintype/subtype;options format), and isn't actually about UTF strings. Also, the code of the method is pretty simple - effectively a short one liner - so maybe it can just be used directly in the one place it is being used.

}


/**
* This implementation of <code>nativeToJava</code> converts a platform specific
* representation of plain text to a java <code>String</code>.
Expand Down Expand Up @@ -145,7 +170,7 @@ protected int[] getTypeIds() {
if(GTK.GTK4) {
return new int[] {(int) OS.G_TYPE_STRING()};
}
return new int[] {UTF8_STRING_ID, STRING_ID};
return new int[] {UTF8_STRING_ID, STRING_ID, TEXT_PLAIN_UTF8_ID};
}

@Override
Expand All @@ -157,7 +182,7 @@ protected String[] getTypeNames() {
return new String[] {"text/plain", STRING};
}

return new String[] {UTF8_STRING, STRING};
return new String[] {UTF8_STRING, STRING, TEXT_PLAIN_UTF8};
}

boolean checkText(Object object) {
Expand Down
Loading