Repository: hyprwm/Hyprland
File: src/protocols/core/DataDevice.cpp (C++)

Code before:
    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();

    dnd.focusedDevice.reset();
    dnd.currentSource.reset();

    g_pInputManager->simulateMouseMovement();
    g_pSeatManager->resendEnterEvents();
}

void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, timespec* when) {
    if (!dnd.dndSurface || !dnd.dndSurface->current.texture)
        return;

    const auto POS     = g_pInputManager->getMouseCoordsInternal();
    const auto HOTSPOT = g_pPointerManager->cursorHotspot();

    Vector2D   surfacePos = POS - HOTSPOT;

    surfacePos += dnd.dndSurface->current.offset;

    CBox                         box = CBox{surfacePos, dnd.dndSurface->current.size}.translate(-pMonitor->vecPosition).scale(pMonitor->scale);

    CTexPassElement::SRenderData data;
    data.tex = dnd.dndSurface->current.texture;
    data.box = box;
    g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data));

    CBox damageBox = CBox{surfacePos, dnd.dndSurface->current.size}.expand(5);
    g_pHyprRenderer->damageBox(damageBox);

    dnd.dndSurface->frame(when);
}

bool CWLDataDeviceProtocol::dndActive() {
    return dnd.currentSource;
}

void CWLDataDeviceProtocol::abortDndIfPresent() {
    if (!dndActive())
        return;
    abortDrag();
}

Review comment (bug):
the logic here is wrong. 

>  Initially, the top-left corner of the icon surface is placed at the cursor hotspot

what you are doing is placing it at the top left of the cursor surface. This `- HOTSPOT` is wrong, and the entire fn `cursorHotspot` can be dropped.

Code after:
    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();

    dnd.focusedDevice.reset();
    dnd.currentSource.reset();

    g_pInputManager->simulateMouseMovement();
    g_pSeatManager->resendEnterEvents();
}

void CWLDataDeviceProtocol::renderDND(PHLMONITOR pMonitor, timespec* when) {
    if (!dnd.dndSurface || !dnd.dndSurface->current.texture)
        return;

    const auto POS = g_pInputManager->getMouseCoordsInternal();

    Vector2D   surfacePos = POS;

    surfacePos += dnd.dndSurface->current.offset;

    CBox                         box = CBox{surfacePos, dnd.dndSurface->current.size}.translate(-pMonitor->vecPosition).scale(pMonitor->scale);

    CTexPassElement::SRenderData data;
    data.tex = dnd.dndSurface->current.texture;
    data.box = box;
    g_pHyprRenderer->m_sRenderPass.add(makeShared<CTexPassElement>(data));

    CBox damageBox = CBox{surfacePos, dnd.dndSurface->current.size}.expand(5);
    g_pHyprRenderer->damageBox(damageBox);

    dnd.dndSurface->frame(when);
}

bool CWLDataDeviceProtocol::dndActive() {
    return dnd.currentSource;
}

void CWLDataDeviceProtocol::abortDndIfPresent() {
    if (!dndActive())
        return;
    abortDrag();
}