-
Notifications
You must be signed in to change notification settings - Fork 718
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(reg): Fix pointer capture broken on Firefox
- Loading branch information
Showing
7 changed files
with
117 additions
and
78 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,43 +1,42 @@ | ||
using System; | ||
using System.Linq; | ||
|
||
namespace Windows.Devices.Input | ||
namespace Windows.Devices.Input; | ||
|
||
internal readonly struct PointerIdentifier : IEquatable<PointerIdentifier> | ||
{ | ||
internal readonly struct PointerIdentifier : IEquatable<PointerIdentifier> | ||
{ | ||
private readonly long _uid; | ||
private readonly long _uid; | ||
|
||
public PointerIdentifier(PointerDeviceType type, uint id) | ||
{ | ||
_uid = (long)type << 32 | id; | ||
} | ||
public PointerIdentifier(PointerDeviceType type, uint id) | ||
{ | ||
_uid = (long)type << 32 | id; | ||
} | ||
|
||
public uint Id => unchecked((uint)(_uid & 0xFFFF_FFFF)); | ||
public uint Id => unchecked((uint)(_uid & 0xFFFF_FFFF)); | ||
|
||
public PointerDeviceType Type => unchecked((PointerDeviceType)(_uid >> 32)); | ||
public PointerDeviceType Type => unchecked((PointerDeviceType)(_uid >> 32)); | ||
|
||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
=> _uid.GetHashCode(); | ||
/// <inheritdoc /> | ||
public override int GetHashCode() | ||
=> _uid.GetHashCode(); | ||
|
||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
=> obj is PointerIdentifier other && Equals(this, other); | ||
/// <inheritdoc /> | ||
public override bool Equals(object obj) | ||
=> obj is PointerIdentifier other && Equals(this, other); | ||
|
||
/// <inheritdoc /> | ||
public bool Equals(PointerIdentifier other) | ||
=> Equals(this, other); | ||
/// <inheritdoc /> | ||
public bool Equals(PointerIdentifier other) | ||
=> Equals(this, other); | ||
|
||
private static bool Equals(PointerIdentifier left, PointerIdentifier right) | ||
=> left._uid == right._uid; | ||
private static bool Equals(PointerIdentifier left, PointerIdentifier right) | ||
=> left._uid == right._uid; | ||
|
||
public static bool operator ==(PointerIdentifier left, PointerIdentifier right) | ||
=> Equals(left, right); | ||
public static bool operator ==(PointerIdentifier left, PointerIdentifier right) | ||
=> Equals(left, right); | ||
|
||
public static bool operator !=(PointerIdentifier left, PointerIdentifier right) | ||
=> !Equals(left, right); | ||
public static bool operator !=(PointerIdentifier left, PointerIdentifier right) | ||
=> !Equals(left, right); | ||
|
||
public static implicit operator long(PointerIdentifier identifier) | ||
=> identifier._uid; | ||
} | ||
public static implicit operator long(PointerIdentifier identifier) | ||
=> identifier._uid; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using Uno.Foundation.Logging; | ||
|
||
namespace Windows.Devices.Input; | ||
|
||
internal static class PointerIdentifierPool | ||
{ | ||
private static readonly Dictionary<PointerIdentifier, PointerIdentifier> _nativeToManagedPointerId = new(); | ||
private static readonly Dictionary<PointerIdentifier, PointerIdentifier> _managedToNativePointerId = new(); | ||
private static uint _lastUsedId; | ||
|
||
public static PointerIdentifier RentManaged(PointerIdentifier nativeId) | ||
{ | ||
if (_nativeToManagedPointerId.TryGetValue(nativeId, out var managedId)) | ||
{ | ||
return managedId; | ||
} | ||
|
||
managedId = new PointerIdentifier(nativeId.Type, ++_lastUsedId); | ||
_managedToNativePointerId[managedId] = nativeId; | ||
_nativeToManagedPointerId[nativeId] = managedId; | ||
|
||
return managedId; | ||
} | ||
|
||
public static bool TryGetNative(PointerIdentifier managedId, out PointerIdentifier nativeId) | ||
=> _managedToNativePointerId.TryGetValue(managedId, out nativeId); | ||
|
||
public static void ReleaseManaged(PointerIdentifier managedId) | ||
{ | ||
if (_managedToNativePointerId.TryGetValue(managedId, out var nativeId)) | ||
{ | ||
_managedToNativePointerId.Remove(managedId); | ||
_nativeToManagedPointerId.Remove(nativeId); | ||
|
||
if (_managedToNativePointerId.Count == 0) | ||
{ | ||
_lastUsedId = 0; // We reset the pointer ID only when there is no active pointer. | ||
} | ||
} | ||
else if (typeof(PointerIdentifierPool).Log().IsEnabled(LogLevel.Warning)) | ||
{ | ||
typeof(PointerIdentifierPool).Log().Warn($"Received an invalid managed pointer id {managedId}"); | ||
} | ||
} | ||
} |