From c2b2d0a92ab1ae39428891886488848a32ef0bcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Gro=C3=9F?= Date: Wed, 8 Dec 2021 00:40:44 +0100 Subject: [PATCH] Do not destroy drag after launchDrag() On X11 we need to keep the QDrag around a little longer. Right now, drag is scoped local to launchDrag() and will be destroyed immediately when launchDrag() finishes. However for X11 we must keep the drag object alive a little longer. It may only be destroyed once the drag operation has been accepted by another window, otherwise drag and drop is broken on Linux and no action happens when something is dragged from Telegram into another window. This is because there is still communication happening in the XDND protocol once QDrag::exec() finishes. See the documentation for reference: https://freedesktop.org/wiki/Specifications/XDND/ Fixes #17291 --- Telegram/SourceFiles/window/main_window.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Telegram/SourceFiles/window/main_window.cpp b/Telegram/SourceFiles/window/main_window.cpp index ec152fc16..73c49355b 100644 --- a/Telegram/SourceFiles/window/main_window.cpp +++ b/Telegram/SourceFiles/window/main_window.cpp @@ -964,7 +964,9 @@ int MainWindow::tryToExtendWidthBy(int addToWidth) { void MainWindow::launchDrag( std::unique_ptr data, Fn &&callback) { - auto drag = std::make_unique(this); + // Qt destroys this QDrag automatically after the drag is finished + // We must not delete this at the end of this function, as this breaks DnD on Linux + auto drag = new QDrag(this); drag->setMimeData(data.release()); drag->exec(Qt::CopyAction);