Skip to content

Commit

Permalink
API for pressure-sensitive pens + XInput2/Wayland
Browse files Browse the repository at this point in the history
This patch adds an API for querying pressure-
sensitive pens, cf. SDL_pen.h:
- Enumerate all pens
- Get pen capabilities, names, GUIDs
- Distinguishes pens and erasers
- Distinguish attached and detached pens
- Pressure and tilt support
- Rotation, distance, throttle wheel support
  (throttle wheel untested)
- Pen type and meta-information reporting
  (partially tested)

Pen event reporting:
- Three new event structures: PenTip, PenMotion, and
  PenButton
- Report location with sub-pixel precision
- Include axis and button status, is-eraser flag

Internal pen tracker, intended to be independent
of platform APIs, cf. SDL_pen_c.h:
- Track known pens
- Handle pen hotplugging

Automatic test:
- testautomation_pen.c

Other features:
- XInput2 implementation, incl. hotplugging
- Wayland implementation, incl. hotplugging
- Backward compatibility: pen events default to
  emulating pens with mouse ID SDL_PEN_MOUSEID
- Can be toggled via SDL_HINT_PEN_NOT_MOUSE
- Test/demo program (testpen)
- Wacom pen feature identification by pen ID

Acknowledgements:
- Ping Cheng (Wacom) provided extensive feedback
  on Wacom pen features and detection so that
  hopefully untested Wacom devices have a
  realistic chance of working out of the box.
  • Loading branch information
creichen committed Aug 26, 2023
1 parent 3b1d1e4 commit 7e2ddcc
Show file tree
Hide file tree
Showing 36 changed files with 5,830 additions and 244 deletions.
2 changes: 2 additions & 0 deletions VisualC-GDK/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_gl2ext.h" />
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_gl2platform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_khrplatform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_pen.h" />
<ClInclude Include="..\..\include\SDL3\SDL_pixels.h" />
<ClInclude Include="..\..\include\SDL3\SDL_platform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_platform_defines.h" />
Expand Down Expand Up @@ -578,6 +579,7 @@
<ClCompile Include="..\..\src\events\SDL_events.c" />
<ClCompile Include="..\..\src\events\SDL_keyboard.c" />
<ClCompile Include="..\..\src\events\SDL_mouse.c" />
<ClCompile Include="..\..\src\events\SDL_pen.c" />
<ClCompile Include="..\..\src\events\SDL_quit.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" />
<ClCompile Include="..\..\src\events\SDL_windowevents.c" />
Expand Down
6 changes: 6 additions & 0 deletions VisualC-GDK/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_khrplatform.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_pen.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_pixels.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -904,6 +907,9 @@
<ClCompile Include="..\..\src\events\SDL_mouse.c">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\src\events\SDL_pen.c">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\src\events\SDL_quit.c">
<Filter>events</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions VisualC-WinRT/SDL-UWP.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
<ClInclude Include="..\include\SDL3\SDL_mouse.h" />
<ClInclude Include="..\include\SDL3\SDL_mutex.h" />
<ClInclude Include="..\include\SDL3\SDL_opengles2.h" />
<ClInclude Include="..\include\SDL3\SDL_pen.h" />
<ClInclude Include="..\include\SDL3\SDL_pixels.h" />
<ClInclude Include="..\include\SDL3\SDL_platform.h" />
<ClInclude Include="..\include\SDL3\SDL_platform_defines.h" />
Expand Down Expand Up @@ -296,6 +297,7 @@
<ClCompile Include="..\src\events\SDL_events.c" />
<ClCompile Include="..\src\events\SDL_keyboard.c" />
<ClCompile Include="..\src\events\SDL_mouse.c" />
<ClCompile Include="..\src\events\SDL_pen.c" />
<ClCompile Include="..\src\events\SDL_quit.c" />
<ClCompile Include="..\src\events\SDL_touch.c" />
<ClCompile Include="..\src\events\SDL_windowevents.c" />
Expand Down
6 changes: 6 additions & 0 deletions VisualC-WinRT/SDL-UWP.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,9 @@
<ClInclude Include="..\include\SDL3\SDL_opengles2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_pen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL3\SDL_pixels.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -519,6 +522,9 @@
<ClCompile Include="..\src\events\SDL_mouse.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\events\SDL_pen.c">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="..\src\events\SDL_quit.c">
<Filter>Source Files</Filter>
</ClCompile>
Expand Down
2 changes: 2 additions & 0 deletions VisualC/SDL/SDL.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_gl2ext.h" />
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_gl2platform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_khrplatform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_pen.h" />
<ClInclude Include="..\..\include\SDL3\SDL_pixels.h" />
<ClInclude Include="..\..\include\SDL3\SDL_platform.h" />
<ClInclude Include="..\..\include\SDL3\SDL_platform_defines.h" />
Expand Down Expand Up @@ -497,6 +498,7 @@
<ClCompile Include="..\..\src\events\SDL_events.c" />
<ClCompile Include="..\..\src\events\SDL_keyboard.c" />
<ClCompile Include="..\..\src\events\SDL_mouse.c" />
<ClCompile Include="..\..\src\events\SDL_pen.c" />
<ClCompile Include="..\..\src\events\SDL_quit.c" />
<ClCompile Include="..\..\src\events\SDL_touch.c" />
<ClCompile Include="..\..\src\events\SDL_windowevents.c" />
Expand Down
6 changes: 6 additions & 0 deletions VisualC/SDL/SDL.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,9 @@
<ClInclude Include="..\..\include\SDL3\SDL_opengles2_khrplatform.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_pen.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL3\SDL_pixels.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -883,6 +886,9 @@
<ClCompile Include="..\..\src\events\SDL_mouse.c">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\src\events\SDL_pen.c">
<Filter>events</Filter>
</ClCompile>
<ClCompile Include="..\..\src\events\SDL_quit.c">
<Filter>events</Filter>
</ClCompile>
Expand Down
6 changes: 6 additions & 0 deletions VisualC/tests/testautomation/testautomation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,12 @@
<ClCompile Include="..\..\..\test\testautomation_main.c" />
<ClCompile Include="..\..\..\test\testautomation_math.c" />
<ClCompile Include="..\..\..\test\testautomation_mouse.c" />
<ClCompile Include="..\..\..\test\testautomation_pen.c">
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">$(ProjectDir)\..\..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">$(ProjectDir)\..\..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">$(ProjectDir)\..\..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories Condition="'$(Configuration)|$(Platform)'=='Release|x64'">$(ProjectDir)\..\..\..\src;%(AdditionalIncludeDirectories)</AdditionalIncludeDirectories>
</ClCompile>
<ClCompile Include="..\..\..\test\testautomation_pixels.c" />
<ClCompile Include="..\..\..\test\testautomation_platform.c" />
<ClCompile Include="..\..\..\test\testautomation_rect.c" />
Expand Down
33 changes: 33 additions & 0 deletions Xcode/SDL/SDL.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,27 @@
00D0D0D810675E46004B05EF /* Carbon.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 007317C10858E15000B2BC32 /* Carbon.framework */; platformFilters = (macos, ); };
557D0CFA254586CA003913E3 /* CoreHaptics.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F37DC5F225350EBC0002E6F7 /* CoreHaptics.framework */; platformFilters = (ios, maccatalyst, macos, tvos, ); };
557D0CFB254586D7003913E3 /* GameController.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = A75FDABD23E28B6200529352 /* GameController.framework */; settings = {ATTRIBUTES = (Weak, ); }; };
63125C002A790B12008EF011 /* SDL_pen.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125BFF2A790B12008EF011 /* SDL_pen.h */; };
63125C012A790B12008EF011 /* SDL_pen.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125BFF2A790B12008EF011 /* SDL_pen.h */; };
63125C022A790B12008EF011 /* SDL_pen.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125BFF2A790B12008EF011 /* SDL_pen.h */; };
63125C0A2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C0B2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C0C2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C0D2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C0E2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C0F2A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C102A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C112A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C122A790B69008EF011 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63125C092A790B69008EF011 /* SDL_pen.c */; };
63125C142A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C152A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C162A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C172A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C182A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C192A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C1A2A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C1B2A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
63125C1C2A790B9A008EF011 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63125C132A790B9A008EF011 /* SDL_pen_c.h */; };
5616CA4C252BB2A6005D5928 /* SDL_url.c in Sources */ = {isa = PBXBuildFile; fileRef = 5616CA49252BB2A5005D5928 /* SDL_url.c */; };
5616CA4D252BB2A6005D5928 /* SDL_sysurl.h in Headers */ = {isa = PBXBuildFile; fileRef = 5616CA4A252BB2A6005D5928 /* SDL_sysurl.h */; };
5616CA4E252BB2A6005D5928 /* SDL_sysurl.m in Sources */ = {isa = PBXBuildFile; fileRef = 5616CA4B252BB2A6005D5928 /* SDL_sysurl.m */; };
Expand All @@ -49,6 +70,9 @@
566E26D8246274CC00718109 /* SDL_locale.c in Sources */ = {isa = PBXBuildFile; fileRef = 566E26CD246274CB00718109 /* SDL_locale.c */; };
566E26E1246274CC00718109 /* SDL_syslocale.h in Headers */ = {isa = PBXBuildFile; fileRef = 566E26CE246274CC00718109 /* SDL_syslocale.h */; };
56A2373329F9C113003CCA5F /* SDL_sysrwlock.c in Sources */ = {isa = PBXBuildFile; fileRef = 56A2373229F9C113003CCA5F /* SDL_sysrwlock.c */; };
63134A222A7902CF0021E9A6 /* SDL_pen.h in Headers */ = {isa = PBXBuildFile; fileRef = 63134A212A7902CF0021E9A6 /* SDL_pen.h */; };
63134A252A7902FD0021E9A6 /* SDL_pen_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 63134A232A7902FD0021E9A6 /* SDL_pen_c.h */; };
63134A262A7902FD0021E9A6 /* SDL_pen.c in Sources */ = {isa = PBXBuildFile; fileRef = 63134A242A7902FD0021E9A6 /* SDL_pen.c */; };
75E0915A241EA924004729E1 /* SDL_virtualjoystick.c in Sources */ = {isa = PBXBuildFile; fileRef = 75E09158241EA924004729E1 /* SDL_virtualjoystick.c */; };
75E09163241EA924004729E1 /* SDL_virtualjoystick_c.h in Headers */ = {isa = PBXBuildFile; fileRef = 75E09159241EA924004729E1 /* SDL_virtualjoystick_c.h */; };
9846B07C287A9020000C35C8 /* SDL_hidapi_shield.c in Sources */ = {isa = PBXBuildFile; fileRef = 9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */; };
Expand Down Expand Up @@ -506,6 +530,9 @@
566E26CD246274CB00718109 /* SDL_locale.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; name = SDL_locale.c; path = locale/SDL_locale.c; sourceTree = "<group>"; };
566E26CE246274CC00718109 /* SDL_syslocale.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_syslocale.h; path = locale/SDL_syslocale.h; sourceTree = "<group>"; };
56A2373229F9C113003CCA5F /* SDL_sysrwlock.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_sysrwlock.c; sourceTree = "<group>"; };
63134A212A7902CF0021E9A6 /* SDL_pen.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = SDL_pen.h; path = SDL3/SDL_pen.h; sourceTree = "<group>"; };
63134A232A7902FD0021E9A6 /* SDL_pen_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_pen_c.h; sourceTree = "<group>"; };
63134A242A7902FD0021E9A6 /* SDL_pen.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_pen.c; sourceTree = "<group>"; };
75E09158241EA924004729E1 /* SDL_virtualjoystick.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_virtualjoystick.c; sourceTree = "<group>"; };
75E09159241EA924004729E1 /* SDL_virtualjoystick_c.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SDL_virtualjoystick_c.h; sourceTree = "<group>"; };
9846B07B287A9020000C35C8 /* SDL_hidapi_shield.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = SDL_hidapi_shield.c; sourceTree = "<group>"; };
Expand Down Expand Up @@ -1027,6 +1054,7 @@
F3F7D8BD2933074A00816151 /* SDL_opengles2_gl2ext.h */,
F3F7D8C92933074B00816151 /* SDL_opengles2_gl2platform.h */,
F3F7D8B12933074900816151 /* SDL_opengles2_khrplatform.h */,
63134A212A7902CF0021E9A6 /* SDL_pen.h */,
F3F7D8B52933074A00816151 /* SDL_pixels.h */,
F3F7D8AB2933074900816151 /* SDL_platform.h */,
F3B38CCB296E2E52005DA6D3 /* SDL_platform_defines.h */,
Expand Down Expand Up @@ -1971,6 +1999,8 @@
A7D8A93823E2514000DCD162 /* SDL_keyboard.c */,
A7D8A92B23E2514000DCD162 /* SDL_mouse_c.h */,
A7D8A92A23E2514000DCD162 /* SDL_mouse.c */,
63134A232A7902FD0021E9A6 /* SDL_pen_c.h */,
63134A242A7902FD0021E9A6 /* SDL_pen.c */,
A7D8A93C23E2514000DCD162 /* SDL_quit.c */,
A7D8A93723E2514000DCD162 /* SDL_touch_c.h */,
A7D8A93E23E2514000DCD162 /* SDL_touch.c */,
Expand Down Expand Up @@ -2257,6 +2287,8 @@
A7D8B3D423E2514300DCD162 /* yuv_rgb.h in Headers */,
A7D8B3C823E2514200DCD162 /* yuv_rgb_sse_func.h in Headers */,
A7D8B3CE23E2514300DCD162 /* yuv_rgb_std_func.h in Headers */,
63134A222A7902CF0021E9A6 /* SDL_pen.h in Headers */,
63134A252A7902FD0021E9A6 /* SDL_pen_c.h in Headers */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -2568,6 +2600,7 @@
A7D8AEA023E2514100DCD162 /* SDL_cocoavulkan.m in Sources */,
A7D8AB6123E2514100DCD162 /* SDL_offscreenwindow.c in Sources */,
566E26D8246274CC00718109 /* SDL_locale.c in Sources */,
63134A262A7902FD0021E9A6 /* SDL_pen.c in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
Loading

0 comments on commit 7e2ddcc

Please sign in to comment.