From 3381e2b55b9eaf8d30344c301aacfc664519688b Mon Sep 17 00:00:00 2001 From: Vaxry Date: Wed, 15 May 2024 16:25:56 +0100 Subject: [PATCH] datadevice: guard surface in dnd for null fixes #6076 --- src/protocols/core/DataDevice.cpp | 34 ++++++++++++++++--------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/src/protocols/core/DataDevice.cpp b/src/protocols/core/DataDevice.cpp index 2b9503b13..354259fe1 100644 --- a/src/protocols/core/DataDevice.cpp +++ b/src/protocols/core/DataDevice.cpp @@ -233,7 +233,7 @@ CWLDataDeviceResource::CWLDataDeviceResource(SP resource_) : reso source->dnd = true; - PROTO::data->initiateDrag(source, wlr_surface_from_resource(icon), wlr_surface_from_resource(origin)); + PROTO::data->initiateDrag(source, icon ? wlr_surface_from_resource(icon) : nullptr, wlr_surface_from_resource(origin)); }); } @@ -471,22 +471,24 @@ void CWLDataDeviceProtocol::initiateDrag(WP currentSource 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 (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"); + 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(e);