Skip to content

API for pressure-sensitive pens + XInput2 & Wayland implementations #5481

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

Closed
wants to merge 1 commit into from
Closed
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
1 change: 1 addition & 0 deletions Makefile.in
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ HDRS = \
SDL_opengles2_gl2platform.h \
SDL_opengles2.h \
SDL_opengles2_khrplatform.h \
SDL_pen.h \
SDL_pixels.h \
SDL_platform.h \
SDL_power.h \
Expand Down
2 changes: 1 addition & 1 deletion Makefile.os2
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ SRCS+= SDL_rwops.c SDL_power.c
SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SDL_wave.c
SRCS+= SDL_events.c SDL_quit.c SDL_keyboard.c SDL_mouse.c SDL_windowevents.c &
SDL_clipboardevents.c SDL_dropevents.c SDL_displayevents.c SDL_gesture.c &
SDL_sensor.c SDL_touch.c
SDL_pen.c SDL_sensor.c SDL_touch.c
SRCS+= SDL_haptic.c SDL_hidapi.c SDL_gamecontroller.c SDL_joystick.c controller_type.c
SRCS+= SDL_render.c yuv_rgb.c SDL_yuv.c SDL_yuv_sw.c SDL_blendfillrect.c &
SDL_blendline.c SDL_blendpoint.c SDL_drawline.c SDL_drawpoint.c &
Expand Down
2 changes: 1 addition & 1 deletion Makefile.w32
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ SRCS+= SDL_rwops.c SDL_power.c
SRCS+= SDL_audio.c SDL_audiocvt.c SDL_audiodev.c SDL_audiotypecvt.c SDL_mixer.c SDL_wave.c
SRCS+= SDL_events.c SDL_quit.c SDL_keyboard.c SDL_mouse.c SDL_windowevents.c &
SDL_clipboardevents.c SDL_dropevents.c SDL_displayevents.c SDL_gesture.c &
SDL_sensor.c SDL_touch.c
SDL_pen.c SDL_sensor.c SDL_touch.c
SRCS+= SDL_haptic.c SDL_hidapi.c SDL_gamecontroller.c SDL_joystick.c controller_type.c
SRCS+= SDL_render.c yuv_rgb.c SDL_yuv.c SDL_yuv_sw.c SDL_blendfillrect.c &
SDL_blendline.c SDL_blendpoint.c SDL_drawline.c SDL_drawpoint.c &
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 @@ -62,6 +62,7 @@
<ClInclude Include="..\include\SDL_mutex.h" />
<ClInclude Include="..\include\SDL_name.h" />
<ClInclude Include="..\include\SDL_opengles2.h" />
<ClInclude Include="..\include\SDL_pen.h" />
<ClInclude Include="..\include\SDL_pixels.h" />
<ClInclude Include="..\include\SDL_platform.h" />
<ClInclude Include="..\include\SDL_power.h" />
Expand Down Expand Up @@ -232,6 +233,7 @@
<ClCompile Include="..\src\events\SDL_gesture.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 @@ -111,6 +111,9 @@
<ClInclude Include="..\include\SDL_opengles2.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL_pen.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="..\include\SDL_pixels.h">
<Filter>Header Files</Filter>
</ClInclude>
Expand Down Expand Up @@ -525,6 +528,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 @@ -259,6 +259,7 @@
<ClInclude Include="..\..\include\SDL_opengles2_gl2ext.h" />
<ClInclude Include="..\..\include\SDL_opengles2_gl2platform.h" />
<ClInclude Include="..\..\include\SDL_opengles2_khrplatform.h" />
<ClInclude Include="..\..\include\SDL_pen.h" />
<ClInclude Include="..\..\include\SDL_pixels.h" />
<ClInclude Include="..\..\include\SDL_platform.h" />
<ClInclude Include="..\..\include\SDL_power.h" />
Expand Down Expand Up @@ -469,6 +470,7 @@
<ClCompile Include="..\..\src\events\SDL_gesture.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 @@ -303,6 +303,9 @@
<ClInclude Include="..\..\include\SDL_opengles2_khrplatform.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_pen.h">
<Filter>API Headers</Filter>
</ClInclude>
<ClInclude Include="..\..\include\SDL_pixels.h">
<Filter>API Headers</Filter>
</ClInclude>
Expand Down Expand Up @@ -909,6 +912,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
1 change: 1 addition & 0 deletions VisualC/tests/testautomation/testautomation.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@
<ClCompile Include="..\..\..\test\testautomation_main.c" />
<ClCompile Include="..\..\..\test\testautomation_math.c" />
<ClCompile Include="..\..\..\test\testautomation_mouse.c" />
<ClCompile Include="..\..\..\test\testautomation_pen.c" />
<ClCompile Include="..\..\..\test\testautomation_pixels.c" />
<ClCompile Include="..\..\..\test\testautomation_platform.c" />
<ClCompile Include="..\..\..\test\testautomation_rect.c" />
Expand Down
46 changes: 43 additions & 3 deletions include/SDL_events.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
#include "SDL_quit.h"
#include "SDL_gesture.h"
#include "SDL_touch.h"
#include "SDL_pen.h"

#include "begin_code.h"
/* Set up for C function definitions, even when using C++ */
Expand Down Expand Up @@ -158,6 +159,11 @@ typedef enum
/* Sensor events */
SDL_SENSORUPDATE = 0x1200, /**< A sensor was updated */

/* Pressure-sensitive pen events */
SDL_PENMOTION = 0x1300, /**< Pressure-sensitive pen moved, or change in angle/pressure changed */
SDL_PENBUTTONDOWN, /**< Pressure-sensitive pen button pressed */
SDL_PENBUTTONUP, /**< Pressure-sensitive pen button released */

/* Render events */
SDL_RENDER_TARGETS_RESET = 0x2000, /**< The render targets have been reset and their contents need to be updated */
SDL_RENDER_DEVICE_RESET, /**< The device has been reset and all textures need to be recreated */
Expand Down Expand Up @@ -279,7 +285,7 @@ typedef struct SDL_MouseMotionEvent
Uint32 type; /**< ::SDL_MOUSEMOTION */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with mouse focus, if any */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint32 which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
Uint32 state; /**< The current button state */
Sint32 x; /**< X coordinate, relative to window */
Sint32 y; /**< Y coordinate, relative to window */
Expand All @@ -295,7 +301,7 @@ typedef struct SDL_MouseButtonEvent
Uint32 type; /**< ::SDL_MOUSEBUTTONDOWN or ::SDL_MOUSEBUTTONUP */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with mouse focus, if any */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint32 which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
Uint8 button; /**< The mouse button index */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
Uint8 clicks; /**< 1 for single-click, 2 for double-click, etc. */
Expand All @@ -312,7 +318,7 @@ typedef struct SDL_MouseWheelEvent
Uint32 type; /**< ::SDL_MOUSEWHEEL */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with mouse focus, if any */
Uint32 which; /**< The mouse instance id, or SDL_TOUCH_MOUSEID */
Uint32 which; /**< The mouse instance id, SDL_TOUCH_MOUSEID, or SDL_PEN_MOUSEID */
Sint32 x; /**< The amount scrolled horizontally, positive to the right and negative to the left */
Sint32 y; /**< The amount scrolled vertically, positive away from the user and negative toward the user */
Uint32 direction; /**< Set to one of the SDL_MOUSEWHEEL_* defines. When FLIPPED the values in X and Y will be opposite. Multiply by -1 to change them back */
Expand Down Expand Up @@ -541,6 +547,38 @@ typedef struct SDL_DollarGestureEvent
float y; /**< Normalized center of gesture */
} SDL_DollarGestureEvent;

/**
* \brief Pressure-sensitive pen motion / pressure / angle event structure (event.pmotion.*)
*/
typedef struct SDL_PenMotionEvent
{
Uint32 type; /**< ::SDL_PENMOTION */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with pen focus, if any */
SDL_PenID which; /**< The pen instance id */
Uint16 padding1;
Uint16 pen_state; /**< Pen button msks (where SDL_BUTTON_LMASK is the pen tip). ::SDL_PEN_ERASER_MASK is set if the pen is (used as) an eraser. */
float x; /**< X coordinate, relative to window */
float y; /**< Y coordinate, relative to window */
float axes[SDL_PEN_NUM_AXES]; /**< Pen axes such as pressure and tilt (ordered as per ::SDL_PenAxis) */
} SDL_PenMotionEvent;

/**
* \brief Pressure-sensitive pen button event structure (event.pbutton.*)
*/
typedef struct SDL_PenButtonEvent
{
Uint32 type; /**< ::SDL_PENBUTTONDOWN or ::SDL_PENBUTTONUP */
Uint32 timestamp; /**< In milliseconds, populated using SDL_GetTicks() */
Uint32 windowID; /**< The window with pen focus, if any */
SDL_PenID which; /**< The pen instance id */
Uint8 button; /**< The pen button index (1 represents the pen tip for compatibility with mouse events) */
Uint8 state; /**< ::SDL_PRESSED or ::SDL_RELEASED */
Uint16 pen_state; /**< Pen button msks (where SDL_BUTTON_LMASK is the pen tip). ::SDL_PEN_ERASER_MASK is set if the pen is (used as) an eraser. */
float x; /**< X coordinate, relative to window */
float y; /**< Y coordinate, relative to window */
float axes[SDL_PEN_NUM_AXES]; /**< Pen axes such as pressure and tilt (ordered as per ::SDL_PenAxis) */
} SDL_PenButtonEvent;

/**
* \brief An event used to request a file open by the system (event.drop.*)
Expand Down Expand Up @@ -650,6 +688,8 @@ typedef union SDL_Event
SDL_TouchFingerEvent tfinger; /**< Touch finger event data */
SDL_MultiGestureEvent mgesture; /**< Gesture event data */
SDL_DollarGestureEvent dgesture; /**< Gesture event data */
SDL_PenMotionEvent pmotion; /**< Pen change in position, pressure, or angle */
SDL_PenButtonEvent pbutton; /**< Pen button press */
SDL_DropEvent drop; /**< Drag and drop event data */

/* This is necessary for ABI compatibility between Visual C++ and GCC.
Expand Down
34 changes: 34 additions & 0 deletions include/SDL_hints.h
Original file line number Diff line number Diff line change
Expand Up @@ -1184,6 +1184,40 @@ extern "C" {
*/
#define SDL_HINT_MOUSE_AUTO_CAPTURE "SDL_MOUSE_AUTO_CAPTURE"

/**
* \brief Treat pen movement as separate from mouse movement
*
* By default, pens report both ::SDL_MouseMotionEvent and ::SDL_PenMotionEvent updates
* (analogously for button presses). This hint allows decoupling mouse and pen updates.
*
* This variable toggles between the following behaviour:
* "0" - (Default) Pen acts as a mouse with mouse ID ::SDL_PEN_MOUSEID.
* Use case: client application is not pen aware, user wants to
* use pen instead of mouse to interact.
* "1" - Pen reports mouse clicks and movement events but does not update
* SDL-internal mouse state (buttons pressed, current mouse location).
* Use case: client application is not pen aware, user frequently
* alternates between pen and "real" mouse.
* "2" - Pen reports no mouse events.
* Use case: pen-aware client application uses this hint to allow user to
* toggle between pen+mouse mode ("2") and pen-only mode ("1" or "0").
*/
#define SDL_HINT_PEN_NOT_MOUSE "SDL_HINT_PEN_NOT_MOUSE"

/**
* \brief Pen mouse button emulation triggers only when the pen touches the tablet surface
*
* "0" - The pen reports mouse button press/release immediately when the pen
* button is pressed/released, and the pen tip touching the surface counts
* as left mouse button press.
* "1" - (Default) Mouse button presses are sent when the pen first touches
* the tablet (analogously for releases). Not pressing a pen button
* simulates mouse button 1, pressing the first pen button simulates
* mouse button 2 etc.; it is not possible to report multiple buttons
* as pressed at the same time.
*/
#define SDL_HINT_PEN_DELAY_MOUSE_BUTTON "SDL_HINT_PEN_DELAY_MOUSE_BUTTON"

/**
* \brief Tell SDL not to catch the SIGINT or SIGTERM signals.
*
Expand Down
Loading