[AppKit] Create a better binding for [NSEvent eventWithGCEvent:]. (#20362)

Create a better binding for `[NSEvent eventWithGCEvent:]` by binding it as
`NSEvent.Create(CGEvent)` instead of `NSEvent.EventWithGCEvent(IntPtr)`.

Partial fix for https://github.com/xamarin/xamarin-macios/issues/12650.
This commit is contained in:
Rolf Bjarne Kvinge 2024-03-25 08:30:27 +01:00 коммит произвёл GitHub
Родитель a150c6068c
Коммит 5f442fbc88
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
3 изменённых файлов: 36 добавлений и 0 удалений

Просмотреть файл

@ -13,6 +13,15 @@ namespace AppKit {
[DebuggerTypeProxy (typeof (NSEvent.NSEventDebuggerProxy))]
public partial class NSEvent {
/// <summary>Create a new <see cref="AppKit.NSEvent" /> using the specified <see cref="CoreGraphics.CGEvent" />.</summary>
/// <param name="event">The <see cref="CoreGraphics.CGEvent" /> that will be wrapped.</param>
/// <returns>The newly created <see cref="AppKit.NSEvent" />.</returns>
/// <remarks>This method will return null if there's no corresponding Cocoa event.</remarks>
public static NSEvent? Create (CGEvent @event)
{
return EventWithCGEvent (@event.GetNonNullHandle (nameof (@event)));
}
class NSEventDebuggerProxy {
NSEvent target;

Просмотреть файл

@ -7956,6 +7956,10 @@ namespace AppKit {
[Static]
[Export ("eventWithCGEvent:")]
[Obsolete ("Use 'Create (CGEvent)' instead.")]
#if XAMCORE_5_0
[Internal]
#endif
NSEvent EventWithCGEvent (IntPtr cgEventPtr);
[Export ("magnification")]

Просмотреть файл

@ -0,0 +1,23 @@
#if __MACOS__
using NUnit.Framework;
using System;
using AppKit;
using CoreGraphics;
using Foundation;
using ObjCRuntime;
namespace Xamarin.Mac.Tests {
[TestFixture]
[Preserve (AllMembers = true)]
public class NSEventTests {
[Test]
public void Create ()
{
using var cgevent = new CGEvent (null, (ushort) 1, true);
using var nsevent = NSEvent.Create (cgevent);
Assert.AreEqual ((int) cgevent.EventType, (int) nsevent.Type, "[Event]Type");
}
}
}
#endif // __MACOS__