mirror of
https://github.com/libretro/RetroArch
synced 2025-01-30 21:32:45 +00:00
(Wayland) Mouse grab cleanup (#15114)
This commit is contained in:
parent
90694a3cf1
commit
d2c40b48ab
@ -130,7 +130,7 @@ static void wl_keyboard_handle_key(void *data,
|
||||
return;
|
||||
#endif
|
||||
input_keyboard_event(value,
|
||||
input_keymaps_translate_keysym_to_rk(keysym),
|
||||
input_keymaps_translate_keysym_to_rk(keysym),
|
||||
0, 0, RETRO_DEVICE_KEYBOARD);
|
||||
}
|
||||
|
||||
@ -439,12 +439,12 @@ static void handle_relative_motion(void *data,
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
locked_pointer_locked(void *data, struct zwp_locked_pointer_v1 *locked_pointer)
|
||||
{
|
||||
}
|
||||
|
||||
static void
|
||||
static void
|
||||
locked_pointer_unlocked(void *data, struct zwp_locked_pointer_v1 *locked_pointer)
|
||||
{
|
||||
}
|
||||
@ -490,7 +490,7 @@ static void wl_seat_handle_capabilities(void *data,
|
||||
wl_pointer_add_listener(wl->wl_pointer, &pointer_listener, wl);
|
||||
wl->wl_relative_pointer =
|
||||
zwp_relative_pointer_manager_v1_get_relative_pointer(
|
||||
wl->relative_pointer_manager, wl->wl_pointer);
|
||||
wl->relative_pointer_manager, wl->wl_pointer);
|
||||
zwp_relative_pointer_v1_add_listener(wl->wl_relative_pointer,
|
||||
&relative_pointer_listener, wl);
|
||||
}
|
||||
@ -724,31 +724,31 @@ static ssize_t wl_read_pipe(int fd, void** buffer, size_t* total_length,
|
||||
bytes_read = -1;
|
||||
else
|
||||
{
|
||||
if ((bytes_read = read(fd, temp, sizeof(temp))) > 0)
|
||||
{
|
||||
pos = *total_length;
|
||||
*total_length += bytes_read;
|
||||
if ((bytes_read = read(fd, temp, sizeof(temp))) > 0)
|
||||
{
|
||||
pos = *total_length;
|
||||
*total_length += bytes_read;
|
||||
|
||||
if (null_terminate)
|
||||
new_buffer_length = *total_length + 1;
|
||||
else
|
||||
new_buffer_length = *total_length;
|
||||
if (null_terminate)
|
||||
new_buffer_length = *total_length + 1;
|
||||
else
|
||||
new_buffer_length = *total_length;
|
||||
|
||||
if (*buffer == NULL)
|
||||
output_buffer = malloc(new_buffer_length);
|
||||
else
|
||||
output_buffer = realloc(*buffer, new_buffer_length);
|
||||
if (*buffer == NULL)
|
||||
output_buffer = malloc(new_buffer_length);
|
||||
else
|
||||
output_buffer = realloc(*buffer, new_buffer_length);
|
||||
|
||||
if (output_buffer)
|
||||
{
|
||||
memcpy((uint8_t*)output_buffer + pos, temp, bytes_read);
|
||||
if (output_buffer)
|
||||
{
|
||||
memcpy((uint8_t*)output_buffer + pos, temp, bytes_read);
|
||||
|
||||
if (null_terminate)
|
||||
memset((uint8_t*)output_buffer + (new_buffer_length - 1), 0, 1);
|
||||
if (null_terminate)
|
||||
memset((uint8_t*)output_buffer + (new_buffer_length - 1), 0, 1);
|
||||
|
||||
*buffer = output_buffer;
|
||||
}
|
||||
}
|
||||
*buffer = output_buffer;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return bytes_read;
|
||||
|
@ -84,12 +84,6 @@ static void input_wl_poll(void *data)
|
||||
|
||||
if (wl->gfx->locked_pointer)
|
||||
{
|
||||
/* Get effective 'absolute' pointer location
|
||||
* (last position + delta, bounded by current
|
||||
* application window dimensions) */
|
||||
wl->mouse.x += wl->mouse.delta_x;
|
||||
wl->mouse.y += wl->mouse.delta_y;
|
||||
|
||||
/* Clamp X */
|
||||
if (wl->mouse.x < 0)
|
||||
wl->mouse.x = 0;
|
||||
@ -287,14 +281,14 @@ static int16_t input_wl_state(
|
||||
wl->mouse.wd = false;
|
||||
return state;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
x = screen ? wl->mouse.x : wl->mouse.delta_x;
|
||||
x = screen ? wl->mouse.x : wl->mouse.delta_x;
|
||||
wl->mouse.delta_x = 0;
|
||||
return x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
y = screen ? wl->mouse.y : wl->mouse.delta_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
y = screen ? wl->mouse.y : wl->mouse.delta_y;
|
||||
wl->mouse.delta_y = 0;
|
||||
return y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return wl->mouse.right;
|
||||
@ -311,6 +305,7 @@ static int16_t input_wl_state(
|
||||
struct video_viewport vp;
|
||||
bool screen =
|
||||
(device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
@ -327,26 +322,22 @@ static int16_t input_wl_state(
|
||||
wl->mouse.x, wl->mouse.y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y))
|
||||
{
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
|
||||
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
|
||||
if (!inside)
|
||||
return 0;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
if ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */
|
||||
return res_x;
|
||||
break;
|
||||
return res_x;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
if ((res_x >= -0x7fff) && (res_y >= -0x7fff)) /* Inside? */
|
||||
return res_y;
|
||||
break;
|
||||
return res_y;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
@ -430,9 +421,8 @@ static uint64_t input_wl_get_capabilities(void *data)
|
||||
|
||||
static void input_wl_grab_mouse(void *data, bool state)
|
||||
{
|
||||
input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data;
|
||||
|
||||
gfx_ctx_wayland_data_t *gfx = (gfx_ctx_wayland_data_t*)wl->gfx;
|
||||
input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data;
|
||||
gfx_ctx_wayland_data_t *gfx = (gfx_ctx_wayland_data_t*)wl->gfx;
|
||||
|
||||
if (gfx->pointer_constraints)
|
||||
{
|
||||
@ -440,8 +430,8 @@ static void input_wl_grab_mouse(void *data, bool state)
|
||||
{
|
||||
gfx->locked_pointer = zwp_pointer_constraints_v1_lock_pointer(gfx->pointer_constraints,
|
||||
gfx->surface, gfx->wl_pointer, NULL, ZWP_POINTER_CONSTRAINTS_V1_LIFETIME_PERSISTENT);
|
||||
zwp_locked_pointer_v1_add_listener(gfx->locked_pointer,
|
||||
&locked_pointer_listener, gfx);
|
||||
zwp_locked_pointer_v1_add_listener(gfx->locked_pointer,
|
||||
&locked_pointer_listener, gfx);
|
||||
}
|
||||
else if (gfx->locked_pointer)
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user