Browse Source

Xdnd: handle rejected drop in process

pull/20926/head
Julien Lebosquain 6 months ago
parent
commit
d5702c6a24
No known key found for this signature in database GPG Key ID: 1833CAD10ACC46FD
  1. 35
      src/Avalonia.X11/Selections/DragDrop/X11DragSource.cs

35
src/Avalonia.X11/Selections/DragDrop/X11DragSource.cs

@ -183,7 +183,11 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
if (target is { } newTarget) if (target is { } newTarget)
{ {
if (newTarget.InProcessWindow is { } window) if (newTarget.InProcessWindow is { } window)
ProcessRawDragEvent(window, RawDragEventType.DragEnter, rootPosition, modifiers); {
var effects = ProcessRawDragEvent(window, RawDragEventType.DragEnter, rootPosition, modifiers);
_targetCanAcceptDrop = effects != DragDropEffects.None;
UpdateCurrentEffects(effects);
}
else else
SendXdndEnter(newTarget); SendXdndEnter(newTarget);
} }
@ -192,7 +196,11 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
if (target is { } currentTarget) if (target is { } currentTarget)
{ {
if (currentTarget.InProcessWindow is { } window) if (currentTarget.InProcessWindow is { } window)
ProcessRawDragEvent(window, RawDragEventType.DragOver, rootPosition, modifiers); {
var effects = ProcessRawDragEvent(window, RawDragEventType.DragOver, rootPosition, modifiers);
_targetCanAcceptDrop = effects != DragDropEffects.None;
UpdateCurrentEffects(effects);
}
else else
{ {
var action = XdndActionHelper.EffectsToAction(effectiveAllowedEffects, _platform.Info.Atoms); var action = XdndActionHelper.EffectsToAction(effectiveAllowedEffects, _platform.Info.Atoms);
@ -213,9 +221,19 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
var rootPosition = new PixelPoint(button.x_root, button.y_root); var rootPosition = new PixelPoint(button.x_root, button.y_root);
var modifiers = button.state.ToRawInputModifiers(); var modifiers = button.state.ToRawInputModifiers();
ProcessRawDragEvent(lastTarget.InProcessWindow, RawDragEventType.Drop, rootPosition, modifiers); if (_targetCanAcceptDrop)
{
var effects = ProcessRawDragEvent(lastTarget.InProcessWindow, RawDragEventType.Drop, rootPosition, modifiers);
UpdateCurrentEffects(effects);
}
else
{
ProcessRawDragEvent(lastTarget.InProcessWindow, RawDragEventType.DragLeave, rootPosition, modifiers);
UpdateCurrentEffects(DragDropEffects.None);
}
_lastTarget = null; _lastTarget = null;
_targetCanAcceptDrop = false;
Complete(_currentEffects); Complete(_currentEffects);
} }
else else
@ -259,6 +277,7 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
return; return;
_lastTarget = null; _lastTarget = null;
_targetCanAcceptDrop = false;
DisposeTimeoutManager(); DisposeTimeoutManager();
if (lastTarget.Version >= 5) if (lastTarget.Version >= 5)
@ -404,17 +423,14 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
XFlush(_platform.Display); XFlush(_platform.Display);
} }
private void ProcessRawDragEvent( private DragDropEffects ProcessRawDragEvent(
X11Window targetWindow, X11Window targetWindow,
RawDragEventType eventType, RawDragEventType eventType,
PixelPoint rootPosition, PixelPoint rootPosition,
RawInputModifiers modifiers) RawInputModifiers modifiers)
{ {
if (targetWindow.DragDropDevice is not { } dragDropDevice) if (targetWindow.DragDropDevice is not { } dragDropDevice)
{ return DragDropEffects.None;
UpdateCurrentEffects(DragDropEffects.None);
return;
}
var localPosition = targetWindow.PointToClient(rootPosition); var localPosition = targetWindow.PointToClient(rootPosition);
var effectiveAllowedEffects = GetEffectiveAllowedEffects(modifiers.ToKeyModifiers()); var effectiveAllowedEffects = GetEffectiveAllowedEffects(modifiers.ToKeyModifiers());
@ -430,7 +446,7 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
dragDropDevice.ProcessRawEvent(dragEvent); dragDropDevice.ProcessRawEvent(dragEvent);
UpdateCurrentEffects(dragEvent.Effects & _allowedEffects); return dragEvent.Effects & _allowedEffects;
} }
private void UngrabPointer() private void UngrabPointer()
@ -511,6 +527,7 @@ internal sealed class X11DragSource(AvaloniaX11Platform platform) : IPlatformDra
} }
_lastTarget = null; _lastTarget = null;
_targetCanAcceptDrop = false;
_currentEffects = DragDropEffects.None; _currentEffects = DragDropEffects.None;
DisposeTimeoutManager(); DisposeTimeoutManager();

Loading…
Cancel
Save