TS_READ(3)
π TS_READ(3) β tslib π
okay bestie, gather round, because today we're reading touch samples and it's literally the moment this whole library was born for β¨
πΈ NAME πΈ
ts_read, ts_read_raw, ts_read_mt, ts_read_raw_mt β the four functions that hand you tslib touch samples, no cap π«Ά
π SYNOPSIS π
#include <tslib.h>
int ts_read(struct tsdev *dev, struct ts_sample *samp, int nr);
int ts_read_raw(struct tsdev *dev, struct ts_sample *samp, int nr);
int ts_read_mt(struct tsdev *dev, struct ts_sample_mt **samp, int slots, int nr);
int ts_read_raw_mt(struct tsdev *dev, struct ts_sample_mt **samp, int slots, int nr);
π DESCRIPTION π
ts_read() reads nr input samples with tslib's filters applied π«. And the struct it fills in, struct ts_sample, is defined like this:
struct ts_sample {
int x;
int y;
unsigned int pressure;
struct timeval tv;
};
ts_read_mt() is the multitouch girlie π
β she reads nr * slots input samples, also with tslib's filters applied. Her struct, struct ts_sample_mt, is defined as follows:
struct ts_sample_mt {
/* most recent ABS_MT_* event codes.
* see linux/input.h for descriptions */
int x;
int y;
unsigned int pressure;
int slot;
int tracking_id;
int tool_type;
int tool_x;
int tool_y;
unsigned int touch_major;
unsigned int width_major;
unsigned int touch_minor;
unsigned int width_minor;
int orientation;
int distance;
int blob_id;
struct timeval tv;
/* BTN_TOUCH state */
short pen_down;
/* the TSLIB_MT_VALID bit is set in valid if this sample
* contains new data;
* valid is set to 0 otherwise */
short valid;
};
β οΈ bestie this one is on YOU: the user has to provide the amount of memory described innrandslotsto hold them. Like, malloc it yourself, we're not your mom π
ts_read_raw() and ts_read_raw_mt() do the exact same thing, except no filters β raw, unfiltered, unbothered, in their own lane π¦
π₯ RETURN VALUE π₯
The number of actually read samples gets returned. And here's the tea π: especially when opened in non-blocking mode (peep ts_setup()), that number can be less than requested in the call. On failure? A negative error number comes back. Not me getting -1'd π
β¨ EXAMPLE β¨
The following program continuously reads tslib multitouch input samples and prints slot and position values to stdout as the touch screen is touched ππ±
#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <tslib.h>
#define READ_SAMPLES 1
#define MAX_SLOTS 5
int main(int argc, char **argv)
{
struct tsdev *ts;
struct ts_sample_mt **samp_mt = NULL;
int i, j;
int ret;
ts = ts_setup(NULL, 0);
if (!ts)
return -1;
samp_mt = malloc(READ_SAMPLES * sizeof(struct ts_sample_mt **));
if (!samp_mt)
return -1;
for (i = 0; i < READ_SAMPLES; i++) {
samp_mt[i] = calloc(MAX_SLOTS, sizeof(struct ts_sample_mt));
if (!samp_mt[i])
return -1;
}
while(1) {
ret = ts_read_mt(ts, samp_mt, MAX_SLOTS, READ_SAMPLES);
for (i = 0; i < ret; i++) {
printf("sample nr %d0, i);
for (j = 0; i < MAX_SLOTS; j++) {
if (!(samp_mt[i][j].valid & TSLIB_MT_VALID))
continue;
printf("slot %d: X:%d Y: %d0,
samp_mt[i][j].slot,
samp_mt[i][j].x,
samp_mt[i][j].y);
}
}
}
}
π SEE ALSO π
ts_setup(3), ts_config(3), ts_open(3), ts_close(3), ts.conf(5) β go read the whole friend group, iykyk π
mwah π that's the whole page, bestie. this one came from the tslib manual, page TS_READ(3), and yeah that's the same name as the top because that's just how manpages roll π β she's giving iconic, she's giving tslib, and she said periodt. πβ¨π¦
π¦ where this page comes from
- alpine 3.24: tslib-doc 1.24-r0 Β· LGPL-2.0-or-later
- arch rolling: tslib 1.24-1 Β· LGPL-2.1-only
- debian bookworm: libts0 1.22-1+b1 Β· LGPL-2.0-or-later
- debian trixie: libts0t64 1.22-1.1+b1 Β· LGPL-2.0-or-later
- epel 10: tslib 1.23-2.el10_2 Β· LGPL-2.1-only
- epel 9: tslib 1.22-5.el9 Β· LGPLv2
- fedora 43: tslib 1.23-2.fc43 Β· LGPL-2.1-only
- fedora 43: tslib 1.23-2.fc43 Β· LGPL-2.1-only
- fedora 44: tslib 1.24-2.fc44 Β· LGPL-2.1-only
- fedora 44: tslib 1.24-2.fc44 Β· LGPL-2.1-only
- nixos 26.05: tslib 1.24
- nixpkgs unstable: tslib 1.24
- opensuse-leap 16.0: tslib 1.22-160000.2.2 Β· LGPL-2.1-or-later AND GPL-2.0-only
- opensuse-leap 16.0: tslib 1.22-160000.2.2 Β· LGPL-2.1-or-later AND GPL-2.0-only
- opensuse-leap 16.0: tslib 1.22-160000.2.2 Β· LGPL-2.1-or-later AND GPL-2.0-only
- opensuse-leap 16.0: tslib 1.22-160000.2.2 Β· LGPL-2.1-or-later AND GPL-2.0-only
- ubuntu jammy: libts0 1.22-1 Β· LGPL-2.0-or-later
- ubuntu noble: libts0t64 1.22-1.1build1 Β· LGPL-2.0-or-later
- ubuntu questing: libts0t64 1.22-1.1build1
- ubuntu resolute: libts0t64 1.22-1.1build2 Β· LGPL-2.0-or-later
- ubuntu stonking: libts0t64 1.22-1.1build2 Β· LGPL-2.0-or-later
- Copyright (c) 2017, Martin Kepplinger <martink@posteo.de>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms