SDL 3.0
SDL_touch.h
Go to the documentation of this file.
1/*
2 Simple DirectMedia Layer
3 Copyright (C) 1997-2025 Sam Lantinga <slouken@libsdl.org>
4
5 This software is provided 'as-is', without any express or implied
6 warranty. In no event will the authors be held liable for any damages
7 arising from the use of this software.
8
9 Permission is granted to anyone to use this software for any purpose,
10 including commercial applications, and to alter it and redistribute it
11 freely, subject to the following restrictions:
12
13 1. The origin of this software must not be misrepresented; you must not
14 claim that you wrote the original software. If you use this software
15 in a product, an acknowledgment in the product documentation would be
16 appreciated but is not required.
17 2. Altered source versions must be plainly marked as such, and must not be
18 misrepresented as being the original software.
19 3. This notice may not be removed or altered from any source distribution.
20*/
21
22/**
23 * # CategoryTouch
24 *
25 * SDL touch management.
26 */
27
28#ifndef SDL_touch_h_
29#define SDL_touch_h_
30
31#include <SDL3/SDL_stdinc.h>
32#include <SDL3/SDL_error.h>
33#include <SDL3/SDL_mouse.h>
34
35#include <SDL3/SDL_begin_code.h>
36/* Set up for C function definitions, even when using C++ */
37#ifdef __cplusplus
38extern "C" {
39#endif
40
41/**
42 * A unique ID for a touch device.
43 *
44 * This ID is valid for the time the device is connected to the system, and is
45 * never reused for the lifetime of the application.
46 *
47 * The value 0 is an invalid ID.
48 *
49 * \since This datatype is available since SDL 3.1.3.
50 */
52
53/**
54 * A unique ID for a single finger on a touch device.
55 *
56 * This ID is valid for the time the finger (stylus, etc) is touching and will
57 * be unique for all fingers currently in contact, so this ID tracks the
58 * lifetime of a single continuous touch. This value may represent an index, a
59 * pointer, or some other unique ID, depending on the platform.
60 *
61 * The value 0 is an invalid ID.
62 *
63 * \since This datatype is available since SDL 3.1.3.
64 */
66
67/**
68 * An enum that describes the type of a touch device.
69 *
70 * \since This enum is available since SDL 3.1.3.
71 */
73{
75 SDL_TOUCH_DEVICE_DIRECT, /**< touch screen with window-relative coordinates */
76 SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE, /**< trackpad with absolute device coordinates */
77 SDL_TOUCH_DEVICE_INDIRECT_RELATIVE /**< trackpad with screen cursor-relative coordinates */
79
80/**
81 * Data about a single finger in a multitouch event.
82 *
83 * Each touch event is a collection of fingers that are simultaneously in
84 * contact with the touch device (so a "touch" can be a "multitouch," in
85 * reality), and this struct reports details of the specific fingers.
86 *
87 * \since This struct is available since SDL 3.1.3.
88 *
89 * \sa SDL_GetTouchFingers
90 */
91typedef struct SDL_Finger
92{
93 SDL_FingerID id; /**< the finger ID */
94 float x; /**< the x-axis location of the touch event, normalized (0...1) */
95 float y; /**< the y-axis location of the touch event, normalized (0...1) */
96 float pressure; /**< the quantity of pressure applied, normalized (0...1) */
98
99/**
100 * The SDL_MouseID for mouse events simulated with touch input.
101 *
102 * \since This macro is available since SDL 3.1.3.
103 */
104#define SDL_TOUCH_MOUSEID ((SDL_MouseID)-1)
105
106/**
107 * The SDL_TouchID for touch events simulated with mouse input.
108 *
109 * \since This macro is available since SDL 3.1.3.
110 */
111#define SDL_MOUSE_TOUCHID ((SDL_TouchID)-1)
112
113
114/**
115 * Get a list of registered touch devices.
116 *
117 * On some platforms SDL first sees the touch device if it was actually used.
118 * Therefore the returned list might be empty, although devices are available.
119 * After using all devices at least once the number will be correct.
120 *
121 * \param count a pointer filled in with the number of devices returned, may
122 * be NULL.
123 * \returns a 0 terminated array of touch device IDs or NULL on failure; call
124 * SDL_GetError() for more information. This should be freed with
125 * SDL_free() when it is no longer needed.
126 *
127 * \since This function is available since SDL 3.1.3.
128 */
129extern SDL_DECLSPEC SDL_TouchID * SDLCALL SDL_GetTouchDevices(int *count);
130
131/**
132 * Get the touch device name as reported from the driver.
133 *
134 * \param touchID the touch device instance ID.
135 * \returns touch device name, or NULL on failure; call SDL_GetError() for
136 * more information.
137 *
138 * \since This function is available since SDL 3.1.3.
139 */
140extern SDL_DECLSPEC const char * SDLCALL SDL_GetTouchDeviceName(SDL_TouchID touchID);
141
142/**
143 * Get the type of the given touch device.
144 *
145 * \param touchID the ID of a touch device.
146 * \returns touch device type.
147 *
148 * \since This function is available since SDL 3.1.3.
149 */
150extern SDL_DECLSPEC SDL_TouchDeviceType SDLCALL SDL_GetTouchDeviceType(SDL_TouchID touchID);
151
152/**
153 * Get a list of active fingers for a given touch device.
154 *
155 * \param touchID the ID of a touch device.
156 * \param count a pointer filled in with the number of fingers returned, can
157 * be NULL.
158 * \returns a NULL terminated array of SDL_Finger pointers or NULL on failure;
159 * call SDL_GetError() for more information. This is a single
160 * allocation that should be freed with SDL_free() when it is no
161 * longer needed.
162 *
163 * \since This function is available since SDL 3.1.3.
164 */
165extern SDL_DECLSPEC SDL_Finger ** SDLCALL SDL_GetTouchFingers(SDL_TouchID touchID, int *count);
166
167/* Ends C function definitions when using C++ */
168#ifdef __cplusplus
169}
170#endif
171#include <SDL3/SDL_close_code.h>
172
173#endif /* SDL_touch_h_ */
uint64_t Uint64
Definition SDL_stdinc.h:483
Uint64 SDL_TouchID
Definition SDL_touch.h:51
SDL_Finger ** SDL_GetTouchFingers(SDL_TouchID touchID, int *count)
SDL_TouchID * SDL_GetTouchDevices(int *count)
SDL_TouchDeviceType
Definition SDL_touch.h:73
@ SDL_TOUCH_DEVICE_INDIRECT_ABSOLUTE
Definition SDL_touch.h:76
@ SDL_TOUCH_DEVICE_DIRECT
Definition SDL_touch.h:75
@ SDL_TOUCH_DEVICE_INDIRECT_RELATIVE
Definition SDL_touch.h:77
@ SDL_TOUCH_DEVICE_INVALID
Definition SDL_touch.h:74
SDL_TouchDeviceType SDL_GetTouchDeviceType(SDL_TouchID touchID)
const char * SDL_GetTouchDeviceName(SDL_TouchID touchID)
Uint64 SDL_FingerID
Definition SDL_touch.h:65
float y
Definition SDL_touch.h:95
float pressure
Definition SDL_touch.h:96
SDL_FingerID id
Definition SDL_touch.h:93
float x
Definition SDL_touch.h:94