AvaloniaUI / Avalonia

Develop Desktop, Embedded, Mobile and WebAssembly apps with C# and XAML. The most popular .NET UI client technology
https://avaloniaui.net
MIT License
25.91k stars 2.24k forks source link

Pointer events on NativeControl #5256

Open redbaty opened 3 years ago

redbaty commented 3 years ago

Describe the bug Pointer events doesnt work properly on NativeControlHost, is it by design?

To Reproduce Go to the NativeEmbedSample, override or subscribe to the "OnPointerEnter" event, but it never gets called.

Expected behavior The event is called whenever the pointer enters the control area.

Desktop (please complete the following information):

Additional context If it is by design, is there another way to find if the pointer is hovering the NativeControlHost area?

kekekeks commented 3 years ago

Pointer events get intercepted by the native control, I believe. Please, check if WPF's HwndHost fires pointer enter/leave events. If it doesn't then it's by design, if it does, we might be able to do something about that.

redbaty commented 3 years ago

It can be done on HwndHost but it requires you to either use WndProc and parse the messages, or to create a host window for the control, but I have no idea how these will work on Linux.

I'll do some testing later today and post my findings.

redbaty commented 3 years ago

Sorry for the delay following this up, apparently it can be done by parsing window messages (or x11 events). On Win32Platform and X11Platform there is already a loop/event-handling method, but there isn't a way to "hook" into it, but if there was we could either let the user parse the messages themselves, or handle it inside the "DumbWindow" control and fire up the events.

Maybe we could create an "IPlatformEvent" interface to provide a way to parse messages.

kekekeks commented 3 years ago

For Win32 you can already use SetWindowLong(Ptr) with GWL_WNDPROC to intercept any messages sent to a particular HWND.

For Linux I'm not sure that the messages you are looking for are actually being sent to our message loop at all since your native control is running its own event loop. It's possible, however, to use XOpenDisplay to open a separate X11 connection and then use XSelectInput to get notifications for any XID.

Regarding the API. I'm not quite sure how it should look like. For Windows we'll probably have something like HwndSourceHook. However in case of Linux there are actually two XIDs involved, the outer window and the inner render window (we had to do that to make resize smoother). Which one should we install the hook for?

For macOS it becomes even weirder since Cocoa doesn't communicate with us with events and calls various stuff on our NSWindow/NSView subclasses. There is NSEvent and a way to intercept it from NSApplication, however I'm not sure how much worth is that.

Aurumaker72 commented 1 year ago

For Win32 you can already use SetWindowLong(Ptr) with GWL_WNDPROC to intercept any messages sent to a particular HWND.

I have verified this with two methods:

Neither method worked.

jgcodes2020 commented 1 year ago

I did some more testing with this. On Windows:

On X11:

jgcodes2020 commented 1 year ago

@kekekeks would this be possible to setup a spec issue for? If we have a spec, it can be implemented.

alvanrahimli commented 8 months ago

Has anyone managed to do something about this? Does setting window input-transparent work now?

sandsc commented 7 months ago

Same issue for me, can't receive events on X11, has anyone have updates on this?

etkramer commented 6 months ago

Fwiw setting HTTRANSPARENT doesn't pass the input through to the NativeControlHost itself, but if you wrap it in another control that one will get the pointer events (if its background is set to something non-null ofc)