Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix mouse support for melondsds on osx #15837

Merged
merged 1 commit into from
Oct 30, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions input/drivers/cocoa_input.m
Original file line number Diff line number Diff line change
Expand Up @@ -383,30 +383,23 @@ static void cocoa_input_poll(void *data)
cocoa_input_data_t *apple = (cocoa_input_data_t*)data;
#ifndef IOS
float backing_scale_factor = cocoa_screen_get_backing_scale_factor();
#else
int backing_scale_factor = 1;
#endif

if (!apple)
return;

for (i = 0; i < apple->touch_count; i++)
for (i = 0; i < apple->touch_count || i == 0; i++)
{
struct video_viewport vp;

vp.x = 0;
vp.y = 0;
vp.width = 0;
vp.height = 0;
vp.full_width = 0;
vp.full_height = 0;
memset(&vp, 0, sizeof(vp));

#ifndef IOS
apple->touches[i].screen_x *= backing_scale_factor;
apple->touches[i].screen_y *= backing_scale_factor;
#endif
video_driver_translate_coord_viewport_wrap(
&vp,
apple->touches[i].screen_x,
apple->touches[i].screen_y,
apple->touches[i].screen_x * backing_scale_factor,
apple->touches[i].screen_y * backing_scale_factor,
&apple->touches[i].fixed_x,
&apple->touches[i].fixed_y,
&apple->touches[i].full_x,
Expand Down Expand Up @@ -568,8 +561,13 @@ static int16_t cocoa_input_state(
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
{

if (idx < apple->touch_count && (idx < MAX_TOUCHES))
#ifdef IOS
if (!apple->touch_count)
return 0;
#endif
// with a physical mouse that is hovering, the touch_count will be 0
// and apple->touches[0] will have the hover position
if ((idx == 0 || idx < apple->touch_count) && (idx < MAX_TOUCHES))
{
const cocoa_touch_data_t *touch = (const cocoa_touch_data_t *)
&apple->touches[idx];
Expand All @@ -579,6 +577,8 @@ static int16_t cocoa_input_state(
switch (id)
{
case RETRO_DEVICE_ID_POINTER_PRESSED:
if (!apple->touch_count)
return 0;
if (device == RARCH_DEVICE_POINTER_SCREEN)
return (touch->full_x != -0x8000) && (touch->full_y != -0x8000); /* Inside? */
return (touch->fixed_x != -0x8000) && (touch->fixed_y != -0x8000); /* Inside? */
Expand Down
Loading