From a2d97fef17c472a282e4153a5578a75dade7fcae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20Gr=C3=A4=C3=9Flin?= Date: Wed, 28 Aug 2013 15:50:46 +0200 Subject: [PATCH] Port KWinSelectionOwner to XCB One usage of DefaultScreen is still present as QX11Info is not yet providing the primaryScreen from QXcbConnection. --- main.cpp | 40 +++++++++++++++++++++++++--------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/main.cpp b/main.cpp index 9f53a6765e..94381f4467 100644 --- a/main.cpp +++ b/main.cpp @@ -96,38 +96,48 @@ xcb_atom_t KWinSelectionOwner::make_selection_atom(int screen_P) { if (screen_P < 0) screen_P = DefaultScreen(display()); - char tmp[ 30 ]; - sprintf(tmp, "WM_S%d", screen_P); - return XInternAtom(display(), tmp, False); + QByteArray screen(QByteArrayLiteral("WM_S")); + screen.append(QByteArray::number(screen_P)); + ScopedCPointer atom(xcb_intern_atom_reply( + connection(), + xcb_intern_atom_unchecked(connection(), false, screen.length(), screen.constData()), + nullptr)); + if (atom.isNull()) { + return XCB_ATOM_NONE; + } + return atom->atom; } void KWinSelectionOwner::getAtoms() { KSelectionOwner::getAtoms(); - if (xa_version == None) { - Atom atoms[ 1 ]; - const char* const names[] = - { "VERSION" }; - XInternAtoms(display(), const_cast< char** >(names), 1, False, atoms); - xa_version = atoms[ 0 ]; + if (xa_version == XCB_ATOM_NONE) { + const QByteArray name(QByteArrayLiteral("VERSION")); + ScopedCPointer atom(xcb_intern_atom_reply( + connection(), + xcb_intern_atom_unchecked(connection(), false, name.length(), name.constData()), + nullptr)); + if (!atom.isNull()) { + xa_version = atom->atom; + } } } void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P) { KSelectionOwner::replyTargets(property_P, requestor_P); - Atom atoms[ 1 ] = { xa_version }; + xcb_atom_t atoms[ 1 ] = { xa_version }; // PropModeAppend ! - XChangeProperty(display(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend, - reinterpret_cast< unsigned char* >(atoms), 1); + xcb_change_property(connection(), XCB_PROP_MODE_APPEND, requestor_P, + property_P, XCB_ATOM_ATOM, 32, 1, atoms); } bool KWinSelectionOwner::genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P) { if (target_P == xa_version) { - long version[] = { 2, 0 }; - XChangeProperty(display(), requestor_P, property_P, XA_INTEGER, 32, - PropModeReplace, reinterpret_cast< unsigned char* >(&version), 2); + int32_t version[] = { 2, 0 }; + xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, requestor_P, + property_P, XCB_ATOM_INTEGER, 32, 2, version); } else return KSelectionOwner::genericReply(target_P, property_P, requestor_P); return true;