Skip to content

Commit

Permalink
Adapt the sanitized pointer handling, discussed at libretro#17196 :
Browse files Browse the repository at this point in the history
Cocoa driver specific changes:

- make sure pointer position is always within [-0x7fff,0x7fff] by using the confined wrapper
- enable pointer offscreen query
  • Loading branch information
zoltanvb committed Dec 29, 2024
1 parent d2dae40 commit e8ec6b4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
1 change: 1 addition & 0 deletions input/drivers/cocoa_input.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ typedef struct
int16_t screen_x, screen_y;
int16_t fixed_x, fixed_y;
int16_t full_x, full_y;
int16_t confined_x, confined_y;
} cocoa_touch_data_t;

typedef struct
Expand Down
15 changes: 13 additions & 2 deletions input/drivers/cocoa_input.m
Original file line number Diff line number Diff line change
Expand Up @@ -402,6 +402,15 @@ static void cocoa_input_poll(void *data)

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

video_driver_translate_coord_viewport_confined_wrap(
&vp,
apple->touches[i].screen_x * backing_scale_factor,
apple->touches[i].screen_y * backing_scale_factor,
&apple->touches[i].confined_x,
&apple->touches[i].confined_y,
&apple->touches[i].full_x,
&apple->touches[i].full_y);

video_driver_translate_coord_viewport_wrap(
&vp,
apple->touches[i].screen_x * backing_scale_factor,
Expand Down Expand Up @@ -588,11 +597,13 @@ static int16_t cocoa_input_state(
return (touch->full_x != -0x8000) && (touch->full_y != -0x8000); /* Inside? */
return (touch->fixed_x != -0x8000) && (touch->fixed_y != -0x8000); /* Inside? */
case RETRO_DEVICE_ID_POINTER_X:
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_x : touch->fixed_x;
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_x : touch->confined_x;
case RETRO_DEVICE_ID_POINTER_Y:
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_y : touch->fixed_y;
return (device == RARCH_DEVICE_POINTER_SCREEN) ? touch->full_y : touch->confined_y;
case RETRO_DEVICE_ID_POINTER_COUNT:
return apple->touch_count;
case RETRO_DEVICE_ID_POINTER_IS_OFFSCREEN:
return input_driver_pointer_is_offscreen(touch->fixed_x, touch->fixed_y);
}
}
}
Expand Down

0 comments on commit e8ec6b4

Please sign in to comment.