Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 25, 2025

Touch Input System Redesign - COMPLETED ✅

  • Create new gesture event argument classes (GestureEventArgs with subclasses for each gesture type)
  • Update ITouchControl interface to replace raw touch events with gesture events (Tap, Pan, Zoom, Rotate, TwoFingerTap, PressAndTap)
  • Add native gesture interop structures and methods to WinFormsUtils.NativeMethods.cs
  • Implement gesture message handling in WinFormsUtils.Touch.cs (replace raw touch handling with WM_GESTURE handling)
  • Update TouchForm.cs to implement new gesture events
  • Update TouchPanel.cs to implement new gesture events
  • Remove obsolete TouchEventArgs.cs file (replaced by gesture event args)
  • Code review and verification
  • Security check (no vulnerabilities found)
  • Use non-generic Marshal.SizeOf for .NET Framework compatibility

Summary

Successfully redesigned the touch input system from raw touch events to high-level Windows Touch Gestures. The implementation follows the Microsoft Windows classic samples and provides a clean, gesture-based API for WinForms applications on Windows 7+.

Key Changes:

  • Events: Replaced TouchDown, TouchUp, TouchMove with Pan, Zoom, Rotate, Tap, PressAndTap
  • Native Code: All gesture interop code is cleanly isolated in WinFormsUtils.Touch.cs
  • API Design: Each gesture has its own strongly-typed event args with relevant properties
  • Compatibility: Maintained API structure while switching underlying implementation, using non-generic Marshal.SizeOf for .NET Framework compatibility
Original prompt

This section details on the original issue you should resolve

<issue_title>Redesign touch input system</issue_title>
<issue_description>This project contains incomplete code for adding touch support to WinForms projects. This code lives in:

  • src/Common.WinForms/Controls/ITouchControl.cs
  • src/Common.WinForms/Controls/TouchForm.cs
  • src/Common.WinForms/Controls/TouchPanel.cs
  • src/Common.WinForms/Native/WinFormsUtils.Touch.cs

Currently it tries to represent raw touch events. We should redesign this to expose the higher-level Windows Touch Gestures instead.

Replace the delegates in ITouchControl and its implementations from TouchDown, TouchUp and TouchMove with Tap, Pan, Zoom, etc..

Look at https://github.com/microsoft/Windows-classic-samples/blob/main/Samples/Win7Samples/Touch/MTGestures/CS/MTGestures.cs for details how the native interop works.
In our own implementation we want to keep all the native code nicely isolated in WinFormsUtils.Touch.cs.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 2 commits December 25, 2025 21:11
- Replace raw touch events (TouchDown, TouchUp, TouchMove) with high-level gesture events (Pan, Zoom, Rotate, Tap, PressAndTap)
- Add GestureEventArgs classes for each gesture type
- Update ITouchControl interface to expose gesture events
- Replace touch input handling with WM_GESTURE message handling in WinFormsUtils.Touch.cs
- Add gesture-related native interop structures (GestureConfig, GestureInfo) and P/Invoke declarations
- Update TouchForm and TouchPanel to implement new gesture events
- Remove obsolete TouchEventArgs.cs file

Co-authored-by: bastianeicher <414366+bastianeicher@users.noreply.github.com>
- Add missing using System directive for Flags attribute
- Use Marshal.SizeOf<T>() instead of Marshal.SizeOf(new T()) to avoid allocations
- Add clarifying comment for RegisterGestureWindow API compatibility
- Add detailed comments explaining pan distance bit unpacking

Co-authored-by: bastianeicher <414366+bastianeicher@users.noreply.github.com>
Copilot AI changed the title [WIP] Redesign touch input system for WinForms projects Replace raw touch events with Windows Touch Gestures API Dec 25, 2025
Copilot AI requested a review from bastianeicher December 25, 2025 21:17
Copy link
Member

@bastianeicher bastianeicher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use the non-generic variant of Marshal.SizeOf, so that the code also compiles on .NET Framework.

Replace Marshal.SizeOf<T>() with Marshal.SizeOf(typeof(T)) to ensure compatibility with .NET Framework.

Co-authored-by: bastianeicher <414366+bastianeicher@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Dec 26, 2025

Use the non-generic variant of Marshal.SizeOf, so that the code also compiles on .NET Framework.

Changed to use Marshal.SizeOf(typeof(T)) instead of the generic variant in commit 49e8ed5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redesign touch input system

2 participants