Skip to content

Commit b66263a

Browse files
authored
Adapt the sanitized pointer handling, discussed at #17196 : (#17312)
Cocoa driver specific changes: - make sure pointer position is always within [-0x7fff,0x7fff] by using the confined wrapper - enable pointer offscreen query
1 parent 33ec893 commit b66263a

2 files changed

Lines changed: 14 additions & 2 deletions

File tree

input/drivers/cocoa_input.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ typedef struct
3434
int16_t screen_x, screen_y;
3535
int16_t fixed_x, fixed_y;
3636
int16_t full_x, full_y;
37+
int16_t confined_x, confined_y;
3738
} cocoa_touch_data_t;
3839

3940
typedef struct

input/drivers/cocoa_input.m

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,6 +402,15 @@ static void cocoa_input_poll(void *data)
402402

403403
memset(&vp, 0, sizeof(vp));
404404

405+
video_driver_translate_coord_viewport_confined_wrap(
406+
&vp,
407+
apple->touches[i].screen_x * backing_scale_factor,
408+
apple->touches[i].screen_y * backing_scale_factor,
409+
&apple->touches[i].confined_x,
410+
&apple->touches[i].confined_y,
411+
&apple->touches[i].full_x,
412+
&apple->touches[i].full_y);
413+
405414
video_driver_translate_coord_viewport_wrap(
406415
&vp,
407416
apple->touches[i].screen_x * backing_scale_factor,
@@ -588,11 +597,13 @@ static int16_t cocoa_input_state(
588597
return (touch->full_x != -0x8000) && (touch->full_y != -0x8000); /* Inside? */
589598
return (touch->fixed_x != -0x8000) && (touch->fixed_y != -0x8000); /* Inside? */
590599
case RETRO_DEVICE_ID_POINTER_X:
591-
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_x : touch->fixed_x;
600+
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_x : touch->confined_x;
592601
case RETRO_DEVICE_ID_POINTER_Y:
593-
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_y : touch->fixed_y;
602+
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_y : touch->confined_y;
594603
case RETRO_DEVICE_ID_POINTER_COUNT:
595604
return apple->touch_count;
605+
case RETRO_DEVICE_ID_POINTER_IS_OFFSCREEN:
606+
return input_driver_pointer_is_offscreen(touch->fixed_x, touch->fixed_y);
596607
}
597608
}
598609
}

0 commit comments

Comments
 (0)