From 44a2bf26120a00dd56488c803ddbb73cf2fe1bb2 Mon Sep 17 00:00:00 2001 From: Eric Warmenhoven Date: Sat, 28 Oct 2023 22:48:38 -0400 Subject: [PATCH] Fix mouse support for melondsds on osx --- input/drivers/cocoa_input.m | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/input/drivers/cocoa_input.m b/input/drivers/cocoa_input.m index a7b3033326f..d2704d12e65 100644 --- a/input/drivers/cocoa_input.m +++ b/input/drivers/cocoa_input.m @@ -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, @@ -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]; @@ -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? */