Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP - CSWin32 in tablet usecase #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
global using SR = MS.Internal.PresentationCore.SR;

global using DllImport = MS.Internal.PresentationCore.DllImport;
global using Windows.Win32;
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using System.Runtime.InteropServices;
using WinInputPointer = Windows.Win32.UI.Input.Pointer;

namespace MS.Win32.Pointer
{
Expand Down Expand Up @@ -515,7 +516,7 @@ internal struct INTERACTION_CONTEXT_OUTPUT
#region Imports

#region WM_POINTER

/*
/// <summary>
/// Gets the list of pointer devices currently installed on the system. Analogous to TabletDevice for WPF.
/// </summary>
Expand Down Expand Up @@ -575,7 +576,7 @@ internal struct INTERACTION_CONTEXT_OUTPUT
/// </summary>
[DllImport(DllImport.User32, EntryPoint = "GetRawPointerDeviceData", SetLastError = true)]
internal static extern bool GetRawPointerDeviceData([In] UInt32 pointerId, [In] UInt32 historyCount, [In] UInt32 propertiesCount, [In] POINTER_DEVICE_PROPERTY[] pProperties, [In, Out] int[] pValues);

*/
#endregion

#region Interaction
Expand Down Expand Up @@ -637,6 +638,15 @@ internal struct INTERACTION_CONTEXT_OUTPUT
[DllImport(DllImport.NInput, EntryPoint = "BufferPointerPacketsInteractionContext", SetLastError = true, PreserveSig = false)]
internal static extern void BufferPointerPacketsInteractionContext([In] IntPtr interactionContext, [In] UInt32 entriesCount, [In] POINTER_INFO[] pointerInfo);

/// <summary>
/// Adds a WM_POINTER POINTER_INFO structure to the buffer of unprocessed WM_POINTER messages waiting
/// </summary>
/// <param name="interactionContext"></param>
/// <param name="entriesCount"></param>
/// <param name="pointerInfo"></param>
[DllImport(DllImport.NInput, EntryPoint = "BufferPointerPacketsInteractionContext", SetLastError = true, PreserveSig = false)]
internal static extern void BufferPointerPacketsInteractionContext([In] IntPtr interactionContext, [In] UInt32 entriesCount, [In] WinInputPointer.POINTER_INFO[] pointerInfo);

/// <summary>
/// Forces processing of the buffered WM_POINTER messages.
/// </summary>
Expand Down
11 changes: 11 additions & 0 deletions src/Microsoft.DotNet.Wpf/src/PresentationCore/NativeMethods.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"$schema": "https://aka.ms/CsWin32.schema.json",
"className": "PInvokeCore",
"allowMarshaling": true,
"useSafeHandles": false,
"comInterop": {
"preserveSigMethods": [
"*"
]
}
}
10 changes: 10 additions & 0 deletions src/Microsoft.DotNet.Wpf/src/PresentationCore/NativeMethods.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
GetPointerDevices
GetPointerDeviceCursors
GetPointerInfo
GetPointerInfoHistory
GetPointerDeviceProperties
GetPointerDeviceRects
GetPointerCursorId
GetPointerPenInfo
GetPointerTouchInfo
GetRawPointerDeviceData
Original file line number Diff line number Diff line change
Expand Up @@ -1425,6 +1425,7 @@
<PackageReference Include="System.Windows.Extensions" Version="$(SystemWindowsExtensionsPackageVersion)" />
<PackageReference Include="$(SystemIOPackagingPackage)" Version="$(SystemIOPackagingVersion)" />
<PackageReference Include="System.Formats.Nrbf" Version="$(SystemFormatsNrbfVersion)" />
<PackageReference Include="Microsoft.Windows.CsWin32" Version="$(MicrosoftWindowsCsWin32PackageVersion)" PrivateAssets="all" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using static MS.Win32.Pointer.UnsafeNativeMethods;
// using static MS.Win32.Pointer.UnsafeNativeMethods;
using WinPointer = Windows.Win32.UI.Input.Pointer;
using WinPointerInput = Windows.Win32.UI.WindowsAndMessaging;

namespace System.Windows.Input.StylusPointer
{
Expand All @@ -17,22 +19,22 @@ internal class PointerData
/// <summary>
/// Standard pointer information
/// </summary>
private POINTER_INFO _info;
private WinPointer.POINTER_INFO _info;

/// <summary>
/// Pointer information specific to a touch device
/// </summary>
private POINTER_TOUCH_INFO _touchInfo;
private WinPointer.POINTER_TOUCH_INFO _touchInfo;

/// <summary>
/// Pointer information specific to a pen device
/// </summary>
private POINTER_PEN_INFO _penInfo;
private WinPointer.POINTER_PEN_INFO _penInfo;

/// <summary>
/// The full history available for the current pointer (used for coalesced input)
/// </summary>
private POINTER_INFO[] _history;
private WinPointer.POINTER_INFO[] _history;

#endregion

Expand All @@ -46,7 +48,7 @@ internal class PointerData
/// <summary>
/// Standard pointer information
/// </summary>
internal POINTER_INFO Info
internal WinPointer.POINTER_INFO Info
{
get
{
Expand All @@ -57,7 +59,7 @@ internal POINTER_INFO Info
/// <summary>
/// Pointer information specific to a touch device
/// </summary>
internal POINTER_TOUCH_INFO TouchInfo
internal WinPointer.POINTER_TOUCH_INFO TouchInfo
{
get
{
Expand All @@ -68,7 +70,7 @@ internal POINTER_TOUCH_INFO TouchInfo
/// <summary>
/// Pointer information specific to a pen device
/// </summary>
internal POINTER_PEN_INFO PenInfo
internal WinPointer.POINTER_PEN_INFO PenInfo
{
get
{
Expand All @@ -79,7 +81,7 @@ internal POINTER_PEN_INFO PenInfo
/// <summary>
/// The full history available for the current pointer (used for coalesced input)
/// </summary>
internal POINTER_INFO[] History
internal WinPointer.POINTER_INFO[] History
{
get
{
Expand All @@ -96,31 +98,38 @@ internal POINTER_INFO[] History
/// it locally.
/// </summary>
/// <param name="pointerId">The id of the pointer message</param>
internal PointerData(uint pointerId)
internal unsafe PointerData(uint pointerId)
{
if (IsValid = GetPointerInfo(pointerId, ref _info))
if (IsValid = PInvokeCore.GetPointerInfo(pointerId, out _info))
{
_history = new POINTER_INFO[_info.historyCount];
_history = new WinPointer.POINTER_INFO[_info.historyCount];

// Fill the pointer history
// If we fail just return a blank history
if (!GetPointerInfoHistory(pointerId, ref _info.historyCount, _history))
bool isSuccessful = true;

fixed (WinPointer.POINTER_INFO* ptrHistory = _history)
{
_history = Array.Empty<POINTER_INFO>();
// Fill the pointer history
// If we fail just return a blank history
if (!PInvokeCore.GetPointerInfoHistory(pointerId, ref _info.historyCount, ptrHistory))
{
isSuccessful = false;
}
}

if(!isSuccessful) _history = Array.Empty<WinPointer.POINTER_INFO>();

switch (_info.pointerType)
{
case POINTER_INPUT_TYPE.PT_TOUCH:
case WinPointerInput.POINTER_INPUT_TYPE.PT_TOUCH:
{
// If we have a touch device, pull the touch specific information down
IsValid &= GetPointerTouchInfo(pointerId, ref _touchInfo);
IsValid &= PInvokeCore.GetPointerTouchInfo(pointerId, out _touchInfo);
}
break;
case POINTER_INPUT_TYPE.PT_PEN:
case WinPointerInput.POINTER_INPUT_TYPE.PT_PEN:
{
// Otherwise we have a pen device, so pull down pen specific information
IsValid &= GetPointerPenInfo(pointerId, ref _penInfo);
IsValid &= PInvokeCore.GetPointerPenInfo(pointerId, out _penInfo);
}
break;
default:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.


using MS.Win32.Pointer;
using System.Windows.Media;
using WinInputPointer = Windows.Win32.UI.Input.Pointer;

namespace System.Windows.Input.StylusPointer
{
Expand Down Expand Up @@ -241,7 +242,7 @@ internal void Update(RawStylusInputReport rsir)
try
{
// Queue up the latest message for processing
UnsafeNativeMethods.BufferPointerPacketsInteractionContext(_interactionContext, 1, new UnsafeNativeMethods.POINTER_INFO[] { _stylusDevice.CurrentPointerInfo });
UnsafeNativeMethods.BufferPointerPacketsInteractionContext(_interactionContext, 1, new WinInputPointer.POINTER_INFO[] { _stylusDevice.CurrentPointerInfo });

// Hover processing should occur directly from message receipt.
// Do this prior to the IC engine processing so HoverEnter/Leave has priority.
Expand Down
Loading