dotnet / wpf

WPF is a .NET Core UI framework for building Windows desktop applications.
MIT License
7.08k stars 1.17k forks source link

Stylus.SetIsPressAndHoldEnabled does not work when Switch.System.Windows.Input.Stylus.EnablePointerSupport is enabled #5939

Open aquinn39 opened 2 years ago

aquinn39 commented 2 years ago
lindexi commented 2 years ago

The Initialize method in System.Windows.Interop.HwndSource will check the StylusLogic.IsPointerStackEnabled as the code:

            if (StylusLogic.IsStylusAndTouchSupportEnabled)
            {
                // Choose between Wisp and Pointer stacks
                if (StylusLogic.IsPointerStackEnabled)
                {
                    // Enable the pointer support.
                    _stylus = new SecurityCriticalDataClass<IStylusInputProvider>(new HwndPointerInputProvider(this));
                }
                else
                {
                    _stylus = new SecurityCriticalDataClass<IStylusInputProvider>(new HwndStylusInputProvider(this));
                }
            }

Before enable the pointer support, it will enter the logic of HwndStylusInputProvider. And the HwndStylusInputProvider will return the flags when receive the WM_TABLET_QUERYSYSTEMGESTURESTATUS message in Hook.

       private IntPtr Hook(IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam, ref bool handled)
        {
            const int WM_TABLET_DEFBASE =0x02C0;
            const int WM_TABLET_QUERYSYSTEMGESTURESTATUS = WM_TABLET_DEFBASE + 12;
            const int WM_TABLET_FLICK = WM_TABLET_DEFBASE + 11;

            if (msg == WM_TABLET_QUERYSYSTEMGESTURESTATUS)
            {
                uint flags = 0;

                flags |= TABLET_PRESSANDHOLD_DISABLED;
                flags |= TABLET_TAPFEEDBACK_DISABLED;
                flags |= TABLET_TOUCHUI_FORCEON;
                flags |= TABLET_TOUCHUI_FORCEOFF;
                flags |= TABLET_FLICKS_DISABLED;

                handled = true;
                return new IntPtr(flags);
            }
            else if (msg == WM_TABLET_FLICK)
            {
                handled = true;
                return new IntPtr(1);
            }

            return IntPtr.Zero;
        }

        private const uint TABLET_PRESSANDHOLD_DISABLED = 0x00000001;
        private const uint TABLET_TAPFEEDBACK_DISABLED = 0x00000008;
        private const uint TABLET_TOUCHUI_FORCEON = 0x00000100;
        private const uint TABLET_TOUCHUI_FORCEOFF = 0x00000200;
        private const uint TABLET_FLICKS_DISABLED = 0x00010000;

But it will do nothing, although we add the hook manually, when we enable the pointer support.

See https://github.com/dotnet/wpf/issues/3379

bastio84 commented 1 year ago

Hello! Are there any news on this? We are facing the same problem: we cannot figure out how to disable the right click press-and-hold behavior when we have Switch.System.Windows.Input.Stylus.EnablePointerSupport enabled. Thanks a lot in advance for any help!

lindexi commented 1 year ago

@bastio84 Seems like the Windows limitation

lindexi commented 12 months ago

@bastio84 I find the soluction, see https://github.com/dotnet/wpf/issues/3379#issuecomment-1819092721