Avalonia icon indicating copy to clipboard operation
Avalonia copied to clipboard

Strange behavior of cursor after `PointerPressed` and `ShowDialog` (Linux)

Open Tulesha opened this issue 10 months ago • 1 comments

Describe the bug

When I catch PointerPressed event of InputElement (testing on TextBlock and ContentPresenter) and showing dialog window, I got strange behavior of pointer like it is still pointing to the InputElement.

To Reproduce

I define interface ILinkInfo which has method Navigate. In implementations of method I can navigate through application and opening windows:

public interface ILinkInfo
{
    void Navigate(PointerPressedEventArgs e);
}

public class LinkInfoDialog : ILinkInfo
{
    private readonly Window _ownerWindow;

    public LinkInfoDialog(Window ownerWindow)
    {
        _ownerWindow = ownerWindow;
    }

    public async void Navigate(PointerPressedEventArgs e)
    {
        if (e.KeyModifiers == KeyModifiers.Control)
        {
            // Show ContextMenu
            var contextMenu = new ContextMenu
            {
                Items = { new MenuItem { Header = "Menu1" }, new MenuItem { Header = "Menu2" } }
            };
            contextMenu.Open(e.Source as Control);
            return;
        }

        // Some kind of dialog
        var window = new Window
        {
            Width = 300,
            Height = 300,
            WindowStartupLocation = WindowStartupLocation.CenterOwner
        };
        await window.ShowDialog(_ownerWindow);
    }
}

public class LinkInfoSmth : ILinkInfo
{
    public LinkInfoSmth()
    {
    }

    public void Navigate(PointerPressedEventArgs e)
    {
        // Do smth
    }
}

I got Window.xaml with two TextBlock's which imitating Link behaviour:

<Window xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:vm="using:AvaloniaApplication1.ViewModels"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
        x:Class="AvaloniaApplication1.Views.MainWindow"
        x:DataType="vm:MainWindowViewModel"
        Icon="/Assets/avalonia-logo.ico"
        Title="AvaloniaApplication1">

    <Window.Styles>
        <Style Selector="TextBlock.hyperLink">
            <Setter Property="Foreground" Value="Aqua" />
            <Setter Property="Cursor" Value="Hand" />
            <Style Selector="^:pointerover">
                <Setter Property="TextDecorations" Value="Underline" />
            </Style>
        </Style>
    </Window.Styles>

    <StackPanel Orientation="Vertical" Spacing="5">
        <TextBlock Name="Link1"
                   Text="Link1"
                   FontSize="30"
                   Classes="hyperLink"
                   PointerPressed="Link_OnPointerPressed" />

        <TextBlock Name="Link2"
                   Text="Link2"
                   FontSize="30"
                   Classes="hyperLink"
                   PointerPressed="Link_OnPointerPressed" />
    </StackPanel>

</Window>

In code behind of MainWindow I catch PointerPressed event of TextBlock's and calling Navigate method of ILinkInfo:

public partial class MainWindow : Window
{
    private readonly ILinkInfo _linkInfo1;
    private readonly ILinkInfo _linkInfo2;

    public MainWindow()
    {
        InitializeComponent();

        _linkInfo1 = new LinkInfoDialog(this);
        _linkInfo2 = new LinkInfoSmth();
    }

    private void Link_OnPointerPressed(object? sender, PointerPressedEventArgs e)
    {
        if (!e.GetCurrentPoint(this).Properties.IsLeftButtonPressed)
            return;

        if (Equals(sender, Link1))
            _linkInfo1.Navigate(e);
        else
            _linkInfo2.Navigate(e);

        e.Handled = true;
    }
}

And when I'm click to the TextBlock, which open window, I getting behaviour of cursor like this: pointerover

It seems like application think that I'm steel pointed to the TextBlock.

I publish this code to GitHub repo

Expected behavior

InputElement should be not pointed after closing Window

Avalonia version

release: 11.0.10 night: 11.2.999-cibuild0047060-alpha

OS

Linux (Ubuntu 23.10)

Additional context

This is can be reproduce only on Linux. On Windows it handles like it should be.

I testing this behaviour on cathing Tapped event and I got right behaviour. But it this strange thing that I can't repoduce this in PointerPressed event handler. And also in my application I should use PointerPressed event to mark it handled if I navigate through application.

Tulesha avatar Apr 09 '24 08:04 Tulesha