xwayland: Support cross DnD from Wayland (#8708)
Adds support for drag-and-drop from Wayland clients to XWayland ones
This commit is contained in:
parent
9f7a96b997
commit
db24964877
10 changed files with 699 additions and 108 deletions
211
src/xwayland/Dnd.cpp
Normal file
211
src/xwayland/Dnd.cpp
Normal file
|
|
@ -0,0 +1,211 @@
|
|||
#include "Dnd.hpp"
|
||||
#include "XWM.hpp"
|
||||
#include "XWayland.hpp"
|
||||
#include "Server.hpp"
|
||||
#include "../managers/XWaylandManager.hpp"
|
||||
#include "../desktop/WLSurface.hpp"
|
||||
|
||||
static xcb_atom_t dndActionToAtom(uint32_t actions) {
|
||||
if (actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_COPY)
|
||||
return HYPRATOMS["XdndActionCopy"];
|
||||
else if (actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE)
|
||||
return HYPRATOMS["XdndActionMove"];
|
||||
else if (actions & WL_DATA_DEVICE_MANAGER_DND_ACTION_ASK)
|
||||
return HYPRATOMS["XdndActionAsk"];
|
||||
|
||||
return XCB_ATOM_NONE;
|
||||
}
|
||||
|
||||
eDataSourceType CX11DataOffer::type() {
|
||||
return DATA_SOURCE_TYPE_X11;
|
||||
}
|
||||
|
||||
SP<CWLDataOfferResource> CX11DataOffer::getWayland() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SP<CX11DataOffer> CX11DataOffer::getX11() {
|
||||
return self.lock();
|
||||
}
|
||||
|
||||
SP<IDataSource> CX11DataOffer::getSource() {
|
||||
return source.lock();
|
||||
}
|
||||
|
||||
void CX11DataOffer::markDead() {
|
||||
#ifndef NO_XWAYLAND
|
||||
std::erase(g_pXWayland->pWM->dndDataOffers, self);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendDataOffer(SP<IDataOffer> offer) {
|
||||
; // no-op, I don't think this has an X equiv
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendEnter(uint32_t serial, SP<CWLSurfaceResource> surf, const Vector2D& local, SP<IDataOffer> offer) {
|
||||
#ifndef NO_XWAYLAND
|
||||
auto XSURF = g_pXWayland->pWM->windowForWayland(surf);
|
||||
|
||||
if (offer == lastOffer)
|
||||
return;
|
||||
|
||||
if (!XSURF) {
|
||||
Debug::log(ERR, "CX11DataDevice::sendEnter: No xwayland surface for destination");
|
||||
return;
|
||||
}
|
||||
|
||||
auto SOURCE = offer->getSource();
|
||||
|
||||
if (!SOURCE) {
|
||||
Debug::log(ERR, "CX11DataDevice::sendEnter: No source");
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_set_selection_owner(g_pXWayland->pWM->connection, g_pXWayland->pWM->dndSelection.window, HYPRATOMS["XdndSelection"], XCB_TIME_CURRENT_TIME);
|
||||
|
||||
xcb_client_message_data_t data = {0};
|
||||
data.data32[0] = g_pXWayland->pWM->dndSelection.window;
|
||||
data.data32[1] = XDND_VERSION << 24;
|
||||
|
||||
// let the client know it needs to check for DND_TYPE_LIST
|
||||
data.data32[1] |= 1;
|
||||
|
||||
std::vector<xcb_atom_t> targets;
|
||||
|
||||
for (auto& mime : SOURCE->mimes()) {
|
||||
targets.emplace_back(g_pXWayland->pWM->mimeToAtom(mime));
|
||||
}
|
||||
|
||||
xcb_change_property(g_pXWayland->pWM->connection, XCB_PROP_MODE_REPLACE, g_pXWayland->pWM->dndSelection.window, HYPRATOMS["XdndTypeList"], XCB_ATOM_ATOM, 32, targets.size(),
|
||||
targets.data());
|
||||
|
||||
g_pXWayland->pWM->sendDndEvent(surf, HYPRATOMS["XdndEnter"], data);
|
||||
|
||||
lastSurface = XSURF;
|
||||
lastOffer = offer;
|
||||
|
||||
auto hlSurface = CWLSurface::fromResource(surf);
|
||||
if (!hlSurface) {
|
||||
Debug::log(ERR, "CX11DataDevice::sendEnter: Non desktop x surface?!");
|
||||
lastSurfaceCoords = {};
|
||||
return;
|
||||
}
|
||||
|
||||
lastSurfaceCoords = hlSurface->getSurfaceBoxGlobal().value_or(CBox{}).pos();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendLeave() {
|
||||
#ifndef NO_XWAYLAND
|
||||
if (!lastSurface)
|
||||
return;
|
||||
|
||||
xcb_client_message_data_t data = {0};
|
||||
data.data32[0] = g_pXWayland->pWM->dndSelection.window;
|
||||
|
||||
g_pXWayland->pWM->sendDndEvent(lastSurface->surface.lock(), HYPRATOMS["XdndLeave"], data);
|
||||
|
||||
lastSurface.reset();
|
||||
lastOffer.reset();
|
||||
|
||||
xcb_set_selection_owner(g_pXWayland->pWM->connection, g_pXWayland->pWM->dndSelection.window, XCB_ATOM_NONE, XCB_TIME_CURRENT_TIME);
|
||||
#endif
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendMotion(uint32_t timeMs, const Vector2D& local) {
|
||||
#ifndef NO_XWAYLAND
|
||||
if (!lastSurface || !lastOffer || !lastOffer->getSource())
|
||||
return;
|
||||
|
||||
const auto XCOORDS = g_pXWaylandManager->waylandToXWaylandCoords(lastSurfaceCoords + local);
|
||||
|
||||
xcb_client_message_data_t data = {0};
|
||||
data.data32[0] = g_pXWayland->pWM->dndSelection.window;
|
||||
data.data32[2] = (((int32_t)XCOORDS.x) << 16) | (int32_t)XCOORDS.y;
|
||||
data.data32[3] = timeMs;
|
||||
data.data32[4] = dndActionToAtom(lastOffer->getSource()->actions());
|
||||
|
||||
g_pXWayland->pWM->sendDndEvent(lastSurface->surface.lock(), HYPRATOMS["XdndPosition"], data);
|
||||
lastTime = timeMs;
|
||||
#endif
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendDrop() {
|
||||
#ifndef NO_XWAYLAND
|
||||
if (!lastSurface || !lastOffer)
|
||||
return;
|
||||
|
||||
// we don't have timeMs here, just send last time + 1
|
||||
xcb_client_message_data_t data = {0};
|
||||
data.data32[0] = g_pXWayland->pWM->dndSelection.window;
|
||||
data.data32[2] = lastTime + 1;
|
||||
|
||||
g_pXWayland->pWM->sendDndEvent(lastSurface->surface.lock(), HYPRATOMS["XdndDrop"], data);
|
||||
|
||||
sendLeave();
|
||||
#endif
|
||||
}
|
||||
|
||||
void CX11DataDevice::sendSelection(SP<IDataOffer> offer) {
|
||||
; // no-op. Selection is done separately.
|
||||
}
|
||||
|
||||
eDataSourceType CX11DataDevice::type() {
|
||||
return DATA_SOURCE_TYPE_X11;
|
||||
}
|
||||
|
||||
SP<CWLDataDeviceResource> CX11DataDevice::getWayland() {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
SP<CX11DataDevice> CX11DataDevice::getX11() {
|
||||
return self.lock();
|
||||
}
|
||||
|
||||
std::vector<std::string> CX11DataSource::mimes() {
|
||||
return mimeTypes;
|
||||
}
|
||||
|
||||
void CX11DataSource::send(const std::string& mime, uint32_t fd) {
|
||||
;
|
||||
}
|
||||
|
||||
void CX11DataSource::accepted(const std::string& mime) {
|
||||
;
|
||||
}
|
||||
|
||||
void CX11DataSource::cancelled() {
|
||||
;
|
||||
}
|
||||
|
||||
bool CX11DataSource::hasDnd() {
|
||||
return dnd;
|
||||
}
|
||||
|
||||
bool CX11DataSource::dndDone() {
|
||||
return dropped;
|
||||
}
|
||||
|
||||
void CX11DataSource::error(uint32_t code, const std::string& msg) {
|
||||
Debug::log(ERR, "CX11DataSource::error: this fn is a stub: code {} msg {}", code, msg);
|
||||
}
|
||||
|
||||
void CX11DataSource::sendDndFinished() {
|
||||
;
|
||||
}
|
||||
|
||||
uint32_t CX11DataSource::actions() {
|
||||
return supportedActions;
|
||||
}
|
||||
|
||||
eDataSourceType CX11DataSource::type() {
|
||||
return DATA_SOURCE_TYPE_X11;
|
||||
}
|
||||
|
||||
void CX11DataSource::sendDndDropPerformed() {
|
||||
;
|
||||
}
|
||||
|
||||
void CX11DataSource::sendDndAction(wl_data_device_manager_dnd_action a) {
|
||||
;
|
||||
}
|
||||
82
src/xwayland/Dnd.hpp
Normal file
82
src/xwayland/Dnd.hpp
Normal file
|
|
@ -0,0 +1,82 @@
|
|||
#pragma once
|
||||
|
||||
#include "../protocols/types/DataDevice.hpp"
|
||||
#include <wayland-server-protocol.h>
|
||||
|
||||
#define XDND_VERSION 5
|
||||
|
||||
class CXWaylandSurface;
|
||||
|
||||
class CX11DataOffer : public IDataOffer {
|
||||
public:
|
||||
CX11DataOffer() = default;
|
||||
~CX11DataOffer() = default;
|
||||
|
||||
virtual eDataSourceType type();
|
||||
virtual SP<CWLDataOfferResource> getWayland();
|
||||
virtual SP<CX11DataOffer> getX11();
|
||||
virtual SP<IDataSource> getSource();
|
||||
virtual void markDead();
|
||||
|
||||
WP<IDataSource> source;
|
||||
WP<CX11DataOffer> self;
|
||||
WP<CXWaylandSurface> xwaylandSurface;
|
||||
|
||||
bool dead = false;
|
||||
bool accepted = false;
|
||||
bool recvd = false;
|
||||
|
||||
uint32_t actions = 0;
|
||||
};
|
||||
|
||||
class CX11DataSource : public IDataSource {
|
||||
public:
|
||||
CX11DataSource() = default;
|
||||
~CX11DataSource() = default;
|
||||
|
||||
virtual std::vector<std::string> mimes();
|
||||
virtual void send(const std::string& mime, uint32_t fd);
|
||||
virtual void accepted(const std::string& mime);
|
||||
virtual void cancelled();
|
||||
virtual bool hasDnd();
|
||||
virtual bool dndDone();
|
||||
virtual void error(uint32_t code, const std::string& msg);
|
||||
virtual void sendDndFinished();
|
||||
virtual uint32_t actions(); // wl_data_device_manager.dnd_action
|
||||
virtual eDataSourceType type();
|
||||
virtual void sendDndDropPerformed();
|
||||
virtual void sendDndAction(wl_data_device_manager_dnd_action a);
|
||||
|
||||
bool used = false;
|
||||
bool dnd = true;
|
||||
bool dndSuccess = false;
|
||||
bool dropped = false;
|
||||
|
||||
WP<CX11DataSource> self;
|
||||
|
||||
std::vector<std::string> mimeTypes;
|
||||
uint32_t supportedActions = 0;
|
||||
};
|
||||
|
||||
class CX11DataDevice : public IDataDevice {
|
||||
public:
|
||||
CX11DataDevice() = default;
|
||||
|
||||
virtual SP<CWLDataDeviceResource> getWayland();
|
||||
virtual SP<CX11DataDevice> getX11();
|
||||
virtual void sendDataOffer(SP<IDataOffer> offer);
|
||||
virtual void sendEnter(uint32_t serial, SP<CWLSurfaceResource> surf, const Vector2D& local, SP<IDataOffer> offer);
|
||||
virtual void sendLeave();
|
||||
virtual void sendMotion(uint32_t timeMs, const Vector2D& local);
|
||||
virtual void sendDrop();
|
||||
virtual void sendSelection(SP<IDataOffer> offer);
|
||||
virtual eDataSourceType type();
|
||||
|
||||
WP<CX11DataDevice> self;
|
||||
|
||||
private:
|
||||
WP<CXWaylandSurface> lastSurface;
|
||||
WP<IDataOffer> lastOffer;
|
||||
Vector2D lastSurfaceCoords;
|
||||
uint32_t lastTime = 0;
|
||||
};
|
||||
|
|
@ -387,6 +387,28 @@ void CXWM::handleClientMessage(xcb_client_message_event_t* e) {
|
|||
}
|
||||
} else if (e->type == HYPRATOMS["_NET_ACTIVE_WINDOW"]) {
|
||||
XSURF->events.activate.emit();
|
||||
} else if (e->type == HYPRATOMS["XdndStatus"]) {
|
||||
if (dndDataOffers.empty() || !dndDataOffers.at(0)->getSource()) {
|
||||
Debug::log(TRACE, "[xwm] Rejecting XdndStatus message: nothing to get");
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_client_message_data_t* data = &e->data;
|
||||
const bool ACCEPTED = data->data32[1] & 1;
|
||||
|
||||
if (ACCEPTED)
|
||||
dndDataOffers.at(0)->getSource()->accepted("");
|
||||
|
||||
Debug::log(LOG, "[xwm] XdndStatus: accepted: {}");
|
||||
} else if (e->type == HYPRATOMS["XdndFinished"]) {
|
||||
if (dndDataOffers.empty() || !dndDataOffers.at(0)->getSource()) {
|
||||
Debug::log(TRACE, "[xwm] Rejecting XdndFinished message: nothing to get");
|
||||
return;
|
||||
}
|
||||
|
||||
dndDataOffers.at(0)->getSource()->sendDndFinished();
|
||||
|
||||
Debug::log(LOG, "[xwm] XdndFinished");
|
||||
} else {
|
||||
Debug::log(TRACE, "[xwm] Unhandled message prop {} -> {}", e->type, propName);
|
||||
return;
|
||||
|
|
@ -545,22 +567,22 @@ std::string CXWM::mimeFromAtom(xcb_atom_t atom) {
|
|||
void CXWM::handleSelectionNotify(xcb_selection_notify_event_t* e) {
|
||||
Debug::log(TRACE, "[xwm] Selection notify for {} prop {} target {}", e->selection, e->property, e->target);
|
||||
|
||||
SXSelection& sel = clipboard;
|
||||
SXSelection* sel = getSelection(e->selection);
|
||||
|
||||
if (e->property == XCB_ATOM_NONE) {
|
||||
if (sel.transfer) {
|
||||
if (sel->transfer) {
|
||||
Debug::log(TRACE, "[xwm] converting selection failed");
|
||||
sel.transfer.reset();
|
||||
sel->transfer.reset();
|
||||
}
|
||||
} else if (e->target == HYPRATOMS["TARGETS"]) {
|
||||
} else if (e->target == HYPRATOMS["TARGETS"] && sel == &clipboard) {
|
||||
if (!focusedSurface) {
|
||||
Debug::log(TRACE, "[xwm] denying access to write to clipboard because no X client is in focus");
|
||||
return;
|
||||
}
|
||||
|
||||
setClipboardToWayland(sel);
|
||||
} else if (sel.transfer)
|
||||
getTransferData(sel);
|
||||
setClipboardToWayland(*sel);
|
||||
} else if (sel->transfer)
|
||||
getTransferData(*sel);
|
||||
}
|
||||
|
||||
bool CXWM::handleSelectionPropertyNotify(xcb_property_notify_event_t* e) {
|
||||
|
|
@ -571,13 +593,22 @@ bool CXWM::handleSelectionPropertyNotify(xcb_property_notify_event_t* e) {
|
|||
return false;
|
||||
}
|
||||
|
||||
SXSelection* CXWM::getSelection(xcb_atom_t atom) {
|
||||
if (atom == HYPRATOMS["CLIPBOARD"])
|
||||
return &clipboard;
|
||||
else if (atom == HYPRATOMS["XdndSelection"])
|
||||
return &dndSelection;
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CXWM::handleSelectionRequest(xcb_selection_request_event_t* e) {
|
||||
Debug::log(TRACE, "[xwm] Selection request for {} prop {} target {} time {} requestor {} selection {}", e->selection, e->property, e->target, e->time, e->requestor,
|
||||
e->selection);
|
||||
|
||||
SXSelection& sel = clipboard;
|
||||
SXSelection* sel = getSelection(e->selection);
|
||||
|
||||
if (!g_pSeatManager->selection.currentSelection) {
|
||||
if (!sel) {
|
||||
Debug::log(ERR, "[xwm] No selection");
|
||||
selectionSendNotify(e, false);
|
||||
return;
|
||||
|
|
@ -588,8 +619,8 @@ void CXWM::handleSelectionRequest(xcb_selection_request_event_t* e) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (sel.window != e->owner && e->time != XCB_CURRENT_TIME && e->time < sel.timestamp) {
|
||||
Debug::log(ERR, "[xwm] outdated selection request. Time {} < {}", e->time, sel.timestamp);
|
||||
if (sel->window != e->owner && e->time != XCB_CURRENT_TIME && e->time < sel->timestamp) {
|
||||
Debug::log(ERR, "[xwm] outdated selection request. Time {} < {}", e->time, sel->timestamp);
|
||||
selectionSendNotify(e, false);
|
||||
return;
|
||||
}
|
||||
|
|
@ -615,12 +646,11 @@ void CXWM::handleSelectionRequest(xcb_selection_request_event_t* e) {
|
|||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, e->requestor, e->property, XCB_ATOM_ATOM, 32, atoms.size(), atoms.data());
|
||||
selectionSendNotify(e, true);
|
||||
} else if (e->target == HYPRATOMS["TIMESTAMP"]) {
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, e->requestor, e->property, XCB_ATOM_INTEGER, 32, 1, &sel.timestamp);
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, e->requestor, e->property, XCB_ATOM_INTEGER, 32, 1, &sel->timestamp);
|
||||
selectionSendNotify(e, true);
|
||||
} else if (e->target == HYPRATOMS["DELETE"]) {
|
||||
selectionSendNotify(e, true);
|
||||
} else {
|
||||
|
||||
std::string mime = mimeFromAtom(e->target);
|
||||
|
||||
if (mime == "INVALID") {
|
||||
|
|
@ -629,7 +659,7 @@ void CXWM::handleSelectionRequest(xcb_selection_request_event_t* e) {
|
|||
return;
|
||||
}
|
||||
|
||||
if (!sel.sendData(e, mime)) {
|
||||
if (!sel->sendData(e, mime)) {
|
||||
Debug::log(LOG, "[xwm] Failed to send selection :(");
|
||||
selectionSendNotify(e, false);
|
||||
return;
|
||||
|
|
@ -641,24 +671,27 @@ bool CXWM::handleSelectionXFixesNotify(xcb_xfixes_selection_notify_event_t* e) {
|
|||
Debug::log(TRACE, "[xwm] Selection xfixes notify for {}", e->selection);
|
||||
|
||||
// IMPORTANT: mind the g_pSeatManager below
|
||||
SXSelection& sel = clipboard;
|
||||
SXSelection* sel = getSelection(e->selection);
|
||||
|
||||
if (sel == &dndSelection)
|
||||
return true;
|
||||
|
||||
if (e->owner == XCB_WINDOW_NONE) {
|
||||
if (sel.owner != sel.window)
|
||||
if (sel->owner != sel->window && sel == &clipboard)
|
||||
g_pSeatManager->setCurrentSelection(nullptr);
|
||||
|
||||
sel.owner = 0;
|
||||
sel->owner = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
sel.owner = e->owner;
|
||||
sel->owner = e->owner;
|
||||
|
||||
if (sel.owner == sel.window) {
|
||||
sel.timestamp = e->timestamp;
|
||||
if (sel->owner == sel->window) {
|
||||
sel->timestamp = e->timestamp;
|
||||
return true;
|
||||
}
|
||||
|
||||
xcb_convert_selection(connection, sel.window, HYPRATOMS["CLIPBOARD"], HYPRATOMS["TARGETS"], HYPRATOMS["_WL_SELECTION"], e->timestamp);
|
||||
xcb_convert_selection(connection, sel->window, HYPRATOMS["CLIPBOARD"], HYPRATOMS["TARGETS"], HYPRATOMS["_WL_SELECTION"], e->timestamp);
|
||||
xcb_flush(connection);
|
||||
|
||||
return true;
|
||||
|
|
@ -854,6 +887,8 @@ CXWM::CXWM() : connection(g_pXWayland->pServer->xwmFDs[0]) {
|
|||
return;
|
||||
}
|
||||
|
||||
dndDataDevice->self = dndDataDevice;
|
||||
|
||||
xcb_screen_iterator_t screen_iterator = xcb_setup_roots_iterator(xcb_get_setup(connection));
|
||||
screen = screen_iterator.data;
|
||||
|
||||
|
|
@ -1015,6 +1050,15 @@ void CXWM::readWindowData(SP<CXWaylandSurface> surf) {
|
|||
}
|
||||
}
|
||||
|
||||
SP<CXWaylandSurface> CXWM::windowForWayland(SP<CWLSurfaceResource> surf) {
|
||||
for (auto& s : surfaces) {
|
||||
if (s->surface == surf)
|
||||
return s;
|
||||
}
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void CXWM::associate(SP<CXWaylandSurface> surf, SP<CWLSurfaceResource> wlSurf) {
|
||||
if (surf->surface)
|
||||
return;
|
||||
|
|
@ -1068,7 +1112,7 @@ void CXWM::updateClientList() {
|
|||
}
|
||||
|
||||
bool CXWM::isWMWindow(xcb_window_t w) {
|
||||
return w == wmWindow || w == clipboard.window;
|
||||
return w == wmWindow || w == clipboard.window || w == dndSelection.window;
|
||||
}
|
||||
|
||||
void CXWM::updateOverrideRedirect(SP<CXWaylandSurface> surf, bool overrideRedirect) {
|
||||
|
|
@ -1090,6 +1134,13 @@ void CXWM::initSelection() {
|
|||
xcb_xfixes_select_selection_input(connection, clipboard.window, HYPRATOMS["CLIPBOARD"], mask2);
|
||||
|
||||
clipboard.listeners.setSelection = g_pSeatManager->events.setSelection.registerListener([this](std::any d) { clipboard.onSelection(); });
|
||||
|
||||
dndSelection.window = xcb_generate_id(connection);
|
||||
xcb_create_window(connection, XCB_COPY_FROM_PARENT, dndSelection.window, screen->root, 0, 0, 8192, 8192, 0, XCB_WINDOW_CLASS_INPUT_ONLY, screen->root_visual, XCB_CW_EVENT_MASK,
|
||||
mask);
|
||||
|
||||
uint32_t val1 = XDND_VERSION;
|
||||
xcb_change_property(connection, XCB_PROP_MODE_REPLACE, dndSelection.window, HYPRATOMS["XdndAware"], XCB_ATOM_ATOM, 32, 1, &val1);
|
||||
}
|
||||
|
||||
void CXWM::setClipboardToWayland(SXSelection& sel) {
|
||||
|
|
@ -1172,6 +1223,52 @@ void CXWM::setCursor(unsigned char* pixData, uint32_t stride, const Vector2D& si
|
|||
xcb_flush(connection);
|
||||
}
|
||||
|
||||
void CXWM::sendDndEvent(SP<CWLSurfaceResource> destination, xcb_atom_t type, xcb_client_message_data_t& data) {
|
||||
auto XSURF = windowForWayland(destination);
|
||||
|
||||
if (!XSURF) {
|
||||
Debug::log(ERR, "[xwm] No xwayland surface for destination in sendDndEvent");
|
||||
return;
|
||||
}
|
||||
|
||||
xcb_client_message_event_t event = {
|
||||
.response_type = XCB_CLIENT_MESSAGE,
|
||||
.format = 32,
|
||||
.sequence = 0,
|
||||
.window = XSURF->xID,
|
||||
.type = type,
|
||||
.data = data,
|
||||
};
|
||||
|
||||
xcb_send_event(g_pXWayland->pWM->connection,
|
||||
0, // propagate
|
||||
XSURF->xID, XCB_EVENT_MASK_NO_EVENT, (const char*)&event);
|
||||
xcb_flush(g_pXWayland->pWM->connection);
|
||||
}
|
||||
|
||||
SP<CX11DataDevice> CXWM::getDataDevice() {
|
||||
return dndDataDevice;
|
||||
}
|
||||
|
||||
SP<IDataOffer> CXWM::createX11DataOffer(SP<CWLSurfaceResource> surf, SP<IDataSource> source) {
|
||||
auto XSURF = windowForWayland(surf);
|
||||
|
||||
if (!XSURF) {
|
||||
Debug::log(ERR, "[xwm] No xwayland surface for destination in createX11DataOffer");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// invalidate old
|
||||
g_pXWayland->pWM->dndDataOffers.clear();
|
||||
|
||||
auto offer = dndDataOffers.emplace_back(makeShared<CX11DataOffer>());
|
||||
offer->self = offer;
|
||||
offer->xwaylandSurface = XSURF;
|
||||
offer->source = source;
|
||||
|
||||
return offer;
|
||||
}
|
||||
|
||||
void SXSelection::onSelection() {
|
||||
if (g_pSeatManager->selection.currentSelection && g_pSeatManager->selection.currentSelection->type() == DATA_SOURCE_TYPE_X11)
|
||||
return;
|
||||
|
|
@ -1220,7 +1317,11 @@ static int readDataSource(int fd, uint32_t mask, void* data) {
|
|||
}
|
||||
|
||||
bool SXSelection::sendData(xcb_selection_request_event_t* e, std::string mime) {
|
||||
WP<IDataSource> selection = g_pSeatManager->selection.currentSelection;
|
||||
WP<IDataSource> selection;
|
||||
if (this == &g_pXWayland->pWM->clipboard)
|
||||
selection = g_pSeatManager->selection.currentSelection;
|
||||
else if (!g_pXWayland->pWM->dndDataOffers.empty())
|
||||
selection = g_pXWayland->pWM->dndDataOffers.at(0)->getSource();
|
||||
|
||||
if (!selection)
|
||||
return false;
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@
|
|||
|
||||
#include "../macros.hpp"
|
||||
#include "XDataSource.hpp"
|
||||
#include "Dnd.hpp"
|
||||
#include "../helpers/memory/Memory.hpp"
|
||||
#include "../helpers/signal/Signal.hpp"
|
||||
|
||||
|
|
@ -104,7 +105,9 @@ class CXWM {
|
|||
CXWM();
|
||||
~CXWM();
|
||||
|
||||
int onEvent(int fd, uint32_t mask);
|
||||
int onEvent(int fd, uint32_t mask);
|
||||
SP<CX11DataDevice> getDataDevice();
|
||||
SP<IDataOffer> createX11DataOffer(SP<CWLSurfaceResource> surf, SP<IDataSource> source);
|
||||
|
||||
private:
|
||||
void setCursor(unsigned char* pixData, uint32_t stride, const Vector2D& size, const Vector2D& hotspot);
|
||||
|
|
@ -128,6 +131,7 @@ class CXWM {
|
|||
void sendWMMessage(SP<CXWaylandSurface> surf, xcb_client_message_data_t* data, uint32_t mask);
|
||||
|
||||
SP<CXWaylandSurface> windowForXID(xcb_window_t wid);
|
||||
SP<CXWaylandSurface> windowForWayland(SP<CWLSurfaceResource> surf);
|
||||
|
||||
void readWindowData(SP<CXWaylandSurface> surf);
|
||||
void associate(SP<CXWaylandSurface> surf, SP<CWLSurfaceResource> wlSurf);
|
||||
|
|
@ -135,33 +139,37 @@ class CXWM {
|
|||
|
||||
void updateClientList();
|
||||
|
||||
void sendDndEvent(SP<CWLSurfaceResource> destination, xcb_atom_t type, xcb_client_message_data_t& data);
|
||||
|
||||
// event handlers
|
||||
void handleCreate(xcb_create_notify_event_t* e);
|
||||
void handleDestroy(xcb_destroy_notify_event_t* e);
|
||||
void handleConfigure(xcb_configure_request_event_t* e);
|
||||
void handleConfigureNotify(xcb_configure_notify_event_t* e);
|
||||
void handleMapRequest(xcb_map_request_event_t* e);
|
||||
void handleMapNotify(xcb_map_notify_event_t* e);
|
||||
void handleUnmapNotify(xcb_unmap_notify_event_t* e);
|
||||
void handlePropertyNotify(xcb_property_notify_event_t* e);
|
||||
void handleClientMessage(xcb_client_message_event_t* e);
|
||||
void handleFocusIn(xcb_focus_in_event_t* e);
|
||||
void handleFocusOut(xcb_focus_out_event_t* e);
|
||||
void handleError(xcb_value_error_t* e);
|
||||
void handleCreate(xcb_create_notify_event_t* e);
|
||||
void handleDestroy(xcb_destroy_notify_event_t* e);
|
||||
void handleConfigure(xcb_configure_request_event_t* e);
|
||||
void handleConfigureNotify(xcb_configure_notify_event_t* e);
|
||||
void handleMapRequest(xcb_map_request_event_t* e);
|
||||
void handleMapNotify(xcb_map_notify_event_t* e);
|
||||
void handleUnmapNotify(xcb_unmap_notify_event_t* e);
|
||||
void handlePropertyNotify(xcb_property_notify_event_t* e);
|
||||
void handleClientMessage(xcb_client_message_event_t* e);
|
||||
void handleFocusIn(xcb_focus_in_event_t* e);
|
||||
void handleFocusOut(xcb_focus_out_event_t* e);
|
||||
void handleError(xcb_value_error_t* e);
|
||||
|
||||
bool handleSelectionEvent(xcb_generic_event_t* e);
|
||||
void handleSelectionNotify(xcb_selection_notify_event_t* e);
|
||||
bool handleSelectionPropertyNotify(xcb_property_notify_event_t* e);
|
||||
void handleSelectionRequest(xcb_selection_request_event_t* e);
|
||||
bool handleSelectionXFixesNotify(xcb_xfixes_selection_notify_event_t* e);
|
||||
bool handleSelectionEvent(xcb_generic_event_t* e);
|
||||
void handleSelectionNotify(xcb_selection_notify_event_t* e);
|
||||
bool handleSelectionPropertyNotify(xcb_property_notify_event_t* e);
|
||||
void handleSelectionRequest(xcb_selection_request_event_t* e);
|
||||
bool handleSelectionXFixesNotify(xcb_xfixes_selection_notify_event_t* e);
|
||||
|
||||
void selectionSendNotify(xcb_selection_request_event_t* e, bool success);
|
||||
xcb_atom_t mimeToAtom(const std::string& mime);
|
||||
std::string mimeFromAtom(xcb_atom_t atom);
|
||||
void setClipboardToWayland(SXSelection& sel);
|
||||
void getTransferData(SXSelection& sel);
|
||||
std::string getAtomName(uint32_t atom);
|
||||
void readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_reply_t* reply);
|
||||
void selectionSendNotify(xcb_selection_request_event_t* e, bool success);
|
||||
xcb_atom_t mimeToAtom(const std::string& mime);
|
||||
std::string mimeFromAtom(xcb_atom_t atom);
|
||||
void setClipboardToWayland(SXSelection& sel);
|
||||
void getTransferData(SXSelection& sel);
|
||||
std::string getAtomName(uint32_t atom);
|
||||
void readProp(SP<CXWaylandSurface> XSURF, uint32_t atom, xcb_get_property_reply_t* reply);
|
||||
|
||||
SXSelection* getSelection(xcb_atom_t atom);
|
||||
|
||||
//
|
||||
CXCBConnection connection;
|
||||
|
|
@ -191,6 +199,9 @@ class CXWM {
|
|||
uint64_t lastFocusSeq = 0;
|
||||
|
||||
SXSelection clipboard;
|
||||
SXSelection dndSelection;
|
||||
SP<CX11DataDevice> dndDataDevice = makeShared<CX11DataDevice>();
|
||||
std::vector<SP<CX11DataOffer>> dndDataOffers;
|
||||
|
||||
struct {
|
||||
CHyprSignalListener newWLSurface;
|
||||
|
|
@ -200,6 +211,10 @@ class CXWM {
|
|||
friend class CXWaylandSurface;
|
||||
friend class CXWayland;
|
||||
friend class CXDataSource;
|
||||
friend class CX11DataDevice;
|
||||
friend class CX11DataSource;
|
||||
friend class CX11DataOffer;
|
||||
friend class CWLDataDeviceProtocol;
|
||||
friend struct SXSelection;
|
||||
friend struct SXTransfer;
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue