correctly decode pasted text
This commit is contained in:
parent
ec23bf0457
commit
ab74e89f5f
@ -489,14 +489,13 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
|
||||
static inline int maxSelectionIncr(xcb_connection_t *c)
|
||||
{
|
||||
int l = xcb_get_maximum_request_length(c);
|
||||
return l > 65536 ? 65536*4 : l*4 - 100;
|
||||
return (l > 65536 ? 65536*4 : l*4) - 100;
|
||||
}
|
||||
|
||||
bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property, bool deleteProperty, QByteArray *buffer, int *size, xcb_atom_t *type, int *format) const
|
||||
{
|
||||
int maxsize = maxSelectionIncr(m_connection->xcb_connection());
|
||||
ulong bytes_left; // bytes_after
|
||||
ulong length; // nitems
|
||||
xcb_atom_t dummy_type;
|
||||
int dummy_format;
|
||||
int r;
|
||||
@ -514,7 +513,6 @@ bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property,
|
||||
return false;
|
||||
}
|
||||
*type = reply->type;
|
||||
length = reply->length;
|
||||
*format = reply->format;
|
||||
bytes_left = reply->bytes_after;
|
||||
free(reply);
|
||||
@ -550,14 +548,16 @@ bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property,
|
||||
// more to read...
|
||||
|
||||
xcb_get_property_cookie_t cookie = xcb_get_property(m_connection->xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, offset, maxsize/4);
|
||||
xcb_get_property_reply_t *reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0);
|
||||
if (!reply || reply->type == XCB_NONE)
|
||||
reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0);
|
||||
if (!reply || reply->type == XCB_NONE) {
|
||||
free(reply);
|
||||
break;
|
||||
}
|
||||
*type = reply->type;
|
||||
length = reply->length;
|
||||
*format = reply->format;
|
||||
bytes_left = reply->bytes_after;
|
||||
char *data = (char *)xcb_get_property_value(reply);
|
||||
int length = xcb_get_property_value_length(reply);
|
||||
|
||||
offset += length / (32 / *format);
|
||||
length *= format_inc * (*format) / 8;
|
||||
@ -780,6 +780,7 @@ QByteArray QXcbClipboard::getDataInFormat(xcb_atom_t modeAtom, xcb_atom_t fmtAto
|
||||
xcb_atom_t type;
|
||||
if (clipboardReadProperty(win, m_connection->atom(QXcbAtom::_QT_SELECTION), true, &buf, 0, &type, 0)) {
|
||||
if (type == m_connection->atom(QXcbAtom::INCR)) {
|
||||
qDebug() << "INCR";
|
||||
int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
|
||||
buf = clipboardReadIncrementalProperty(win, m_connection->atom(QXcbAtom::_QT_SELECTION), nbytes, false);
|
||||
}
|
||||
|
@ -44,6 +44,7 @@
|
||||
#include <QtCore/QTextCodec>
|
||||
#include <QtGui/QImageWriter>
|
||||
#include <QtCore/QBuffer>
|
||||
#include <qdebug.h>
|
||||
|
||||
#include <X11/Xutil.h>
|
||||
|
||||
@ -181,8 +182,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
QVariant::Type requestedType, const QByteArray &encoding)
|
||||
{
|
||||
QString atomName = mimeAtomToString(connection, a);
|
||||
if (atomName == format)
|
||||
return data;
|
||||
// qDebug() << "mimeConvertDataToFormat" << format << atomName << data;
|
||||
|
||||
if (!encoding.isEmpty()
|
||||
&& atomName == format + QLatin1String(";charset=") + QString::fromLatin1(encoding)) {
|
||||
@ -198,8 +198,10 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
|
||||
// special cases for string types
|
||||
if (format == QLatin1String("text/plain")) {
|
||||
if (a == connection->atom(QXcbAtom::UTF8_STRING))
|
||||
if (a == connection->atom(QXcbAtom::UTF8_STRING)) {
|
||||
qDebug() << data;
|
||||
return QString::fromUtf8(data);
|
||||
}
|
||||
if (a == QXcbAtom::XA_STRING)
|
||||
return QString::fromLatin1(data);
|
||||
if (a == connection->atom(QXcbAtom::TEXT)
|
||||
@ -221,6 +223,9 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
|
||||
}
|
||||
}
|
||||
|
||||
if (atomName == format)
|
||||
return data;
|
||||
|
||||
#if 0 // ###
|
||||
// special case for images
|
||||
if (format == QLatin1String("image/ppm")) {
|
||||
|
Loading…
Reference in New Issue
Block a user