cleanups code

Make QXcbClipboard and QXcbDrag a QXcbObject to simplify
the code.
Use the predefined atoms in xproto.h instead of our own
defines.
This commit is contained in:
Lars Knoll 2011-06-07 16:29:35 +02:00
parent 4386425ce3
commit 52e5fd336b
9 changed files with 147 additions and 166 deletions

View File

@ -62,11 +62,11 @@ public:
{ {
switch (mode) { switch (mode) {
case QClipboard::Selection: case QClipboard::Selection:
modeAtom = QXcbAtom::XA_PRIMARY; modeAtom = XCB_ATOM_PRIMARY;
break; break;
case QClipboard::Clipboard: case QClipboard::Clipboard:
modeAtom = m_clipboard->connection()->atom(QXcbAtom::CLIPBOARD); modeAtom = m_clipboard->atom(QXcbAtom::CLIPBOARD);
break; break;
default: default:
@ -86,7 +86,7 @@ protected:
// get the list of targets from the current clipboard owner - we do this // get the list of targets from the current clipboard owner - we do this
// once so that multiple calls to this function don't require multiple // once so that multiple calls to this function don't require multiple
// server round trips... // server round trips...
that->format_atoms = m_clipboard->getDataInFormat(modeAtom, m_clipboard->connection()->atom(QXcbAtom::TARGETS)); that->format_atoms = m_clipboard->getDataInFormat(modeAtom, m_clipboard->atom(QXcbAtom::TARGETS));
if (format_atoms.size() > 0) { if (format_atoms.size() > 0) {
xcb_atom_t *targets = (xcb_atom_t *) format_atoms.data(); xcb_atom_t *targets = (xcb_atom_t *) format_atoms.data();
@ -148,9 +148,8 @@ private:
const int QXcbClipboard::clipboard_timeout = 5000; const int QXcbClipboard::clipboard_timeout = 5000;
QXcbClipboard::QXcbClipboard(QXcbConnection *connection) QXcbClipboard::QXcbClipboard(QXcbConnection *c)
: QPlatformClipboard() : QXcbObject(c), QPlatformClipboard()
, m_connection(connection)
, m_xClipboard(0) , m_xClipboard(0)
, m_clientClipboard(0) , m_clientClipboard(0)
, m_xSelection(0) , m_xSelection(0)
@ -158,12 +157,12 @@ QXcbClipboard::QXcbClipboard(QXcbConnection *connection)
, m_requestor(XCB_NONE) , m_requestor(XCB_NONE)
, m_owner(XCB_NONE) , m_owner(XCB_NONE)
{ {
m_screen = m_connection->screens().at(m_connection->primaryScreen()); m_screen = connection()->screens().at(connection()->primaryScreen());
} }
xcb_window_t QXcbClipboard::getSelectionOwner(xcb_atom_t atom) const xcb_window_t QXcbClipboard::getSelectionOwner(xcb_atom_t atom) const
{ {
xcb_connection_t *c = m_connection->xcb_connection(); xcb_connection_t *c = xcb_connection();
xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(c, atom); xcb_get_selection_owner_cookie_t cookie = xcb_get_selection_owner(c, atom);
xcb_get_selection_owner_reply_t *reply; xcb_get_selection_owner_reply_t *reply;
reply = xcb_get_selection_owner_reply(c, cookie, 0); reply = xcb_get_selection_owner_reply(c, cookie, 0);
@ -178,7 +177,7 @@ QMimeData * QXcbClipboard::mimeData(QClipboard::Mode mode)
if (!m_xClipboard) { if (!m_xClipboard) {
m_xClipboard = new QXcbClipboardMime(mode, this); m_xClipboard = new QXcbClipboardMime(mode, this);
} }
xcb_window_t clipboardOwner = getSelectionOwner(m_connection->atom(QXcbAtom::CLIPBOARD)); xcb_window_t clipboardOwner = getSelectionOwner(atom(QXcbAtom::CLIPBOARD));
if (clipboardOwner == owner()) { if (clipboardOwner == owner()) {
return m_clientClipboard; return m_clientClipboard;
} else { } else {
@ -188,7 +187,7 @@ QMimeData * QXcbClipboard::mimeData(QClipboard::Mode mode)
if (!m_xSelection) { if (!m_xSelection) {
m_xSelection = new QXcbClipboardMime(mode, this); m_xSelection = new QXcbClipboardMime(mode, this);
} }
xcb_window_t clipboardOwner = getSelectionOwner(QXcbAtom::XA_PRIMARY); xcb_window_t clipboardOwner = getSelectionOwner(XCB_ATOM_PRIMARY);
if (clipboardOwner == owner()) { if (clipboardOwner == owner()) {
return m_clientSelection; return m_clientSelection;
} else { } else {
@ -204,12 +203,12 @@ void QXcbClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
QMimeData **d; QMimeData **d;
switch (mode) { switch (mode) {
case QClipboard::Selection: case QClipboard::Selection:
modeAtom = QXcbAtom::XA_PRIMARY; modeAtom = XCB_ATOM_PRIMARY;
d = &m_clientSelection; d = &m_clientSelection;
break; break;
case QClipboard::Clipboard: case QClipboard::Clipboard:
modeAtom = m_connection->atom(QXcbAtom::CLIPBOARD); modeAtom = atom(QXcbAtom::CLIPBOARD);
d = &m_clientClipboard; d = &m_clientClipboard;
break; break;
@ -228,7 +227,7 @@ void QXcbClipboard::setMimeData(QMimeData *data, QClipboard::Mode mode)
*d = data; *d = data;
} }
xcb_set_selection_owner(m_connection->xcb_connection(), newOwner, modeAtom, m_connection->time()); xcb_set_selection_owner(xcb_connection(), newOwner, modeAtom, connection()->time());
if (getSelectionOwner(modeAtom) != newOwner) { if (getSelectionOwner(modeAtom) != newOwner) {
qWarning("QClipboard::setData: Cannot set X11 selection owner"); qWarning("QClipboard::setData: Cannot set X11 selection owner");
@ -249,8 +248,8 @@ xcb_window_t QXcbClipboard::requestor() const
const int x = 0, y = 0, w = 3, h = 3; const int x = 0, y = 0, w = 3, h = 3;
QXcbClipboard *that = const_cast<QXcbClipboard *>(this); QXcbClipboard *that = const_cast<QXcbClipboard *>(this);
xcb_window_t window = xcb_generate_id(m_connection->xcb_connection()); xcb_window_t window = xcb_generate_id(xcb_connection());
Q_XCB_CALL(xcb_create_window(m_connection->xcb_connection(), Q_XCB_CALL(xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root XCB_COPY_FROM_PARENT, // depth -- same as root
window, // window id window, // window id
m_screen->screen()->root, // parent window id m_screen->screen()->root, // parent window id
@ -262,7 +261,7 @@ xcb_window_t QXcbClipboard::requestor() const
0)); // value list 0)); // value list
uint32_t mask = XCB_EVENT_MASK_PROPERTY_CHANGE; uint32_t mask = XCB_EVENT_MASK_PROPERTY_CHANGE;
xcb_change_window_attributes(m_connection->xcb_connection(), window, XCB_CW_EVENT_MASK, &mask); xcb_change_window_attributes(xcb_connection(), window, XCB_CW_EVENT_MASK, &mask);
that->setRequestor(window); that->setRequestor(window);
} }
@ -272,7 +271,7 @@ xcb_window_t QXcbClipboard::requestor() const
void QXcbClipboard::setRequestor(xcb_window_t window) void QXcbClipboard::setRequestor(xcb_window_t window)
{ {
if (m_requestor != XCB_NONE) { if (m_requestor != XCB_NONE) {
xcb_destroy_window(m_connection->xcb_connection(), m_requestor); xcb_destroy_window(xcb_connection(), m_requestor);
} }
m_requestor = window; m_requestor = window;
} }
@ -283,8 +282,8 @@ xcb_window_t QXcbClipboard::owner() const
int x = 0, y = 0, w = 3, h = 3; int x = 0, y = 0, w = 3, h = 3;
QXcbClipboard *that = const_cast<QXcbClipboard *>(this); QXcbClipboard *that = const_cast<QXcbClipboard *>(this);
xcb_window_t window = xcb_generate_id(m_connection->xcb_connection()); xcb_window_t window = xcb_generate_id(xcb_connection());
Q_XCB_CALL(xcb_create_window(m_connection->xcb_connection(), Q_XCB_CALL(xcb_create_window(xcb_connection(),
XCB_COPY_FROM_PARENT, // depth -- same as root XCB_COPY_FROM_PARENT, // depth -- same as root
window, // window id window, // window id
m_screen->screen()->root, // parent window id m_screen->screen()->root, // parent window id
@ -303,7 +302,7 @@ xcb_window_t QXcbClipboard::owner() const
void QXcbClipboard::setOwner(xcb_window_t window) void QXcbClipboard::setOwner(xcb_window_t window)
{ {
if (m_owner != XCB_NONE){ if (m_owner != XCB_NONE){
xcb_destroy_window(m_connection->xcb_connection(), m_owner); xcb_destroy_window(xcb_connection(), m_owner);
} }
m_owner = window; m_owner = window;
} }
@ -313,18 +312,18 @@ xcb_atom_t QXcbClipboard::sendTargetsSelection(QMimeData *d, xcb_window_t window
QVector<xcb_atom_t> types; QVector<xcb_atom_t> types;
QStringList formats = QInternalMimeData::formatsHelper(d); QStringList formats = QInternalMimeData::formatsHelper(d);
for (int i = 0; i < formats.size(); ++i) { for (int i = 0; i < formats.size(); ++i) {
QList<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(m_connection, formats.at(i)); QList<xcb_atom_t> atoms = QXcbMime::mimeAtomsForFormat(connection(), formats.at(i));
for (int j = 0; j < atoms.size(); ++j) { for (int j = 0; j < atoms.size(); ++j) {
if (!types.contains(atoms.at(j))) if (!types.contains(atoms.at(j)))
types.append(atoms.at(j)); types.append(atoms.at(j));
} }
} }
types.append(m_connection->atom(QXcbAtom::TARGETS)); types.append(atom(QXcbAtom::TARGETS));
types.append(m_connection->atom(QXcbAtom::MULTIPLE)); types.append(atom(QXcbAtom::MULTIPLE));
types.append(m_connection->atom(QXcbAtom::TIMESTAMP)); types.append(atom(QXcbAtom::TIMESTAMP));
types.append(m_connection->atom(QXcbAtom::SAVE_TARGETS)); types.append(atom(QXcbAtom::SAVE_TARGETS));
xcb_change_property(m_connection->xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, QXcbAtom::XA_ATOM, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, XCB_ATOM_ATOM,
32, types.size(), (const void *)types.constData()); 32, types.size(), (const void *)types.constData());
return property; return property;
} }
@ -335,26 +334,26 @@ xcb_atom_t QXcbClipboard::sendSelection(QMimeData *d, xcb_atom_t target, xcb_win
int dataFormat = 0; int dataFormat = 0;
QByteArray data; QByteArray data;
QString fmt = QXcbMime::mimeAtomToString(m_connection, target); QString fmt = QXcbMime::mimeAtomToString(connection(), target);
if (fmt.isEmpty()) { // Not a MIME type we have if (fmt.isEmpty()) { // Not a MIME type we have
qDebug() << "QClipboard: send_selection(): converting to type '%s' is not supported" << fmt.data(); qDebug() << "QClipboard: send_selection(): converting to type '%s' is not supported" << fmt.data();
return XCB_NONE; return XCB_NONE;
} }
qDebug() << "QClipboard: send_selection(): converting to type '%s'" << fmt.data(); qDebug() << "QClipboard: send_selection(): converting to type '%s'" << fmt.data();
if (QXcbMime::mimeDataForAtom(m_connection, target, d, &data, &atomFormat, &dataFormat)) { if (QXcbMime::mimeDataForAtom(connection(), target, d, &data, &atomFormat, &dataFormat)) {
// don't allow INCR transfers when using MULTIPLE or to // don't allow INCR transfers when using MULTIPLE or to
// Motif clients (since Motif doesn't support INCR) // Motif clients (since Motif doesn't support INCR)
static xcb_atom_t motif_clip_temporary = m_connection->atom(QXcbAtom::CLIP_TEMPORARY); static xcb_atom_t motif_clip_temporary = atom(QXcbAtom::CLIP_TEMPORARY);
bool allow_incr = property != motif_clip_temporary; bool allow_incr = property != motif_clip_temporary;
// X_ChangeProperty protocol request is 24 bytes // X_ChangeProperty protocol request is 24 bytes
const int increment = (xcb_get_maximum_request_length(m_connection->xcb_connection()) * 4) - 24; const int increment = (xcb_get_maximum_request_length(xcb_connection()) * 4) - 24;
if (data.size() > increment && allow_incr) { if (data.size() > increment && allow_incr) {
long bytes = data.size(); long bytes = data.size();
xcb_change_property(m_connection->xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property,
m_connection->atom(QXcbAtom::INCR), 32, 1, (const void *)&bytes); atom(QXcbAtom::INCR), 32, 1, (const void *)&bytes);
// (void)new QClipboardINCRTransaction(window, property, atomFormat, dataFormat, data, increment); // (void)new QClipboardINCRTransaction(window, property, atomFormat, dataFormat, data, increment);
qDebug() << "not implemented INCRT just YET!"; qDebug() << "not implemented INCRT just YET!";
@ -366,7 +365,7 @@ xcb_atom_t QXcbClipboard::sendSelection(QMimeData *d, xcb_atom_t target, xcb_win
return XCB_NONE; // ### perhaps use several XChangeProperty calls w/ PropModeAppend? return XCB_NONE; // ### perhaps use several XChangeProperty calls w/ PropModeAppend?
int dataSize = data.size() / (dataFormat / 8); int dataSize = data.size() / (dataFormat / 8);
// use a single request to transfer data // use a single request to transfer data
xcb_change_property(m_connection->xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, atomFormat, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, window, property, atomFormat,
dataFormat, dataSize, (const void *)data.constData()); dataFormat, dataSize, (const void *)data.constData());
} }
return property; return property;
@ -388,25 +387,25 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
event.time = req->time; event.time = req->time;
QMimeData *d; QMimeData *d;
if (req->selection == QXcbAtom::XA_PRIMARY) { if (req->selection == XCB_ATOM_PRIMARY) {
d = m_clientSelection; d = m_clientSelection;
} else if (req->selection == m_connection->atom(QXcbAtom::CLIPBOARD)) { } else if (req->selection == atom(QXcbAtom::CLIPBOARD)) {
d = m_clientClipboard; d = m_clientClipboard;
} else { } else {
qWarning() << "QClipboard: Unknown selection" << m_connection->atomName(req->selection); qWarning() << "QClipboard: Unknown selection" << connection()->atomName(req->selection);
xcb_send_event(m_connection->xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
return; return;
} }
if (!d) { if (!d) {
qWarning("QClipboard: Cannot transfer data, no data available"); qWarning("QClipboard: Cannot transfer data, no data available");
xcb_send_event(m_connection->xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
return; return;
} }
xcb_atom_t xa_targets = m_connection->atom(QXcbAtom::TARGETS); xcb_atom_t xa_targets = atom(QXcbAtom::TARGETS);
xcb_atom_t xa_multiple = m_connection->atom(QXcbAtom::MULTIPLE); xcb_atom_t xa_multiple = atom(QXcbAtom::MULTIPLE);
xcb_atom_t xa_timestamp = m_connection->atom(QXcbAtom::TIMESTAMP); xcb_atom_t xa_timestamp = atom(QXcbAtom::TIMESTAMP);
struct AtomPair { xcb_atom_t target; xcb_atom_t property; } *multi = 0; struct AtomPair { xcb_atom_t target; xcb_atom_t property; } *multi = 0;
xcb_atom_t multi_type = XCB_NONE; xcb_atom_t multi_type = XCB_NONE;
@ -422,7 +421,7 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
0, &multi_type, &multi_format) 0, &multi_type, &multi_format)
|| multi_format != 32) { || multi_format != 32) {
// MULTIPLE property not formatted correctly // MULTIPLE property not formatted correctly
xcb_send_event(m_connection->xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
return; return;
} }
nmulti = multi_data.size()/sizeof(*multi); nmulti = multi_data.size()/sizeof(*multi);
@ -450,7 +449,7 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
; ;
} else if (target == xa_timestamp) { } else if (target == xa_timestamp) {
// if (d->timestamp != CurrentTime) { // if (d->timestamp != CurrentTime) {
// XChangeProperty(DISPLAY_FROM_XCB(m_connection), req->requestor, property, QXcbAtom::XA_INTEGER, 32, // XChangeProperty(DISPLAY_FROM_XCB(connection()), req->requestor, property, QXcbAtom::XA_INTEGER, 32,
// PropModeReplace, CurrentTime, 1); // PropModeReplace, CurrentTime, 1);
// ret = property; // ret = property;
// } else { // } else {
@ -477,7 +476,7 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
if (multi_writeback) { if (multi_writeback) {
// according to ICCCM 2.6.2 says to put None back // according to ICCCM 2.6.2 says to put None back
// into the original property on the requestor window // into the original property on the requestor window
xcb_change_property(m_connection->xcb_connection(), XCB_PROP_MODE_REPLACE, req->requestor, req->property, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, req->requestor, req->property,
multi_type, 32, nmulti*2, (const void *)multi); multi_type, 32, nmulti*2, (const void *)multi);
} }
@ -486,7 +485,7 @@ void QXcbClipboard::handleSelectionRequest(xcb_selection_request_event_t *req)
} }
// send selection notify to requestor // send selection notify to requestor
xcb_send_event(m_connection->xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event); xcb_send_event(xcb_connection(), false, req->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&event);
} }
static inline int maxSelectionIncr(xcb_connection_t *c) static inline int maxSelectionIncr(xcb_connection_t *c)
@ -497,7 +496,7 @@ static inline int maxSelectionIncr(xcb_connection_t *c)
bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property, bool deleteProperty, QByteArray *buffer, int *size, xcb_atom_t *type, int *format) const 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()); int maxsize = maxSelectionIncr(xcb_connection());
ulong bytes_left; // bytes_after ulong bytes_left; // bytes_after
xcb_atom_t dummy_type; xcb_atom_t dummy_type;
int dummy_format; int dummy_format;
@ -508,8 +507,8 @@ bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property,
format = &dummy_format; format = &dummy_format;
// Don't read anything, just get the size of the property data // Don't read anything, just get the size of the property data
xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(m_connection->xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, 0, 0)); xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, 0, 0));
xcb_get_property_reply_t *reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
if (!reply || reply->type == XCB_NONE) { if (!reply || reply->type == XCB_NONE) {
buffer->resize(0); buffer->resize(0);
return false; return false;
@ -549,8 +548,8 @@ bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property,
while (bytes_left) { while (bytes_left) {
// more to read... // more to read...
xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(m_connection->xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, offset, maxsize/4)); xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(xcb_connection(), false, win, property, XCB_GET_PROPERTY_TYPE_ANY, offset, maxsize/4));
reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0); reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
if (!reply || reply->type == XCB_NONE) { if (!reply || reply->type == XCB_NONE) {
free(reply); free(reply);
break; break;
@ -587,9 +586,9 @@ bool QXcbClipboard::clipboardReadProperty(xcb_window_t win, xcb_atom_t property,
*size = buffer_offset; *size = buffer_offset;
if (deleteProperty) if (deleteProperty)
xcb_delete_property(m_connection->xcb_connection(), win, property); xcb_delete_property(xcb_connection(), win, property);
m_connection->flush(); connection()->flush();
return ok; return ok;
} }
@ -632,10 +631,10 @@ namespace
int type = e->response_type & 0x7f; int type = e->response_type & 0x7f;
if (type == XCB_SELECTION_REQUEST) { if (type == XCB_SELECTION_REQUEST) {
xcb_selection_request_event_t *sr = (xcb_selection_request_event_t *)e; xcb_selection_request_event_t *sr = (xcb_selection_request_event_t *)e;
return sr->selection == QXcbAtom::XA_PRIMARY || sr->selection == clipboard; return sr->selection == XCB_ATOM_PRIMARY || sr->selection == clipboard;
} else if (type == XCB_SELECTION_CLEAR) { } else if (type == XCB_SELECTION_CLEAR) {
xcb_selection_clear_event_t *sc = (xcb_selection_clear_event_t *)e; xcb_selection_clear_event_t *sc = (xcb_selection_clear_event_t *)e;
return sc->selection == QXcbAtom::XA_PRIMARY || sc->selection == clipboard; return sc->selection == XCB_ATOM_PRIMARY || sc->selection == clipboard;
} }
return false; return false;
} }
@ -648,19 +647,19 @@ xcb_generic_event_t *QXcbClipboard::waitForClipboardEvent(xcb_window_t win, int
timer.start(); timer.start();
do { do {
Notify notify(win, type); Notify notify(win, type);
xcb_generic_event_t *e = m_connection->checkEvent(notify); xcb_generic_event_t *e = connection()->checkEvent(notify);
if (e) if (e)
return e; return e;
// process other clipboard events, since someone is probably requesting data from us // process other clipboard events, since someone is probably requesting data from us
ClipboardEvent clipboard(m_connection); ClipboardEvent clipboard(connection());
e = m_connection->checkEvent(clipboard); e = connection()->checkEvent(clipboard);
if (e) { if (e) {
m_connection->handleXcbEvent(e); connection()->handleXcbEvent(e);
free(e); free(e);
} }
m_connection->flush(); connection()->flush();
// sleep 50 ms, so we don't use up CPU cycles all the time. // sleep 50 ms, so we don't use up CPU cycles all the time.
struct timeval usleep_tv; struct timeval usleep_tv;
@ -689,7 +688,7 @@ QByteArray QXcbClipboard::clipboardReadIncrementalProperty(xcb_window_t win, xcb
} }
for (;;) { for (;;) {
m_connection->flush(); connection()->flush();
xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_PROPERTY_NOTIFY, clipboard_timeout); xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_PROPERTY_NOTIFY, clipboard_timeout);
if (!ge) if (!ge)
break; break;
@ -734,7 +733,7 @@ QByteArray QXcbClipboard::clipboardReadIncrementalProperty(xcb_window_t win, xcb
QByteArray QXcbClipboard::getDataInFormat(xcb_atom_t modeAtom, xcb_atom_t fmtAtom) QByteArray QXcbClipboard::getDataInFormat(xcb_atom_t modeAtom, xcb_atom_t fmtAtom)
{ {
return getSelection(modeAtom, fmtAtom, m_connection->atom(QXcbAtom::_QT_SELECTION)); return getSelection(modeAtom, fmtAtom, atom(QXcbAtom::_QT_SELECTION));
} }
QByteArray QXcbClipboard::getSelection(xcb_atom_t selection, xcb_atom_t target, xcb_atom_t property) QByteArray QXcbClipboard::getSelection(xcb_atom_t selection, xcb_atom_t target, xcb_atom_t property)
@ -742,10 +741,10 @@ QByteArray QXcbClipboard::getSelection(xcb_atom_t selection, xcb_atom_t target,
QByteArray buf; QByteArray buf;
xcb_window_t win = requestor(); xcb_window_t win = requestor();
xcb_delete_property(m_connection->xcb_connection(), win, property); xcb_delete_property(xcb_connection(), win, property);
xcb_convert_selection(m_connection->xcb_connection(), win, selection, target, property, m_connection->time()); xcb_convert_selection(xcb_connection(), win, selection, target, property, connection()->time());
m_connection->sync(); connection()->sync();
xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_SELECTION_NOTIFY, clipboard_timeout); xcb_generic_event_t *ge = waitForClipboardEvent(win, XCB_SELECTION_NOTIFY, clipboard_timeout);
bool no_selection = !ge || ((xcb_selection_notify_event_t *)ge)->property == XCB_NONE; bool no_selection = !ge || ((xcb_selection_notify_event_t *)ge)->property == XCB_NONE;
@ -756,7 +755,7 @@ QByteArray QXcbClipboard::getSelection(xcb_atom_t selection, xcb_atom_t target,
xcb_atom_t type; xcb_atom_t type;
if (clipboardReadProperty(win, property, true, &buf, 0, &type, 0)) { if (clipboardReadProperty(win, property, true, &buf, 0, &type, 0)) {
if (type == m_connection->atom(QXcbAtom::INCR)) { if (type == atom(QXcbAtom::INCR)) {
int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0; int nbytes = buf.size() >= 4 ? *((int*)buf.data()) : 0;
buf = clipboardReadIncrementalProperty(win, property, nbytes, false); buf = clipboardReadIncrementalProperty(win, property, nbytes, false);
} }

View File

@ -43,13 +43,13 @@
#define QXCBCLIPBOARD_H #define QXCBCLIPBOARD_H
#include <QPlatformClipboard> #include <QPlatformClipboard>
#include <qxcbobject.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
class QXcbConnection; class QXcbConnection;
class QXcbScreen; class QXcbScreen;
class QXcbClipboard : public QPlatformClipboard class QXcbClipboard : public QXcbObject, public QPlatformClipboard
{ {
public: public:
QXcbClipboard(QXcbConnection *connection); QXcbClipboard(QXcbConnection *connection);
@ -59,7 +59,6 @@ public:
bool supportsMode(QClipboard::Mode mode) const; bool supportsMode(QClipboard::Mode mode) const;
QXcbConnection *connection() const { return m_connection; }
QXcbScreen *screen() const { return m_screen; } QXcbScreen *screen() const { return m_screen; }
xcb_window_t requestor() const; xcb_window_t requestor() const;
@ -85,7 +84,6 @@ private:
xcb_atom_t sendTargetsSelection(QMimeData *d, xcb_window_t window, xcb_atom_t property); xcb_atom_t sendTargetsSelection(QMimeData *d, xcb_window_t window, xcb_atom_t property);
xcb_atom_t sendSelection(QMimeData *d, xcb_atom_t target, xcb_window_t window, xcb_atom_t property); xcb_atom_t sendSelection(QMimeData *d, xcb_atom_t target, xcb_window_t window, xcb_atom_t property);
QXcbConnection *m_connection;
QXcbScreen *m_screen; QXcbScreen *m_screen;
QMimeData *m_xClipboard; QMimeData *m_xClipboard;

View File

@ -61,15 +61,6 @@ class QXcbWMSupport;
typedef QHash<xcb_window_t, QXcbWindow *> WindowMapper; typedef QHash<xcb_window_t, QXcbWindow *> WindowMapper;
namespace QXcbAtom { namespace QXcbAtom {
static const xcb_atom_t XA_PRIMARY = 1;
static const xcb_atom_t XA_SECONDARY = 2;
static const xcb_atom_t XA_ATOM = 4;
static const xcb_atom_t XA_PIXMAP = 20;
static const xcb_atom_t XA_BITMAP = 5;
static const xcb_atom_t XA_STRING = 32;
static const xcb_atom_t XA_WINDOW = 33;
static const xcb_atom_t XA_CARDINAL = 6;
enum Atom { enum Atom {
// window-manager <-> client protocols // window-manager <-> client protocols
WM_PROTOCOLS, WM_PROTOCOLS,

View File

@ -81,10 +81,10 @@ static xcb_window_t xdndProxy(QXcbConnection *c, xcb_window_t w)
xcb_window_t proxy = XCB_NONE; xcb_window_t proxy = XCB_NONE;
xcb_get_property_cookie_t cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, w, c->atom(QXcbAtom::XdndProxy), xcb_get_property_cookie_t cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, w, c->atom(QXcbAtom::XdndProxy),
QXcbAtom::XA_WINDOW, 0, 1), c); XCB_ATOM_WINDOW, 0, 1), c);
xcb_get_property_reply_t *reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0); xcb_get_property_reply_t *reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0);
if (reply && reply->type == QXcbAtom::XA_WINDOW) if (reply && reply->type == XCB_ATOM_WINDOW)
proxy = *((xcb_window_t *)xcb_get_property_value(reply)); proxy = *((xcb_window_t *)xcb_get_property_value(reply));
free(reply); free(reply);
@ -93,10 +93,10 @@ static xcb_window_t xdndProxy(QXcbConnection *c, xcb_window_t w)
// exists and is real? // exists and is real?
cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, proxy, c->atom(QXcbAtom::XdndProxy), cookie = Q_XCB_CALL2(xcb_get_property(c->xcb_connection(), false, proxy, c->atom(QXcbAtom::XdndProxy),
QXcbAtom::XA_WINDOW, 0, 1), c); XCB_ATOM_WINDOW, 0, 1), c);
reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0); reply = xcb_get_property_reply(c->xcb_connection(), cookie, 0);
if (reply && reply->type == QXcbAtom::XA_WINDOW) { if (reply && reply->type == XCB_ATOM_WINDOW) {
xcb_window_t p = *((xcb_window_t *)xcb_get_property_value(reply)); xcb_window_t p = *((xcb_window_t *)xcb_get_property_value(reply));
if (proxy != p) if (proxy != p)
proxy = 0; proxy = 0;
@ -128,8 +128,8 @@ protected:
QXcbDrag::QXcbDrag(QXcbConnection *c) QXcbDrag::QXcbDrag(QXcbConnection *c)
: QXcbObject(c)
{ {
m_connection = c;
dropData = new QDropData(this); dropData = new QDropData(this);
init(); init();
@ -196,8 +196,8 @@ void QXcbDrag::startDrag()
heartbeat = startTimer(200); heartbeat = startTimer(200);
xdnd_dragging = true; xdnd_dragging = true;
xcb_set_selection_owner(connection()->xcb_connection(), connection()->clipboard()->owner(), xcb_set_selection_owner(xcb_connection(), connection()->clipboard()->owner(),
connection()->atom(QXcbAtom::XdndSelection), connection()->time()); atom(QXcbAtom::XdndSelection), connection()->time());
QDragManager *manager = QDragManager::self(); QDragManager *manager = QDragManager::self();
QStringList fmts = QXcbMime::formatsHelper(manager->dropData()); QStringList fmts = QXcbMime::formatsHelper(manager->dropData());
@ -209,9 +209,9 @@ void QXcbDrag::startDrag()
} }
} }
if (drag_types.size() > 3) if (drag_types.size() > 3)
xcb_change_property(connection()->xcb_connection(), XCB_PROP_MODE_REPLACE, connection()->clipboard()->owner(), xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, connection()->clipboard()->owner(),
connection()->atom(QXcbAtom::XdndTypelist), atom(QXcbAtom::XdndTypelist),
QXcbAtom::XA_ATOM, 32, drag_types.size(), (const void *)drag_types.constData()); XCB_ATOM_ATOM, 32, drag_types.size(), (const void *)drag_types.constData());
QMouseEvent me(QEvent::MouseMove, QCursor::pos(), QCursor::pos(), Qt::LeftButton, QMouseEvent me(QEvent::MouseMove, QCursor::pos(), QCursor::pos(), Qt::LeftButton,
QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers()); QGuiApplication::mouseButtons(), QGuiApplication::keyboardModifiers());
@ -306,9 +306,9 @@ void QXcbDrag::move(const QMouseEvent *me)
free(translate); free(translate);
// check if it has XdndAware // check if it has XdndAware
xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(connection()->xcb_connection(), false, target, xcb_get_property_cookie_t cookie = Q_XCB_CALL(xcb_get_property(xcb_connection(), false, target,
connection()->atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 0)); atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 0));
xcb_get_property_reply_t *reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
bool aware = reply && reply->type != XCB_NONE; bool aware = reply && reply->type != XCB_NONE;
free(reply); free(reply);
if (aware) { if (aware) {
@ -352,9 +352,9 @@ void QXcbDrag::move(const QMouseEvent *me)
int target_version = 1; int target_version = 1;
if (proxy_target) { if (proxy_target) {
xcb_get_property_cookie_t cookie = xcb_get_property(connection()->xcb_connection(), false, target, xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, target,
connection()->atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 1); atom(QXcbAtom::XdndAware), XCB_GET_PROPERTY_TYPE_ANY, 0, 1);
xcb_get_property_reply_t *reply = xcb_get_property_reply(m_connection->xcb_connection(), cookie, 0); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
if (!reply || reply->type == XCB_NONE) if (!reply || reply->type == XCB_NONE)
target = 0; target = 0;
target_version = xcb_get_property_value_length(reply) == 1 ? *(uint32_t *)xcb_get_property_value(reply) : 1; target_version = xcb_get_property_value_length(reply) == 1 ? *(uint32_t *)xcb_get_property_value(reply) : 1;
@ -380,7 +380,7 @@ void QXcbDrag::move(const QMouseEvent *me)
enter.response_type = XCB_CLIENT_MESSAGE; enter.response_type = XCB_CLIENT_MESSAGE;
enter.window = target; enter.window = target;
enter.format = 32; enter.format = 32;
enter.type = connection()->atom(QXcbAtom::XdndEnter); enter.type = atom(QXcbAtom::XdndEnter);
enter.data.data32[0] = connection()->clipboard()->owner(); enter.data.data32[0] = connection()->clipboard()->owner();
enter.data.data32[1] = flags; enter.data.data32[1] = flags;
enter.data.data32[2] = drag_types.size()>0 ? drag_types.at(0) : 0; enter.data.data32[2] = drag_types.size()>0 ? drag_types.at(0) : 0;
@ -393,7 +393,7 @@ void QXcbDrag::move(const QMouseEvent *me)
if (w) if (w)
handleEnter(w->window(), &enter); handleEnter(w->window(), &enter);
else if (target) else if (target)
xcb_send_event(connection()->xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&enter); xcb_send_event(xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&enter);
waiting_for_status = false; waiting_for_status = false;
} }
} }
@ -409,7 +409,7 @@ void QXcbDrag::move(const QMouseEvent *me)
move.response_type = XCB_CLIENT_MESSAGE; move.response_type = XCB_CLIENT_MESSAGE;
move.window = target; move.window = target;
move.format = 32; move.format = 32;
move.type = connection()->atom(QXcbAtom::XdndPosition); move.type = atom(QXcbAtom::XdndPosition);
move.window = target; move.window = target;
move.data.data32[0] = connection()->clipboard()->owner(); move.data.data32[0] = connection()->clipboard()->owner();
move.data.data32[1] = 0; // flags move.data.data32[1] = 0; // flags
@ -423,7 +423,7 @@ void QXcbDrag::move(const QMouseEvent *me)
if (w) if (w)
handle_xdnd_position(w->window(), &move, false); handle_xdnd_position(w->window(), &move, false);
else else
xcb_send_event(connection()->xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&move); xcb_send_event(xcb_connection(), false, proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&move);
} else { } else {
if (m->willDrop) { if (m->willDrop) {
m->willDrop = false; m->willDrop = false;
@ -444,7 +444,7 @@ void QXcbDrag::drop(const QMouseEvent *)
drop.response_type = XCB_CLIENT_MESSAGE; drop.response_type = XCB_CLIENT_MESSAGE;
drop.window = current_target; drop.window = current_target;
drop.format = 32; drop.format = 32;
drop.type = connection()->atom(QXcbAtom::XdndDrop); drop.type = atom(QXcbAtom::XdndDrop);
drop.data.data32[0] = connection()->clipboard()->owner(); drop.data.data32[0] = connection()->clipboard()->owner();
drop.data.data32[1] = 0; // flags drop.data.data32[1] = 0; // flags
drop.data.data32[2] = connection()->time(); drop.data.data32[2] = connection()->time();
@ -473,7 +473,7 @@ void QXcbDrag::drop(const QMouseEvent *)
if (w) if (w)
handleDrop(w->window(), &drop, false); handleDrop(w->window(), &drop, false);
else else
xcb_send_event(connection()->xcb_connection(), false, current_proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&drop); xcb_send_event(xcb_connection(), false, current_proxy_target, XCB_EVENT_MASK_NO_EVENT, (const char *)&drop);
current_target = 0; current_target = 0;
current_proxy_target = 0; current_proxy_target = 0;
@ -482,15 +482,13 @@ void QXcbDrag::drop(const QMouseEvent *)
manager->object = 0; manager->object = 0;
} }
#define ATOM(x) connection()->atom(QXcbAtom::x) Qt::DropAction QXcbDrag::toDropAction(xcb_atom_t a) const
Qt::DropAction QXcbDrag::toDropAction(xcb_atom_t atom) const
{ {
if (atom == ATOM(XdndActionCopy) || atom == 0) if (a == atom(QXcbAtom::XdndActionCopy) || a == 0)
return Qt::CopyAction; return Qt::CopyAction;
if (atom == ATOM(XdndActionLink)) if (a == atom(QXcbAtom::XdndActionLink))
return Qt::LinkAction; return Qt::LinkAction;
if (atom == ATOM(XdndActionMove)) if (a == atom(QXcbAtom::XdndActionMove))
return Qt::MoveAction; return Qt::MoveAction;
return Qt::CopyAction; return Qt::CopyAction;
} }
@ -499,21 +497,19 @@ xcb_atom_t QXcbDrag::toXdndAction(Qt::DropAction a) const
{ {
switch (a) { switch (a) {
case Qt::CopyAction: case Qt::CopyAction:
return ATOM(XdndActionCopy); return atom(QXcbAtom::XdndActionCopy);
case Qt::LinkAction: case Qt::LinkAction:
return ATOM(XdndActionLink); return atom(QXcbAtom::XdndActionLink);
case Qt::MoveAction: case Qt::MoveAction:
case Qt::TargetMoveAction: case Qt::TargetMoveAction:
return ATOM(XdndActionMove); return atom(QXcbAtom::XdndActionMove);
case Qt::IgnoreAction: case Qt::IgnoreAction:
return XCB_NONE; return XCB_NONE;
default: default:
return ATOM(XdndActionCopy); return atom(QXcbAtom::XdndActionCopy);
} }
} }
#undef ATOM
// timer used to discard old XdndDrop transactions // timer used to discard old XdndDrop transactions
enum { XdndDropTransactionTimeout = 5000 }; // 5 seconds enum { XdndDropTransactionTimeout = 5000 }; // 5 seconds
@ -700,10 +696,10 @@ void QXcbDrag::handleEnter(QWindow *window, const xcb_client_message_event_t *ev
if (event->data.data32[1] & 1) { if (event->data.data32[1] & 1) {
// get the types from XdndTypeList // get the types from XdndTypeList
xcb_get_property_cookie_t cookie = xcb_get_property(connection()->xcb_connection(), false, xdnd_dragsource, xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, xdnd_dragsource,
connection()->atom(QXcbAtom::XdndTypelist), QXcbAtom::XA_ATOM, atom(QXcbAtom::XdndTypelist), XCB_ATOM_ATOM,
0, xdnd_max_type); 0, xdnd_max_type);
xcb_get_property_reply_t *reply = xcb_get_property_reply(connection()->xcb_connection(), cookie, 0); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, 0);
if (reply && reply->type != XCB_NONE && reply->format == 32) { if (reply && reply->type != XCB_NONE && reply->format == 32) {
int length = xcb_get_property_value_length(reply) / 4; int length = xcb_get_property_value_length(reply) / 4;
if (length > xdnd_max_type) if (length > xdnd_max_type)
@ -756,7 +752,7 @@ void QXcbDrag::handle_xdnd_position(QWindow *w, const xcb_client_message_event_t
response.response_type = XCB_CLIENT_MESSAGE; response.response_type = XCB_CLIENT_MESSAGE;
response.window = xdnd_dragsource; response.window = xdnd_dragsource;
response.format = 32; response.format = 32;
response.type = connection()->atom(QXcbAtom::XdndStatus); response.type = atom(QXcbAtom::XdndStatus);
response.data.data32[0] = xcb_window(w); response.data.data32[0] = xcb_window(w);
response.data.data32[1] = 0; // flags response.data.data32[1] = 0; // flags
response.data.data32[2] = 0; // x, y response.data.data32[2] = 0; // x, y
@ -836,7 +832,7 @@ void QXcbDrag::handle_xdnd_position(QWindow *w, const xcb_client_message_event_t
if (xdnd_dragsource == connection()->clipboard()->owner()) if (xdnd_dragsource == connection()->clipboard()->owner())
handle_xdnd_status(&response, passive); handle_xdnd_status(&response, passive);
else else
Q_XCB_CALL(xcb_send_event(connection()->xcb_connection(), false, xdnd_dragsource, Q_XCB_CALL(xcb_send_event(xcb_connection(), false, xdnd_dragsource,
XCB_EVENT_MASK_NO_EVENT, (const char *)&response)); XCB_EVENT_MASK_NO_EVENT, (const char *)&response));
} }
@ -860,7 +856,7 @@ void QXcbDrag::handlePosition(QWindow * w, const xcb_client_message_event_t *eve
{ {
xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event); xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event);
xcb_generic_event_t *nextEvent; xcb_generic_event_t *nextEvent;
ClientMessageScanner scanner(connection()->atom(QXcbAtom::XdndPosition)); ClientMessageScanner scanner(atom(QXcbAtom::XdndPosition));
while ((nextEvent = connection()->checkEvent(scanner))) { while ((nextEvent = connection()->checkEvent(scanner))) {
if (lastEvent != event) if (lastEvent != event)
free(lastEvent); free(lastEvent);
@ -907,7 +903,7 @@ void QXcbDrag::handleStatus(const xcb_client_message_event_t *event, bool passiv
xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event); xcb_client_message_event_t *lastEvent = const_cast<xcb_client_message_event_t *>(event);
qDebug() << "handleStatus" << lastEvent->window << lastEvent->data.data32[0]; qDebug() << "handleStatus" << lastEvent->window << lastEvent->data.data32[0];
xcb_generic_event_t *nextEvent; xcb_generic_event_t *nextEvent;
ClientMessageScanner scanner(connection()->atom(QXcbAtom::XdndStatus)); ClientMessageScanner scanner(atom(QXcbAtom::XdndStatus));
while ((nextEvent = connection()->checkEvent(scanner))) { while ((nextEvent = connection()->checkEvent(scanner))) {
if (lastEvent != event) if (lastEvent != event)
free(lastEvent); free(lastEvent);
@ -957,7 +953,7 @@ void QXcbDrag::send_leave()
leave.response_type = XCB_CLIENT_MESSAGE; leave.response_type = XCB_CLIENT_MESSAGE;
leave.window = current_target; leave.window = current_target;
leave.format = 32; leave.format = 32;
leave.type = connection()->atom(QXcbAtom::XdndLeave); leave.type = atom(QXcbAtom::XdndLeave);
leave.data.data32[0] = connection()->clipboard()->owner(); leave.data.data32[0] = connection()->clipboard()->owner();
leave.data.data32[1] = 0; // flags leave.data.data32[1] = 0; // flags
leave.data.data32[2] = 0; // x, y leave.data.data32[2] = 0; // x, y
@ -972,7 +968,7 @@ void QXcbDrag::send_leave()
if (w) if (w)
handleLeave(w->window(), (const xcb_client_message_event_t *)&leave, false); handleLeave(w->window(), (const xcb_client_message_event_t *)&leave, false);
else else
xcb_send_event(connection()->xcb_connection(), false,current_proxy_target, xcb_send_event(xcb_connection(), false,current_proxy_target,
XCB_EVENT_MASK_NO_EVENT, (const char *)&leave); XCB_EVENT_MASK_NO_EVENT, (const char *)&leave);
// reset the drag manager state // reset the drag manager state
@ -1064,14 +1060,14 @@ void QXcbDrag::handleDrop(QWindow *, const xcb_client_message_event_t *event, bo
finished.response_type = XCB_CLIENT_MESSAGE; finished.response_type = XCB_CLIENT_MESSAGE;
finished.window = xdnd_dragsource; finished.window = xdnd_dragsource;
finished.format = 32; finished.format = 32;
finished.type = connection()->atom(QXcbAtom::XdndFinished); finished.type = atom(QXcbAtom::XdndFinished);
DNDDEBUG << "xdndHandleDrop" DNDDEBUG << "xdndHandleDrop"
<< "currentWindow" << currentWindow.data() << "currentWindow" << currentWindow.data()
<< (currentWindow ? xcb_window(currentWindow.data()) : 0); << (currentWindow ? xcb_window(currentWindow.data()) : 0);
finished.data.data32[0] = currentWindow ? xcb_window(currentWindow.data()) : XCB_NONE; finished.data.data32[0] = currentWindow ? xcb_window(currentWindow.data()) : XCB_NONE;
finished.data.data32[1] = de.isAccepted() ? 1 : 0; // flags finished.data.data32[1] = de.isAccepted() ? 1 : 0; // flags
finished.data.data32[2] = toXdndAction(manager->global_accepted_action); finished.data.data32[2] = toXdndAction(manager->global_accepted_action);
Q_XCB_CALL(xcb_send_event(connection()->xcb_connection(), false, xdnd_dragsource, Q_XCB_CALL(xcb_send_event(xcb_connection(), false, xdnd_dragsource,
XCB_EVENT_MASK_NO_EVENT, (char *)&finished)); XCB_EVENT_MASK_NO_EVENT, (char *)&finished));
} else { } else {
QDragLeaveEvent e; QDragLeaveEvent e;
@ -1306,7 +1302,7 @@ void QXcbDrag::handleSelectionRequest(const xcb_selection_request_event_t *event
if (QXcbMime::mimeDataForAtom(connection(), event->target, manager->dragPrivate()->data, if (QXcbMime::mimeDataForAtom(connection(), event->target, manager->dragPrivate()->data,
&data, &atomFormat, &dataFormat)) { &data, &atomFormat, &dataFormat)) {
int dataSize = data.size() / (dataFormat / 8); int dataSize = data.size() / (dataFormat / 8);
xcb_change_property(connection()->xcb_connection(), XCB_PROP_MODE_REPLACE, event->requestor, event->property, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, event->requestor, event->property,
atomFormat, dataFormat, dataSize, (const void *)data.constData()); atomFormat, dataFormat, dataSize, (const void *)data.constData());
notify.property = event->property; notify.property = event->property;
notify.target = atomFormat; notify.target = atomFormat;
@ -1318,7 +1314,7 @@ void QXcbDrag::handleSelectionRequest(const xcb_selection_request_event_t *event
// ### this can die if event->requestor crashes at the wrong // ### this can die if event->requestor crashes at the wrong
// ### moment // ### moment
xcb_send_event(connection()->xcb_connection(), false, event->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&notify); xcb_send_event(xcb_connection(), false, event->requestor, XCB_EVENT_MASK_NO_EVENT, (const char *)&notify);
} }
@ -1331,7 +1327,7 @@ bool QXcbDrag::dndEnable(QXcbWindow *w, bool on)
if (desktop_proxy) // *WE* already have one. if (desktop_proxy) // *WE* already have one.
return false; return false;
xcb_grab_server(connection()->xcb_connection()); xcb_grab_server(xcb_connection());
// As per Xdnd4, use XdndProxy // As per Xdnd4, use XdndProxy
xcb_window_t proxy_id = xdndProxy(connection(), w->xcb_window()); xcb_window_t proxy_id = xdndProxy(connection(), w->xcb_window());
@ -1340,29 +1336,29 @@ bool QXcbDrag::dndEnable(QXcbWindow *w, bool on)
desktop_proxy = new QWindow; desktop_proxy = new QWindow;
xdnd_widget = static_cast<QXcbWindow *>(desktop_proxy->handle()); xdnd_widget = static_cast<QXcbWindow *>(desktop_proxy->handle());
proxy_id = xdnd_widget->xcb_window(); proxy_id = xdnd_widget->xcb_window();
xcb_atom_t xdnd_proxy = connection()->atom(QXcbAtom::XdndProxy); xcb_atom_t xdnd_proxy = atom(QXcbAtom::XdndProxy);
xcb_change_property(connection()->xcb_connection(), XCB_PROP_MODE_REPLACE, w->xcb_window(), xdnd_proxy, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, w->xcb_window(), xdnd_proxy,
QXcbAtom::XA_WINDOW, 32, 1, &proxy_id); XCB_ATOM_WINDOW, 32, 1, &proxy_id);
xcb_change_property(connection()->xcb_connection(), XCB_PROP_MODE_REPLACE, proxy_id, xdnd_proxy, xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, proxy_id, xdnd_proxy,
QXcbAtom::XA_WINDOW, 32, 1, &proxy_id); XCB_ATOM_WINDOW, 32, 1, &proxy_id);
} }
xcb_ungrab_server(connection()->xcb_connection()); xcb_ungrab_server(xcb_connection());
} else { } else {
xdnd_widget = w; xdnd_widget = w;
} }
if (xdnd_widget) { if (xdnd_widget) {
DNDDEBUG << "setting XdndAware for" << xdnd_widget << xdnd_widget->xcb_window(); DNDDEBUG << "setting XdndAware for" << xdnd_widget << xdnd_widget->xcb_window();
xcb_atom_t atm = xdnd_version; xcb_atom_t atm = xdnd_version;
xcb_change_property(connection()->xcb_connection(), XCB_PROP_MODE_REPLACE, xdnd_widget->xcb_window(), xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, xdnd_widget->xcb_window(),
connection()->atom(QXcbAtom::XdndAware), QXcbAtom::XA_ATOM, 32, 1, &atm); atom(QXcbAtom::XdndAware), XCB_ATOM_ATOM, 32, 1, &atm);
return true; return true;
} else { } else {
return false; return false;
} }
} else { } else {
if ((w->window()->windowType() == Qt::Desktop)) { if ((w->window()->windowType() == Qt::Desktop)) {
xcb_delete_property(connection()->xcb_connection(), w->xcb_window(), connection()->atom(QXcbAtom::XdndProxy)); xcb_delete_property(xcb_connection(), w->xcb_window(), atom(QXcbAtom::XdndProxy));
delete desktop_proxy; delete desktop_proxy;
desktop_proxy = 0; desktop_proxy = 0;
} else { } else {
@ -1414,7 +1410,7 @@ QVariant QDropData::xdndObtainData(const QByteArray &format, QVariant::Type requ
if (a == XCB_NONE) if (a == XCB_NONE)
return result; return result;
if (c->clipboard()->getSelectionOwner(drag->connection()->atom(QXcbAtom::XdndSelection)) == XCB_NONE) if (c->clipboard()->getSelectionOwner(drag->atom(QXcbAtom::XdndSelection)) == XCB_NONE)
return result; // should never happen? return result; // should never happen?
xcb_atom_t xdnd_selection = c->atom(QXcbAtom::XdndSelection); xcb_atom_t xdnd_selection = c->atom(QXcbAtom::XdndSelection);

View File

@ -42,10 +42,10 @@
#ifndef QXCBDRAG_H #ifndef QXCBDRAG_H
#define QXCBDRAG_H #define QXCBDRAG_H
#include <qlist.h>
#include <qplatformdrag_qpa.h> #include <qplatformdrag_qpa.h>
#include <qnamespace.h> #include <qxcbobject.h>
#include <xcb/xcb.h> #include <xcb/xcb.h>
#include <qlist.h>
#include <qpoint.h> #include <qpoint.h>
#include <qrect.h> #include <qrect.h>
#include <qsharedpointer.h> #include <qsharedpointer.h>
@ -61,7 +61,7 @@ class QDropData;
class QXcbScreen; class QXcbScreen;
class QDrag; class QDrag;
class QXcbDrag : public QObject, public QPlatformDrag class QXcbDrag : public QObject, public QXcbObject, public QPlatformDrag
{ {
public: public:
QXcbDrag(QXcbConnection *c); QXcbDrag(QXcbConnection *c);
@ -88,8 +88,6 @@ public:
bool dndEnable(QXcbWindow *win, bool on); bool dndEnable(QXcbWindow *win, bool on);
QXcbConnection *connection() const { return m_connection; }
protected: protected:
void timerEvent(QTimerEvent* e); void timerEvent(QTimerEvent* e);
@ -108,7 +106,6 @@ private:
QWeakPointer<QWindow> currentWindow; QWeakPointer<QWindow> currentWindow;
QPoint currentPosition; QPoint currentPosition;
QXcbConnection *m_connection;
QDropData *dropData; QDropData *dropData;
QWindow *desktop_proxy; QWindow *desktop_proxy;

View File

@ -48,9 +48,9 @@
#include <X11/Xutil.h> #include <X11/Xutil.h>
#undef XA_STRING #undef XCB_ATOM_STRING
#undef XA_PIXMAP #undef XCB_ATOM_PIXMAP
#undef XA_BITMAP #undef XCB_ATOM_BITMAP
QXcbMime::QXcbMime() QXcbMime::QXcbMime()
: QInternalMimeData() : QInternalMimeData()
@ -67,13 +67,13 @@ QString QXcbMime::mimeAtomToString(QXcbConnection *connection, xcb_atom_t a)
return 0; return 0;
// special cases for string type // special cases for string type
if (a == QXcbAtom::XA_STRING if (a == XCB_ATOM_STRING
|| a == connection->atom(QXcbAtom::UTF8_STRING) || a == connection->atom(QXcbAtom::UTF8_STRING)
|| a == connection->atom(QXcbAtom::TEXT)) || a == connection->atom(QXcbAtom::TEXT))
return QLatin1String("text/plain"); return QLatin1String("text/plain");
// special case for images // special case for images
if (a == QXcbAtom::XA_PIXMAP) if (a == XCB_ATOM_PIXMAP)
return QLatin1String("image/ppm"); return QLatin1String("image/ppm");
QByteArray atomName = connection->atomName(a); QByteArray atomName = connection->atomName(a);
@ -96,13 +96,13 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa
*dataFormat = 8; *dataFormat = 8;
if ((a == connection->atom(QXcbAtom::UTF8_STRING) if ((a == connection->atom(QXcbAtom::UTF8_STRING)
|| a == QXcbAtom::XA_STRING || a == XCB_ATOM_STRING
|| a == connection->atom(QXcbAtom::TEXT)) || a == connection->atom(QXcbAtom::TEXT))
&& QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) { && QInternalMimeData::hasFormatHelper(QLatin1String("text/plain"), mimeData)) {
if (a == connection->atom(QXcbAtom::UTF8_STRING)) { if (a == connection->atom(QXcbAtom::UTF8_STRING)) {
*data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData); *data = QInternalMimeData::renderDataHelper(QLatin1String("text/plain"), mimeData);
ret = true; ret = true;
} else if (a == QXcbAtom::XA_STRING || } else if (a == XCB_ATOM_STRING ||
a == connection->atom(QXcbAtom::TEXT)) { a == connection->atom(QXcbAtom::TEXT)) {
// ICCCM says STRING is latin1 // ICCCM says STRING is latin1
*data = QString::fromUtf8(QInternalMimeData::renderDataHelper( *data = QString::fromUtf8(QInternalMimeData::renderDataHelper(
@ -126,7 +126,7 @@ bool QXcbMime::mimeDataForAtom(QXcbConnection *connection, xcb_atom_t a, QMimeDa
mozUri += QLatin1Char('\n'); mozUri += QLatin1Char('\n');
*data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2); *data = QByteArray(reinterpret_cast<const char *>(mozUri.utf16()), mozUri.length() * 2);
ret = true; ret = true;
} else if ((a == QXcbAtom::XA_PIXMAP || a == QXcbAtom::XA_BITMAP) && mimeData->hasImage()) { } else if ((a == XCB_ATOM_PIXMAP || a == XCB_ATOM_BITMAP) && mimeData->hasImage()) {
ret = true; ret = true;
} }
return ret; return ret;
@ -140,7 +140,7 @@ QList<xcb_atom_t> QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, const
// special cases for strings // special cases for strings
if (format == QLatin1String("text/plain")) { if (format == QLatin1String("text/plain")) {
atoms.append(connection->atom(QXcbAtom::UTF8_STRING)); atoms.append(connection->atom(QXcbAtom::UTF8_STRING));
atoms.append(QXcbAtom::XA_STRING); atoms.append(XCB_ATOM_STRING);
atoms.append(connection->atom(QXcbAtom::TEXT)); atoms.append(connection->atom(QXcbAtom::TEXT));
} }
@ -150,9 +150,9 @@ QList<xcb_atom_t> QXcbMime::mimeAtomsForFormat(QXcbConnection *connection, const
//special cases for images //special cases for images
if (format == QLatin1String("image/ppm")) if (format == QLatin1String("image/ppm"))
atoms.append(QXcbAtom::XA_PIXMAP); atoms.append(XCB_ATOM_PIXMAP);
if (format == QLatin1String("image/pbm")) if (format == QLatin1String("image/pbm"))
atoms.append(QXcbAtom::XA_BITMAP); atoms.append(XCB_ATOM_BITMAP);
return atoms; return atoms;
} }
@ -179,7 +179,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
if (format == QLatin1String("text/plain")) { if (format == QLatin1String("text/plain")) {
if (a == connection->atom(QXcbAtom::UTF8_STRING)) if (a == connection->atom(QXcbAtom::UTF8_STRING))
return QString::fromUtf8(data); return QString::fromUtf8(data);
if (a == QXcbAtom::XA_STRING || if (a == XCB_ATOM_STRING ||
a == connection->atom(QXcbAtom::TEXT)) a == connection->atom(QXcbAtom::TEXT))
return QString::fromLatin1(data); return QString::fromLatin1(data);
} }
@ -203,7 +203,7 @@ QVariant QXcbMime::mimeConvertToFormat(QXcbConnection *connection, xcb_atom_t a,
#if 0 // ### #if 0 // ###
// special case for images // special case for images
if (format == QLatin1String("image/ppm")) { if (format == QLatin1String("image/ppm")) {
if (a == XA_PIXMAP && data.size() == sizeof(Pixmap)) { if (a == XCB_ATOM_PIXMAP && data.size() == sizeof(Pixmap)) {
Pixmap xpm = *((Pixmap*)data.data()); Pixmap xpm = *((Pixmap*)data.data());
if (!xpm) if (!xpm)
return QByteArray(); return QByteArray();
@ -242,8 +242,8 @@ xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString
if (format == QLatin1String("text/plain")) { if (format == QLatin1String("text/plain")) {
if (atoms.contains(connection->atom(QXcbAtom::UTF8_STRING))) if (atoms.contains(connection->atom(QXcbAtom::UTF8_STRING)))
return connection->atom(QXcbAtom::UTF8_STRING); return connection->atom(QXcbAtom::UTF8_STRING);
if (atoms.contains(QXcbAtom::XA_STRING)) if (atoms.contains(XCB_ATOM_STRING))
return QXcbAtom::XA_STRING; return XCB_ATOM_STRING;
if (atoms.contains(connection->atom(QXcbAtom::TEXT))) if (atoms.contains(connection->atom(QXcbAtom::TEXT)))
return connection->atom(QXcbAtom::TEXT); return connection->atom(QXcbAtom::TEXT);
} }
@ -260,8 +260,8 @@ xcb_atom_t QXcbMime::mimeAtomForFormat(QXcbConnection *connection, const QString
// find match for image // find match for image
if (format == QLatin1String("image/ppm")) { if (format == QLatin1String("image/ppm")) {
if (atoms.contains(QXcbAtom::XA_PIXMAP)) if (atoms.contains(XCB_ATOM_PIXMAP))
return QXcbAtom::XA_PIXMAP; return XCB_ATOM_PIXMAP;
} }
// for string/text requests try to use a format with a well-defined charset // for string/text requests try to use a format with a well-defined charset

View File

@ -833,7 +833,7 @@ void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
0)); // value list 0)); // value list
wid = m_netWmUserTimeWindow; wid = m_netWmUserTimeWindow;
xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW), xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, m_window, atom(QXcbAtom::_NET_WM_USER_TIME_WINDOW),
QXcbAtom::XA_WINDOW, 32, 1, &m_netWmUserTimeWindow); XCB_ATOM_WINDOW, 32, 1, &m_netWmUserTimeWindow);
xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME)); xcb_delete_property(xcb_connection(), m_window, atom(QXcbAtom::_NET_WM_USER_TIME));
} else if (!isSupportedByWM) { } else if (!isSupportedByWM) {
// WM no longer supports it, then we should remove the // WM no longer supports it, then we should remove the
@ -846,7 +846,7 @@ void QXcbWindow::updateNetWmUserTime(xcb_timestamp_t timestamp)
} }
} }
xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME), xcb_change_property(xcb_connection(), XCB_PROP_MODE_REPLACE, wid, atom(QXcbAtom::_NET_WM_USER_TIME),
QXcbAtom::XA_CARDINAL, 32, 1, &timestamp); XCB_ATOM_CARDINAL, 32, 1, &timestamp);
} }

View File

@ -67,14 +67,14 @@ void QXcbWMSupport::updateNetWMAtoms()
int remaining = 0; int remaining = 0;
do { do {
xcb_generic_error_t *error = 0; xcb_generic_error_t *error = 0;
xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_SUPPORTED), QXcbAtom::XA_ATOM, offset, 1024); xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_SUPPORTED), XCB_ATOM_ATOM, offset, 1024);
xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error);
if (!reply || error) if (!reply || error)
break; break;
remaining = 0; remaining = 0;
if (reply->type == QXcbAtom::XA_ATOM && reply->format == 32) { if (reply->type == XCB_ATOM_ATOM && reply->format == 32) {
int len = xcb_get_property_value_length(reply)/4; int len = xcb_get_property_value_length(reply)/4;
xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply); xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
int s = net_wm_atoms.size(); int s = net_wm_atoms.size();
@ -107,14 +107,14 @@ void QXcbWMSupport::updateVirtualRoots()
int remaining = 0; int remaining = 0;
do { do {
xcb_generic_error_t *error = 0; xcb_generic_error_t *error = 0;
xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_VIRTUAL_ROOTS), QXcbAtom::XA_ATOM, offset, 1024); xcb_get_property_cookie_t cookie = xcb_get_property(xcb_connection(), false, root, atom(QXcbAtom::_NET_VIRTUAL_ROOTS), XCB_ATOM_ATOM, offset, 1024);
xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error); xcb_get_property_reply_t *reply = xcb_get_property_reply(xcb_connection(), cookie, &error);
if (!reply || error) if (!reply || error)
break; break;
remaining = 0; remaining = 0;
if (reply->type == QXcbAtom::XA_ATOM && reply->format == 32) { if (reply->type == XCB_ATOM_ATOM && reply->format == 32) {
int len = xcb_get_property_value_length(reply)/4; int len = xcb_get_property_value_length(reply)/4;
xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply); xcb_atom_t *atoms = (xcb_atom_t *)xcb_get_property_value(reply);
int s = net_wm_atoms.size(); int s = net_wm_atoms.size();

View File

@ -70,7 +70,7 @@ contains(QT_CONFIG, opengl) {
LIBS += -lxcb -lxcb-image -lxcb-keysyms -lxcb-icccm -lxcb-sync LIBS += -lxcb -lxcb-image -lxcb-keysyms -lxcb-icccm -lxcb-sync
DEFINES += $$QMAKE_DEFINES_XCB DEFINES += $$QMAKE_DEFINES_XCB QT_NO_XCB_XKB
LIBS += $$QMAKE_LIBS_XCB LIBS += $$QMAKE_LIBS_XCB
QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XCB QMAKE_CXXFLAGS += $$QMAKE_CFLAGS_XCB