mirror of
https://github.com/libretro/RetroArch
synced 2025-03-03 04:14:00 +00:00
Simplify input drivers
This commit is contained in:
parent
06ac5217ac
commit
6f92c56ca3
@ -84,9 +84,9 @@ enum {
|
||||
* Last port is used for keyboard state */
|
||||
static uint8_t android_key_state[DEFAULT_MAX_PADS + 1][MAX_KEYS];
|
||||
|
||||
#define android_keyboard_port_input_pressed(binds, id) (BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[(binds)[(id)].key]))
|
||||
#define ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds, id) (BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[(binds)[(id)].key]))
|
||||
|
||||
#define android_keyboard_input_pressed(key) (BIT_GET(android_key_state[0], (key)))
|
||||
#define ANDROID_KEYBOARD_INPUT_PRESSED(key) (BIT_GET(android_key_state[0], (key)))
|
||||
|
||||
uint8_t *android_keyboard_state_get(unsigned port)
|
||||
{
|
||||
@ -125,16 +125,16 @@ static int kbd_num = 0;
|
||||
|
||||
enum
|
||||
{
|
||||
AXIS_X = 0,
|
||||
AXIS_Y = 1,
|
||||
AXIS_Z = 11,
|
||||
AXIS_RZ = 14,
|
||||
AXIS_HAT_X = 15,
|
||||
AXIS_HAT_Y = 16,
|
||||
AXIS_X = 0,
|
||||
AXIS_Y = 1,
|
||||
AXIS_Z = 11,
|
||||
AXIS_RZ = 14,
|
||||
AXIS_HAT_X = 15,
|
||||
AXIS_HAT_Y = 16,
|
||||
AXIS_LTRIGGER = 17,
|
||||
AXIS_RTRIGGER = 18,
|
||||
AXIS_GAS = 22,
|
||||
AXIS_BRAKE = 23
|
||||
AXIS_GAS = 22,
|
||||
AXIS_BRAKE = 23
|
||||
};
|
||||
|
||||
typedef struct state_device
|
||||
@ -178,12 +178,12 @@ static typeof(AMotionEvent_getAxisValue) *p_AMotionEvent_getAxisValue;
|
||||
|
||||
#define AMotionEvent_getAxisValue (*p_AMotionEvent_getAxisValue)
|
||||
|
||||
#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState)
|
||||
|
||||
extern int32_t AMotionEvent_getButtonState(const AInputEvent* motion_event);
|
||||
|
||||
static typeof(AMotionEvent_getButtonState) *p_AMotionEvent_getButtonState;
|
||||
|
||||
#define AMotionEvent_getButtonState (*p_AMotionEvent_getButtonState)
|
||||
|
||||
#ifdef HAVE_DYNAMIC
|
||||
static void *libandroid_handle;
|
||||
#endif
|
||||
@ -460,8 +460,8 @@ static void engine_handle_dpad_getaxisvalue(android_input_t *android,
|
||||
float brake = AMotionEvent_getAxisValue(event, AXIS_BRAKE, motion_ptr);
|
||||
float gas = AMotionEvent_getAxisValue(event, AXIS_GAS, motion_ptr);
|
||||
|
||||
android->hat_state[port][0] = (int)hatx;
|
||||
android->hat_state[port][1] = (int)haty;
|
||||
android->hat_state[port][0] = (int)hatx;
|
||||
android->hat_state[port][1] = (int)haty;
|
||||
|
||||
/* XXX: this could be a loop instead, but do we really want to
|
||||
* loop through every axis? */
|
||||
@ -497,9 +497,10 @@ static bool android_input_init_handle(void)
|
||||
|
||||
if ((p_AMotionEvent_getAxisValue = dlsym(RTLD_DEFAULT,
|
||||
"AMotionEvent_getAxisValue")))
|
||||
engine_handle_dpad = engine_handle_dpad_getaxisvalue;
|
||||
engine_handle_dpad = engine_handle_dpad_getaxisvalue;
|
||||
|
||||
p_AMotionEvent_getButtonState = dlsym(RTLD_DEFAULT,"AMotionEvent_getButtonState");
|
||||
p_AMotionEvent_getButtonState = dlsym(RTLD_DEFAULT,
|
||||
"AMotionEvent_getButtonState");
|
||||
#endif
|
||||
|
||||
pad_id1 = -1;
|
||||
@ -551,7 +552,8 @@ static int android_check_quick_tap(android_input_t *android)
|
||||
* and then not touched again for 200ms
|
||||
* If so then return true and deactivate quick tap timer */
|
||||
retro_time_t now = cpu_features_get_time_usec();
|
||||
if (android->quick_tap_time && (now/1000 - android->quick_tap_time/1000000) >= 200)
|
||||
if (android->quick_tap_time &&
|
||||
(now / 1000 - android->quick_tap_time / 1000000) >= 200)
|
||||
{
|
||||
android->quick_tap_time = 0;
|
||||
return 1;
|
||||
@ -560,74 +562,6 @@ static int android_check_quick_tap(android_input_t *android)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t android_mouse_state(android_input_t *android, unsigned id)
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
val = android->mouse_l || android_check_quick_tap(android);
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
val = android->mouse_r;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
val = android->mouse_m;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
val = android->mouse_x_delta;
|
||||
android->mouse_x_delta = 0; /* flush delta after it has been read */
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
val = android->mouse_y_delta; /* flush delta after it has been read */
|
||||
android->mouse_y_delta = 0;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
val = android->mouse_wu;
|
||||
android->mouse_wu = 0;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
val = android->mouse_wd;
|
||||
android->mouse_wd = 0;
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static int16_t android_lightgun_device_state(android_input_t *android, unsigned id)
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
val = android->mouse_x_delta;
|
||||
android->mouse_x_delta = 0; /* flush delta after it has been read */
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
val = android->mouse_y_delta; /* flush delta after it has been read */
|
||||
android->mouse_y_delta = 0;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
val = android->mouse_l || android_check_quick_tap(android);
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
val = android->mouse_m;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
val = android->mouse_r;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
val = android->mouse_m && android->mouse_r;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
val = android->mouse_m && android->mouse_l;
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
static INLINE void android_mouse_calculate_deltas(android_input_t *android,
|
||||
AInputEvent *event,size_t motion_ptr)
|
||||
{
|
||||
@ -646,16 +580,22 @@ static INLINE void android_mouse_calculate_deltas(android_input_t *android,
|
||||
y_scale = 2 * (float)geom->base_height / (float)custom_vp->height;
|
||||
}
|
||||
|
||||
/* This axis is only available on Android Nougat and on Android devices with NVIDIA extensions */
|
||||
/* This axis is only available on Android Nougat and on
|
||||
* Android devices with NVIDIA extensions */
|
||||
if (p_AMotionEvent_getAxisValue)
|
||||
{
|
||||
x = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_X, motion_ptr);
|
||||
y = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_Y, motion_ptr);
|
||||
x = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_X,
|
||||
motion_ptr);
|
||||
y = AMotionEvent_getAxisValue(event,AMOTION_EVENT_AXIS_RELATIVE_Y,
|
||||
motion_ptr);
|
||||
}
|
||||
|
||||
/* If AXIS_RELATIVE had 0 values it might be because we're not running Android Nougat or on a device
|
||||
* with NVIDIA extension, so re-calculate deltas based on AXIS_X and AXIS_Y. This has limitations
|
||||
* compared to AXIS_RELATIVE because once the Android mouse cursor hits the edge of the screen it is
|
||||
/* If AXIS_RELATIVE had 0 values it might be because we're not
|
||||
* running Android Nougat or on a device
|
||||
* with NVIDIA extension, so re-calculate deltas based on
|
||||
* AXIS_X and AXIS_Y. This has limitations
|
||||
* compared to AXIS_RELATIVE because once the Android mouse cursor
|
||||
* hits the edge of the screen it is
|
||||
* not possible to move the in-game mouse any further in that direction.
|
||||
*/
|
||||
if (!x && !y)
|
||||
@ -692,13 +632,14 @@ static INLINE void android_input_poll_event_type_motion(
|
||||
/* getButtonState requires API level 14 */
|
||||
if (p_AMotionEvent_getButtonState)
|
||||
{
|
||||
btn = (int)AMotionEvent_getButtonState(event);
|
||||
btn = (int)AMotionEvent_getButtonState(event);
|
||||
|
||||
android->mouse_l = (btn & AMOTION_EVENT_BUTTON_PRIMARY);
|
||||
android->mouse_r = (btn & AMOTION_EVENT_BUTTON_SECONDARY);
|
||||
android->mouse_m = (btn & AMOTION_EVENT_BUTTON_TERTIARY);
|
||||
|
||||
btn = (int)AMotionEvent_getAxisValue(event, AMOTION_EVENT_AXIS_VSCROLL, motion_ptr);
|
||||
btn = (int)AMotionEvent_getAxisValue(event,
|
||||
AMOTION_EVENT_AXIS_VSCROLL, motion_ptr);
|
||||
|
||||
if (btn > 0)
|
||||
android->mouse_wu = btn;
|
||||
@ -759,11 +700,13 @@ static INLINE void android_input_poll_event_type_motion(
|
||||
if ((AMotionEvent_getEventTime(event) - android->quick_tap_time)/1000000 < 200)
|
||||
{
|
||||
android->quick_tap_time = 0;
|
||||
android->mouse_l = 1;
|
||||
android->mouse_l = 1;
|
||||
}
|
||||
}
|
||||
|
||||
if ((action == AMOTION_EVENT_ACTION_MOVE || action == AMOTION_EVENT_ACTION_HOVER_MOVE) && ENABLE_TOUCH_SCREEN_MOUSE)
|
||||
if (( action == AMOTION_EVENT_ACTION_MOVE
|
||||
|| action == AMOTION_EVENT_ACTION_HOVER_MOVE)
|
||||
&& ENABLE_TOUCH_SCREEN_MOUSE)
|
||||
android_mouse_calculate_deltas(android,event,motion_ptr);
|
||||
|
||||
for (motion_ptr = 0; motion_ptr < pointer_max; motion_ptr++)
|
||||
@ -812,7 +755,8 @@ static bool android_is_keyboard_id(int id)
|
||||
static INLINE void android_input_poll_event_type_keyboard(
|
||||
AInputEvent *event, int keycode, int *handled)
|
||||
{
|
||||
int keydown = (AKeyEvent_getAction(event) == AKEY_EVENT_ACTION_DOWN);
|
||||
int keydown = (AKeyEvent_getAction(event)
|
||||
== AKEY_EVENT_ACTION_DOWN);
|
||||
unsigned keyboardcode = input_keymaps_translate_keysym_to_rk(keycode);
|
||||
/* Set keyboard modifier based on shift,ctrl and alt state */
|
||||
uint16_t mod = 0;
|
||||
@ -825,7 +769,8 @@ static INLINE void android_input_poll_event_type_keyboard(
|
||||
if (meta & AMETA_SHIFT_ON)
|
||||
mod |= RETROKMOD_SHIFT;
|
||||
|
||||
input_keyboard_event(keydown, keyboardcode, keyboardcode, mod, RETRO_DEVICE_KEYBOARD);
|
||||
input_keyboard_event(keydown, keyboardcode,
|
||||
keyboardcode, mod, RETRO_DEVICE_KEYBOARD);
|
||||
|
||||
if ((keycode == AKEYCODE_VOLUME_UP || keycode == AKEYCODE_VOLUME_DOWN))
|
||||
*handled = 0;
|
||||
@ -1229,7 +1174,8 @@ static void android_input_poll_input(android_input_t *android,
|
||||
while (AInputQueue_getEvent(android_app->inputQueue, &event) >= 0)
|
||||
{
|
||||
int32_t handled = 1;
|
||||
int predispatched = AInputQueue_preDispatchEvent(android_app->inputQueue, event);
|
||||
int predispatched = AInputQueue_preDispatchEvent(
|
||||
android_app->inputQueue, event);
|
||||
int source = AInputEvent_getSource(event);
|
||||
int type_event = AInputEvent_getType(event);
|
||||
int id = android_input_get_id(event);
|
||||
@ -1243,7 +1189,8 @@ static void android_input_poll_input(android_input_t *android,
|
||||
{
|
||||
case AINPUT_EVENT_TYPE_MOTION:
|
||||
/* Only handle events from a touchscreen or mouse */
|
||||
if ((source & (AINPUT_SOURCE_TOUCHSCREEN | AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE)))
|
||||
if ((source & (AINPUT_SOURCE_TOUCHSCREEN
|
||||
| AINPUT_SOURCE_STYLUS | AINPUT_SOURCE_MOUSE)))
|
||||
android_input_poll_event_type_motion(android, event,
|
||||
port, source, vibrate_on_keypress);
|
||||
else
|
||||
@ -1257,8 +1204,11 @@ static void android_input_poll_input(android_input_t *android,
|
||||
{
|
||||
if (!predispatched)
|
||||
{
|
||||
android_input_poll_event_type_keyboard(event, keycode, &handled);
|
||||
android_input_poll_event_type_key(android_app, event, ANDROID_KEYBOARD_PORT, keycode, source, type_event, &handled);
|
||||
android_input_poll_event_type_keyboard(
|
||||
event, keycode, &handled);
|
||||
android_input_poll_event_type_key(
|
||||
android_app, event, ANDROID_KEYBOARD_PORT,
|
||||
keycode, source, type_event, &handled);
|
||||
}
|
||||
}
|
||||
else
|
||||
@ -1284,7 +1234,8 @@ static void android_input_poll_user(android_input_t *android)
|
||||
&& android_app->accelerometerSensor)
|
||||
{
|
||||
ASensorEvent event;
|
||||
while (ASensorEventQueue_getEvents(android_app->sensorEventQueue, &event, 1) > 0)
|
||||
while (ASensorEventQueue_getEvents(
|
||||
android_app->sensorEventQueue, &event, 1) > 0)
|
||||
{
|
||||
android->accelerometer_state.x = event.acceleration.x;
|
||||
android->accelerometer_state.y = event.acceleration.y;
|
||||
@ -1322,7 +1273,7 @@ static void android_input_poll(void *data, const void *joypad_data)
|
||||
while ((ident =
|
||||
ALooper_pollAll((input_config_binds[0][RARCH_PAUSE_TOGGLE].valid
|
||||
&& input_key_pressed(joypad, RARCH_PAUSE_TOGGLE,
|
||||
android_keyboard_port_input_pressed(input_config_binds[0],
|
||||
ANDROID_KEYBOARD_PORT_INPUT_PRESSED(input_config_binds[0],
|
||||
RARCH_PAUSE_TOGGLE)))
|
||||
? -1 : settings->uints.input_block_timeout,
|
||||
NULL, NULL, NULL)) >= 0)
|
||||
@ -1414,7 +1365,7 @@ static int16_t android_input_state(
|
||||
{
|
||||
if (binds[port][i].valid)
|
||||
{
|
||||
if (android_keyboard_port_input_pressed(binds[port], i))
|
||||
if (ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], i))
|
||||
ret |= (1 << i);
|
||||
}
|
||||
}
|
||||
@ -1428,7 +1379,7 @@ static int16_t android_input_state(
|
||||
button_is_pressed(
|
||||
joypad, joypad_info, binds[port],
|
||||
port, id)
|
||||
|| android_keyboard_port_input_pressed(binds[port], id)
|
||||
|| ANDROID_KEYBOARD_PORT_INPUT_PRESSED(binds[port], id)
|
||||
)
|
||||
return 1;
|
||||
}
|
||||
@ -1437,11 +1388,69 @@ static int16_t android_input_state(
|
||||
case RETRO_DEVICE_ANALOG:
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return (id < RETROK_LAST) && BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT], rarch_keysym_lut[id]);
|
||||
return (id < RETROK_LAST)
|
||||
&& BIT_GET(android_key_state[ANDROID_KEYBOARD_PORT],
|
||||
rarch_keysym_lut[id]);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return android_mouse_state(android, id);
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return android->mouse_l || android_check_quick_tap(android);
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return android->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return android->mouse_m;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
val = android->mouse_x_delta;
|
||||
android->mouse_x_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
val = android->mouse_y_delta;
|
||||
android->mouse_y_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
val = android->mouse_wu;
|
||||
android->mouse_wu = 0;
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
val = android->mouse_wd;
|
||||
android->mouse_wd = 0;
|
||||
return val;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
return android_lightgun_device_state(android, id);
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
val = android->mouse_x_delta;
|
||||
android->mouse_x_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
val = android->mouse_y_delta;
|
||||
android->mouse_y_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return android->mouse_l || android_check_quick_tap(android);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
return android->mouse_m;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
return android->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return android->mouse_m && android->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return android->mouse_m && android->mouse_l;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
switch (id)
|
||||
{
|
||||
@ -1457,9 +1466,10 @@ static int16_t android_input_state(
|
||||
return android->pointer_count;
|
||||
case RARCH_DEVICE_ID_POINTER_BACK:
|
||||
{
|
||||
const struct retro_keybind *keyptr = &input_autoconf_binds[0][RARCH_MENU_TOGGLE];
|
||||
const struct retro_keybind *keyptr =
|
||||
&input_autoconf_binds[0][RARCH_MENU_TOGGLE];
|
||||
if (keyptr->joykey == 0)
|
||||
return android_keyboard_input_pressed(AKEYCODE_BACK);
|
||||
return ANDROID_KEYBOARD_INPUT_PRESSED(AKEYCODE_BACK);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1478,9 +1488,10 @@ static int16_t android_input_state(
|
||||
return android->pointer_count;
|
||||
case RARCH_DEVICE_ID_POINTER_BACK:
|
||||
{
|
||||
const struct retro_keybind *keyptr = &input_autoconf_binds[0][RARCH_MENU_TOGGLE];
|
||||
const struct retro_keybind *keyptr =
|
||||
&input_autoconf_binds[0][RARCH_MENU_TOGGLE];
|
||||
if (keyptr->joykey == 0)
|
||||
return android_keyboard_input_pressed(AKEYCODE_BACK);
|
||||
return ANDROID_KEYBOARD_INPUT_PRESSED(AKEYCODE_BACK);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@ -1513,8 +1524,6 @@ static void android_input_free_input(void *data)
|
||||
|
||||
static uint64_t android_input_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
return
|
||||
(1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_POINTER) |
|
||||
@ -1571,7 +1580,7 @@ static bool android_input_set_sensor_state(void *data, unsigned port,
|
||||
BIT64_SET(android_app->sensor_state_mask, RETRO_SENSOR_ACCELEROMETER_DISABLE);
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -1595,12 +1604,6 @@ static float android_input_get_sensor_input(void *data,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void android_input_grab_mouse(void *data, bool state)
|
||||
{
|
||||
(void)data;
|
||||
(void)state;
|
||||
}
|
||||
|
||||
static bool android_input_set_rumble(
|
||||
const input_device_driver_t *joypad,
|
||||
const input_device_driver_t *sec_joypad,
|
||||
@ -1622,7 +1625,7 @@ input_driver_t input_android = {
|
||||
android_input_get_capabilities,
|
||||
"android",
|
||||
|
||||
android_input_grab_mouse,
|
||||
NULL, /* grab_mouse */
|
||||
NULL,
|
||||
android_input_set_rumble
|
||||
};
|
||||
|
@ -86,102 +86,6 @@ static void cocoa_input_poll(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t cocoa_mouse_state(cocoa_input_data_t *apple,
|
||||
unsigned id)
|
||||
{
|
||||
int16_t val;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
val = apple->window_pos_x - apple->mouse_x_last;
|
||||
apple->mouse_x_last = apple->window_pos_x;
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
val = apple->window_pos_y - apple->mouse_y_last;
|
||||
apple->mouse_y_last = apple->window_pos_y;
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return apple->mouse_buttons & 1;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return apple->mouse_buttons & 2;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
return apple->mouse_wu;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
return apple->mouse_wd;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
return apple->mouse_wl;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
return apple->mouse_wr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t cocoa_mouse_state_screen(cocoa_input_data_t *apple,
|
||||
unsigned id)
|
||||
{
|
||||
int16_t val;
|
||||
#ifndef IOS
|
||||
float backing_scale_factor = get_backing_scale_factor();
|
||||
#endif
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
val = apple->window_pos_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
val = apple->window_pos_y;
|
||||
break;
|
||||
default:
|
||||
return cocoa_mouse_state(apple, id);
|
||||
}
|
||||
|
||||
#ifndef IOS
|
||||
val *= backing_scale_factor;
|
||||
#endif
|
||||
return val;
|
||||
}
|
||||
|
||||
static int16_t cocoa_pointer_state(cocoa_input_data_t *apple,
|
||||
unsigned device, unsigned idx, unsigned id)
|
||||
{
|
||||
const bool want_full = (device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
|
||||
if (idx < apple->touch_count && (idx < MAX_TOUCHES))
|
||||
{
|
||||
int16_t x, y;
|
||||
const cocoa_touch_data_t *touch = (const cocoa_touch_data_t *)
|
||||
&apple->touches[idx];
|
||||
|
||||
if (!touch)
|
||||
return 0;
|
||||
|
||||
x = touch->fixed_x;
|
||||
y = touch->fixed_y;
|
||||
|
||||
if (want_full)
|
||||
{
|
||||
x = touch->full_x;
|
||||
y = touch->full_y;
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return (x != -0x8000) && (y != -0x8000);
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return x;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return y;
|
||||
case RETRO_DEVICE_ID_POINTER_COUNT:
|
||||
return apple->touch_count;
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t cocoa_input_state(
|
||||
void *data,
|
||||
const input_device_driver_t *joypad,
|
||||
@ -249,12 +153,87 @@ static int16_t cocoa_input_state(
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return (id < RETROK_LAST) && apple_key_state[rarch_keysym_lut[(enum retro_key)id]];
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return cocoa_mouse_state(apple, id);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return cocoa_mouse_state_screen(apple, id);
|
||||
{
|
||||
int16_t val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (device == RARCH_DEVICE_MOUSE_SCREEN)
|
||||
{
|
||||
#ifdef IOS
|
||||
return apple->window_pos_x;
|
||||
#else
|
||||
return apple->window_pos_x * get_backing_scale_factor();
|
||||
#endif
|
||||
}
|
||||
val = apple->window_pos_x - apple->mouse_x_last;
|
||||
apple->mouse_x_last = apple->window_pos_x;
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
if (device == RARCH_DEVICE_MOUSE_SCREEN)
|
||||
{
|
||||
#ifdef IOS
|
||||
return apple->window_pos_y;
|
||||
#else
|
||||
return apple->window_pos_y * get_backing_scale_factor();
|
||||
#endif
|
||||
}
|
||||
val = apple->window_pos_y - apple->mouse_y_last;
|
||||
apple->mouse_y_last = apple->window_pos_y;
|
||||
return val;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return apple->mouse_buttons & 1;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return apple->mouse_buttons & 2;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
return apple->mouse_wu;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
return apple->mouse_wd;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
return apple->mouse_wl;
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
return apple->mouse_wr;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
return cocoa_pointer_state(apple, device, idx, id);
|
||||
{
|
||||
const bool want_full = (device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
|
||||
if (idx < apple->touch_count && (idx < MAX_TOUCHES))
|
||||
{
|
||||
int16_t x, y;
|
||||
const cocoa_touch_data_t *touch = (const cocoa_touch_data_t *)
|
||||
&apple->touches[idx];
|
||||
|
||||
if (!touch)
|
||||
return 0;
|
||||
|
||||
x = touch->fixed_x;
|
||||
y = touch->fixed_y;
|
||||
|
||||
if (want_full)
|
||||
{
|
||||
x = touch->full_x;
|
||||
y = touch->full_y;
|
||||
}
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return (x != -0x8000) && (y != -0x8000);
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return x;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return y;
|
||||
case RETRO_DEVICE_ID_POINTER_COUNT:
|
||||
return apple->touch_count;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -292,8 +271,6 @@ static bool cocoa_input_set_rumble(
|
||||
|
||||
static uint64_t cocoa_input_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
return
|
||||
(1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_MOUSE) |
|
||||
|
@ -40,14 +40,6 @@ typedef struct dos_input
|
||||
/* TODO/FIXME - static globals */
|
||||
static uint16_t dos_key_state[DEFAULT_MAX_PADS+1][MAX_KEYS];
|
||||
|
||||
static bool dos_keyboard_port_input_pressed(
|
||||
const struct retro_keybind *binds, unsigned id)
|
||||
{
|
||||
if (id < RARCH_BIND_LIST_END)
|
||||
return dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[id].key]];
|
||||
return false;
|
||||
}
|
||||
|
||||
uint16_t *dos_keyboard_state_get(unsigned port)
|
||||
{
|
||||
return dos_key_state[port];
|
||||
@ -74,7 +66,7 @@ static int16_t dos_input_state(
|
||||
unsigned idx,
|
||||
unsigned id)
|
||||
{
|
||||
dos_input_t *dos = (dos_input_t*)data;
|
||||
dos_input_t *dos = (dos_input_t*)data;
|
||||
|
||||
if (port > 0)
|
||||
return 0;
|
||||
@ -93,7 +85,8 @@ static int16_t dos_input_state(
|
||||
if (binds[port][i].valid)
|
||||
{
|
||||
if (id < RARCH_BIND_LIST_END)
|
||||
if (dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[i].key]])
|
||||
if (dos_key_state[DOS_KEYBOARD_PORT]
|
||||
[rarch_keysym_lut[binds[i].key]])
|
||||
ret |= (1 << i);
|
||||
}
|
||||
}
|
||||
@ -108,7 +101,9 @@ static int16_t dos_input_state(
|
||||
button_is_pressed(
|
||||
joypad, joypad_info, binds[port],
|
||||
port, id)
|
||||
|| dos_keyboard_port_input_pressed(binds[port], id)
|
||||
|| (id < RARCH_BIND_LIST_END
|
||||
&& dos_key_state[DOS_KEYBOARD_PORT]
|
||||
[rarch_keysym_lut[binds[port][id].key]])
|
||||
)
|
||||
return 1;
|
||||
}
|
||||
@ -116,7 +111,8 @@ static int16_t dos_input_state(
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
if (id < RARCH_BIND_LIST_END)
|
||||
return (dos_key_state[DOS_KEYBOARD_PORT][rarch_keysym_lut[binds[id].key]]);
|
||||
return (dos_key_state[DOS_KEYBOARD_PORT]
|
||||
[rarch_keysym_lut[binds[id].key]]);
|
||||
break;
|
||||
}
|
||||
|
||||
|
@ -22,6 +22,7 @@
|
||||
|
||||
#include <boolean.h>
|
||||
#include <retro_miscellaneous.h>
|
||||
#include <retro_inline.h>
|
||||
|
||||
#include <libretro.h>
|
||||
|
||||
@ -35,7 +36,9 @@
|
||||
#ifdef HW_RVL
|
||||
/* gx joypad functions */
|
||||
bool gxpad_mousevalid(unsigned port);
|
||||
void gx_joypad_read_mouse(unsigned port, int *irx, int *iry, uint32_t *button);
|
||||
|
||||
void gx_joypad_read_mouse(unsigned port,
|
||||
int *irx, int *iry, uint32_t *button);
|
||||
|
||||
typedef struct
|
||||
{
|
||||
@ -48,96 +51,13 @@ typedef struct
|
||||
typedef struct gx_input
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
int mouse_max;
|
||||
gx_input_mouse_t *mouse;
|
||||
int mouse_max;
|
||||
#else
|
||||
void *empty;
|
||||
#endif
|
||||
} gx_input_t;
|
||||
|
||||
#ifdef HW_RVL
|
||||
static int16_t gx_lightgun_state(gx_input_t *gx,
|
||||
unsigned id, uint16_t joy_idx)
|
||||
{
|
||||
struct video_viewport vp = {0};
|
||||
video_driver_get_viewport_info(&vp);
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
x = gx->mouse[joy_idx].x_abs;
|
||||
y = gx->mouse[joy_idx].y_abs;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, x, y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
return res_screen_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||
return res_screen_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_TRIGGER);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_A);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_B);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_C);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_START);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_LIGHTGUN_SELECT);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !gxpad_mousevalid(joy_idx);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t gx_mouse_state(gx_input_t *gx, unsigned id, uint16_t joy_idx)
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
unsigned input_mouse_scale = settings->uints.input_mouse_scale;
|
||||
int x_scale = input_mouse_scale;
|
||||
int y_scale = input_mouse_scale;
|
||||
int x = (gx->mouse[joy_idx].x_abs
|
||||
- gx->mouse[joy_idx].x_last) * x_scale;
|
||||
int y = (gx->mouse[joy_idx].y_abs
|
||||
- gx->mouse[joy_idx].y_last) * y_scale;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_MOUSE_LEFT);
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return gx->mouse[joy_idx].button & (1 << RETRO_DEVICE_ID_MOUSE_RIGHT);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int16_t gx_input_state(
|
||||
void *data,
|
||||
const input_device_driver_t *joypad,
|
||||
@ -172,10 +92,92 @@ static int16_t gx_input_state(
|
||||
break;
|
||||
#ifdef HW_RVL
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return gx_mouse_state(gx, id, joypad_info->joy_idx);
|
||||
{
|
||||
settings_t *settings = config_get_ptr();
|
||||
uint16_t joy_idx = joypad_info->joy_idx;
|
||||
unsigned input_mouse_scale = settings->uints.input_mouse_scale;
|
||||
int x_scale = input_mouse_scale;
|
||||
int y_scale = input_mouse_scale;
|
||||
int x = (gx->mouse[joy_idx].x_abs
|
||||
- gx->mouse[joy_idx].x_last) * x_scale;
|
||||
int y = (gx->mouse[joy_idx].y_abs
|
||||
- gx->mouse[joy_idx].y_last) * y_scale;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_MOUSE_LEFT);
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_MOUSE_RIGHT);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
return gx_lightgun_state(gx, id, joypad_info->joy_idx);
|
||||
{
|
||||
struct video_viewport vp = {0};
|
||||
uint16_t joy_idx = joypad_info->joy_idx;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
int16_t x = 0;
|
||||
int16_t y = 0;
|
||||
|
||||
video_driver_get_viewport_info(&vp);
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
x = gx->mouse[joy_idx].x_abs;
|
||||
y = gx->mouse[joy_idx].y_abs;
|
||||
|
||||
if (video_driver_translate_coord_viewport_wrap(&vp, x, y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y))
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
return res_screen_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||
return res_screen_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_TRIGGER);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_A:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_A);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_B:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_B);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_AUX_C:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_AUX_C);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_START);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SELECT:
|
||||
return gx->mouse[joy_idx].button &
|
||||
(1 << RETRO_DEVICE_ID_LIGHTGUN_SELECT);
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !gxpad_mousevalid(joy_idx);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
@ -214,14 +216,11 @@ static void *gx_input_init(const char *joypad_driver)
|
||||
}
|
||||
|
||||
#ifdef HW_RVL
|
||||
static inline int gx_count_mouse(gx_input_t *gx)
|
||||
static INLINE int rvl_count_mouse(gx_input_t *gx)
|
||||
{
|
||||
unsigned i;
|
||||
int count = 0;
|
||||
|
||||
if (!gx)
|
||||
return 0;
|
||||
|
||||
for (i = 0; i < DEFAULT_MAX_PADS; i++)
|
||||
{
|
||||
const char *joypad_name = joypad_driver_name(i);
|
||||
@ -233,63 +232,61 @@ static inline int gx_count_mouse(gx_input_t *gx)
|
||||
return count;
|
||||
}
|
||||
|
||||
static void gx_input_poll_mouse(gx_input_t *gx)
|
||||
{
|
||||
int count = gx_count_mouse(gx);
|
||||
|
||||
if (gx && count > 0)
|
||||
{
|
||||
unsigned i;
|
||||
if (count != gx->mouse_max)
|
||||
{
|
||||
gx_input_mouse_t *tmp = (gx_input_mouse_t*)realloc(
|
||||
gx->mouse, count * sizeof(gx_input_mouse_t));
|
||||
if (!tmp)
|
||||
free(gx->mouse);
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
gx->mouse = tmp;
|
||||
gx->mouse_max = count;
|
||||
|
||||
for (i = 0; i < gx->mouse_max; i++)
|
||||
{
|
||||
gx->mouse[i].x_last = 0;
|
||||
gx->mouse[i].y_last = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < gx->mouse_max; i++)
|
||||
{
|
||||
gx->mouse[i].x_last = gx->mouse[i].x_abs;
|
||||
gx->mouse[i].y_last = gx->mouse[i].y_abs;
|
||||
gx_joypad_read_mouse(i, &gx->mouse[i].x_abs,
|
||||
&gx->mouse[i].y_abs, &gx->mouse[i].button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void rvl_input_poll(void *data)
|
||||
{
|
||||
gx_input_t *gx = (gx_input_t*)data;
|
||||
if (gx && gx->mouse)
|
||||
gx_input_poll_mouse(gx);
|
||||
}
|
||||
#endif
|
||||
{
|
||||
int count = rvl_count_mouse(gx);
|
||||
|
||||
static uint64_t gx_input_get_capabilities(void *data)
|
||||
if (gx && count > 0)
|
||||
{
|
||||
unsigned i;
|
||||
if (count != gx->mouse_max)
|
||||
{
|
||||
gx_input_mouse_t *tmp = (gx_input_mouse_t*)realloc(
|
||||
gx->mouse, count * sizeof(gx_input_mouse_t));
|
||||
if (!tmp)
|
||||
free(gx->mouse);
|
||||
else
|
||||
{
|
||||
unsigned i;
|
||||
gx->mouse = tmp;
|
||||
gx->mouse_max = count;
|
||||
|
||||
for (i = 0; i < gx->mouse_max; i++)
|
||||
{
|
||||
gx->mouse[i].x_last = 0;
|
||||
gx->mouse[i].y_last = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < gx->mouse_max; i++)
|
||||
{
|
||||
gx->mouse[i].x_last = gx->mouse[i].x_abs;
|
||||
gx->mouse[i].y_last = gx->mouse[i].y_abs;
|
||||
gx_joypad_read_mouse(i, &gx->mouse[i].x_abs,
|
||||
&gx->mouse[i].y_abs, &gx->mouse[i].button);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static uint64_t rvl_input_get_capabilities(void *data)
|
||||
{
|
||||
#ifdef HW_RVL
|
||||
return (1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_ANALOG) |
|
||||
(1 << RETRO_DEVICE_MOUSE) |
|
||||
(1 << RETRO_DEVICE_LIGHTGUN);
|
||||
}
|
||||
#else
|
||||
static uint64_t gx_input_get_capabilities(void *data)
|
||||
{
|
||||
return (1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_ANALOG);
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
input_driver_t input_gx = {
|
||||
gx_input_init,
|
||||
@ -302,7 +299,11 @@ input_driver_t input_gx = {
|
||||
gx_input_free_input,
|
||||
NULL,
|
||||
NULL,
|
||||
#ifdef HW_RVL
|
||||
rvl_input_get_capabilities,
|
||||
#else
|
||||
gx_input_get_capabilities,
|
||||
#endif
|
||||
"gx",
|
||||
|
||||
NULL, /* grab_mouse */
|
||||
|
@ -203,8 +203,8 @@ static void linuxraw_input_poll(void *data)
|
||||
if (c == KEY_C && (linuxraw->state[KEY_LEFTCTRL] || linuxraw->state[KEY_RIGHTCTRL]))
|
||||
kill(getpid(), SIGINT);
|
||||
|
||||
pressed = !(c & 0x80);
|
||||
c &= ~0x80;
|
||||
pressed = !(c & 0x80);
|
||||
c &= ~0x80;
|
||||
|
||||
/* ignore extended scancodes */
|
||||
if (!c)
|
||||
|
@ -82,8 +82,6 @@ static void* ps2_input_initialize(const char *joypad_driver)
|
||||
|
||||
static uint64_t ps2_input_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
return (1 << RETRO_DEVICE_JOYPAD) | (1 << RETRO_DEVICE_ANALOG);
|
||||
}
|
||||
|
||||
|
@ -53,18 +53,16 @@ typedef struct ps3_input
|
||||
#endif
|
||||
} ps3_input_t;
|
||||
|
||||
#ifdef HAVE_MOUSE
|
||||
static void ps3_input_poll(void *data)
|
||||
{
|
||||
#ifdef HAVE_MOUSE
|
||||
CellMouseInfo mouse_info;
|
||||
ps3_input_t *ps3 = (ps3_input_t*)data;
|
||||
|
||||
cellMouseGetInfo(&mouse_info);
|
||||
ps3->mice_connected = mouse_info.now_connect;
|
||||
#endif
|
||||
}
|
||||
|
||||
#ifdef HAVE_MOUSE
|
||||
static int16_t ps3_mouse_device_state(ps3_input_t *ps3,
|
||||
unsigned user, unsigned id)
|
||||
{
|
||||
@ -129,16 +127,13 @@ static int16_t ps3_input_state(
|
||||
{
|
||||
/* Fixed range of 0x000 - 0x3ff */
|
||||
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_X:
|
||||
retval = ps3->accelerometer_state[port].x;
|
||||
break;
|
||||
return ps3->accelerometer_state[port].x;
|
||||
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Y:
|
||||
retval = ps3->accelerometer_state[port].y;
|
||||
break;
|
||||
return ps3->accelerometer_state[port].y;
|
||||
case RETRO_DEVICE_ID_SENSOR_ACCELEROMETER_Z:
|
||||
retval = ps3->accelerometer_state[port].z;
|
||||
break;
|
||||
return ps3->accelerometer_state[port].z;
|
||||
default:
|
||||
retval = 0;
|
||||
break;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
@ -179,7 +174,6 @@ static void* ps3_input_init(const char *joypad_driver)
|
||||
|
||||
static uint64_t ps3_input_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
return
|
||||
#ifdef HAVE_MOUSE
|
||||
(1 << RETRO_DEVICE_MOUSE) |
|
||||
@ -229,7 +223,11 @@ static bool ps3_input_set_rumble(
|
||||
|
||||
input_driver_t input_ps3 = {
|
||||
ps3_input_init,
|
||||
#ifdef HAVE_MOUSE
|
||||
ps3_input_poll,
|
||||
#else
|
||||
NULL, /* poll */
|
||||
#endif
|
||||
ps3_input_state,
|
||||
ps3_input_free_input,
|
||||
ps3_input_set_sensor_state,
|
||||
|
@ -112,12 +112,16 @@ static void ps3_input_poll(void *data)
|
||||
/* Set keyboard modifier based on shift,ctrl and alt state */
|
||||
uint16_t mod = 0;
|
||||
|
||||
if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_alt || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_alt)
|
||||
if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_alt
|
||||
|| ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_alt)
|
||||
mod |= RETROKMOD_ALT;
|
||||
if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_ctrl || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_ctrl)
|
||||
if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_ctrl
|
||||
|| ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_ctrl)
|
||||
mod |= RETROKMOD_CTRL;
|
||||
if (ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_shift || ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_shift)
|
||||
if ( ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.l_shift
|
||||
|| ps3->kbdata[i].mkey._KbMkeyU._KbMkeyS.r_shift)
|
||||
mod |= RETROKMOD_SHIFT;
|
||||
|
||||
/* TODO: windows keys. */
|
||||
|
||||
for (j = 0; j < last_kbdata[i].nb_keycode; j++)
|
||||
@ -127,11 +131,13 @@ static void ps3_input_poll(void *data)
|
||||
int newly_depressed = 1;
|
||||
|
||||
for (k = 0; k < MAX_KB_PORT_NUM; i++)
|
||||
{
|
||||
if (ps3->kbdata[i].keycode[k] == code)
|
||||
{
|
||||
newly_depressed = 0;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (newly_depressed)
|
||||
{
|
||||
@ -164,12 +170,8 @@ static void ps3_input_poll(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef HAVE_MOUSE
|
||||
static int16_t ps3_mouse_device_state(ps3_input_t *ps3,
|
||||
unsigned user, unsigned id) { }
|
||||
#endif
|
||||
|
||||
static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id)
|
||||
static bool psl1ght_keyboard_port_input_pressed(
|
||||
ps3_input_t *ps3, unsigned id)
|
||||
{
|
||||
int code;
|
||||
unsigned i, j;
|
||||
@ -183,8 +185,8 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id)
|
||||
{
|
||||
for (j = 0; j < MAX_KB_PORT_NUM; j++)
|
||||
{
|
||||
if (ps3->kbinfo.status[j] && (ps3->kbdata[j].mkey._KbMkeyU.mkeys &
|
||||
(1 << i)))
|
||||
if (ps3->kbinfo.status[j]
|
||||
&& (ps3->kbdata[j].mkey._KbMkeyU.mkeys & (1 << i)))
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
@ -197,11 +199,13 @@ static bool psl1ght_keyboard_port_input_pressed(ps3_input_t *ps3, unsigned id)
|
||||
for (i = 0; i < MAX_KB_PORT_NUM; i++)
|
||||
{
|
||||
if (ps3->kbinfo.status[i])
|
||||
{
|
||||
for (j = 0; j < ps3->kbdata[i].nb_keycode; j++)
|
||||
{
|
||||
if (ps3->kbdata[i].keycode[j] == code)
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
|
@ -55,7 +55,6 @@
|
||||
* fix game focus toggle */
|
||||
|
||||
#ifdef VITA
|
||||
|
||||
#include "../input_keymaps.h"
|
||||
|
||||
uint8_t modifier_lut[VITA_NUM_MODIFIERS][2] =
|
||||
@ -91,7 +90,7 @@ typedef struct psp_input
|
||||
|
||||
static void vita_input_poll(void *data)
|
||||
{
|
||||
psp_input_t *psp = (psp_input_t*)data;
|
||||
psp_input_t *psp = (psp_input_t*)data;
|
||||
unsigned int i = 0;
|
||||
int key_sym = 0;
|
||||
unsigned key_code = 0;
|
||||
@ -99,7 +98,6 @@ static void vita_input_poll(void *data)
|
||||
uint16_t mod = 0;
|
||||
uint8_t modifiers[2] = { 0, 0 };
|
||||
bool key_held = false;
|
||||
int numReports = 0;
|
||||
int mouse_velocity_x = 0;
|
||||
int mouse_velocity_y = 0;
|
||||
SceHidKeyboardReport k_reports[SCE_HID_MAX_REPORT];
|
||||
@ -107,7 +105,7 @@ static void vita_input_poll(void *data)
|
||||
|
||||
if (psp->keyboard_hid_handle > 0)
|
||||
{
|
||||
numReports = sceHidKeyboardRead(
|
||||
int numReports = sceHidKeyboardRead(
|
||||
psp->keyboard_hid_handle,
|
||||
(SceHidKeyboardReport**)&k_reports, SCE_HID_MAX_REPORT);
|
||||
|
||||
@ -135,9 +133,9 @@ static void vita_input_poll(void *data)
|
||||
|
||||
for (i = 0; i < VITA_NUM_MODIFIERS; i++)
|
||||
{
|
||||
key_sym = (int) modifier_lut[i][0];
|
||||
mod_code = modifier_lut[i][1];
|
||||
key_code = input_keymaps_translate_keysym_to_rk(key_sym);
|
||||
key_sym = (int)modifier_lut[i][0];
|
||||
mod_code = modifier_lut[i][1];
|
||||
key_code = input_keymaps_translate_keysym_to_rk(key_sym);
|
||||
if (i < 8)
|
||||
key_held = (modifiers[0] & mod_code);
|
||||
else
|
||||
@ -189,7 +187,7 @@ static void vita_input_poll(void *data)
|
||||
|
||||
if (psp->mouse_hid_handle > 0)
|
||||
{
|
||||
numReports = sceHidMouseRead(psp->mouse_hid_handle,
|
||||
int numReports = sceHidMouseRead(psp->mouse_hid_handle,
|
||||
(SceHidMouseReport**)&m_reports, SCE_HID_MAX_REPORT);
|
||||
|
||||
if (numReports > 0)
|
||||
@ -219,50 +217,19 @@ static void vita_input_poll(void *data)
|
||||
}
|
||||
}
|
||||
|
||||
psp->mouse_x_delta = mouse_velocity_x;
|
||||
psp->mouse_y_delta = mouse_velocity_y;
|
||||
psp->mouse_x += mouse_velocity_x;
|
||||
psp->mouse_y += mouse_velocity_y;
|
||||
psp->mouse_x_delta = mouse_velocity_x;
|
||||
psp->mouse_y_delta = mouse_velocity_y;
|
||||
psp->mouse_x += mouse_velocity_x;
|
||||
psp->mouse_y += mouse_velocity_y;
|
||||
if (psp->mouse_x < 0)
|
||||
psp->mouse_x = 0;
|
||||
psp->mouse_x = 0;
|
||||
else if (psp->mouse_x > MOUSE_MAX_X)
|
||||
psp->mouse_x = MOUSE_MAX_X;
|
||||
psp->mouse_x = MOUSE_MAX_X;
|
||||
|
||||
if (psp->mouse_y < 0)
|
||||
psp->mouse_y = 0;
|
||||
psp->mouse_y = 0;
|
||||
else if (psp->mouse_y > MOUSE_MAX_Y)
|
||||
psp->mouse_y = MOUSE_MAX_Y;
|
||||
}
|
||||
|
||||
static int16_t psp_input_mouse_state(
|
||||
psp_input_t *psp, unsigned id, bool screen)
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return psp->mouse_button_left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return psp->mouse_button_right;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return psp->mouse_button_middle;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (screen)
|
||||
return psp->mouse_x;
|
||||
|
||||
val = psp->mouse_x_delta;
|
||||
psp->mouse_x_delta = 0; /* flush delta after it has been read */
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
if (screen)
|
||||
return psp->mouse_y;
|
||||
|
||||
val = psp->mouse_y_delta;
|
||||
psp->mouse_y_delta = 0; /* flush delta after it has been read */
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
psp->mouse_y = MOUSE_MAX_Y;
|
||||
}
|
||||
#else
|
||||
typedef struct psp_input
|
||||
@ -307,13 +274,39 @@ static int16_t psp_input_state(
|
||||
break;
|
||||
#ifdef VITA
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return ((id < RETROK_LAST) && psp->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]);
|
||||
break;
|
||||
return ((id < RETROK_LAST) &&
|
||||
psp->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return psp_input_mouse_state(psp, id, false);
|
||||
break;
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return psp_input_mouse_state(psp, id, true);
|
||||
{
|
||||
bool screen = device == RARCH_DEVICE_MOUSE_SCREEN;
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return psp->mouse_button_left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return psp->mouse_button_right;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return psp->mouse_button_middle;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (screen)
|
||||
return psp->mouse_x;
|
||||
|
||||
val = psp->mouse_x_delta;
|
||||
psp->mouse_x_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
if (screen)
|
||||
return psp->mouse_y;
|
||||
val = psp->mouse_y_delta;
|
||||
psp->mouse_y_delta = 0;
|
||||
/* flush delta after it has been read */
|
||||
break;
|
||||
}
|
||||
return val;
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
@ -220,17 +220,16 @@ static void rwebinput_generate_lut(void)
|
||||
|
||||
/* sanity check: make sure there's no collisions */
|
||||
for (j = 0; j < i; j++)
|
||||
{
|
||||
retro_assert(rarch_key_map_rwebinput[j].sym != crc);
|
||||
}
|
||||
|
||||
key_map->rk = key_to_code->rk;
|
||||
key_map->rk = key_to_code->rk;
|
||||
key_map->sym = crc;
|
||||
}
|
||||
|
||||
/* set terminating entry */
|
||||
key_map = &rarch_key_map_rwebinput[ARRAY_SIZE(rarch_key_map_rwebinput) - 1];
|
||||
key_map->rk = RETROK_UNKNOWN;
|
||||
key_map = &rarch_key_map_rwebinput[
|
||||
ARRAY_SIZE(rarch_key_map_rwebinput) - 1];
|
||||
key_map->rk = RETROK_UNKNOWN;
|
||||
key_map->sym = 0;
|
||||
}
|
||||
|
||||
@ -301,24 +300,27 @@ static void *rwebinput_input_init(const char *joypad_driver)
|
||||
|
||||
rwebinput_generate_lut();
|
||||
|
||||
r = emscripten_set_keydown_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
r = emscripten_set_keydown_callback(
|
||||
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
"[EMSCRIPTEN/INPUT] failed to create keydown callback: %d\n", r);
|
||||
}
|
||||
|
||||
r = emscripten_set_keyup_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
r = emscripten_set_keyup_callback(
|
||||
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
"[EMSCRIPTEN/INPUT] failed to create keydown callback: %d\n", r);
|
||||
}
|
||||
|
||||
r = emscripten_set_keypress_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
r = emscripten_set_keypress_callback(
|
||||
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_keyboard_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
@ -326,7 +328,7 @@ static void *rwebinput_input_init(const char *joypad_driver)
|
||||
}
|
||||
|
||||
r = emscripten_set_mousedown_callback("#canvas", rwebinput, false,
|
||||
rwebinput_mouse_cb);
|
||||
rwebinput_mouse_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
@ -334,7 +336,7 @@ static void *rwebinput_input_init(const char *joypad_driver)
|
||||
}
|
||||
|
||||
r = emscripten_set_mouseup_callback("#canvas", rwebinput, false,
|
||||
rwebinput_mouse_cb);
|
||||
rwebinput_mouse_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
@ -342,15 +344,16 @@ static void *rwebinput_input_init(const char *joypad_driver)
|
||||
}
|
||||
|
||||
r = emscripten_set_mousemove_callback("#canvas", rwebinput, false,
|
||||
rwebinput_mouse_cb);
|
||||
rwebinput_mouse_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
"[EMSCRIPTEN/INPUT] failed to create mousemove callback: %d\n", r);
|
||||
}
|
||||
|
||||
r = emscripten_set_wheel_callback(EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_wheel_cb);
|
||||
r = emscripten_set_wheel_callback(
|
||||
EMSCRIPTEN_EVENT_TARGET_DOCUMENT, rwebinput, false,
|
||||
rwebinput_wheel_cb);
|
||||
if (r != EMSCRIPTEN_RESULT_SUCCESS)
|
||||
{
|
||||
RARCH_ERR(
|
||||
@ -360,10 +363,6 @@ static void *rwebinput_input_init(const char *joypad_driver)
|
||||
input_keymaps_init_keyboard_lut(rarch_key_map_rwebinput);
|
||||
|
||||
return rwebinput;
|
||||
|
||||
error:
|
||||
free(rwebinput);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key)
|
||||
@ -374,61 +373,6 @@ static bool rwebinput_key_pressed(rwebinput_input_t *rwebinput, int key)
|
||||
return rwebinput->keys[key];
|
||||
}
|
||||
|
||||
static int16_t rwebinput_pointer_device_state(
|
||||
rwebinput_mouse_state_t *mouse,
|
||||
unsigned id, bool screen)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
const int edge_detect = 32700;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, mouse->x, mouse->x,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
|
||||
inside = (res_x >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTNL));
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t rwebinput_mouse_state(
|
||||
rwebinput_mouse_state_t *mouse,
|
||||
unsigned id, bool screen)
|
||||
@ -484,7 +428,8 @@ static int16_t rwebinput_is_pressed(
|
||||
if (port == 0 && !!rwebinput_mouse_state(&rwebinput->mouse,
|
||||
bind->mbutton, false))
|
||||
return 1;
|
||||
if ((uint16_t)joykey != NO_BTN && joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
|
||||
if ((uint16_t)joykey != NO_BTN
|
||||
&& joypad->button(joypad_info->joy_idx, (uint16_t)joykey))
|
||||
return 1;
|
||||
if (((float)abs(joypad->axis(joypad_info->joy_idx, joyaxis))
|
||||
/ 0x8000) > joypad_info->axis_threshold)
|
||||
@ -579,15 +524,68 @@ static int16_t rwebinput_input_state(
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return rwebinput_key_pressed(rwebinput, id);
|
||||
return ((id < RETROK_LAST) && rwebinput->keys[id]);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return rwebinput_mouse_state(&rwebinput->mouse, id, false);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return rwebinput_mouse_state(&rwebinput->mouse, id, true);
|
||||
return rwebinput_mouse_state(&rwebinput->mouse, id,
|
||||
device == RARCH_DEVICE_MOUSE_SCREEN);
|
||||
case RETRO_DEVICE_POINTER:
|
||||
return rwebinput_pointer_device_state(&rwebinput->mouse, id, false);
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
return rwebinput_pointer_device_state(&rwebinput->mouse, id, true);
|
||||
{
|
||||
struct video_viewport vp;
|
||||
rwebinput_mouse_state_t
|
||||
*mouse = &rwebinput->mouse;
|
||||
const int edge_detect = 32700;
|
||||
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;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(
|
||||
&vp, mouse->x, mouse->x,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
|
||||
inside = (res_x >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return !!(mouse->buttons & (1 << RWEBINPUT_MOUSE_BTNL));
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -603,21 +601,23 @@ static void rwebinput_input_free(void *data)
|
||||
free(rwebinput);
|
||||
}
|
||||
|
||||
static void rwebinput_process_keyboard_events(rwebinput_input_t *rwebinput,
|
||||
rwebinput_keyboard_event_t *event)
|
||||
static void rwebinput_process_keyboard_events(
|
||||
rwebinput_input_t *rwebinput,
|
||||
rwebinput_keyboard_event_t *event)
|
||||
{
|
||||
uint32_t keycode;
|
||||
unsigned translated_keycode;
|
||||
uint32_t character = 0;
|
||||
uint16_t mod = 0;
|
||||
uint32_t character = 0;
|
||||
uint16_t mod = 0;
|
||||
const EmscriptenKeyboardEvent *key_event = &event->event;
|
||||
bool keydown = event->type == EMSCRIPTEN_EVENT_KEYDOWN;
|
||||
bool keydown =
|
||||
event->type == EMSCRIPTEN_EVENT_KEYDOWN;
|
||||
|
||||
/* a printable key: populate character field */
|
||||
if (utf8len(key_event->key) == 1)
|
||||
{
|
||||
const char *key_ptr = &key_event->key[0];
|
||||
character = utf8_walk(&key_ptr);
|
||||
character = utf8_walk(&key_ptr);
|
||||
}
|
||||
|
||||
if (key_event->ctrlKey)
|
||||
@ -653,20 +653,21 @@ static void rwebinput_process_keyboard_events(rwebinput_input_t *rwebinput,
|
||||
static void rwebinput_input_poll(void *data)
|
||||
{
|
||||
size_t i;
|
||||
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
||||
rwebinput_input_t *rwebinput = (rwebinput_input_t*)data;
|
||||
|
||||
for (i = 0; i < rwebinput->keyboard.count; i++)
|
||||
rwebinput_process_keyboard_events(rwebinput,
|
||||
&rwebinput->keyboard.events[i]);
|
||||
rwebinput->keyboard.count = 0;
|
||||
|
||||
rwebinput->mouse.delta_x = rwebinput->mouse.pending_delta_x;
|
||||
rwebinput->mouse.delta_y = rwebinput->mouse.pending_delta_y;
|
||||
rwebinput->mouse.pending_delta_x = 0;
|
||||
rwebinput->mouse.pending_delta_y = 0;
|
||||
rwebinput->keyboard.count = 0;
|
||||
|
||||
rwebinput->mouse.scroll_x = rwebinput->mouse.pending_scroll_x;
|
||||
rwebinput->mouse.scroll_y = rwebinput->mouse.pending_scroll_y;
|
||||
rwebinput->mouse.delta_x = rwebinput->mouse.pending_delta_x;
|
||||
rwebinput->mouse.delta_y = rwebinput->mouse.pending_delta_y;
|
||||
rwebinput->mouse.pending_delta_x = 0;
|
||||
rwebinput->mouse.pending_delta_y = 0;
|
||||
|
||||
rwebinput->mouse.scroll_x = rwebinput->mouse.pending_scroll_x;
|
||||
rwebinput->mouse.scroll_y = rwebinput->mouse.pending_scroll_y;
|
||||
rwebinput->mouse.pending_scroll_x = 0;
|
||||
rwebinput->mouse.pending_scroll_y = 0;
|
||||
}
|
||||
|
@ -79,105 +79,6 @@ static bool sdl_key_pressed(int key)
|
||||
return keymap[sym];
|
||||
}
|
||||
|
||||
static int16_t sdl_mouse_device_state(sdl_input_t *sdl, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
return sdl->mouse_wu;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
return sdl->mouse_wd;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return sdl->mouse_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return sdl->mouse_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return sdl->mouse_m;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
|
||||
return sdl->mouse_b4;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
|
||||
return sdl->mouse_b5;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t sdl_pointer_device_state(sdl_input_t *sdl,
|
||||
unsigned idx, unsigned id, bool screen)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
const int edge_detect = 32700;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(
|
||||
&vp, sdl->mouse_abs_x, sdl->mouse_abs_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
if (screen)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
}
|
||||
|
||||
inside = (res_x >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
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 sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t sdl_lightgun_device_state(sdl_input_t *sdl, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return sdl->mouse_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return sdl->mouse_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
return sdl->mouse_m;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
return sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return sdl->mouse_m && sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return sdl->mouse_m && sdl->mouse_l;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t sdl_input_state(
|
||||
void *data,
|
||||
const input_device_driver_t *joypad,
|
||||
@ -260,23 +161,103 @@ static int16_t sdl_input_state(
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
if (config_get_ptr()->uints.input_mouse_index[ port ] == 0)
|
||||
return sdl_mouse_device_state(sdl, id);
|
||||
break;
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
if (config_get_ptr()->uints.input_mouse_index[ port ] == 0)
|
||||
return sdl_mouse_device_state(sdl, id);
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
return sdl->mouse_wu;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
return sdl->mouse_wd;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return sdl->mouse_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return sdl->mouse_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return sdl->mouse_m;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_4:
|
||||
return sdl->mouse_b4;
|
||||
case RETRO_DEVICE_ID_MOUSE_BUTTON_5:
|
||||
return sdl->mouse_b5;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
if (idx == 0)
|
||||
return sdl_pointer_device_state(sdl, idx, id,
|
||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
{
|
||||
struct video_viewport vp;
|
||||
bool screen = device ==
|
||||
RARCH_DEVICE_POINTER_SCREEN;
|
||||
const int edge_detect = 32700;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (video_driver_translate_coord_viewport_wrap(
|
||||
&vp, sdl->mouse_abs_x, sdl->mouse_abs_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 >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
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 sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return (id < RETROK_LAST) && sdl_key_pressed(id);
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
return sdl_lightgun_device_state(sdl, id);
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return sdl->mouse_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return sdl->mouse_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return sdl->mouse_l;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
return sdl->mouse_m;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
return sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return sdl->mouse_m && sdl->mouse_r;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return sdl->mouse_m && sdl->mouse_l;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
@ -277,97 +277,6 @@ static void switch_input_poll(void *data)
|
||||
|
||||
sw->mouse_wheel = mouse_pos.scrollVelocityY;
|
||||
}
|
||||
|
||||
static int16_t switch_pointer_screen_device_state(switch_input_t *sw,
|
||||
unsigned id, unsigned idx)
|
||||
{
|
||||
if (idx >= MULTITOUCH_LIMIT)
|
||||
return 0;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return sw->touch_state[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return sw->touch_x_screen[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return sw->touch_y_screen[idx];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t switch_pointer_device_state(
|
||||
switch_input_t *sw,
|
||||
unsigned id, unsigned idx)
|
||||
{
|
||||
if (idx >= MULTITOUCH_LIMIT)
|
||||
return 0;
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return sw->touch_state[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return sw->touch_x_viewport[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return sw->touch_y_viewport[idx];
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t switch_input_mouse_state(
|
||||
switch_input_t *sw, unsigned id, bool screen)
|
||||
{
|
||||
int val = 0;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
val = sw->mouse_button_left;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
val = sw->mouse_button_right;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
val = sw->mouse_button_middle;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (screen)
|
||||
val = sw->mouse_x;
|
||||
else
|
||||
{
|
||||
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)
|
||||
val = sw->mouse_y;
|
||||
else
|
||||
{
|
||||
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;
|
||||
sw->mouse_wheel = 0;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
if (sw->mouse_wheel < 0)
|
||||
{
|
||||
val = sw->mouse_wheel;
|
||||
sw->mouse_wheel = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int16_t switch_input_state(
|
||||
@ -402,15 +311,84 @@ static int16_t switch_input_state(
|
||||
break;
|
||||
#ifdef HAVE_LIBNX
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return ((id < RETROK_LAST) && sw->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]);
|
||||
return ((id < RETROK_LAST) &&
|
||||
sw->keyboard_state[rarch_keysym_lut[(enum retro_key)id]]);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return switch_input_mouse_state(sw, id, false);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return switch_input_mouse_state(sw, id, true);
|
||||
{
|
||||
int16_t val = 0;
|
||||
bool screen = (device == RARCH_DEVICE_MOUSE_SCREEN);
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return sw->mouse_button_left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return sw->mouse_button_right;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return sw->mouse_button_middle;
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (screen)
|
||||
return sw->mouse_x;
|
||||
|
||||
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;
|
||||
/* flush delta after it has been read */
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
if (sw->mouse_wheel > 0)
|
||||
{
|
||||
val = sw->mouse_wheel;
|
||||
sw->mouse_wheel = 0;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
if (sw->mouse_wheel < 0)
|
||||
{
|
||||
val = sw->mouse_wheel;
|
||||
sw->mouse_wheel = 0;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
return switch_pointer_device_state(sw, id, idx);
|
||||
if (idx < MULTITOUCH_LIMIT)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return sw->touch_state[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return sw->touch_x_viewport[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return sw->touch_y_viewport[idx];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
return switch_pointer_screen_device_state(sw, id, idx);
|
||||
if (idx < MULTITOUCH_LIMIT)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return sw->touch_state[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return sw->touch_x_screen[idx];
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return sw->touch_y_screen[idx];
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
@ -1090,17 +1090,15 @@ static int16_t udev_input_state(
|
||||
return (id < RETROK_LAST) && udev_keyboard_pressed(udev, id);
|
||||
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return udev_mouse_state(udev, port, id, false);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return udev_mouse_state(udev, port, id, true);
|
||||
return udev_mouse_state(udev, port, id,
|
||||
device == RARCH_DEVICE_MOUSE_SCREEN);
|
||||
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (idx == 0) /* multi-touch unsupported (for now) */
|
||||
return udev_pointer_state(udev, port, id, false);
|
||||
break;
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
if (idx == 0) /* multi-touch unsupported (for now) */
|
||||
return udev_pointer_state(udev, port, id, true);
|
||||
return udev_pointer_state(udev, port, id,
|
||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
break;
|
||||
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
@ -1112,7 +1110,7 @@ static int16_t udev_input_state(
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return udev_lightgun_aiming_state( udev, port, id );
|
||||
|
||||
/*buttons*/
|
||||
/*buttons*/
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return udev_input_lightgun_state(udev, joypad,
|
||||
joypad_info,
|
||||
@ -1179,7 +1177,7 @@ static int16_t udev_input_state(
|
||||
binds,
|
||||
keyboard_mapping_blocked,
|
||||
port, device, idx, RARCH_LIGHTGUN_DPAD_RIGHT);
|
||||
/*deprecated*/
|
||||
/*deprecated*/
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
{
|
||||
udev_input_mouse_t *mouse = udev_get_mouse(udev, port);
|
||||
@ -1375,8 +1373,6 @@ error:
|
||||
|
||||
static uint64_t udev_input_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
return
|
||||
(1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_ANALOG) |
|
||||
|
@ -52,58 +52,11 @@
|
||||
|
||||
void flush_wayland_fd(void *data);
|
||||
|
||||
static int16_t input_wl_mouse_state(
|
||||
input_ctx_wayland_data_t *wl, unsigned id, bool screen)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return screen ? wl->mouse.x : wl->mouse.delta_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return screen ? wl->mouse.y : wl->mouse.delta_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return wl->mouse.middle;
|
||||
|
||||
/* TODO: Rest of the mouse inputs. */
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t input_wl_lightgun_state(
|
||||
input_ctx_wayland_data_t *wl, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return wl->mouse.delta_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return wl->mouse.delta_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
return wl->mouse.middle;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
return wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return wl->mouse.middle && wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return wl->mouse.middle && wl->mouse.left;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* forward declaration */
|
||||
static bool wayland_context_gettouchpos(void *data, unsigned id,
|
||||
static bool wayland_context_gettouchpos(
|
||||
gfx_ctx_wayland_data_t *wl,
|
||||
unsigned id,
|
||||
unsigned* touch_x, unsigned* touch_y)
|
||||
{
|
||||
gfx_ctx_wayland_data_t *wl = (gfx_ctx_wayland_data_t*)data;
|
||||
|
||||
if (id >= MAX_TOUCHES)
|
||||
return false;
|
||||
*touch_x = wl->active_touch_positions[id].x;
|
||||
@ -111,30 +64,12 @@ static bool wayland_context_gettouchpos(void *data, unsigned id,
|
||||
return wl->active_touch_positions[id].active;
|
||||
}
|
||||
|
||||
static void input_wl_touch_pool(void *data)
|
||||
static void input_wl_poll(void *data)
|
||||
{
|
||||
int id;
|
||||
unsigned touch_x = 0;
|
||||
unsigned touch_y = 0;
|
||||
input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data;
|
||||
|
||||
if (!wl)
|
||||
return;
|
||||
|
||||
for (id = 0; id < MAX_TOUCHES; id++)
|
||||
{
|
||||
if (wayland_context_gettouchpos(wl, id, &touch_x, &touch_y))
|
||||
wl->touches[id].active = true;
|
||||
else
|
||||
wl->touches[id].active = false;
|
||||
wl->touches[id].x = touch_x;
|
||||
wl->touches[id].y = touch_y;
|
||||
}
|
||||
}
|
||||
|
||||
static void input_wl_poll(void *data)
|
||||
{
|
||||
input_ctx_wayland_data_t *wl = (input_ctx_wayland_data_t*)data;
|
||||
if (!wl)
|
||||
return;
|
||||
|
||||
@ -151,68 +86,15 @@ static void input_wl_poll(void *data)
|
||||
wl->mouse.delta_y = 0;
|
||||
}
|
||||
|
||||
input_wl_touch_pool(wl);
|
||||
}
|
||||
|
||||
static bool input_wl_state_kb(input_ctx_wayland_data_t *wl,
|
||||
const struct retro_keybind **binds,
|
||||
unsigned port, unsigned device, unsigned idx, unsigned id)
|
||||
{
|
||||
unsigned bit = rarch_keysym_lut[(enum retro_key)id];
|
||||
return id < RETROK_LAST && BIT_GET(wl->key_state, bit);
|
||||
}
|
||||
|
||||
static int16_t input_wl_pointer_state(input_ctx_wayland_data_t *wl,
|
||||
unsigned idx, unsigned id, bool screen)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp,
|
||||
wl->mouse.x, wl->mouse.y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
|
||||
return 0;
|
||||
|
||||
if (screen)
|
||||
for (id = 0; id < MAX_TOUCHES; id++)
|
||||
{
|
||||
res_x = res_screen_x;
|
||||
res_y = res_screen_y;
|
||||
if (wayland_context_gettouchpos(wl, id, &touch_x, &touch_y))
|
||||
wl->touches[id].active = true;
|
||||
else
|
||||
wl->touches[id].active = false;
|
||||
wl->touches[id].x = touch_x;
|
||||
wl->touches[id].y = touch_y;
|
||||
}
|
||||
|
||||
inside = (res_x >= -0x7fff) && (res_y >= -0x7fff);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t input_wl_touch_state(input_ctx_wayland_data_t *wl,
|
||||
@ -352,15 +234,78 @@ static int16_t input_wl_state(
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return input_wl_state_kb(wl, binds, port, device, idx, id);
|
||||
return id < RETROK_LAST &&
|
||||
BIT_GET(wl->key_state, rarch_keysym_lut[(enum retro_key)id]);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return input_wl_mouse_state(wl, id, false);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return input_wl_mouse_state(wl, id, true);
|
||||
{
|
||||
bool screen = device == RARCH_DEVICE_MOUSE_SCREEN;
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return screen ? wl->mouse.x : wl->mouse.delta_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return screen ? wl->mouse.y : wl->mouse.delta_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return wl->mouse.middle;
|
||||
/* TODO: Rest of the mouse inputs. */
|
||||
}
|
||||
}
|
||||
breka;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
if (idx == 0)
|
||||
return input_wl_pointer_state(wl, idx, id,
|
||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
{
|
||||
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;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (video_driver_translate_coord_viewport_wrap(&vp,
|
||||
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);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
if (idx < MAX_TOUCHES)
|
||||
@ -368,7 +313,24 @@ static int16_t input_wl_state(
|
||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
break;
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
return input_wl_lightgun_state(wl, id);
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return wl->mouse.delta_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return wl->mouse.delta_y;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
return wl->mouse.left;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_CURSOR:
|
||||
return wl->mouse.middle;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TURBO:
|
||||
return wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_START:
|
||||
return wl->mouse.middle && wl->mouse.right;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return wl->mouse.middle && wl->mouse.left;
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -396,8 +358,6 @@ bool input_wl_init(void *data, const char *joypad_name)
|
||||
|
||||
static uint64_t input_wl_get_capabilities(void *data)
|
||||
{
|
||||
(void)data;
|
||||
|
||||
return
|
||||
(1 << RETRO_DEVICE_JOYPAD) |
|
||||
(1 << RETRO_DEVICE_ANALOG) |
|
||||
@ -406,13 +366,6 @@ static uint64_t input_wl_get_capabilities(void *data)
|
||||
(1 << RETRO_DEVICE_LIGHTGUN);
|
||||
}
|
||||
|
||||
static void input_wl_grab_mouse(void *data, bool state)
|
||||
{
|
||||
/* Dummy for now. Might be useful in the future. */
|
||||
(void)data;
|
||||
(void)state;
|
||||
}
|
||||
|
||||
static bool input_wl_set_rumble(
|
||||
const input_device_driver_t *joypad,
|
||||
const input_device_driver_t *sec_joypad,
|
||||
@ -433,7 +386,7 @@ input_driver_t input_wayland = {
|
||||
NULL,
|
||||
input_wl_get_capabilities,
|
||||
"wayland",
|
||||
input_wl_grab_mouse,
|
||||
NULL, /* grab_mouse */
|
||||
NULL,
|
||||
input_wl_set_rumble
|
||||
};
|
||||
|
@ -90,32 +90,6 @@ static void kb_key_callback(KBDKeyEvent *key)
|
||||
RETRO_DEVICE_KEYBOARD);
|
||||
}
|
||||
|
||||
/* TODO: emulate a relative mouse. This is suprisingly
|
||||
hard to get working nicely.
|
||||
*/
|
||||
|
||||
static int16_t wiiu_pointer_device_state(
|
||||
wiiu_input_t* wiiu,
|
||||
const input_device_driver_t *joypad,
|
||||
unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
{
|
||||
input_bits_t state;
|
||||
joypad->get_buttons(0, &state);
|
||||
return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0;
|
||||
}
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return joypad->axis(0, 0xFFFF0004UL);
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return joypad->axis(0, 0xFFFF0005UL);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t wiiu_input_state(
|
||||
void *data,
|
||||
const input_device_driver_t *joypad,
|
||||
@ -153,7 +127,23 @@ static int16_t wiiu_input_state(
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
return wiiu_pointer_device_state(wiiu, joypad, id);
|
||||
/* TODO: Emulate a relative mouse.
|
||||
* This is suprisingly hard to get working nicely.
|
||||
*/
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
{
|
||||
input_bits_t state;
|
||||
joypad->get_buttons(0, &state);
|
||||
return BIT256_GET(state, VPAD_BUTTON_TOUCH_BIT) ? 1 : 0;
|
||||
}
|
||||
case RETRO_DEVICE_ID_POINTER_X:
|
||||
return joypad->axis(0, 0xFFFF0004UL);
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return joypad->axis(0, 0xFFFF0005UL);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
@ -174,8 +164,10 @@ static void* wiiu_input_init(const char *joypad_driver)
|
||||
if (!wiiu)
|
||||
return NULL;
|
||||
|
||||
KBDSetup(&kb_connection_callback,
|
||||
&kb_disconnection_callback,&kb_key_callback);
|
||||
KBDSetup(
|
||||
&kb_connection_callback,
|
||||
&kb_disconnection_callback,
|
||||
&kb_key_callback);
|
||||
|
||||
input_keymaps_init_keyboard_lut(rarch_key_map_wiiu);
|
||||
|
||||
|
@ -79,21 +79,15 @@ error:
|
||||
|
||||
static void winraw_destroy_window(HWND wnd)
|
||||
{
|
||||
BOOL r;
|
||||
|
||||
if (!wnd)
|
||||
return;
|
||||
|
||||
r = DestroyWindow(wnd);
|
||||
|
||||
if (!r)
|
||||
if (!DestroyWindow(wnd))
|
||||
{
|
||||
RARCH_WARN("[WINRAW]: DestroyWindow failed with error %lu.\n", GetLastError());
|
||||
}
|
||||
|
||||
r = UnregisterClassA("winraw-input", NULL);
|
||||
|
||||
if (!r)
|
||||
if (!UnregisterClassA("winraw-input", NULL))
|
||||
{
|
||||
RARCH_WARN("[WINRAW]: UnregisterClassA failed with error %lu.\n", GetLastError());
|
||||
}
|
||||
@ -117,7 +111,7 @@ static void winraw_log_mice_info(winraw_mouse_t *mice, unsigned mouse_cnt)
|
||||
char name[256];
|
||||
UINT name_size = sizeof(name);
|
||||
|
||||
name[0] = '\0';
|
||||
name[0] = '\0';
|
||||
|
||||
for (i = 0; i < mouse_cnt; ++i)
|
||||
{
|
||||
@ -237,7 +231,7 @@ static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr,
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
switch ( id )
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
if (inside)
|
||||
@ -256,7 +250,7 @@ static int16_t winraw_lightgun_aiming_state(winraw_input_t *wr,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t winraw_mouse_state(winraw_input_t *wr,
|
||||
static int16_t winraw_mouse_state(
|
||||
winraw_mouse_t *mouse,
|
||||
unsigned port, bool abs, unsigned id)
|
||||
{
|
||||
@ -338,22 +332,6 @@ static void winraw_init_mouse_xy_mapping(void)
|
||||
}
|
||||
}
|
||||
|
||||
static int16_t winraw_deprecated_lightgun_state(
|
||||
winraw_input_t *wr,
|
||||
winraw_mouse_t *mouse,
|
||||
unsigned port, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return mouse->dlt_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return mouse->dlt_y;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state)
|
||||
{
|
||||
POINT crs_pos;
|
||||
@ -431,7 +409,8 @@ static void winraw_update_mouse_state(winraw_mouse_t *mouse, RAWMOUSE *state)
|
||||
}
|
||||
}
|
||||
|
||||
static LRESULT CALLBACK winraw_callback(HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar)
|
||||
static LRESULT CALLBACK winraw_callback(
|
||||
HWND wnd, UINT msg, WPARAM wpar, LPARAM lpar)
|
||||
{
|
||||
unsigned i;
|
||||
static uint8_t data[1024];
|
||||
@ -693,9 +672,8 @@ static int16_t winraw_input_state(
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
if (mouse)
|
||||
return winraw_mouse_state(wr, mouse, port,
|
||||
(device == RARCH_DEVICE_MOUSE_SCREEN)
|
||||
? true : false,
|
||||
return winraw_mouse_state(mouse, port,
|
||||
(device == RARCH_DEVICE_MOUSE_SCREEN),
|
||||
id);
|
||||
break;
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
@ -779,7 +757,15 @@ static int16_t winraw_input_state(
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
if (mouse)
|
||||
return winraw_deprecated_lightgun_state(wr, mouse, port, id);
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_X:
|
||||
return mouse->dlt_x;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_Y:
|
||||
return mouse->dlt_y;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_PAUSE:
|
||||
return winraw_input_lightgun_state(wr, mouse, joypad,
|
||||
|
@ -44,6 +44,9 @@ typedef struct x11_input
|
||||
bool grab_mouse;
|
||||
} x11_input_t;
|
||||
|
||||
/* Public global variable */
|
||||
extern bool g_x11_entered;
|
||||
|
||||
static void *x_input_init(const char *joypad_driver)
|
||||
{
|
||||
x11_input_t *x11;
|
||||
@ -76,9 +79,7 @@ static bool x_keyboard_pressed(x11_input_t *x11, unsigned key)
|
||||
static bool x_mouse_button_pressed(
|
||||
x11_input_t *x11, unsigned port, unsigned key)
|
||||
{
|
||||
bool result;
|
||||
|
||||
switch ( key )
|
||||
switch (key)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return x11->mouse_l;
|
||||
@ -102,137 +103,6 @@ static bool x_mouse_button_pressed(
|
||||
return false;
|
||||
}
|
||||
|
||||
static int16_t x_lightgun_aiming_state(
|
||||
x11_input_t *x11, unsigned idx, unsigned id )
|
||||
{
|
||||
struct video_viewport vp;
|
||||
const int edge_detect = 32700;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(&vp, x11->mouse_x, x11->mouse_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
inside = (res_x >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
switch ( id )
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t x_mouse_state(x11_input_t *x11, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return x11->mouse_x - x11->mouse_last_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return x11->mouse_y - x11->mouse_last_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return x11->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return x11->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
return x_mouse_state_wheel(id);
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return x11->mouse_m;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t x_mouse_state_screen(x11_input_t *x11, unsigned id)
|
||||
{
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
return x11->mouse_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
return x11->mouse_y;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return x_mouse_state(x11, id);
|
||||
}
|
||||
|
||||
static int16_t x_pointer_state(x11_input_t *x11,
|
||||
unsigned idx, unsigned id, bool screen)
|
||||
{
|
||||
struct video_viewport vp;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (!(video_driver_translate_coord_viewport_wrap(
|
||||
&vp, x11->mouse_x, x11->mouse_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y)))
|
||||
return 0;
|
||||
|
||||
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:
|
||||
return res_x;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return res_y;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return x11->mouse_l;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int16_t x_input_state(
|
||||
void *data,
|
||||
const input_device_driver_t *joypad,
|
||||
@ -352,15 +222,75 @@ static int16_t x_input_state(
|
||||
case RETRO_DEVICE_KEYBOARD:
|
||||
return (id < RETROK_LAST) && x_keyboard_pressed(x11, id);
|
||||
case RETRO_DEVICE_MOUSE:
|
||||
return x_mouse_state(x11, id);
|
||||
case RARCH_DEVICE_MOUSE_SCREEN:
|
||||
return x_mouse_state_screen(x11, id);
|
||||
|
||||
switch (id)
|
||||
{
|
||||
case RETRO_DEVICE_ID_MOUSE_X:
|
||||
if (device == RARCH_DEVICE_MOUSE_SCREEN)
|
||||
return x11->mouse_x;
|
||||
return x11->mouse_x - x11->mouse_last_x;
|
||||
case RETRO_DEVICE_ID_MOUSE_Y:
|
||||
if (device == RARCH_DEVICE_MOUSE_SCREEN)
|
||||
return x11->mouse_y;
|
||||
return x11->mouse_y - x11->mouse_last_y;
|
||||
case RETRO_DEVICE_ID_MOUSE_LEFT:
|
||||
return x11->mouse_l;
|
||||
case RETRO_DEVICE_ID_MOUSE_RIGHT:
|
||||
return x11->mouse_r;
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELUP:
|
||||
case RETRO_DEVICE_ID_MOUSE_WHEELDOWN:
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELUP:
|
||||
case RETRO_DEVICE_ID_MOUSE_HORIZ_WHEELDOWN:
|
||||
return x_mouse_state_wheel(id);
|
||||
case RETRO_DEVICE_ID_MOUSE_MIDDLE:
|
||||
return x11->mouse_m;
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_POINTER:
|
||||
case RARCH_DEVICE_POINTER_SCREEN:
|
||||
if (idx == 0)
|
||||
return x_pointer_state(x11, idx, id,
|
||||
device == RARCH_DEVICE_POINTER_SCREEN);
|
||||
{
|
||||
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;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (video_driver_translate_coord_viewport_wrap(
|
||||
&vp, x11->mouse_x, x11->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:
|
||||
return res_x;
|
||||
case RETRO_DEVICE_ID_POINTER_Y:
|
||||
return res_y;
|
||||
case RETRO_DEVICE_ID_POINTER_PRESSED:
|
||||
return x11->mouse_l;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
case RETRO_DEVICE_LIGHTGUN:
|
||||
switch ( id )
|
||||
@ -369,8 +299,49 @@ static int16_t x_input_state(
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return x_lightgun_aiming_state( x11, idx, id );
|
||||
{
|
||||
struct video_viewport vp;
|
||||
const int edge_detect = 32700;
|
||||
bool inside = false;
|
||||
int16_t res_x = 0;
|
||||
int16_t res_y = 0;
|
||||
int16_t res_screen_x = 0;
|
||||
int16_t res_screen_y = 0;
|
||||
|
||||
vp.x = 0;
|
||||
vp.y = 0;
|
||||
vp.width = 0;
|
||||
vp.height = 0;
|
||||
vp.full_width = 0;
|
||||
vp.full_height = 0;
|
||||
|
||||
if (video_driver_translate_coord_viewport_wrap(&vp,
|
||||
x11->mouse_x, x11->mouse_y,
|
||||
&res_x, &res_y, &res_screen_x, &res_screen_y))
|
||||
{
|
||||
inside = (res_x >= -edge_detect)
|
||||
&& (res_y >= -edge_detect)
|
||||
&& (res_x <= edge_detect)
|
||||
&& (res_y <= edge_detect);
|
||||
|
||||
switch ( id )
|
||||
{
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_X:
|
||||
if (inside)
|
||||
return res_x;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_SCREEN_Y:
|
||||
if (inside)
|
||||
return res_y;
|
||||
break;
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_IS_OFFSCREEN:
|
||||
return !inside;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
break;
|
||||
/*buttons*/
|
||||
case RETRO_DEVICE_ID_LIGHTGUN_TRIGGER:
|
||||
{
|
||||
@ -670,14 +641,18 @@ static void x_input_free(void *data)
|
||||
free(x11);
|
||||
}
|
||||
|
||||
extern bool g_x11_entered;
|
||||
|
||||
static void x_input_poll_mouse(x11_input_t *x11,
|
||||
bool video_has_focus)
|
||||
static void x_input_poll(void *data)
|
||||
{
|
||||
unsigned mask;
|
||||
int root_x, root_y, win_x, win_y;
|
||||
Window root_win, child_win;
|
||||
x11_input_t *x11 = (x11_input_t*)data;
|
||||
bool video_has_focus = video_driver_has_focus();
|
||||
|
||||
if (video_has_focus)
|
||||
XQueryKeymap(x11->display, x11->state);
|
||||
else
|
||||
memset(x11->state, 0, sizeof(x11->state));
|
||||
|
||||
x11->mouse_last_x = x11->mouse_x;
|
||||
x11->mouse_last_y = x11->mouse_y;
|
||||
@ -728,19 +703,6 @@ static void x_input_poll_mouse(x11_input_t *x11,
|
||||
}
|
||||
}
|
||||
|
||||
static void x_input_poll(void *data)
|
||||
{
|
||||
x11_input_t *x11 = (x11_input_t*)data;
|
||||
bool video_has_focus = video_driver_has_focus();
|
||||
|
||||
if (video_has_focus)
|
||||
XQueryKeymap(x11->display, x11->state);
|
||||
else
|
||||
memset(x11->state, 0, sizeof(x11->state));
|
||||
|
||||
x_input_poll_mouse(x11, video_has_focus);
|
||||
}
|
||||
|
||||
static void x_grab_mouse(void *data, bool state)
|
||||
{
|
||||
x11_input_t *x11 = (x11_input_t*)data;
|
||||
|
@ -35,8 +35,9 @@ static uint64_t state[DEFAULT_MAX_PADS];
|
||||
|
||||
static void xenon360_input_poll(void *data)
|
||||
{
|
||||
(void)data;
|
||||
for (unsigned i = 0; i < DEFAULT_MAX_PADS; i++)
|
||||
unsigned i;
|
||||
|
||||
for (i = 0; i < DEFAULT_MAX_PADS; i++)
|
||||
{
|
||||
struct controller_data_s pad;
|
||||
uint64_t *cur_state;
|
||||
|
Loading…
x
Reference in New Issue
Block a user