summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorVaxry <vaxry@vaxry.net>2024-05-11 17:13:20 +0100
committerVaxry <vaxry@vaxry.net>2024-05-14 23:13:35 +0100
commit7eeee2c94e882a5df1914234df0571b221f9aa35 (patch)
tree51099a811781579c68724b4a0d6fe5bb4ab87a02 /src
parentfc72df8e58bc127442a245f2f29a3246acf77cce (diff)
wl-data-device: move to hyprland impl
Diffstat (limited to 'src')
-rw-r--r--src/Compositor.cpp10
-rw-r--r--src/events/Events.hpp10
-rw-r--r--src/events/Misc.cpp92
-rw-r--r--src/helpers/WLClasses.hpp19
-rw-r--r--src/managers/PointerManager.cpp4
-rw-r--r--src/managers/PointerManager.hpp1
-rw-r--r--src/managers/ProtocolManager.cpp5
-rw-r--r--src/managers/SeatManager.cpp38
-rw-r--r--src/managers/SeatManager.hpp12
-rw-r--r--src/managers/input/InputManager.cpp28
-rw-r--r--src/managers/input/InputManager.hpp3
-rw-r--r--src/protocols/core/DataDevice.cpp655
-rw-r--r--src/protocols/core/DataDevice.hpp194
-rw-r--r--src/protocols/types/DataDevice.cpp17
-rw-r--r--src/protocols/types/DataDevice.hpp29
-rw-r--r--src/render/Renderer.cpp17
16 files changed, 963 insertions, 171 deletions
diff --git a/src/Compositor.cpp b/src/Compositor.cpp
index 4e0a6357..efbd997f 100644
--- a/src/Compositor.cpp
+++ b/src/Compositor.cpp
@@ -253,11 +253,6 @@ void CCompositor::initServer() {
void CCompositor::initAllSignals() {
addWLSignal(&m_sWLRBackend->events.new_output, &Events::listen_newOutput, m_sWLRBackend, "Backend");
addWLSignal(&m_sWLRBackend->events.new_input, &Events::listen_newInput, m_sWLRBackend, "Backend");
- // addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
- // addWLSignal(&m_sSeat.seat->events.request_start_drag, &Events::listen_requestDrag, &m_sSeat, "Seat");
- // addWLSignal(&m_sSeat.seat->events.start_drag, &Events::listen_startDrag, &m_sSeat, "Seat");
- // addWLSignal(&m_sSeat.seat->events.request_set_selection, &Events::listen_requestSetSel, &m_sSeat, "Seat");
- // addWLSignal(&m_sSeat.seat->events.request_set_primary_selection, &Events::listen_requestSetPrimarySel, &m_sSeat, "Seat");
addWLSignal(&m_sWLRRenderer->events.destroy, &Events::listen_RendererDestroy, m_sWLRRenderer, "WLRRenderer");
if (m_sWRLDRMLeaseMgr)
@@ -270,11 +265,6 @@ void CCompositor::initAllSignals() {
void CCompositor::removeAllSignals() {
removeWLSignal(&Events::listen_newOutput);
removeWLSignal(&Events::listen_newInput);
- removeWLSignal(&Events::listen_requestSetSel);
- removeWLSignal(&Events::listen_requestDrag);
- removeWLSignal(&Events::listen_startDrag);
- removeWLSignal(&Events::listen_requestSetSel);
- removeWLSignal(&Events::listen_requestSetPrimarySel);
removeWLSignal(&Events::listen_RendererDestroy);
if (m_sWRLDRMLeaseMgr)
diff --git a/src/events/Events.hpp b/src/events/Events.hpp
index 7cc0eb32..0b757842 100644
--- a/src/events/Events.hpp
+++ b/src/events/Events.hpp
@@ -59,16 +59,6 @@ namespace Events {
LISTENER(readyXWayland);
LISTENER(surfaceXWayland);
- // Drag & Drop
- LISTENER(requestDrag);
- LISTENER(startDrag);
- DYNLISTENFUNC(destroyDrag);
-
- DYNLISTENFUNC(mapDragIcon);
- DYNLISTENFUNC(unmapDragIcon);
- DYNLISTENFUNC(destroyDragIcon);
- DYNLISTENFUNC(commitDragIcon);
-
// Renderer destroy
LISTENER(RendererDestroy);
diff --git a/src/events/Misc.cpp b/src/events/Misc.cpp
index 703dba6a..7152730e 100644
--- a/src/events/Misc.cpp
+++ b/src/events/Misc.cpp
@@ -25,16 +25,6 @@ void Events::listener_leaseRequest(wl_listener* listener, void* data) {
}
}
-void Events::listener_requestSetPrimarySel(wl_listener* listener, void* data) {
- // const auto EVENT = (wlr_seat_request_set_primary_selection_event*)data;
- // wlr_seat_set_primary_selection(g_pCompositor->m_sSeat.seat, EVENT->source, EVENT->serial);
-}
-
-void Events::listener_requestSetSel(wl_listener* listener, void* data) {
- // const auto EVENT = (wlr_seat_request_set_selection_event*)data;
- // wlr_seat_set_selection(g_pCompositor->m_sSeat.seat, EVENT->source, EVENT->serial);
-}
-
void Events::listener_readyXWayland(wl_listener* listener, void* data) {
#ifndef NO_XWAYLAND
const auto XCBCONNECTION = xcb_connect(g_pXWaylandManager->m_sWLRXWayland->display_name, NULL);
@@ -79,88 +69,6 @@ void Events::listener_readyXWayland(wl_listener* listener, void* data) {
#endif
}
-void Events::listener_requestDrag(wl_listener* listener, void* data) {
- // const auto E = (wlr_seat_request_start_drag_event*)data;
-
- // if (!wlr_seat_validate_pointer_grab_serial(g_pCompositor->m_sSeat.seat, E->origin, E->serial)) {
- // Debug::log(LOG, "Ignoring drag and drop request: serial mismatch.");
- // wlr_data_source_destroy(E->drag->source);
- // return;
- // }
-
- // wlr_seat_start_pointer_drag(g_pCompositor->m_sSeat.seat, E->drag, E->serial);
-}
-
-void Events::listener_startDrag(wl_listener* listener, void* data) {
-
- if (g_pInputManager->m_sDrag.drag)
- return; // don't handle multiple drags
-
- g_pInputManager->m_sDrag.drag = (wlr_drag*)data;
-
- wlr_drag* wlrDrag = (wlr_drag*)data;
-
- Debug::log(LOG, "Started drag {:x}", (uintptr_t)wlrDrag);
-
- wlrDrag->data = data;
-
- g_pInputManager->m_sDrag.hyprListener_destroy.initCallback(&wlrDrag->events.destroy, &Events::listener_destroyDrag, &g_pInputManager->m_sDrag, "Drag");
-
- if (wlrDrag->icon) {
- Debug::log(LOG, "Drag started with an icon {:x}", (uintptr_t)wlrDrag->icon);
-
- g_pInputManager->m_sDrag.dragIcon = wlrDrag->icon;
- wlrDrag->icon->data = g_pInputManager->m_sDrag.dragIcon;
-
- g_pInputManager->m_sDrag.hyprListener_mapIcon.initCallback(&wlrDrag->icon->surface->events.map, &Events::listener_mapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
- g_pInputManager->m_sDrag.hyprListener_unmapIcon.initCallback(&wlrDrag->icon->surface->events.unmap, &Events::listener_unmapDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
- g_pInputManager->m_sDrag.hyprListener_destroyIcon.initCallback(&wlrDrag->icon->events.destroy, &Events::listener_destroyDragIcon, &g_pInputManager->m_sDrag, "DragIcon");
- g_pInputManager->m_sDrag.hyprListener_commitIcon.initCallback(&wlrDrag->icon->surface->events.commit, &Events::listener_commitDragIcon, &g_pInputManager->m_sDrag,
- "DragIcon");
- }
-}
-
-void Events::listener_destroyDrag(void* owner, void* data) {
- Debug::log(LOG, "Drag destroyed.");
-
- if (g_pInputManager->m_sDrag.drag && g_pInputManager->m_sDrag.dragIcon && g_pInputManager->m_sDrag.dragIcon->surface)
- g_pHyprRenderer->damageBox(g_pInputManager->m_sDrag.pos.x - 2, g_pInputManager->m_sDrag.pos.y - 2, g_pInputManager->m_sDrag.dragIcon->surface->current.width + 4,
- g_pInputManager->m_sDrag.dragIcon->surface->current.height + 4);
-
- g_pInputManager->m_sDrag.drag = nullptr;
- g_pInputManager->m_sDrag.dragIcon = nullptr;
- g_pInputManager->m_sDrag.hyprListener_destroy.removeCallback();
-
- g_pCompositor->focusWindow(g_pCompositor->m_pLastWindow.lock(),
- g_pCompositor->m_pLastWindow.lock() ? g_pXWaylandManager->getWindowSurface(g_pCompositor->m_pLastWindow.lock()) : nullptr);
-}
-
-void Events::listener_mapDragIcon(void* owner, void* data) {
- Debug::log(LOG, "Drag icon mapped.");
- g_pInputManager->m_sDrag.iconMapped = true;
-}
-
-void Events::listener_unmapDragIcon(void* owner, void* data) {
- Debug::log(LOG, "Drag icon unmapped.");
- g_pInputManager->m_sDrag.iconMapped = false;
-}
-
-void Events::listener_destroyDragIcon(void* owner, void* data) {
- Debug::log(LOG, "Drag icon destroyed.");
-
- g_pInputManager->m_sDrag.dragIcon = nullptr;
- g_pInputManager->m_sDrag.hyprListener_commitIcon.removeCallback();
- g_pInputManager->m_sDrag.hyprListener_destroyIcon.removeCallback();
- g_pInputManager->m_sDrag.hyprListener_mapIcon.removeCallback();
- g_pInputManager->m_sDrag.hyprListener_unmapIcon.removeCallback();
-}
-
-void Events::listener_commitDragIcon(void* owner, void* data) {
- g_pInputManager->updateDragIcon();
-
- Debug::log(LOG, "Drag icon committed.");
-}
-
void Events::listener_RendererDestroy(wl_listener* listener, void* data) {
Debug::log(LOG, "!!Renderer destroyed!!");
}
diff --git a/src/helpers/WLClasses.hpp b/src/helpers/WLClasses.hpp
index 7b24de7d..30f5aebf 100644
--- a/src/helpers/WLClasses.hpp
+++ b/src/helpers/WLClasses.hpp
@@ -58,25 +58,6 @@ struct SExtensionFindingData {
wlr_surface** found;
};
-struct SDrag {
- wlr_drag* drag = nullptr;
-
- DYNLISTENER(destroy);
-
- // Icon
-
- bool iconMapped = false;
-
- wlr_drag_icon* dragIcon = nullptr;
-
- Vector2D pos;
-
- DYNLISTENER(destroyIcon);
- DYNLISTENER(mapIcon);
- DYNLISTENER(unmapIcon);
- DYNLISTENER(commitIcon);
-};
-
struct SSwipeGesture {
PHLWORKSPACE pWorkspaceBegin = nullptr;
diff --git a/src/managers/PointerManager.cpp b/src/managers/PointerManager.cpp
index 60d11e7f..6a0fb984 100644
--- a/src/managers/PointerManager.cpp
+++ b/src/managers/PointerManager.cpp
@@ -941,3 +941,7 @@ void CPointerManager::damageCursor(SP<CMonitor> pMonitor) {
return;
}
}
+
+Vector2D CPointerManager::cursorSizeLogical() {
+ return currentCursorImage.size / currentCursorImage.scale;
+}
diff --git a/src/managers/PointerManager.hpp b/src/managers/PointerManager.hpp
index 71ab0fc2..b6cb0c7a 100644
--- a/src/managers/PointerManager.hpp
+++ b/src/managers/PointerManager.hpp
@@ -52,6 +52,7 @@ class CPointerManager {
//
Vector2D position();
+ Vector2D cursorSizeLogical();
private:
void recheckPointerPosition();
diff --git a/src/managers/ProtocolManager.cpp b/src/managers/ProtocolManager.cpp
index e53eb111..8167103f 100644
--- a/src/managers/ProtocolManager.cpp
+++ b/src/managers/ProtocolManager.cpp
@@ -28,13 +28,16 @@
#include "../protocols/Tablet.hpp"
#include "../protocols/LayerShell.hpp"
#include "../protocols/PresentationTime.hpp"
-#include "../protocols/core/Seat.hpp"
#include "../protocols/XDGShell.hpp"
+#include "../protocols/core/Seat.hpp"
+#include "../protocols/core/DataDevice.hpp"
+
CProtocolManager::CProtocolManager() {
// Core
PROTO::seat = std::make_unique<CWLSeatProtocol>(&wl_seat_interface, 9, "WLSeat");
+ PROTO::data = std::make_unique<CWLDataDeviceProtocol>(&wl_data_device_manager_interface, 3, "WLDataDevice");
// Extensions
PROTO::tearing = std::make_unique<CTearingControlProtocol>(&wp_tearing_control_manager_v1_interface, 1, "TearingControl");
diff --git a/src/managers/SeatManager.cpp b/src/managers/SeatManager.cpp
index d962dd84..76840bd3 100644
--- a/src/managers/SeatManager.cpp
+++ b/src/managers/SeatManager.cpp
@@ -1,5 +1,6 @@
#include "SeatManager.hpp"
#include "../protocols/core/Seat.hpp"
+#include "../protocols/core/DataDevice.hpp"
#include "../Compositor.hpp"
#include "../devices/IKeyboard.hpp"
#include <algorithm>
@@ -222,6 +223,8 @@ void CSeatManager::sendPointerMotion(uint32_t timeMs, const Vector2D& local) {
p->sendMotion(timeMs, local);
}
+
+ lastLocalCoords = local;
}
void CSeatManager::sendPointerButton(uint32_t timeMs, uint32_t key, wl_pointer_button_state state_) {
@@ -424,6 +427,28 @@ SP<CWLSeatResource> CSeatManager::seatResourceForClient(wl_client* client) {
return PROTO::seat->seatResourceForClient(client);
}
+void CSeatManager::setCurrentSelection(SP<IDataSource> source) {
+ if (source == selection.currentSelection) {
+ Debug::log(WARN, "[seat] duplicated setCurrentSelection?");
+ return;
+ }
+
+ selection.destroySelection.reset();
+
+ if (selection.currentSelection)
+ selection.currentSelection->cancelled();
+
+ if (!source)
+ PROTO::data->setSelection(nullptr);
+
+ selection.currentSelection = source;
+
+ if (source) {
+ selection.destroySelection = source->events.destroy.registerListener([this](std::any d) { setCurrentSelection(nullptr); });
+ PROTO::data->setSelection(source);
+ }
+}
+
void CSeatManager::setGrab(SP<CSeatGrab> grab) {
if (seatGrab) {
auto oldGrab = seatGrab;
@@ -441,6 +466,19 @@ void CSeatManager::setGrab(SP<CSeatGrab> grab) {
refocusGrab();
}
+void CSeatManager::resendEnterEvents() {
+ wlr_surface* kb = state.keyboardFocus;
+ wlr_surface* pt = state.pointerFocus;
+
+ auto last = lastLocalCoords;
+
+ setKeyboardFocus(nullptr);
+ setPointerFocus(nullptr, {});
+
+ setKeyboardFocus(kb);
+ setPointerFocus(pt, last);
+}
+
bool CSeatGrab::accepts(wlr_surface* surf) {
return std::find(surfs.begin(), surfs.end(), surf) != surfs.end();
}
diff --git a/src/managers/SeatManager.hpp b/src/managers/SeatManager.hpp
index 16f11ffd..81ca663d 100644
--- a/src/managers/SeatManager.hpp
+++ b/src/managers/SeatManager.hpp
@@ -5,6 +5,7 @@
#include "../macros.hpp"
#include "../helpers/signal/Signal.hpp"
#include "../helpers/Vector2D.hpp"
+#include "../protocols/types/DataDevice.hpp"
#include <vector>
constexpr size_t MAX_SERIAL_STORE_LEN = 100;
@@ -72,6 +73,8 @@ class CSeatManager {
void sendTouchShape(int32_t id, const Vector2D& shape);
void sendTouchOrientation(int32_t id, double angle);
+ void resendEnterEvents();
+
uint32_t nextSerial(SP<CWLSeatResource> seatResource);
// pops the serial if it was valid, meaning it is consumed.
bool serialValid(SP<CWLSeatResource> seatResource, uint32_t serial);
@@ -103,6 +106,13 @@ class CSeatManager {
CSignal setCursor; // SSetCursorEvent
} events;
+ struct {
+ WP<IDataSource> currentSelection;
+ CHyprSignalListener destroySelection;
+ } selection;
+
+ void setCurrentSelection(SP<IDataSource> source);
+
// do not write to directly, use set...
WP<IPointer> mouse;
WP<IKeyboard> keyboard;
@@ -132,6 +142,8 @@ class CSeatManager {
CHyprSignalListener newSeatResource;
} listeners;
+ Vector2D lastLocalCoords;
+
DYNLISTENER(keyboardSurfaceDestroy);
DYNLISTENER(pointerSurfaceDestroy);
DYNLISTENER(touchSurfaceDestroy);
diff --git a/src/managers/input/InputManager.cpp b/src/managers/input/InputManager.cpp
index fe19c98f..d74657d9 100644
--- a/src/managers/input/InputManager.cpp
+++ b/src/managers/input/InputManager.cpp
@@ -15,6 +15,7 @@
#include "../../protocols/VirtualPointer.hpp"
#include "../../protocols/LayerShell.hpp"
#include "../../protocols/core/Seat.hpp"
+#include "../../protocols/core/DataDevice.hpp"
#include "../../protocols/XDGShell.hpp"
#include "../../devices/Mouse.hpp"
@@ -137,7 +138,7 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
static auto PRESIZECURSORICON = CConfigValue<Hyprlang::INT>("general:hover_icon_on_border");
static auto PZOOMFACTOR = CConfigValue<Hyprlang::FLOAT>("cursor:zoom_factor");
- const auto FOLLOWMOUSE = *PFOLLOWONDND && m_sDrag.drag ? 1 : *PFOLLOWMOUSE;
+ const auto FOLLOWMOUSE = *PFOLLOWONDND && PROTO::data->dndActive() ? 1 : *PFOLLOWMOUSE;
m_pFoundSurfaceToFocus = nullptr;
m_pFoundLSToFocus.reset();
@@ -218,10 +219,9 @@ void CInputManager::mouseMoveUnified(uint32_t time, bool refocus) {
Debug::log(ERR, "BUG THIS: Null SURF/CONSTRAINT in mouse refocus. Ignoring constraints. {:x} {:x}", (uintptr_t)SURF, (uintptr_t)CONSTRAINT.get());
}
- // update stuff
- updateDragIcon();
-
- if (!m_sDrag.drag && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus) {
+ // if we are holding a pointer button,
+ // and we're not dnd-ing, don't refocus. Keep focus on last surface.
+ if (!PROTO::data->dndActive() && !m_lCurrentlyHeldButtons.empty() && g_pCompositor->m_pLastFocus && g_pSeatManager->state.pointerFocus && !m_bHardInput) {
foundSurface = g_pSeatManager->state.pointerFocus;
pFoundLayerSurface = g_pCompositor->getLayerSurfaceFromSurface(foundSurface);
if (pFoundLayerSurface) {
@@ -1356,22 +1356,6 @@ void CInputManager::refocus() {
mouseMoveUnified(0, true);
}
-void CInputManager::updateDragIcon() {
- if (!m_sDrag.dragIcon)
- return;
-
- switch (m_sDrag.dragIcon->drag->grab_type) {
- case WLR_DRAG_GRAB_KEYBOARD: break;
- case WLR_DRAG_GRAB_KEYBOARD_POINTER: {
- CBox box = {m_sDrag.pos.x - 2, m_sDrag.pos.y - 2, m_sDrag.dragIcon->surface->current.width + 4, m_sDrag.dragIcon->surface->current.height + 4};
- g_pHyprRenderer->damageBox(&box);
- m_sDrag.pos = getMouseCoordsInternal();
- break;
- }
- default: break;
- }
-}
-
void CInputManager::unconstrainMouse() {
if (g_pSeatManager->mouse.expired())
return;
@@ -1665,7 +1649,7 @@ std::string CInputManager::getNameForNewDevice(std::string internalName) {
void CInputManager::releaseAllMouseButtons() {
const auto buttonsCopy = m_lCurrentlyHeldButtons;
- if (g_pInputManager->m_sDrag.drag)
+ if (PROTO::data->dndActive())
return;
for (auto& mb : buttonsCopy) {
diff --git a/src/managers/input/InputManager.hpp b/src/managers/input/InputManager.hpp
index 85efecb8..f7d9ae57 100644
--- a/src/managers/input/InputManager.hpp
+++ b/src/managers/input/InputManager.hpp
@@ -112,7 +112,6 @@ class CInputManager {
void setTouchDeviceConfigs(SP<ITouch> dev = nullptr);
void setTabletConfigs();
- void updateDragIcon();
void updateCapabilities();
void updateKeyboardsLeds(SP<IKeyboard>);
@@ -143,8 +142,6 @@ class CInputManager {
// for refocus to be forced
PHLWINDOWREF m_pForcedFocus;
- SDrag m_sDrag;
-
std::vector<SP<IKeyboard>> m_vKeyboards;
std::vector<SP<IPointer>> m_vPointers;
std::vector<SP<ITouch>> m_vTouches;
diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp
new file mode 100644
index 00000000..d332a0be
--- /dev/null
+++ b/src/protocols/core/DataDevice.cpp
@@ -0,0 +1,655 @@
+#include "DataDevice.hpp"
+#include <algorithm>
+#include "../../managers/SeatManager.hpp"
+#include "../../managers/PointerManager.hpp"
+#include "../../Compositor.hpp"
+#include "Seat.hpp"
+
+#define LOGM PROTO::data->protoLog
+
+CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
+ if (!good())
+ return;
+
+ resource->setDestroy([this](CWlDataOffer* r) {
+ if (!dead)
+ PROTO::data->completeDrag();
+ PROTO::data->destroyResource(this);
+ });
+ resource->setOnDestroy([this](CWlDataOffer* r) {
+ if (!dead)
+ PROTO::data->completeDrag();
+ PROTO::data->destroyResource(this);
+ });
+
+ resource->setAccept([this](CWlDataOffer* r, uint32_t serial, const char* mime) {
+ if (!source) {
+ LOGM(WARN, "Possible bug: Accept on an offer w/o a source");
+ return;
+ }
+
+ if (dead) {
+ LOGM(WARN, "Possible bug: Accept on an offer that's dead");
+ return;
+ }
+
+ LOGM(LOG, "Offer {:x} accepts data from source {:x} with mime {}", (uintptr_t)this, (uintptr_t)source.get(), mime ? mime : "null");
+
+ source->accepted(mime ? mime : "");
+ accepted = mime;
+ });
+
+ resource->setReceive([this](CWlDataOffer* r, const char* mime, uint32_t fd) {
+ if (!source) {
+ LOGM(WARN, "Possible bug: Receive on an offer w/o a source");
+ close(fd);
+ return;
+ }
+
+ if (dead) {
+ LOGM(WARN, "Possible bug: Receive on an offer that's dead");
+ close(fd);
+ return;
+ }
+
+ LOGM(LOG, "Offer {:x} asks to send data from source {:x}", (uintptr_t)this, (uintptr_t)source.get());
+
+ if (!accepted) {
+ LOGM(WARN, "Offer was never accepted, sending accept first");
+ source->accepted(mime ? mime : "");
+ }
+
+ source->send(mime ? mime : "", fd);
+
+ recvd = true;
+
+ // if (source->hasDnd())
+ // PROTO::data->completeDrag();
+ });
+
+ resource->setFinish([this](CWlDataOffer* r) {
+ dead = true;
+ if (!source || !recvd || !accepted)
+ PROTO::data->abortDrag();
+ else
+ PROTO::data->completeDrag();
+ });
+}
+
+bool CWLDataOfferResource::good() {
+ return resource->resource();
+}
+
+void CWLDataOfferResource::sendData() {
+ if (!source)
+ return;
+
+ resource->sendSourceActions(7);
+ resource->sendAction(WL_DATA_DEVICE_MANAGER_DND_ACTION_MOVE);
+
+ for (auto& m : source->mimes()) {
+ LOGM(LOG, " | offer {:x} supports mime {}", (uintptr_t)this, m);
+ resource->sendOffer(m.c_str());
+ }
+}
+
+CWLDataSourceResource::CWLDataSourceResource(SP<CWlDataSource> resource_, SP<CWLDataDeviceResource> device_) : device(device_), resource(resource_) {
+ if (!good())
+ return;
+
+ resource->setData(this);
+
+ resource->setDestroy([this](CWlDataSource* r) {
+ events.destroy.emit();
+ PROTO::data->onDestroyDataSource(self);
+ PROTO::data->destroyResource(this);
+ });
+ resource->setOnDestroy([this](CWlDataSource* r) {
+ events.destroy.emit();
+ PROTO::data->onDestroyDataSource(self);
+ PROTO::data->destroyResource(this);
+ });
+
+ resource->setOffer([this](CWlDataSource* r, const char* mime) { mimeTypes.push_back(mime); });
+ resource->setSetActions([this](CWlDataSource* r, uint32_t a) {
+ LOGM(LOG, "DataSource {:x} actions {}", (uintptr_t)this, a);
+ actions = (wl_data_device_manager_dnd_action)a;
+ });
+}
+
+CWLDataSourceResource::~CWLDataSourceResource() {
+ events.destroy.emit();
+ PROTO::data->onDestroyDataSource(self);
+}
+
+SP<CWLDataSourceResource> CWLDataSourceResource::fromResource(wl_resource* res) {
+ auto data = (CWLDataSourceResource*)(((CWlDataSource*)wl_resource_get_user_data(res))->data());
+ return data ? data->self.lock() : nullptr;
+}
+
+bool CWLDataSourceResource::good() {
+ return resource->resource();
+}
+
+void CWLDataSourceResource::accepted(const std::string& mime) {
+ if (mime.empty()) {
+ resource->sendTarget(nullptr);
+ return;
+ }
+
+ if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end()) {
+ LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAccepted with non-existent mime");
+ return;
+ }
+
+ resource->sendTarget(mime.c_str());
+}
+
+std::vector<std::string> CWLDataSourceResource::mimes() {
+ return mimeTypes;
+}
+
+void CWLDataSourceResource::send(const std::string& mime, uint32_t fd) {
+ if (std::find(mimeTypes.begin(), mimeTypes.end(), mime) == mimeTypes.end()) {
+ LOGM(ERR, "Compositor/App bug: CWLDataSourceResource::sendAskSend with non-existent mime");
+ close(fd);
+ return;
+ }
+
+ resource->sendSend(mime.c_str(), fd);
+ close(fd);
+}
+
+void CWLDataSourceResource::cancelled() {
+ resource->sendCancelled();
+}
+
+bool CWLDataSourceResource::hasDnd() {
+ return dnd;
+}
+
+bool CWLDataSourceResource::dndDone() {
+ return dndSuccess;
+}
+
+void CWLDataSourceResource::error(uint32_t code, const std::string& msg) {
+ resource->error(code, msg);
+}
+
+void CWLDataSourceResource::sendDndDropPerformed() {
+ if (resource->version() < 3)
+ return;
+ resource->sendDndDropPerformed();
+}
+
+void CWLDataSourceResource::sendDndFinished() {
+ if (resource->version() < 3)
+ return;
+ resource->sendDndFinished();
+}
+
+void CWLDataSourceResource::sendDndAction(wl_data_device_manager_dnd_action a) {
+ if (resource->version() < 3)
+ return;
+ resource->sendAction(a);
+}
+
+CWLDataDeviceResource::CWLDataDeviceResource(SP<CWlDataDevice> resource_) : resource(resource_) {
+ if (!good())
+ return;
+
+ resource->setRelease([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
+ resource->setOnDestroy([this](CWlDataDevice* r) { PROTO::data->destroyResource(this); });
+
+ pClient = resource->client();
+
+ resource->setSetSelection([this](CWlDataDevice* r, wl_resource* sourceR, uint32_t serial) {
+ auto source = sourceR ? CWLDataSourceResource::fromResource(sourceR) : CSharedPointer<CWLDataSourceResource>{};
+ if (!source) {
+ LOGM(LOG, "Reset selection received");
+ g_pSeatManager->setCurrentSelection(nullptr);
+ return;
+ }
+
+ if (source && source->used)
+ LOGM(WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");
+
+ source->markUsed();
+
+ g_pSeatManager->setCurrentSelection(source);
+ });
+
+ resource->setStartDrag([this](CWlDataDevice* r, wl_resource* sourceR, wl_resource* origin, wl_resource* icon, uint32_t serial) {
+ auto source = CWLDataSourceResource::fromResource(sourceR);
+ if (!source) {
+ LOGM(ERR, "No source in drag");
+ return;
+ }
+
+ if (source && source->used)
+ LOGM(WARN, "setSelection on a used resource. By protocol, this is a violation, but firefox et al insist on doing this.");
+
+ source->markUsed();
+
+ source->dnd = true;
+
+ PROTO::data->initiateDrag(source, wlr_surface_from_resource(icon), wlr_surface_from_resource(origin));
+ });
+}
+
+bool CWLDataDeviceResource::good() {
+ return resource->resource();
+}
+
+wl_client* CWLDataDeviceResource::client() {
+ return pClient;
+}
+
+void CWLDataDeviceResource::sendDataOffer(SP<CWLDataOfferResource> offer) {
+ if (offer)
+ resource->sendDataOffer(offer->resource.get());
+ else
+ resource->sendDataOfferRaw(nullptr);
+}
+
+void CWLDataDeviceResource::sendEnter(uint32_t serial, wlr_surface* surf, const Vector2D& local, SP<CWLDataOfferResource> offer) {
+ resource->sendEnterRaw(serial, surf->resource, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y), offer->resource->resource());
+}
+
+void CWLDataDeviceResource::sendLeave() {
+ resource->sendLeave();
+}
+
+void CWLDataDeviceResource::sendMotion(uint32_t timeMs, const Vector2D& local) {
+ resource->sendMotion(timeMs, wl_fixed_from_double(local.x), wl_fixed_from_double(local.y));
+}
+
+void CWLDataDeviceResource::sendDrop() {
+ resource->sendDrop();
+}
+
+void CWLDataDeviceResource::sendSelection(SP<CWLDataOfferResource> offer) {
+ if (!offer)
+ resource->sendSelectionRaw(nullptr);
+ else
+ resource->sendSelection(offer->resource.get());
+}
+
+CWLDataDeviceManagerResource::CWLDataDeviceManagerResource(SP<CWlDataDeviceManager> resource_) : resource(resource_) {
+ if (!good())
+ return;
+
+ resource->setOnDestroy([this](CWlDataDeviceManager* r) { PROTO::data->destroyResource(this); });
+
+ resource->setCreateDataSource([this](CWlDataDeviceManager* r, uint32_t id) {
+ std::erase_if(sources, [](const auto& e) { return e.expired(); });
+
+ const auto RESOURCE = PROTO::data->m_vSources.emplace_back(makeShared<CWLDataSourceResource>(makeShared<CWlDataSource>(r->client(), r->version(), id), device.lock()));
+
+ if (!RESOURCE->good()) {
+ r->noMemory();
+ PROTO::data->m_vSources.pop_back();
+ return;
+ }
+
+ if (!device)
+ LOGM(WARN, "New data source before a device was created");
+
+ RESOURCE->self = RESOURCE;
+
+ LOGM(LOG, "New data source bound at {:x}", (uintptr_t)RESOURCE.get());
+ });
+
+ resource->setGetDataDevice([this](CWlDataDeviceManager* r, uint32_t id, wl_resource* seat) {
+ const auto RESOURCE = PROTO::data->m_vDevices.emplace_back(makeShared<CWLDataDeviceResource>(makeShared<CWlDataDevice>(r->client(), r->version(), id)));
+
+ if (!RESOURCE->good()) {
+ r->noMemory();
+ PROTO::data->m_vDevices.pop_back();
+ return;
+ }
+
+ RESOURCE->self = RESOURCE;
+
+ for (auto& s : sources) {
+ if (!s)
+ continue;
+ s->device = RESOURCE;
+ }
+
+ LOGM(LOG, "New data device bound at {:x}", (uintptr_t)RESOURCE.get());
+ });
+}
+
+bool CWLDataDeviceManagerResource::good() {
+ return resource->resource();
+}
+
+CWLDataDeviceProtocol::CWLDataDeviceProtocol(const wl_interface* iface, const int& ver, const std::string& name) : IWaylandProtocol(iface, ver, name) {
+ ;
+}
+
+void CWLDataDeviceProtocol::bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id) {
+ const auto RESOURCE = m_vManagers.emplace_back(makeShared<CWLDataDeviceManagerResource>(makeShared<CWlDataDeviceManager>(client, ver, id)));
+
+ if (!RESOURCE->good()) {
+ wl_client_post_no_memory(client);
+ m_vManagers.pop_back();
+ return;
+ }
+
+ LOGM(LOG, "New datamgr resource bound at {:x}", (uintptr_t)RESOURCE.get());
+
+ // we need to do it here because protocols come before seatMgr
+ if (!listeners.onKeyboardFocusChange)
+ listeners.onKeyboardFocusChange = g_pSeatManager->events.keyboardFocusChange.registerListener([this](std::any d) { this->onKeyboardFocus(); });
+}
+
+void CWLDataDeviceProtocol::destroyResource(CWLDataDeviceManagerResource* seat) {
+ std::erase_if(m_vManagers, [&](const auto& other) { return other.get() == seat; });
+}
+
+void CWLDataDeviceProtocol::destroyResource(CWLDataDeviceResource* resource) {
+ std::erase_if(m_vDevices, [&](const auto& other) { return other.get() == resource; });
+}
+
+void CWLDataDeviceProtocol::destroyResource(CWLDataSourceResource* resource) {
+ std::erase_if(m_vSources, [&](const auto& other) { return other.get() == resource; });
+}
+
+void CWLDataDeviceProtocol::destroyResource(CWLDataOfferResource* resource) {
+ std::erase_if(m_vOffers, [&](const auto& other) { return other.get() == resource; });
+}
+
+SP<CWLDataDeviceResource> CWLDataDeviceProtocol::dataDeviceForClient(wl_client* c) {
+ auto it = std::find_if(m_vDevices.begin(), m_vDevices.end(), [c](const auto& e) { return e->client() == c; });
+ if (it == m_vDevices.end())
+ return nullptr;
+ return *it;
+}
+
+void CWLDataDeviceProtocol::sendSelectionToDevice(SP<CWLDataDeviceResource> dev, SP<IDataSource> sel) {
+ if (!sel) {
+ dev->sendSelection(nullptr);
+ return;
+ }
+
+ const auto OFFER = m_vOffers.emplace_back(makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(dev->resource->client(), dev->resource->version(), 0), sel));
+
+ if (!OFFER->good()) {
+ dev->resource->noMemory();
+ m_vOffers.pop_back();
+ return;
+ }
+
+ LOGM(LOG, "New offer {:x} for data source {:x}", (uintptr_t)OFFER.get(), (uintptr_t)sel.get());
+
+ dev->sendDataOffer(OFFER);
+ OFFER->sendData();
+ dev->sendSelection(OFFER);
+}
+
+void CWLDataDeviceProtocol::onDestroyDataSource(WP<CWLDataSourceResource> source) {
+ if (dnd.currentSource == source)
+ abortDrag();
+}
+
+void CWLDataDeviceProtocol::setSelection(SP<IDataSource> source) {
+ for (auto& o : m_vOffers) {
+ if (o->source && o->source->hasDnd())
+ continue;
+ o->dead = true;
+ }
+
+ if (!source) {
+ LOGM(LOG, "resetting selection");
+
+ if (!g_pSeatManager->state.keyboardFocusResource)
+ return;
+
+ auto DESTDEVICE = dataDeviceForClient(g_pSeatManager->state.keyboardFocusResource->client());
+ if (DESTDEVICE)
+ sendSelectionToDevice(DESTDEVICE, nullptr);
+
+ return;
+ }
+
+ LOGM(LOG, "New selection for data source {:x}", (uintptr_t)source.get());
+
+ if (!g_pSeatManager->state.keyboardFocusResource)
+ return;
+
+ auto DESTDEVICE = dataDeviceForClient(g_pSeatManager->state.keyboardFocusResource->client());
+
+ if (!DESTDEVICE) {
+ LOGM(LOG, "CWLDataDeviceProtocol::setSelection: cannot send selection to a client without a data_device");
+ return;
+ }
+
+ sendSelectionToDevice(DESTDEVICE, source);
+}
+
+void CWLDataDeviceProtocol::updateSelection() {
+ if (!g_pSeatManager->state.keyboardFocusResource)
+ return;
+
+ auto DESTDEVICE = dataDeviceForClient(g_pSeatManager->state.keyboardFocusResource->client());
+
+ if (!DESTDEVICE) {
+ LOGM(LOG, "CWLDataDeviceProtocol::onKeyboardFocus: cannot send selection to a client without a data_device");
+ return;
+ }
+
+ sendSelectionToDevice(DESTDEVICE, g_pSeatManager->selection.currentSelection.lock());
+}
+
+void CWLDataDeviceProtocol::onKeyboardFocus() {
+ for (auto& o : m_vOffers) {
+ o->dead = true;
+ }
+
+ updateSelection();
+ updateDrag();
+}
+
+void CWLDataDeviceProtocol::initiateDrag(WP<CWLDataSourceResource> currentSource, wlr_surface* dragSurface, wlr_surface* origin) {
+
+ if (dnd.currentSource) {
+ LOGM(WARN, "New drag started while old drag still active??");
+ abortDrag();
+ }
+
+ g_pInputManager->setCursorImageUntilUnset("grabbing");
+ dnd.overriddenCursor = true;
+
+ LOGM(LOG, "initiateDrag: source {:x}, surface: {:x}, origin: {:x}", (uintptr_t)currentSource.get(), (uintptr_t)dragSurface, (uintptr_t)origin);
+
+ currentSource->used = true;
+
+ dnd.currentSource = currentSource;
+ dnd.originSurface = origin;
+ dnd.dndSurface = dragSurface;
+ dnd.hyprListener_dndSurfaceDestroy.initCallback(
+ &dragSurface->events.destroy, [this](void* owner, void* data) { abortDrag(); }, nullptr, "CWLDataDeviceProtocol::drag");
+ dnd.hyprListener_dndSurfaceCommit.initCallback(
+ &dragSurface->events.commit,
+ [this](void* owner, void* data) {
+ if (dnd.dndSurface->pending.buffer_width > 0 && dnd.dndSurface->pending.buffer_height > 0 && !dnd.dndSurface->mapped) {
+ wlr_surface_map(dnd.dndSurface);
+ return;
+ }
+
+ if (dnd.dndSurface->pending.buffer_width <= 0 && dnd.dndSurface->pending.buffer_height <= 0 && dnd.dndSurface->mapped) {
+ wlr_surface_unmap(dnd.dndSurface);
+ return;
+ }
+ },
+ nullptr, "CWLDataDeviceProtocol::drag");
+
+ dnd.mouseButton = g_pHookSystem->hookDynamic("mouseButton", [this](void* self, SCallbackInfo& info, std::any e) {
+ auto E = std::any_cast<IPointer::SButtonEvent>(e);
+ if (E.state == WL_POINTER_BUTTON_STATE_RELEASED) {
+ LOGM(LOG, "Dropping drag on mouseUp");
+ dropDrag();
+ }
+ });
+
+ dnd.touchUp = g_pHookSystem->hookDynamic("touchUp", [this](void* self, SCallbackInfo& info, std::any e) {
+ LOGM(LOG, "Dropping drag on touchUp");
+ dropDrag();
+ });
+
+ dnd.mouseMove = g_pHookSystem->hookDynamic("mouseMove", [this](void* self, SCallbackInfo& info, std::any e) {
+ auto V = std::any_cast<const Vector2D>(e);
+ if (dnd.focusedDevice && g_pSeatManager->state.keyboardFocus) {
+ auto surf = CWLSurface::surfaceFromWlr(g_pSeatManager->state.keyboardFocus);
+
+ if (!surf)
+ return;
+
+ const auto box = surf->getSurfaceBoxGlobal();
+
+ if (!box.has_value())
+ return;
+
+ dnd.focusedDevice->sendMotion(0 /* this is a hack */, V - box->pos());
+ LOGM(LOG, "Drag motion {}", V - box->pos());
+ }
+ });
+
+ dnd.touchMove = g_pHookSystem->hookDynamic("touchMove", [this](void* self, SCallbackInfo& info, std::any e) {
+ auto E = std::any_cast<ITouch::SMotionEvent>(e);
+ if (dnd.focusedDevice && g_pSeatManager->state.keyboardFocus) {
+ auto surf = CWLSurface::surfaceFromWlr(g_pSeatManager->state.keyboardFocus);
+
+ if (!surf)
+ return;
+
+ const auto box = surf->getSurfaceBoxGlobal();
+
+ if (!box.has_value())
+ return;
+
+ dnd.focusedDevice->sendMotion(E.timeMs, E.pos);
+ LOGM(LOG, "Drag motion {}", E.pos);
+ }
+ });
+
+ // make a new offer, etc
+ updateDrag();
+}
+
+void CWLDataDeviceProtocol::updateDrag() {
+ if (!dnd.currentSource)
+ return;
+
+ if (dnd.focusedDevice)
+ dnd.focusedDevice->sendLeave();
+
+ if (!g_pSeatManager->state.keyboardFocusResource)
+ return;
+
+ dnd.focusedDevice = dataDeviceForClient(g_pSeatManager->state.keyboardFocusResource->client());
+
+ if (!dnd.focusedDevice)
+ return;
+
+ // make a new offer
+ const auto OFFER = m_vOffers.emplace_back(
+ makeShared<CWLDataOfferResource>(makeShared<CWlDataOffer>(dnd.focusedDevice->resource->client(), dnd.focusedDevice->resource->version(), 0), dnd.currentSource.lock()));
+
+ if (!OFFER->good()) {
+ dnd.currentSource->resource->noMemory();
+ m_vOffers.pop_back();
+ return;
+ }
+
+ LOGM(LOG, "New dnd offer {:x} for data source {:x}", (uintptr_t)OFFER.get(), (uintptr_t)dnd.currentSource.get());
+
+ dnd.focusedDevice->sendDataOffer(OFFER);
+ OFFER->sendData();
+ dnd.focusedDevice->sendEnter(wl_display_next_serial(g_pCompositor->m_sWLDisplay), g_pSeatManager->state.keyboardFocus,
+ Vector2D{g_pSeatManager->state.keyboardFocus->current.width, g_pSeatManager->state.keyboardFocus->current.height} / 2.F, OFFER);
+}
+
+void CWLDataDeviceProtocol::resetDndState() {
+ dnd.dndSurface = nullptr;
+ dnd.hyprListener_dndSurfaceDestroy.removeCallback();
+ dnd.hyprListener_dndSurfaceCommit.removeCallback();
+ dnd.mouseButton.reset();
+ dnd.mouseMove.reset();
+ dnd.touchUp.reset();
+ dnd.touchMove.reset();
+}
+
+void CWLDataDeviceProtocol::dropDrag() {
+ if (!dnd.focusedDevice || !dnd.currentSource) {
+ if (dnd.currentSource)
+ abortDrag();
+ return;
+ }
+
+ dnd.currentSource->sendDndDropPerformed();
+ dnd.focusedDevice->sendDrop();
+ dnd.focusedDevice->sendLeave();
+
+ resetDndState();
+
+ if (dnd.overriddenCursor)
+ g_pInputManager->unsetCursorImage();
+ dnd.overriddenCursor = false;
+}
+
+void CWLDataDeviceProtocol::completeDrag() {
+ resetDndState();
+
+ if (!dnd.focusedDevice || !dnd.currentSource)
+ return;
+
+ dnd.currentSource->sendDndFinished();
+
+ dnd.focusedDevice.reset();
+ dnd.currentSource.reset();
+
+ g_pSeatManager->resendEnterEvents();
+}
+
+void CWLDataDeviceProtocol::abortDrag() {
+ resetDndState();
+
+ if (dnd.overriddenCursor)
+ g_pInputManager->unsetCursorImage();
+ dnd.overriddenCursor = false;
+
+ if (!dnd.focusedDevice || !dnd.currentSource)
+ return;
+
+ dnd.focusedDevice->sendLeave();
+ dnd.currentSource->cancelled();
+
+ dnd.focusedDevice.reset();
+ dnd.currentSource.reset();
+
+ g_pSeatManager->resendEnterEvents();
+}
+
+void CWLDataDeviceProtocol::renderDND(CMonitor* pMonitor, timespec* when) {
+ if (!dnd.dndSurface || !wlr_surface_get_texture(dnd.dndSurface))
+ return;
+
+ const auto POS = g_pInputManager->getMouseCoordsInternal();
+
+ CBox box = CBox{POS, {dnd.dndSurface->current.width, dnd.dndSurface->current.height}}
+ .translate(-pMonitor->vecPosition + g_pPointerManager->cursorSizeLogical() / 2.F)
+ .scale(pMonitor->scale);
+ g_pHyprOpenGL->renderTexture(wlr_surface_get_texture(dnd.dndSurface), &box, 1.F);
+
+ box = CBox{POS, {dnd.dndSurface->current.width, dnd.dndSurface->current.height}}.translate(g_pPointerManager->cursorSizeLogical() / 2.F);
+ g_pHyprRenderer->damageBox(&box);
+
+ wlr_surface_send_frame_done(dnd.dndSurface, when);
+}
+
+bool CWLDataDeviceProtocol::dndActive() {
+ return dnd.currentSource;
+}
diff --git a/src/protocols/core/DataDevice.hpp b/src/protocols/core/DataDevice.hpp
new file mode 100644
index 00000000..3112b720
--- /dev/null
+++ b/src/protocols/core/DataDevice.hpp
@@ -0,0 +1,194 @@
+#pragma once
+
+/*
+ Implementations for:
+ - wl_data_offer
+ - wl_data_source
+ - wl_data_device
+ - wl_data_device_manager
+*/
+
+#include <memory>
+#include <vector>
+#include <cstdint>
+#include "../WaylandProtocol.hpp"
+#include <wayland-server-protocol.h>
+#include "wayland.hpp"
+#include "../../helpers/signal/Signal.hpp"
+#include "../../helpers/Vector2D.hpp"
+#include "../types/DataDevice.hpp"
+
+class CWLDataDeviceResource;
+class CWLDataDeviceManagerResource;
+class CWLDataSourceResource;
+class CWLDataOfferResource;
+
+class CMonitor;
+
+class CWLDataOfferResource {
+ public:
+ CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_);
+
+ bool good();
+ void sendData();
+
+ WP<IDataSource> source;
+
+ bool dead = false;
+ bool accepted = false;
+ bool recvd = false;
+
+ uint32_t actions = 0;
+
+ private:
+ SP<CWlDataOffer> resource;
+ wl_client* pClient = nullptr;
+
+ friend class CWLDataDeviceResource;
+};
+
+class CWLDataSourceResource : public IDataSource {
+ public:
+ CWLDataSourceResource(SP<CWlDataSource> resource_, SP<CWLDataDeviceResource> device_);
+ ~CWLDataSourceResource();
+ static SP<CWLDataSourceResource> fromResource(wl_resource*);
+
+ bool good();
+
+ 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);
+
+ void sendDndDropPerformed();
+ void sendDndFinished();
+ void sendDndAction(wl_data_device_manager_dnd_action a);
+
+ bool used = false;
+ bool dnd = false;
+ bool dndSuccess = false;
+
+ WP<CWLDataDeviceResource> device;
+ WP<CWLDataSourceResource> self;
+
+ std::vector<std::string> mimeTypes;
+ uint32_t actions = 0;
+
+ private:
+ SP<CWlDataSource> resource;
+ wl_client* pClient = nullptr;
+
+ friend class CWLDataDeviceProtocol;
+};
+
+class CWLDataDeviceResource {
+ public:
+ CWLDataDeviceResource(SP<CWlDataDevice> resource_);
+
+ bool good();
+ wl_client* client();
+
+ void sendDataOffer(SP<CWLDataOfferResource> offer);
+ void sendEnter(uint32_t serial, wlr_surface* surf, const Vector2D& local, SP<CWLDataOfferResource> offer);
+ void sendLeave();
+ void sendMotion(uint32_t timeMs, const Vector2D& local);
+ void sendDrop();
+ void sendSelection(SP<CWLDataOfferResource> offer);
+
+ WP<CWLDataDeviceResource> self;
+
+ private:
+ SP<CWlDataDevice> resource;
+ wl_client* pClient = nullptr;
+
+ friend class CWLDataDeviceProtocol;
+};
+
+class CWLDataDeviceManagerResource {
+ public:
+ CWLDataDeviceManagerResource(SP<CWlDataDeviceManager> resource_);
+
+ bool good();
+
+ WP<CWLDataDeviceResource> device;
+ std::vector<WP<CWLDataSourceResource>> sources;
+
+ private:
+ SP<CWlDataDeviceManager> resource;
+};
+
+class CWLDataDeviceProtocol : public IWaylandProtocol {
+ public:
+ CWLDataDeviceProtocol(const wl_interface* iface, const int& ver, const std::string& name);
+
+ virtual void bindManager(wl_client* client, void* data, uint32_t ver, uint32_t id);
+
+ // renders and damages the dnd icon, if present
+ void renderDND(CMonitor* pMonitor, timespec* when);
+ // for inputmgr to force refocus
+ // TODO: move handling to seatmgr
+ bool dndActive();
+
+ private:
+ void destroyResource(CWLDataDeviceManagerResource* resource);
+ void destroyResource(CWLDataDeviceResource* resource);
+ void destroyResource(CWLDataSourceResource* resource);
+ void destroyResource(CWLDataOfferResource* resource);
+
+ //
+ std::vector<SP<CWLDataDeviceManagerResource>> m_vManagers;
+ std::vector<SP<CWLDataDeviceResource>> m_vDevices;
+ std::vector<SP<CWLDataSourceResource>> m_vSources;
+ std::vector<SP<CWLDataOfferResource>> m_vOffers;
+
+ //
+
+ void onDestroyDataSource(WP<CWLDataSourceResource> source);
+ void setSelection(SP<IDataSource> source);
+ void sendSelectionToDevice(SP<CWLDataDeviceResource> dev, SP<IDataSource> sel);
+ void updateSelection();
+ void onKeyboardFocus();
+
+ struct {
+ WP<CWLDataDeviceResource> focusedDevice;
+ WP<CWLDataSourceResource> currentSource;
+ wlr_surface* dndSurface = nullptr;
+ wlr_surface* originSurface = nullptr; // READ-ONLY
+ bool overriddenCursor = false;
+ DYNLISTENER(dndSurfaceDestroy);
+ DYNLISTENER(dndSurfaceCommit);
+
+ // for ending a dnd
+ SP<HOOK_CALLBACK_FN> mouseMove;
+ SP<HOOK_CALLBACK_FN> mouseButton;
+ SP<HOOK_CALLBACK_FN> touchUp;
+ SP<HOOK_CALLBACK_FN> touchMove;
+ } dnd;
+
+ void abortDrag();
+ void initiateDrag(WP<CWLDataSourceResource> currentSource, wlr_surface* dragSurface, wlr_surface* origin);
+ void updateDrag();
+ void dropDrag();
+ void completeDrag();
+ void resetDndState();
+
+ //
+ SP<CWLDataDeviceResource> dataDeviceForClient(wl_client*);
+
+ friend class CSeatManager;
+ friend class CWLDataDeviceManagerResource;
+ friend class CWLDataDeviceResource;
+ friend class CWLDataSourceResource;
+ friend class CWLDataOfferResource;
+
+ struct {
+ CHyprSignalListener onKeyboardFocusChange;
+ } listeners;
+};
+
+namespace PROTO {
+ inline UP<CWLDataDeviceProtocol> data;
+};
diff --git a/src/protocols/types/DataDevice.cpp b/src/protocols/types/DataDevice.cpp
new file mode 100644
index 00000000..47cbda8b
--- /dev/null
+++ b/src/protocols/types/DataDevice.cpp
@@ -0,0 +1,17 @@
+#include "DataDevice.hpp"
+
+bool IDataSource::hasDnd() {
+ return false;
+}
+
+bool IDataSource::dndDone() {
+ return false;
+}
+
+bool IDataSource::used() {
+ return wasUsed;
+}
+
+void IDataSource::markUsed() {
+ wasUsed = true;
+}
diff --git a/src/protocols/types/DataDevice.hpp b/src/protocols/types/DataDevice.hpp
new file mode 100644
index 00000000..98a97c14
--- /dev/null
+++ b/src/protocols/types/DataDevice.hpp
@@ -0,0 +1,29 @@
+#pragma once
+
+#include <string>
+#include <vector>
+#include <cstdint>
+#include "../../helpers/signal/Signal.hpp"
+
+class IDataSource {
+ public:
+ IDataSource() {}
+ virtual ~IDataSource() {}
+
+ virtual std::vector<std::string> mimes() = 0;
+ virtual void send(const std::string& mime, uint32_t fd) = 0;
+ virtual void accepted(const std::string& mime) = 0;
+ virtual void cancelled() = 0;
+ virtual bool hasDnd();
+ virtual bool dndDone();
+ virtual bool used();
+ virtual void markUsed();
+ virtual void error(uint32_t code, const std::string& msg) = 0;
+
+ struct {
+ CSignal destroy;
+ } events;
+
+ private:
+ bool wasUsed = false;
+};
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index 1aa246fb..c5c87ea1 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -12,6 +12,7 @@
#include "../protocols/LayerShell.hpp"
#include "../protocols/XDGShell.hpp"
#include "../protocols/PresentationTime.hpp"
+#include "../protocols/core/DataDevice.hpp"
extern "C" {
#include <xf86drm.h>
@@ -1806,19 +1807,7 @@ void CHyprRenderer::damageMirrorsWith(CMonitor* pMonitor, const CRegion& pRegion
}
void CHyprRenderer::renderDragIcon(CMonitor* pMonitor, timespec* time) {
- if (!(g_pInputManager->m_sDrag.dragIcon && g_pInputManager->m_sDrag.iconMapped && g_pInputManager->m_sDrag.dragIcon->surface))
- return;
-
- SRenderData renderdata = {pMonitor, time, g_pInputManager->m_sDrag.pos.x, g_pInputManager->m_sDrag.pos.y};
- renderdata.surface = g_pInputManager->m_sDrag.dragIcon->surface;
- renderdata.w = g_pInputManager->m_sDrag.dragIcon->surface->current.width;
- renderdata.h = g_pInputManager->m_sDrag.dragIcon->surface->current.height;
-
- wlr_surface_for_each_surface(g_pInputManager->m_sDrag.dragIcon->surface, renderSurface, &renderdata);
-
- CBox box = {g_pInputManager->m_sDrag.pos.x - 2, g_pInputManager->m_sDrag.pos.y - 2, g_pInputManager->m_sDrag.dragIcon->surface->current.width + 4,
- g_pInputManager->m_sDrag.dragIcon->surface->current.height + 4};
- g_pHyprRenderer->damageBox(&box);
+ PROTO::data->renderDND(pMonitor, time);
}
DAMAGETRACKINGMODES CHyprRenderer::damageTrackingModeFromStr(const std::string& mode) {
@@ -2500,7 +2489,7 @@ void CHyprRenderer::recheckSolitaryForMonitor(CMonitor* pMonitor) {
const auto PWORKSPACE = pMonitor->activeWorkspace;
- if (!PWORKSPACE || !PWORKSPACE->m_bHasFullscreenWindow || g_pInputManager->m_sDrag.drag || pMonitor->activeSpecialWorkspace || PWORKSPACE->m_fAlpha.value() != 1.f ||
+ if (!PWORKSPACE || !PWORKSPACE->m_bHasFullscreenWindow || PROTO::data->dndActive() || pMonitor->activeSpecialWorkspace || PWORKSPACE->m_fAlpha.value() != 1.f ||
PWORKSPACE->m_vRenderOffset.value() != Vector2D{})
return;