summaryrefslogtreecommitdiff
path: root/src/protocols/core/DataDevice.cpp
diff options
context:
space:
mode:
authornyx <nnyyxxxx@protonmail.com>2025-02-23 21:52:10 -0500
committerGitHub <noreply@github.com>2025-02-24 03:52:10 +0100
commit3458d7ac93a101ea534ef6d0bcbc32725e267045 (patch)
tree0f1f5d39c59a152e7b01610010d9d0a3005fcc05 /src/protocols/core/DataDevice.cpp
parente59464629fd1b0bdc4505786b8186d759933933c (diff)
xwayland: improve dnd and cleanup (#9405)
Minor changes to xwayland dnd / regular dnd to fix various issues --------- Co-authored-by: Vaxry <vaxry@vaxry.net>
Diffstat (limited to 'src/protocols/core/DataDevice.cpp')
-rw-r--r--src/protocols/core/DataDevice.cpp62
1 files changed, 37 insertions, 25 deletions
diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp
index 25117265..f4044ec5 100644
--- a/src/protocols/core/DataDevice.cpp
+++ b/src/protocols/core/DataDevice.cpp
@@ -13,6 +13,7 @@
#include "../../managers/HookSystemManager.hpp"
#include "../../helpers/Monitor.hpp"
#include "../../render/Renderer.hpp"
+#include "../../xwayland/Dnd.hpp"
using namespace Hyprutils::OS;
CWLDataOfferResource::CWLDataOfferResource(SP<CWlDataOffer> resource_, SP<IDataSource> source_) : source(source_), resource(resource_) {
@@ -689,7 +690,7 @@ void CWLDataDeviceProtocol::updateDrag() {
g_pSeatManager->state.dndPointerFocus->current.size / 2.F, offer);
}
-void CWLDataDeviceProtocol::resetDndState() {
+void CWLDataDeviceProtocol::cleanupDndState(bool resetDevice, bool resetSource, bool simulateInput) {
dnd.dndSurface.reset();
dnd.dndSurfaceCommit.reset();
dnd.dndSurfaceDestroy.reset();
@@ -697,6 +698,16 @@ void CWLDataDeviceProtocol::resetDndState() {
dnd.mouseMove.reset();
dnd.touchUp.reset();
dnd.touchMove.reset();
+
+ if (resetDevice)
+ dnd.focusedDevice.reset();
+ if (resetSource)
+ dnd.currentSource.reset();
+
+ if (simulateInput) {
+ g_pInputManager->simulateMouseMovement();
+ g_pSeatManager->resendEnterEvents();
+ }
}
void CWLDataDeviceProtocol::dropDrag() {
@@ -712,21 +723,31 @@ void CWLDataDeviceProtocol::dropDrag() {
}
dnd.focusedDevice->sendDrop();
- dnd.focusedDevice->sendLeave();
- resetDndState();
+#ifndef NO_XWAYLAND
+ if (dnd.focusedDevice->getX11()) {
+ dnd.focusedDevice->sendLeave();
+ if (dnd.overriddenCursor)
+ g_pInputManager->unsetCursorImage();
+ dnd.overriddenCursor = false;
+ cleanupDndState(true, true, true);
+ return;
+ }
+#endif
+ dnd.focusedDevice->sendLeave();
if (dnd.overriddenCursor)
g_pInputManager->unsetCursorImage();
dnd.overriddenCursor = false;
+ cleanupDndState(false, false, false);
}
bool CWLDataDeviceProtocol::wasDragSuccessful() {
- if (!dnd.focusedDevice || !dnd.currentSource)
+ if (!dnd.currentSource)
return false;
for (auto const& o : m_vOffers) {
- if (o->dead || !o->source || !o->source->hasDnd())
+ if (o->dead || o->source != dnd.currentSource)
continue;
if (o->recvd || o->accepted)
@@ -734,25 +755,14 @@ bool CWLDataDeviceProtocol::wasDragSuccessful() {
}
#ifndef NO_XWAYLAND
- if (g_pXWayland->pWM) {
- for (auto const& o : g_pXWayland->pWM->dndDataOffers) {
- if (o->dead || !o->source || !o->source->hasDnd())
- continue;
-
- if (o->source != dnd.currentSource)
- continue;
-
- return true;
- }
- }
+ if (dnd.focusedDevice->getX11())
+ return true;
#endif
return false;
}
void CWLDataDeviceProtocol::completeDrag() {
- resetDndState();
-
if (!dnd.focusedDevice && !dnd.currentSource)
return;
@@ -761,15 +771,11 @@ void CWLDataDeviceProtocol::completeDrag() {
dnd.currentSource->sendDndFinished();
}
- dnd.focusedDevice.reset();
- dnd.currentSource.reset();
-
- g_pInputManager->simulateMouseMovement();
- g_pSeatManager->resendEnterEvents();
+ cleanupDndState(true, true, true);
}
void CWLDataDeviceProtocol::abortDrag() {
- resetDndState();
+ cleanupDndState(false, false, false);
if (dnd.overriddenCursor)
g_pInputManager->unsetCursorImage();
@@ -778,8 +784,14 @@ void CWLDataDeviceProtocol::abortDrag() {
if (!dnd.focusedDevice && !dnd.currentSource)
return;
- if (dnd.focusedDevice)
+ if (dnd.focusedDevice) {
+#ifndef NO_XWAYLAND
+ if (auto x11Device = dnd.focusedDevice->getX11(); x11Device)
+ x11Device->forceCleanupDnd();
+#endif
dnd.focusedDevice->sendLeave();
+ }
+
if (dnd.currentSource)
dnd.currentSource->cancelled();