Changeset View
Changeset View
Standalone View
Standalone View
xwl/selection_source.cpp
Show All 36 Lines | |||||
37 | 37 | | |||
38 | #include <xwayland_logging.h> | 38 | #include <xwayland_logging.h> | ||
39 | 39 | | |||
40 | namespace KWin { | 40 | namespace KWin { | ||
41 | namespace Xwl { | 41 | namespace Xwl { | ||
42 | 42 | | |||
43 | SelectionSource::SelectionSource(Selection *sel) | 43 | SelectionSource::SelectionSource(Selection *sel) | ||
44 | : QObject(sel), | 44 | : QObject(sel), | ||
45 | m_sel(sel) | 45 | m_sel(sel), | ||
46 | m_window(sel->window()) | ||||
46 | { | 47 | { | ||
47 | } | 48 | } | ||
48 | 49 | | |||
49 | WlSource::WlSource(Selection *sel, KWayland::Server::DataDeviceInterface *ddi) | 50 | WlSource::WlSource(Selection *sel, KWayland::Server::DataDeviceInterface *ddi) | ||
50 | : SelectionSource(sel), | 51 | : SelectionSource(sel), | ||
51 | m_ddi(ddi) | 52 | m_ddi(ddi) | ||
52 | { | 53 | { | ||
53 | Q_ASSERT(ddi); | 54 | Q_ASSERT(ddi); | ||
Show All 15 Lines | |||||
69 | 70 | | |||
70 | void WlSource::receiveOffer(const QString &mime) | 71 | void WlSource::receiveOffer(const QString &mime) | ||
71 | { | 72 | { | ||
72 | m_offers << mime; | 73 | m_offers << mime; | ||
73 | } | 74 | } | ||
74 | 75 | | |||
75 | void WlSource::sendSelNotify(xcb_selection_request_event_t *event, bool success) | 76 | void WlSource::sendSelNotify(xcb_selection_request_event_t *event, bool success) | ||
76 | { | 77 | { | ||
77 | selection()->sendSelNotify(event, success); | 78 | Selection::sendSelNotify(event, success); | ||
78 | } | 79 | } | ||
79 | 80 | | |||
80 | bool WlSource::handleSelRequest(xcb_selection_request_event_t *event) | 81 | bool WlSource::handleSelRequest(xcb_selection_request_event_t *event) | ||
81 | { | 82 | { | ||
82 | if (event->target == atoms->targets) { | 83 | if (event->target == atoms->targets) { | ||
83 | sendTargets(event); | 84 | sendTargets(event); | ||
84 | } else if (event->target == atoms->timestamp) { | 85 | } else if (event->target == atoms->timestamp) { | ||
85 | sendTimestamp(event); | 86 | sendTimestamp(event); | ||
▲ Show 20 Lines • Show All 92 Lines • ▼ Show 20 Line(s) | 178 | { | |||
178 | setTimestamp(event->timestamp); | 179 | setTimestamp(event->timestamp); | ||
179 | } | 180 | } | ||
180 | 181 | | |||
181 | void X11Source::getTargets() | 182 | void X11Source::getTargets() | ||
182 | { | 183 | { | ||
183 | auto *xcbConn = kwinApp()->x11Connection(); | 184 | auto *xcbConn = kwinApp()->x11Connection(); | ||
184 | /* will lead to a selection request event for the new owner */ | 185 | /* will lead to a selection request event for the new owner */ | ||
185 | xcb_convert_selection(xcbConn, | 186 | xcb_convert_selection(xcbConn, | ||
186 | selection()->window(), | 187 | window(), | ||
187 | selection()->atom(), | 188 | selection()->atom(), | ||
188 | atoms->targets, | 189 | atoms->targets, | ||
189 | atoms->wl_selection, | 190 | atoms->wl_selection, | ||
190 | timestamp()); | 191 | timestamp()); | ||
191 | xcb_flush(xcbConn); | 192 | xcb_flush(xcbConn); | ||
192 | } | 193 | } | ||
193 | 194 | | |||
194 | using Mime = QPair<QString, xcb_atom_t>; | 195 | using Mime = QPair<QString, xcb_atom_t>; | ||
195 | 196 | | |||
196 | void X11Source::handleTargets() | 197 | void X11Source::handleTargets() | ||
197 | { | 198 | { | ||
198 | // receive targets | 199 | // receive targets | ||
199 | auto *xcbConn = kwinApp()->x11Connection(); | 200 | auto *xcbConn = kwinApp()->x11Connection(); | ||
200 | xcb_get_property_cookie_t cookie = xcb_get_property(xcbConn, | 201 | xcb_get_property_cookie_t cookie = xcb_get_property(xcbConn, | ||
201 | 1, | 202 | 1, | ||
202 | selection()->window(), | 203 | window(), | ||
203 | atoms->wl_selection, | 204 | atoms->wl_selection, | ||
204 | XCB_GET_PROPERTY_TYPE_ANY, | 205 | XCB_GET_PROPERTY_TYPE_ANY, | ||
205 | 0, | 206 | 0, | ||
206 | 4096 | 207 | 4096 | ||
207 | ); | 208 | ); | ||
208 | auto *reply = xcb_get_property_reply(xcbConn, cookie, NULL); | 209 | auto *reply = xcb_get_property_reply(xcbConn, cookie, NULL); | ||
209 | if (reply == NULL) { | 210 | if (reply == NULL) { | ||
210 | return; | 211 | return; | ||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Line(s) | |||||
273 | void X11Source::setOffers(const Mimes &offers) | 274 | void X11Source::setOffers(const Mimes &offers) | ||
274 | { | 275 | { | ||
275 | // TODO: share code with handleTargets and emit signals accordingly? | 276 | // TODO: share code with handleTargets and emit signals accordingly? | ||
276 | m_offers = offers; | 277 | m_offers = offers; | ||
277 | } | 278 | } | ||
278 | 279 | | |||
279 | bool X11Source::handleSelNotify(xcb_selection_notify_event_t *event) | 280 | bool X11Source::handleSelNotify(xcb_selection_notify_event_t *event) | ||
280 | { | 281 | { | ||
281 | if (event->requestor != selection()->window()) { | 282 | if (event->requestor != window()) { | ||
282 | return false; | 283 | return false; | ||
283 | } | 284 | } | ||
284 | if (event->selection != selection()->atom()) { | 285 | if (event->selection != selection()->atom()) { | ||
285 | return false; | 286 | return false; | ||
286 | } | 287 | } | ||
287 | if (event->property == XCB_ATOM_NONE) { | 288 | if (event->property == XCB_ATOM_NONE) { | ||
288 | qCWarning(KWIN_XWL) << "Incoming X selection conversion failed"; | 289 | qCWarning(KWIN_XWL) << "Incoming X selection conversion failed"; | ||
289 | return true; | 290 | return true; | ||
Show All 25 Lines |