(input drivers) Cleanups

This commit is contained in:
libretroadmin 2023-02-20 12:54:26 +01:00
parent 334cb3d5d4
commit 66aebcabea
4 changed files with 432 additions and 434 deletions

View File

@ -111,23 +111,22 @@ void dinput_destroy_context(void)
bool dinput_init_context(void)
{
if (g_dinput_ctx)
return true;
/* Who said we shouldn't have same call signature in a COM API? <_< */
if (!g_dinput_ctx)
{
/* Who said we shouldn't have same call signature in a COM API? <_< */
#ifdef __cplusplus
if (!(SUCCEEDED(DirectInput8Create(
GetModuleHandle(NULL), DIRECTINPUT_VERSION,
IID_IDirectInput8,
(void**)&g_dinput_ctx, NULL))))
#else
if (!(SUCCEEDED(DirectInput8Create(
GetModuleHandle(NULL), DIRECTINPUT_VERSION,
&IID_IDirectInput8,
IID_IDirectInput8,
(void**)&g_dinput_ctx, NULL))))
#else
if (!(SUCCEEDED(DirectInput8Create(
GetModuleHandle(NULL), DIRECTINPUT_VERSION,
&IID_IDirectInput8,
(void**)&g_dinput_ctx, NULL))))
#endif
return false;
return false;
}
return true;
}
@ -138,8 +137,7 @@ static void *dinput_init(const char *joypad_driver)
if (!dinput_init_context())
return NULL;
di = (struct dinput_input*)calloc(1, sizeof(*di));
if (!di)
if (!(di = (struct dinput_input*)calloc(1, sizeof(*di))))
return NULL;
if (!string_is_empty(joypad_driver))
@ -309,12 +307,12 @@ static void dinput_poll(void *data)
BYTE *rgb_buttons_ptr = &mouse_state.rgbButtons[0];
bool swap_mouse_buttons = g_win32_flags & WIN32_CMN_FLAG_SWAP_MOUSE_BTNS;
point.x = 0;
point.y = 0;
point.x = 0;
point.y = 0;
mouse_state.lX = 0;
mouse_state.lY = 0;
mouse_state.lZ = 0;
mouse_state.lX = 0;
mouse_state.lY = 0;
mouse_state.lZ = 0;
for (
; rgb_buttons_ptr < mouse_state.rgbButtons + 8
@ -409,7 +407,7 @@ static void dinput_poll(void *data)
static bool dinput_mouse_button_pressed(
struct dinput_input *di, unsigned port, unsigned key)
{
bool result;
bool result = false;
switch (key)
{
@ -426,22 +424,22 @@ static bool dinput_mouse_button_pressed(
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
result = di->flags & DINP_FLAG_MOUSE_WU_BTN;
di->flags &= ~DINP_FLAG_MOUSE_WU_BTN;
return result;
break;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
result = di->flags & DINP_FLAG_MOUSE_WD_BTN;
di->flags &= ~DINP_FLAG_MOUSE_WD_BTN;
return result;
break;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
result = di->flags & DINP_FLAG_MOUSE_HWU_BTN;
di->flags &= ~DINP_FLAG_MOUSE_HWU_BTN;
return result;
break;
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
result = di->flags & DINP_FLAG_MOUSE_HWD_BTN;
di->flags &= ~DINP_FLAG_MOUSE_HWD_BTN;
return result;
break;
}
return false;
return result;
}
static int16_t dinput_lightgun_aiming_state(
@ -490,10 +488,11 @@ static int16_t dinput_lightgun_aiming_state(
&vp, x, y,
&res_x, &res_y, &res_screen_x, &res_screen_y))
{
bool inside = (res_x >= -edge_detect)
bool inside =
(res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch (id)
{

View File

@ -1,3 +1,16 @@
/* RetroArch - A frontend for libretro.
*
* RetroArch is free software: you can redistribute it and/or modify it under the terms
* of the GNU General Public License as published by the Free Software Found-
* ation, either version 3 of the License, or (at your option) any later version.
*
* RetroArch is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
* PURPOSE. See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with RetroArch.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <stdint.h>
#include <stdlib.h>
@ -136,14 +149,14 @@ typedef struct switch_input
#ifdef HAVE_LIBNX
/* beginning of touch mouse function declarations */
static void handle_touch_mouse(switch_input_t *sw);
static void normalize_touch_mouse_xy(float *normalized_x, float *normalized_y, int reported_x, int reported_y);
static void process_touch_mouse_event(switch_input_t *sw, TouchEvent *event);
static void process_touch_mouse_finger_down(switch_input_t * sw, TouchEvent *event);
static void process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event);
static void process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event);
static void normalized_to_screen_xy(int *screenX, int *screenY, float x, float y);
static void finish_simulated_mouse_clicks(switch_input_t *sw, uint64_t currentTime);
static void switch_handle_touch_mouse(switch_input_t *sw);
static void switch_normalize_touch_mouse_xy(float *normalized_x, float *normalized_y, int reported_x, int reported_y);
static void switch_process_touch_mouse_event(switch_input_t *sw, TouchEvent *event);
static void switch_process_touch_mouse_finger_down(switch_input_t * sw, TouchEvent *event);
static void switch_process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event);
static void switch_process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event);
static void switch_normalized_to_screen_xy(int *screenX, int *screenY, float x, float y);
static void switch_finish_simulated_mouse_clicks(switch_input_t *sw, uint64_t currentTime);
/* end of touch mouse function declarations */
#endif
@ -196,7 +209,6 @@ static void switch_input_poll(void *data)
}
}
mod = 0;
hidGetKeyboardStates(&kbd_state, 1);
if (hidKeyboardStateGetKey(&kbd_state, HidKeyboardKey_LeftAlt) || hidKeyboardStateGetKey(&kbd_state, HidKeyboardKey_RightAlt))
mod |= RETROKMOD_ALT;
@ -207,8 +219,8 @@ static void switch_input_poll(void *data)
for (i = 0; i < SWITCH_NUM_SCANCODES; i++)
{
key_sym = rarch_key_map_switch[i].sym;
key_code = input_keymaps_translate_keysym_to_rk(key_sym);
key_sym = rarch_key_map_switch[i].sym;
key_code = input_keymaps_translate_keysym_to_rk(key_sym);
key_pressed = hidKeyboardStateGetKey(&kbd_state, key_sym);
if (key_pressed && !(sw->keyboard_state[key_sym]))
{
@ -257,25 +269,25 @@ static void switch_input_poll(void *data)
sw->mouse_x_delta = mouse_state.delta_x;
sw->mouse_y_delta = mouse_state.delta_y;
sw->mouse_x = mouse_state.x;
sw->mouse_y = mouse_state.y;
sw->mouse_x = mouse_state.x;
sw->mouse_y = mouse_state.y;
/* touch mouse events
* handle_touch_mouse will update sw->mouse_* variables
* switch_handle_touch_mouse will update sw->mouse_* variables
* depending on touch input gestures
* see first comment in process_touch_mouse_event() for a list of
* see first comment in switch_process_touch_mouse_event() for a list of
* supported touch gestures */
handle_touch_mouse(sw);
switch_handle_touch_mouse(sw);
if (sw->mouse_x < 0)
sw->mouse_x = 0;
sw->mouse_x = 0;
else if (sw->mouse_x > MOUSE_MAX_X)
sw->mouse_x = MOUSE_MAX_X;
sw->mouse_x = MOUSE_MAX_X;
if (sw->mouse_y < 0)
sw->mouse_y = 0;
sw->mouse_y = 0;
else if (sw->mouse_y > MOUSE_MAX_Y)
sw->mouse_y = MOUSE_MAX_Y;
sw->mouse_y = MOUSE_MAX_Y;
sw->mouse_wheel = mouse_state.wheel_delta_y;
}
@ -324,29 +336,29 @@ static int16_t switch_input_state(
if (screen)
return sw->mouse_x;
val = sw->mouse_x_delta;
sw->mouse_x_delta = 0;
val = sw->mouse_x_delta;
sw->mouse_x_delta = 0;
/* flush delta after it has been read */
break;
case RETRO_DEVICE_ID_MOUSE_Y:
if (screen)
return sw->mouse_y;
val = sw->mouse_y_delta;
sw->mouse_y_delta = 0;
val = sw->mouse_y_delta;
sw->mouse_y_delta = 0;
/* flush delta after it has been read */
break;
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
if (sw->mouse_wheel > 0)
{
val = sw->mouse_wheel;
val = sw->mouse_wheel;
sw->mouse_wheel = 0;
}
break;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
if (sw->mouse_wheel < 0)
{
val = sw->mouse_wheel;
val = sw->mouse_wheel;
sw->mouse_wheel = 0;
}
break;
@ -390,12 +402,13 @@ static int16_t switch_input_state(
}
#ifdef HAVE_LIBNX
void handle_touch_mouse(switch_input_t *sw)
static void switch_handle_touch_mouse(switch_input_t *sw)
{
unsigned int i;
int finger_id = 0;
uint64_t current_time = svcGetSystemTick() * 1000 / 19200000;
finish_simulated_mouse_clicks(sw, current_time);
switch_finish_simulated_mouse_clicks(sw, current_time);
for (i = 0; i < MULTITOUCH_LIMIT; i++)
{
@ -403,7 +416,7 @@ void handle_touch_mouse(switch_input_t *sw)
{
float x = 0;
float y = 0;
normalize_touch_mouse_xy(&x, &y, sw->touch_x[i], sw->touch_y[i]);
switch_normalize_touch_mouse_xy(&x, &y, sw->touch_x[i], sw->touch_y[i]);
finger_id = i;
/* Send an initial touch if finger hasn't been down */
@ -415,7 +428,7 @@ void handle_touch_mouse(switch_input_t *sw)
ev.tfinger.fingerId = finger_id;
ev.tfinger.x = x;
ev.tfinger.y = y;
process_touch_mouse_event(sw, &ev);
switch_process_touch_mouse_event(sw, &ev);
}
else
{
@ -426,7 +439,7 @@ void handle_touch_mouse(switch_input_t *sw)
TouchEvent ev;
float oldx = 0;
float oldy = 0;
normalize_touch_mouse_xy(&oldx, &oldy, sw->touch_previous_x[i], sw->touch_previous_y[i]);
switch_normalize_touch_mouse_xy(&oldx, &oldy, sw->touch_previous_x[i], sw->touch_previous_y[i]);
ev.type = FINGERMOTION;
ev.tfinger.timestamp = current_time;
ev.tfinger.fingerId = finger_id;
@ -434,7 +447,7 @@ void handle_touch_mouse(switch_input_t *sw)
ev.tfinger.y = y;
ev.tfinger.dx = x - oldx;
ev.tfinger.dy = y - oldy;
process_touch_mouse_event(sw, &ev);
switch_process_touch_mouse_event(sw, &ev);
}
}
}
@ -445,7 +458,7 @@ void handle_touch_mouse(switch_input_t *sw)
float x = 0;
float y = 0;
TouchEvent ev;
normalize_touch_mouse_xy(&x, &y,
switch_normalize_touch_mouse_xy(&x, &y,
sw->touch_previous_x[i], sw->touch_previous_y[i]);
finger_id = i;
/* finger released from screen */
@ -454,31 +467,31 @@ void handle_touch_mouse(switch_input_t *sw)
ev.tfinger.fingerId = finger_id;
ev.tfinger.x = x;
ev.tfinger.y = y;
process_touch_mouse_event(sw, &ev);
switch_process_touch_mouse_event(sw, &ev);
}
}
}
void normalize_touch_mouse_xy(float *normalized_x,
static void switch_normalize_touch_mouse_xy(float *normalized_x,
float *normalized_y, int reported_x, int reported_y)
{
float x = (float) reported_x / TOUCH_MAX_X;
float y = (float) reported_y / TOUCH_MAX_Y;
if (x < 0.0)
x = 0.0;
else if (x > 1.0)
x = 1.0;
if (x < 0.0f)
x = 0.0f;
else if (x > 1.0f)
x = 1.0f;
if (y < 0.0)
y = 0.0;
else if (y > 1.0)
y = 1.0;
if (y < 0.0f)
y = 0.0f;
else if (y > 1.0f)
y = 1.0f;
*normalized_x = x;
*normalized_y = y;
}
void process_touch_mouse_event(switch_input_t *sw, TouchEvent *event)
static void switch_process_touch_mouse_event(switch_input_t *sw, TouchEvent *event)
{
/* supported touch gestures:
* pointer motion = single finger drag
@ -494,19 +507,19 @@ void process_touch_mouse_event(switch_input_t *sw, TouchEvent *event)
switch (event->type)
{
case FINGERDOWN:
process_touch_mouse_finger_down(sw, event);
switch_process_touch_mouse_finger_down(sw, event);
break;
case FINGERUP:
process_touch_mouse_finger_up(sw, event);
switch_process_touch_mouse_finger_up(sw, event);
break;
case FINGERMOTION:
process_touch_mouse_finger_motion(sw, event);
switch_process_touch_mouse_finger_motion(sw, event);
break;
}
}
}
void process_touch_mouse_finger_down(switch_input_t *sw, TouchEvent *event)
static void switch_process_touch_mouse_finger_down(switch_input_t *sw, TouchEvent *event)
{
/* id (for multitouch) */
unsigned int i;
@ -537,7 +550,7 @@ void process_touch_mouse_finger_down(switch_input_t *sw, TouchEvent *event)
}
}
void process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event)
static void switch_process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event)
{
unsigned int i;
/* id (for multitouch) */
@ -592,11 +605,11 @@ void process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event)
{
int x;
int y;
normalized_to_screen_xy(&x, &y, event->tfinger.x, event->tfinger.y);
switch_normalized_to_screen_xy(&x, &y, event->tfinger.x, event->tfinger.y);
sw->mouse_x_delta = x - sw->mouse_x;
sw->mouse_y_delta = y - sw->mouse_y;
sw->mouse_x = x;
sw->mouse_y = y;
sw->mouse_x = x;
sw->mouse_y = y;
}
simulated_button = TOUCH_MOUSE_BUTTON_LEFT;
/* need to raise the button later */
@ -621,7 +634,7 @@ void process_touch_mouse_finger_up(switch_input_t *sw, TouchEvent *event)
}
}
void process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event)
static void switch_process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event)
{
unsigned int i;
unsigned int j;
@ -701,7 +714,7 @@ void process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event)
{
int x;
int y;
normalized_to_screen_xy(&x, &y, event->tfinger.x, event->tfinger.y);
switch_normalized_to_screen_xy(&x, &y, event->tfinger.x, event->tfinger.y);
sw->mouse_x_delta = x - sw->mouse_x;
sw->mouse_y_delta = y - sw->mouse_y;
sw->mouse_x = x;
@ -730,7 +743,7 @@ void process_touch_mouse_finger_motion(switch_input_t *sw, TouchEvent *event)
}
}
static void normalized_to_screen_xy(
static void switch_normalized_to_screen_xy(
int *screenX, int *screenY, float x, float y)
{
/* map to display */
@ -738,7 +751,7 @@ static void normalized_to_screen_xy(
*screenY = y * TOUCH_MAX_Y;
}
static void finish_simulated_mouse_clicks(
static void switch_finish_simulated_mouse_clicks(
switch_input_t *sw, uint64_t currentTime)
{
unsigned int i;
@ -791,11 +804,7 @@ static void* switch_input_init(const char *joypad_driver)
hidInitializeMouse();
hidInitializeKeyboard();
/*
Here we assume that the touch screen is always 1280x720
Call me back when a Nintendo Switch XL is out
*/
/* Here we assume that the touch screen is always 1280x720 */
input_keymaps_init_keyboard_lut(rarch_key_map_switch);
for (i = 0; i <= SWITCH_MAX_SCANCODE; i++)
sw->keyboard_state[i] = false;
@ -807,7 +816,7 @@ static void* switch_input_init(const char *joypad_driver)
/* touch mouse init */
sw->touch_mouse_indirect = true;
/* direct mode is not calibrated it seems */
sw->touch_mouse_speed_factor = 1.0;
sw->touch_mouse_speed_factor = 1.0f;
for (i = 0; i < MAX_NUM_FINGERS; i++)
sw->finger[i].id = NO_TOUCH;
@ -815,7 +824,6 @@ static void* switch_input_init(const char *joypad_driver)
for (i = 0; i < 2; i++)
sw->simulated_click_start_time[i] = 0;
for (i = 0; i < DEFAULT_MAX_PADS; i++)
sw->sixaxis_handles_count[i] = 0;
#endif
@ -840,48 +848,46 @@ static bool switch_input_set_sensor_state(void *data, unsigned port,
{
#ifdef HAVE_LIBNX
unsigned i, handles_count;
bool available;
switch_input_t *sw = (switch_input_t*) data;
if(!sw)
return false;
switch(action)
if (sw)
{
case RETRO_SENSOR_ILLUMINANCE_ENABLE:
available = false;
appletIsIlluminanceAvailable(&available);
return available;
bool available = false;
switch(action)
{
case RETRO_SENSOR_ILLUMINANCE_ENABLE:
appletIsIlluminanceAvailable(&available);
return available;
case RETRO_SENSOR_ILLUMINANCE_DISABLE:
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
case RETRO_SENSOR_GYROSCOPE_DISABLE:
return true;
case RETRO_SENSOR_ILLUMINANCE_DISABLE:
case RETRO_SENSOR_ACCELEROMETER_DISABLE:
case RETRO_SENSOR_GYROSCOPE_DISABLE:
return true;
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
case RETRO_SENSOR_GYROSCOPE_ENABLE:
if(port < DEFAULT_MAX_PADS && sw->sixaxis_handles_count[port] == 0)
{
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][0], 2, port, HidNpadStyleTag_NpadJoyDual);
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][2], 1, port, HidNpadStyleTag_NpadFullKey);
if(port == 0)
case RETRO_SENSOR_ACCELEROMETER_ENABLE:
case RETRO_SENSOR_GYROSCOPE_ENABLE:
if (port < DEFAULT_MAX_PADS && sw->sixaxis_handles_count[port] == 0)
{
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][3], 1, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
handles_count = 4;
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][0], 2, port, HidNpadStyleTag_NpadJoyDual);
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][2], 1, port, HidNpadStyleTag_NpadFullKey);
if (port == 0)
{
hidGetSixAxisSensorHandles(&sw->sixaxis_handles[port][3], 1, HidNpadIdType_Handheld, HidNpadStyleTag_NpadHandheld);
handles_count = 4;
}
else
handles_count = 3;
for (i = 0; i < handles_count; i++)
hidStartSixAxisSensor(sw->sixaxis_handles[port][i]);
sw->sixaxis_handles_count[port] = handles_count;
}
else
handles_count = 3;
for (i = 0; i < handles_count; i++)
hidStartSixAxisSensor(sw->sixaxis_handles[port][i]);
sw->sixaxis_handles_count[port] = handles_count;
}
return true;
case RETRO_SENSOR_DUMMY:
break;
return true;
case RETRO_SENSOR_DUMMY:
break;
}
}
#endif
@ -900,10 +906,10 @@ static float switch_input_get_sensor_input(void *data,
if (id >= RETRO_SENSOR_ACCELEROMETER_X && id <= RETRO_SENSOR_GYROSCOPE_Z
&& port < DEFAULT_MAX_PADS)
{
for(i = 0; i < sw->sixaxis_handles_count[port]; i++)
for (i = 0; i < sw->sixaxis_handles_count[port]; i++)
{
hidGetSixAxisSensorStates(sw->sixaxis_handles[port][i], &sixaxis, 1);
if(sixaxis.delta_time)
if (sixaxis.delta_time)
break;
}
@ -924,7 +930,7 @@ static float switch_input_get_sensor_input(void *data,
}
}
if(id == RETRO_SENSOR_ILLUMINANCE)
if (id == RETRO_SENSOR_ILLUMINANCE)
{
appletGetCurrentIlluminance(&f);
return f;

View File

@ -101,8 +101,8 @@ static int16_t uwp_input_state(
{
if ((binds[port][id].key < RETROK_LAST)
&& uwp_keyboard_pressed(binds[port][id].key)
&& ((id == RARCH_GAME_FOCUS_TOGGLE) ||
!keyboard_mapping_blocked)
&& ((id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (uwp_mouse_state(port,

View File

@ -96,9 +96,7 @@ static HWND winraw_create_window(WNDPROC wnd_proc)
HWND wnd;
WNDCLASSA wc = {0};
wc.hInstance = GetModuleHandleA(NULL);
if (!wc.hInstance)
if (!(wc.hInstance = GetModuleHandleA(NULL)))
return NULL;
wc.lpfnWndProc = wnd_proc;
@ -148,11 +146,11 @@ static void winraw_log_mice_info(winraw_mouse_t *mice, unsigned mouse_cnt)
{
unsigned i;
char name[256];
UINT name_size = sizeof(name);
char prod_name[128];
wchar_t prod_buf[128];
UINT name_size = sizeof(name);
name[0] = '\0';
name[0] = '\0';
for (i = 0; i < mouse_cnt; ++i)
{
@ -202,14 +200,12 @@ static bool winraw_init_devices(winraw_mouse_t **mice, unsigned *mouse_cnt)
if (r == (UINT)-1)
goto error;
devs = (RAWINPUTDEVICELIST*)malloc(
dev_cnt * sizeof(RAWINPUTDEVICELIST));
if (!devs)
if (!(devs = (RAWINPUTDEVICELIST*)malloc(
dev_cnt * sizeof(RAWINPUTDEVICELIST))))
goto error;
dev_cnt = GetRawInputDeviceList(devs,
&dev_cnt, sizeof(RAWINPUTDEVICELIST));
if (dev_cnt == (UINT)-1)
if ((dev_cnt = GetRawInputDeviceList(devs,
&dev_cnt, sizeof(RAWINPUTDEVICELIST))) == (UINT)-1)
goto error;
for (i = 0; i < dev_cnt; ++i)
@ -217,9 +213,8 @@ static bool winraw_init_devices(winraw_mouse_t **mice, unsigned *mouse_cnt)
if (mouse_cnt_r)
{
mice_r = (winraw_mouse_t*)calloc(
1, mouse_cnt_r * sizeof(winraw_mouse_t));
if (!mice_r)
if (!(mice_r = (winraw_mouse_t*)calloc(
1, mouse_cnt_r * sizeof(winraw_mouse_t))))
goto error;
if (!GetCursorPos(&crs_pos))
@ -293,8 +288,8 @@ static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr,
inside = (res_x >= -edge_detect)
&& (res_y >= -edge_detect)
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
&& (res_x <= edge_detect)
&& (res_y <= edge_detect);
switch (id)
{
@ -357,8 +352,8 @@ static void winraw_init_mouse_xy_mapping(winraw_input_t *wr)
g_mice[i].y = center_y;
}
wr->view_abs_ratio_x = (double)viewport.full_width / 65535.0;
wr->view_abs_ratio_y = (double)viewport.full_height / 65535.0;
wr->view_abs_ratio_x = (double)viewport.full_width / 65535.0f;
wr->view_abs_ratio_y = (double)viewport.full_height / 65535.0f;
wr->mouse_xy_mapping_ready = true;
}
@ -620,18 +615,15 @@ static void *winraw_init(const char *joypad_driver)
input_keymaps_init_keyboard_lut(rarch_key_map_winraw);
wr->window = winraw_create_window(winraw_callback);
if (!wr->window)
if (!(wr->window = winraw_create_window(winraw_callback)))
goto error;
if (!winraw_init_devices(&g_mice, &wr->mouse_cnt))
goto error;
if (wr->mouse_cnt)
{
wr->mice = (winraw_mouse_t*)
malloc(wr->mouse_cnt * sizeof(winraw_mouse_t));
if (!wr->mice)
if (!(wr->mice = (winraw_mouse_t*)
malloc(wr->mouse_cnt * sizeof(winraw_mouse_t))))
goto error;
memcpy(wr->mice, g_mice, wr->mouse_cnt * sizeof(winraw_mouse_t));
@ -747,300 +739,301 @@ static int16_t winraw_input_state(
settings_t *settings = NULL;
winraw_mouse_t *mouse = NULL;
winraw_input_t *wr = (winraw_input_t*)data;
bool process_mouse =
(device == RETRO_DEVICE_JOYPAD)
|| (device == RETRO_DEVICE_MOUSE)
|| (device == RARCH_DEVICE_MOUSE_SCREEN)
|| (device == RETRO_DEVICE_LIGHTGUN)
|| (device == RETRO_DEVICE_POINTER)
|| (device == RARCH_DEVICE_POINTER_SCREEN);
if (port >= MAX_USERS)
return 0;
if (process_mouse)
if (port < MAX_USERS)
{
unsigned i;
settings = config_get_ptr();
for (i = 0; i < wr->mouse_cnt; ++i)
bool process_mouse =
(device == RETRO_DEVICE_JOYPAD)
|| (device == RETRO_DEVICE_MOUSE)
|| (device == RARCH_DEVICE_MOUSE_SCREEN)
|| (device == RETRO_DEVICE_LIGHTGUN)
|| (device == RETRO_DEVICE_POINTER)
|| (device == RARCH_DEVICE_POINTER_SCREEN);
if (process_mouse)
{
if (i == settings->uints.input_mouse_index[port])
unsigned i;
settings = config_get_ptr();
for (i = 0; i < wr->mouse_cnt; ++i)
{
mouse = &wr->mice[i];
if (mouse && device > RETRO_DEVICE_JOYPAD)
g_mice[i].device = device;
break;
if (i == settings->uints.input_mouse_index[port])
{
mouse = &wr->mice[i];
if (mouse && device > RETRO_DEVICE_JOYPAD)
g_mice[i].device = device;
break;
}
}
}
}
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
unsigned i;
if (mouse)
switch (device)
{
case RETRO_DEVICE_JOYPAD:
if (id == RETRO_DEVICE_ID_JOYPAD_MASK)
{
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if (binds[port][i].valid)
{
if (winraw_mouse_button_pressed(wr,
mouse, port, binds[port][i].mbutton))
ret |= (1 << i);
}
}
}
unsigned i;
if (!keyboard_mapping_blocked)
{
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if (binds[port][i].valid)
{
if ((binds[port][i].key < RETROK_LAST) &&
WINRAW_KEYBOARD_PRESSED(wr, binds[port][i].key))
ret |= (1 << i);
}
}
}
return ret;
}
if (id < RARCH_BIND_LIST_END)
{
if (binds[port][id].valid)
{
if (
(binds[port][id].key < RETROK_LAST)
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][id].mbutton))
return 1;
}
}
break;
case RETRO_DEVICE_ANALOG:
{
int id_minus_key = 0;
int id_plus_key = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
bool id_plus_valid = false;
bool id_minus_valid = false;
input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus);
id_minus_valid = binds[port][id_minus].valid;
id_plus_valid = binds[port][id_plus].valid;
id_minus_key = binds[port][id_minus].key;
id_plus_key = binds[port][id_plus].key;
if (id_plus_valid && id_plus_key < RETROK_LAST)
{
if (WINRAW_KEYBOARD_PRESSED(wr, id_plus_key))
ret = 0x7fff;
}
if (id_minus_valid && id_minus_key < RETROK_LAST)
{
if (WINRAW_KEYBOARD_PRESSED(wr, id_minus_key))
ret += -0x7fff;
}
}
return ret;
case RETRO_DEVICE_KEYBOARD:
return (id < RETROK_LAST) && WINRAW_KEYBOARD_PRESSED(wr, id);
case RETRO_DEVICE_MOUSE:
case RARCH_DEVICE_MOUSE_SCREEN:
if (mouse)
{
bool abs = (device == RARCH_DEVICE_MOUSE_SCREEN);
switch (id)
{
case RETRO_DEVICE_ID_MOUSE_X:
return abs ? mouse->x : mouse->dlt_x;
case RETRO_DEVICE_ID_MOUSE_Y:
return abs ? mouse->y : mouse->dlt_y;
case RETRO_DEVICE_ID_MOUSE_LEFT:
if (mouse->btn_l)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_RIGHT:
if (mouse->btn_r)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
if (mouse->whl_u)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
if (mouse->whl_d)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
if (mouse->btn_m)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
if (mouse->btn_b4)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
if (mouse->btn_b5)
return 1;
break;
}
}
break;
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
{
struct video_viewport vp;
bool pointer_down = false;
bool inside = false;
int x = 0;
int y = 0;
int16_t res_x = 0;
int16_t res_y = 0;
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;
unsigned num = 0;
struct winraw_pointer_status *
check_pos = wr->pointer_head.next;
vp.x = 0;
vp.y = 0;
vp.width = 0;
vp.height = 0;
vp.full_width = 0;
vp.full_height = 0;
while (check_pos && num < idx)
{
num++;
check_pos = check_pos->next;
}
if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */
return 0;
if (mouse)
{
x = mouse->x;
y = mouse->y;
pointer_down = mouse->btn_l;
}
if (check_pos)
{
x = check_pos->pointer_x;
y = check_pos->pointer_y;
pointer_down = true;
}
if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (device == RARCH_DEVICE_POINTER_SCREEN)
{
res_x = res_screen_x;
res_y = res_screen_y;
}
if (!(inside = (res_x >= -0x7fff) && (res_y >= -0x7fff)))
return 0;
switch (id)
{
case RETRO_DEVICE_ID_POINTER_X:
return res_x;
case RETRO_DEVICE_ID_POINTER_Y:
return res_y;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return pointer_down;
default:
break;
}
}
break;
case RETRO_DEVICE_LIGHTGUN:
switch (id)
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
if (mouse)
return winraw_lightgun_aiming_state(wr, mouse, port, id);
break;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
case RETRO_DEVICE_ID_LIGHTGUN_START:
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */
{
unsigned new_id = winraw_retro_id_to_rarch(id);
const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if (binds[port][new_id].valid)
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
else if (
binds[port][new_id].key < RETROK_LAST
&& !keyboard_mapping_blocked
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port]
[new_id].key)
)
return 1;
else
if (binds[port][i].valid)
{
if (
mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][new_id].mbutton)
)
return 1;
if (winraw_mouse_button_pressed(wr,
mouse, port, binds[port][i].mbutton))
ret |= (1 << i);
}
}
}
break;
/*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X:
if (!keyboard_mapping_blocked)
{
for (i = 0; i < RARCH_FIRST_CUSTOM_BIND; i++)
{
if (binds[port][i].valid)
{
if ((binds[port][i].key < RETROK_LAST) &&
WINRAW_KEYBOARD_PRESSED(wr, binds[port][i].key))
ret |= (1 << i);
}
}
}
return ret;
}
if (id < RARCH_BIND_LIST_END)
{
if (binds[port][id].valid)
{
if (
(binds[port][id].key < RETROK_LAST)
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port][id].key)
&& (( id == RARCH_GAME_FOCUS_TOGGLE)
|| !keyboard_mapping_blocked)
)
return 1;
else if (mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][id].mbutton))
return 1;
}
}
break;
case RETRO_DEVICE_ANALOG:
{
int id_minus_key = 0;
int id_plus_key = 0;
unsigned id_minus = 0;
unsigned id_plus = 0;
bool id_plus_valid = false;
bool id_minus_valid = false;
input_conv_analog_id_to_bind_id(idx, id, id_minus, id_plus);
id_minus_valid = binds[port][id_minus].valid;
id_plus_valid = binds[port][id_plus].valid;
id_minus_key = binds[port][id_minus].key;
id_plus_key = binds[port][id_plus].key;
if (id_plus_valid && id_plus_key < RETROK_LAST)
{
if (WINRAW_KEYBOARD_PRESSED(wr, id_plus_key))
ret = 0x7fff;
}
if (id_minus_valid && id_minus_key < RETROK_LAST)
{
if (WINRAW_KEYBOARD_PRESSED(wr, id_minus_key))
ret += -0x7fff;
}
}
return ret;
case RETRO_DEVICE_KEYBOARD:
return (id < RETROK_LAST) && WINRAW_KEYBOARD_PRESSED(wr, id);
case RETRO_DEVICE_MOUSE:
case RARCH_DEVICE_MOUSE_SCREEN:
if (mouse)
{
bool abs = (device == RARCH_DEVICE_MOUSE_SCREEN);
switch (id)
{
case RETRO_DEVICE_ID_MOUSE_X:
return abs ? mouse->x : mouse->dlt_x;
case RETRO_DEVICE_ID_MOUSE_Y:
return abs ? mouse->y : mouse->dlt_y;
case RETRO_DEVICE_ID_MOUSE_LEFT:
if (mouse->btn_l)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_RIGHT:
if (mouse->btn_r)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
if (mouse->whl_u)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
if (mouse->whl_d)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
if (mouse->btn_m)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
if (mouse->btn_b4)
return 1;
break;
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
if (mouse->btn_b5)
return 1;
break;
}
}
break;
case RETRO_DEVICE_POINTER:
case RARCH_DEVICE_POINTER_SCREEN:
{
struct video_viewport vp;
bool pointer_down = false;
bool inside = false;
int x = 0;
int y = 0;
int16_t res_x = 0;
int16_t res_y = 0;
int16_t res_screen_x = 0;
int16_t res_screen_y = 0;
unsigned num = 0;
struct winraw_pointer_status *
check_pos = wr->pointer_head.next;
vp.x = 0;
vp.y = 0;
vp.width = 0;
vp.height = 0;
vp.full_width = 0;
vp.full_height = 0;
while (check_pos && num < idx)
{
num++;
check_pos = check_pos->next;
}
if (!check_pos && idx > 0) /* idx = 0 has mouse fallback. */
return 0;
if (mouse)
return mouse->dlt_x;
break;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
if (mouse)
return mouse->dlt_y;
break;
}
break;
{
x = mouse->x;
y = mouse->y;
pointer_down = mouse->btn_l;
}
if (check_pos)
{
x = check_pos->pointer_x;
y = check_pos->pointer_y;
pointer_down = true;
}
if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y,
&res_x, &res_y, &res_screen_x, &res_screen_y)))
return 0;
if (device == RARCH_DEVICE_POINTER_SCREEN)
{
res_x = res_screen_x;
res_y = res_screen_y;
}
if (!(inside = (res_x >= -0x7fff) && (res_y >= -0x7fff)))
return 0;
switch (id)
{
case RETRO_DEVICE_ID_POINTER_X:
return res_x;
case RETRO_DEVICE_ID_POINTER_Y:
return res_y;
case RETRO_DEVICE_ID_POINTER_PRESSED:
return pointer_down;
default:
break;
}
}
break;
case RETRO_DEVICE_LIGHTGUN:
switch (id)
{
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
if (mouse)
return winraw_lightgun_aiming_state(wr, mouse, port, id);
break;
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
case RETRO_DEVICE_ID_LIGHTGUN_RELOAD:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
case RETRO_DEVICE_ID_LIGHTGUN_START:
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_UP:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_DOWN:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_LEFT:
case RETRO_DEVICE_ID_LIGHTGUN_DPAD_RIGHT:
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE: /* deprecated */
{
unsigned new_id = winraw_retro_id_to_rarch(id);
const uint64_t bind_joykey = input_config_binds[port][new_id].joykey;
const uint64_t bind_joyaxis = input_config_binds[port][new_id].joyaxis;
const uint64_t autobind_joykey = input_autoconf_binds[port][new_id].joykey;
const uint64_t autobind_joyaxis= input_autoconf_binds[port][new_id].joyaxis;
uint16_t port = joypad_info->joy_idx;
float axis_threshold = joypad_info->axis_threshold;
const uint64_t joykey = (bind_joykey != NO_BTN)
? bind_joykey : autobind_joykey;
const uint32_t joyaxis = (bind_joyaxis != AXIS_NONE)
? bind_joyaxis : autobind_joyaxis;
if (binds[port][new_id].valid)
{
if ((uint16_t)joykey != NO_BTN && joypad->button(
port, (uint16_t)joykey))
return 1;
if (joyaxis != AXIS_NONE &&
((float)abs(joypad->axis(port, joyaxis))
/ 0x8000) > axis_threshold)
return 1;
else if (
binds[port][new_id].key < RETROK_LAST
&& !keyboard_mapping_blocked
&& WINRAW_KEYBOARD_PRESSED(wr, binds[port]
[new_id].key)
)
return 1;
else
{
if (
mouse && winraw_mouse_button_pressed(wr,
mouse, port, binds[port][new_id].mbutton)
)
return 1;
}
}
}
break;
/*deprecated*/
case RETRO_DEVICE_ID_LIGHTGUN_X:
if (mouse)
return mouse->dlt_x;
break;
case RETRO_DEVICE_ID_LIGHTGUN_Y:
if (mouse)
return mouse->dlt_y;
break;
}
break;
}
}
return 0;
@ -1061,8 +1054,8 @@ bool winraw_handle_message(UINT msg,
case WM_DEVICECHANGE:
#if defined(_WIN32_WINNT) && _WIN32_WINNT >= 0x0500 /* 2K */
if (wpar == DBT_DEVICEARRIVAL ||
wpar == DBT_DEVICEREMOVECOMPLETE)
if ( (wpar == DBT_DEVICEARRIVAL)
|| (wpar == DBT_DEVICEREMOVECOMPLETE))
{
PDEV_BROADCAST_HDR pHdr = (PDEV_BROADCAST_HDR)lpar;
if (pHdr->dbch_devicetype == DBT_DEVTYP_DEVICEINTERFACE)