+/* clamp x to min..max-1 */
+#define clamp(x, min, max) \
+ if (x < (min)) x = min; \
+ if (x >= (max)) x = max
+
+static int ts_event_cb(void *cb_arg, int x, int y, unsigned int pressure)
+{
+ static int was_pressed;
+ SDL_VideoDevice *this = cb_arg;
+ struct SDL_PrivateVideoData *pdata = this->hidden;
+ int xoffs;
+
+ if (!pdata->cfg_no_ts_translate && pdata->layer_w != 0 && pdata->layer_h != 0) {
+ x = pdata->border_l + ((x - pdata->layer_x) * pdata->ts_xmul >> 16);
+ y = pdata->border_t + ((y - pdata->layer_y) * pdata->ts_ymul >> 16);
+ clamp(x, 0, this->screen->w);
+ clamp(y, 0, this->screen->h);
+ }
+
+ SDL_PrivateMouseMotion(0, 0, x, y);
+
+ pressure = !!pressure;
+ if (pressure != was_pressed) {
+ SDL_PrivateMouseButton(pressure ? SDL_PRESSED : SDL_RELEASED, 1, 0, 0);
+ was_pressed = pressure;
+ }
+}
+