| 662 | } |
| 663 | |
| 664 | DragDropEffect Window::DoDragDropWayland(const StringView& data, Window* dragSourceWindow, Float2 dragOffset) |
| 665 | { |
| 666 | // HACK: For drag-and-drop, we need to run another event queue in a separate thread to avoid racing issues |
| 667 | // while SDL is dispatching the main Wayland event queue when receiving the data offer from us. |
| 668 | |
| 669 | Engine::OnDraw(); |
| 670 | |
| 671 | if (WaylandImpl::DraggingActive) |
| 672 | LOG(Fatal, "Previous drag and drop operation was not finished"); |
| 673 | |
| 674 | // Read the latest serial code from mouse event, and check if we are still holding the mouse before committing |
| 675 | auto dragSerial = Platform::AtomicRead(&WaylandImpl::Serial); |
| 676 | SDLPlatform::Tick(); // Handle events to check for serial changes |
| 677 | |
| 678 | if (!Input::Mouse->GetButton(MouseButton::Left) || |
| 679 | dragSerial == 0 || |
| 680 | dragSerial != Platform::AtomicRead(&WaylandImpl::Serial)) |
| 681 | { |
| 682 | // The mouse up event was ignored earlier, release the button now |
| 683 | Input::Mouse->OnMouseUp(Platform::GetMousePosition(), MouseButton::Left, this); |
| 684 | |
| 685 | return DragDropEffect::None; |
| 686 | } |
| 687 | |
| 688 | WaylandImpl::DraggingActive = true; |
| 689 | WaylandImpl::DraggingData = StringView(data.Get(), data.Length()); |
| 690 | WaylandImpl::DragOverFlag = 0; |
| 691 | |
| 692 | auto task = New<WaylandImpl::DragDropJob>(); |
| 693 | task->Window = this; |
| 694 | task->DragSourceWindow = dragSourceWindow; // Needs to be the parent window when dragging a tab to window |
| 695 | task->DragOffset = dragOffset; |
| 696 | task->DragSerial = dragSerial; |
| 697 | Task::StartNew(task); |
| 698 | |
| 699 | while (Platform::AtomicRead(&task->StartFlag) == 0) |
| 700 | { |
| 701 | SDLPlatform::Tick(); |
| 702 | Platform::Sleep(1); |
| 703 | } |
| 704 | |
| 705 | while (Platform::AtomicRead(&WaylandImpl::DragOverFlag) == 0) |
| 706 | { |
| 707 | SDLPlatform::Tick(); |
| 708 | Engine::OnUpdate(); // For docking updates |
| 709 | Engine::OnDraw(); |
| 710 | |
| 711 | // The window needs to be finished showing up before we can start dragging it |
| 712 | if (IsVisible() && Platform::AtomicRead(&task->WaitFlag) == 0) |
| 713 | Platform::AtomicStore(&task->WaitFlag, 1); |
| 714 | |
| 715 | if (!WaylandImpl::DraggingWindow && !Input::Mouse->GetButton(MouseButton::Left)) |
| 716 | { |
| 717 | // Abort in case the dragging was interrupted before receiving any data offers |
| 718 | Platform::AtomicStore(&task->ExitFlag, 1); |
| 719 | break; |
| 720 | } |
| 721 |
nothing calls this directly
no test coverage detected