Skip to content

Commit 96f5f3b

Browse files
committed
Use SendInput for resync
1 parent 1321361 commit 96f5f3b

File tree

3 files changed

+86
-37
lines changed

3 files changed

+86
-37
lines changed
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
using System;
2+
using System.Numerics;
3+
using System.Runtime.InteropServices;
4+
using OpenTabletDriver.Plugin.Platform.Display;
5+
6+
namespace VoiDPlugins.OutputMode
7+
{
8+
[StructLayout(LayoutKind.Sequential)]
9+
public struct INPUT
10+
{
11+
public INPUT_TYPE type;
12+
public MOUSEINPUT mouse;
13+
public static int Size => Marshal.SizeOf(typeof(INPUT));
14+
}
15+
16+
[StructLayout(LayoutKind.Sequential)]
17+
public struct MOUSEINPUT
18+
{
19+
public int dx;
20+
public int dy;
21+
public uint mouseData;
22+
public MOUSEEVENTF dwFlags;
23+
public uint time;
24+
public UIntPtr dwExtraInfo;
25+
}
26+
27+
public enum MOUSEEVENTF : uint
28+
{
29+
ABSOLUTE = 0x8000,
30+
MOVE = 0x0001,
31+
VIRTUALDESK = 0x4000,
32+
LEFTDOWN = 0x0002,
33+
LEFTUP = 0x0004,
34+
MIDDLEDOWN = 0x0020,
35+
MIDDLEUP = 0x0040,
36+
RIGHTDOWN = 0x0008,
37+
RIGHTUP = 0x0010,
38+
XDOWN = 0x0080,
39+
XUP = 0x0100,
40+
MOVE_NOCOALESCE = 0x2000
41+
}
42+
43+
public enum INPUT_TYPE
44+
{
45+
MOUSE_INPUT,
46+
KEYBD_INPUT,
47+
HARDWARE_INPUT
48+
}
49+
50+
public class ThinOSPointer
51+
{
52+
private readonly Vector2 _conversion;
53+
private readonly INPUT[] _inputs = new INPUT[]
54+
{
55+
new INPUT
56+
{
57+
type = INPUT_TYPE.MOUSE_INPUT,
58+
mouse = new MOUSEINPUT
59+
{
60+
time = 0,
61+
dwExtraInfo = UIntPtr.Zero
62+
}
63+
}
64+
};
65+
66+
public ThinOSPointer(IVirtualScreen screen)
67+
{
68+
_conversion = new Vector2(screen.Width, screen.Height) / 65535;
69+
}
70+
71+
public void SetPosition(Vector2 pos)
72+
{
73+
var converted = pos / _conversion;
74+
75+
_inputs[0].mouse.dwFlags = MOUSEEVENTF.ABSOLUTE | MOUSEEVENTF.MOVE | MOUSEEVENTF.VIRTUALDESK;
76+
_inputs[0].mouse.dx = (int)converted.X;
77+
_inputs[0].mouse.dy = (int)converted.Y;
78+
_ = SendInput(1, _inputs, INPUT.Size);
79+
}
80+
81+
[DllImport("user32.dll")]
82+
private static extern uint SendInput(uint nInputs, [MarshalAs(UnmanagedType.LPArray), In] INPUT[] pInputs, int cbSize);
83+
}
84+
}

src/OutputMode/WindowsInk/Pointer/ThinVMultiAbsPointer.cs

Lines changed: 0 additions & 29 deletions
This file was deleted.

src/OutputMode/WindowsInk/Pointer/WinInkBasePointer.cs

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,18 @@ namespace VoiDPlugins.OutputMode
1313
public unsafe abstract class WinInkBasePointer : IPressureHandler, ITiltHandler, IEraserHandler, ISynchronousPointer
1414
{
1515
private readonly IVirtualScreen _screen;
16-
private ThinVMultiAbsPointer? _osPointer;
16+
private ThinOSPointer? _osPointer;
1717
private Vector2 _internalPos;
1818
protected DigitizerInputReport* RawPointer { get; }
1919
protected VMultiInstance<DigitizerInputReport> Instance { get; }
2020
protected SharedStore SharedStore { get; }
2121
protected bool Dirty { get; set; }
2222

23-
[Property("Sync")]
24-
[ToolTip("Synchronize OS cursor with Windows Ink's current position when pen goes out of range.")]
25-
[DefaultPropertyValue(true)]
2623
public bool Sync
2724
{
28-
set => _osPointer = value ? new ThinVMultiAbsPointer(_screen) : null;
25+
set => _osPointer = value ? new ThinOSPointer(_screen) : null;
2926
}
3027

31-
[Property("Forced Sync")]
32-
[ToolTip("If this and \"Sync\" is enabled, the OS cursor will always be resynced with Windows Ink's current position.")]
33-
[DefaultPropertyValue(false)]
3428
public bool ForcedSync { get; set; }
3529

3630
public WinInkBasePointer(string name, TabletReference tabletReference, IVirtualScreen screen)

0 commit comments

Comments
 (0)