Port KWinSelectionOwner to XCB

One usage of DefaultScreen is still present as QX11Info is not yet
providing the primaryScreen from QXcbConnection.
This commit is contained in:
Martin Gräßlin 2013-08-28 15:50:46 +02:00
parent 1f302b0c4a
commit a2d97fef17

View file

@ -96,38 +96,48 @@ xcb_atom_t KWinSelectionOwner::make_selection_atom(int screen_P)
{ {
if (screen_P < 0) if (screen_P < 0)
screen_P = DefaultScreen(display()); screen_P = DefaultScreen(display());
char tmp[ 30 ]; QByteArray screen(QByteArrayLiteral("WM_S"));
sprintf(tmp, "WM_S%d", screen_P); screen.append(QByteArray::number(screen_P));
return XInternAtom(display(), tmp, False); ScopedCPointer<xcb_intern_atom_reply_t> 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() void KWinSelectionOwner::getAtoms()
{ {
KSelectionOwner::getAtoms(); KSelectionOwner::getAtoms();
if (xa_version == None) { if (xa_version == XCB_ATOM_NONE) {
Atom atoms[ 1 ]; const QByteArray name(QByteArrayLiteral("VERSION"));
const char* const names[] = ScopedCPointer<xcb_intern_atom_reply_t> atom(xcb_intern_atom_reply(
{ "VERSION" }; connection(),
XInternAtoms(display(), const_cast< char** >(names), 1, False, atoms); xcb_intern_atom_unchecked(connection(), false, name.length(), name.constData()),
xa_version = atoms[ 0 ]; nullptr));
if (!atom.isNull()) {
xa_version = atom->atom;
}
} }
} }
void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P) void KWinSelectionOwner::replyTargets(xcb_atom_t property_P, xcb_window_t requestor_P)
{ {
KSelectionOwner::replyTargets(property_P, requestor_P); KSelectionOwner::replyTargets(property_P, requestor_P);
Atom atoms[ 1 ] = { xa_version }; xcb_atom_t atoms[ 1 ] = { xa_version };
// PropModeAppend ! // PropModeAppend !
XChangeProperty(display(), requestor_P, property_P, XA_ATOM, 32, PropModeAppend, xcb_change_property(connection(), XCB_PROP_MODE_APPEND, requestor_P,
reinterpret_cast< unsigned char* >(atoms), 1); 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) bool KWinSelectionOwner::genericReply(xcb_atom_t target_P, xcb_atom_t property_P, xcb_window_t requestor_P)
{ {
if (target_P == xa_version) { if (target_P == xa_version) {
long version[] = { 2, 0 }; int32_t version[] = { 2, 0 };
XChangeProperty(display(), requestor_P, property_P, XA_INTEGER, 32, xcb_change_property(connection(), XCB_PROP_MODE_REPLACE, requestor_P,
PropModeReplace, reinterpret_cast< unsigned char* >(&version), 2); property_P, XCB_ATOM_INTEGER, 32, 2, version);
} else } else
return KSelectionOwner::genericReply(target_P, property_P, requestor_P); return KSelectionOwner::genericReply(target_P, property_P, requestor_P);
return true; return true;