Skip to content

Commit 8c1afaa

Browse files
authored
Overlay Mouse: Alt 2-Touch Input option (libretro#18580)
Use second touch as a mouse button while controlling the cursor.
1 parent 35aefa8 commit 8c1afaa

File tree

11 files changed

+113
-22
lines changed

11 files changed

+113
-22
lines changed

config.def.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -640,6 +640,7 @@
640640
#define DEFAULT_INPUT_OVERLAY_MOUSE_DTAP_TO_DRAG false
641641
#define DEFAULT_INPUT_OVERLAY_MOUSE_DTAP_MSEC 200
642642
#define DEFAULT_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD 1.0f
643+
#define DEFAULT_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT OVERLAY_MOUSE_BTN_NONE
643644

644645
#ifdef UDEV_TOUCH_SUPPORT
645646
#define DEFAULT_INPUT_TOUCH_VMOUSE_POINTER true

configuration.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2669,6 +2669,7 @@ static struct config_uint_setting *populate_settings_uint(
26692669
SETTING_UINT("input_overlay_lightgun_four_touch_input", &settings->uints.input_overlay_lightgun_four_touch_input, true, DEFAULT_INPUT_OVERLAY_LIGHTGUN_MULTI_TOUCH_INPUT, false);
26702670
SETTING_UINT("input_overlay_mouse_hold_msec", &settings->uints.input_overlay_mouse_hold_msec, true, DEFAULT_INPUT_OVERLAY_MOUSE_HOLD_MSEC, false);
26712671
SETTING_UINT("input_overlay_mouse_dtap_msec", &settings->uints.input_overlay_mouse_dtap_msec, true, DEFAULT_INPUT_OVERLAY_MOUSE_DTAP_MSEC, false);
2672+
SETTING_UINT("input_overlay_mouse_alt_two_touch_input", &settings->uints.input_overlay_mouse_alt_two_touch_input, true, DEFAULT_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT, false);
26722673
#endif
26732674

26742675
*size = count;

configuration.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@ typedef struct settings
355355
unsigned input_overlay_lightgun_four_touch_input;
356356
unsigned input_overlay_mouse_hold_msec;
357357
unsigned input_overlay_mouse_dtap_msec;
358+
unsigned input_overlay_mouse_alt_two_touch_input;
358359
#endif
359360

360361
unsigned run_ahead_frames;

input/input_driver.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3199,7 +3199,7 @@ void input_overlay_auto_rotate_(
31993199

32003200
/**
32013201
* input_overlay_poll_lightgun
3202-
* @settings: pointer to settings
3202+
* @settings : pointer to settings
32033203
* @ol : overlay handle
32043204
* @old_ptr_count : previous poll's non-hitbox pointer count
32053205
*
@@ -3319,8 +3319,10 @@ static void input_overlay_get_mouse_scale(settings_t *settings,
33193319

33203320
/**
33213321
* input_overlay_poll_mouse
3322-
* @settings: pointer to settings
3322+
* @settings : pointer to settings
3323+
* @mouse_st : pointer to overlay mouse state
33233324
* @ol : overlay handle
3325+
* @ptr_count : this poll's non-hitbox pointer count
33243326
* @old_ptr_count : previous poll's non-hitbox pointer count
33253327
*
33263328
* Updates button state of the overlay mouse.
@@ -3331,15 +3333,16 @@ static void input_overlay_poll_mouse(settings_t *settings,
33313333
const int ptr_count,
33323334
const int old_ptr_count)
33333335
{
3334-
input_overlay_pointer_state_t *ptr_st = &ol->pointer_state;
3335-
const retro_time_t now_usec = cpu_features_get_time_usec();
3336-
const retro_time_t hold_usec = settings->uints.input_overlay_mouse_hold_msec * 1000;
3337-
const retro_time_t dtap_usec = settings->uints.input_overlay_mouse_dtap_msec * 1000;
3338-
int swipe_thres_x = 0;
3339-
int swipe_thres_y = 0;
3340-
const bool hold_to_drag = settings->bools.input_overlay_mouse_hold_to_drag;
3341-
const bool dtap_to_drag = settings->bools.input_overlay_mouse_dtap_to_drag;
3342-
bool want_feedback = false;
3336+
input_overlay_pointer_state_t *ptr_st = &ol->pointer_state;
3337+
const retro_time_t now_usec = cpu_features_get_time_usec();
3338+
const retro_time_t hold_usec = settings->uints.input_overlay_mouse_hold_msec * 1000;
3339+
const retro_time_t dtap_usec = settings->uints.input_overlay_mouse_dtap_msec * 1000;
3340+
const uint8_t alt_2touch = settings->uints.input_overlay_mouse_alt_two_touch_input;
3341+
int swipe_thres_x = 0;
3342+
int swipe_thres_y = 0;
3343+
const bool hold_to_drag = settings->bools.input_overlay_mouse_hold_to_drag;
3344+
const bool dtap_to_drag = settings->bools.input_overlay_mouse_dtap_to_drag;
3345+
bool want_feedback = false;
33433346
bool is_swipe, is_brief, is_long;
33443347

33453348
static retro_time_t start_usec;
@@ -3352,8 +3355,10 @@ static void input_overlay_poll_mouse(settings_t *settings,
33523355
static int y_start;
33533356
static int peak_ptr_count;
33543357
static int old_peak_ptr_count;
3355-
static bool skip_buttons;
3358+
static bool check_gestures;
33563359
static bool pending_click;
3360+
static const uint8_t btns[OVERLAY_MAX_TOUCH + 1] =
3361+
{0x0, 0x1, 0x2, 0x4}; /* none, lmb, rmb, mmb */
33573362

33583363
input_overlay_get_mouse_scale(settings,
33593364
(float*)&mouse_st->scale_x, &mouse_st->scale_y,
@@ -3374,6 +3379,11 @@ static void input_overlay_poll_mouse(settings_t *settings,
33743379
/* Pointer added */
33753380
peak_ptr_count = ptr_count;
33763381
start_usec = now_usec;
3382+
3383+
/* Alt 2-touch input. After gesture checks,
3384+
* use 2nd touch as a button */
3385+
if (!check_gestures && ptr_count == 2)
3386+
mouse_st->hold = btns[alt_2touch];
33773387
}
33783388
else
33793389
{
@@ -3391,15 +3401,15 @@ static void input_overlay_poll_mouse(settings_t *settings,
33913401
is_long = (now_usec - start_usec) > (hold_to_drag ? hold_usec : 250000);
33923402

33933403
/* Check if new button input should be created */
3394-
if (!skip_buttons)
3404+
if (check_gestures)
33953405
{
33963406
if (!is_swipe)
33973407
{
33983408
if ( hold_to_drag
33993409
&& is_long && ptr_count && !mouse_st->hold)
34003410
{
34013411
/* Long press */
3402-
mouse_st->hold = (1 << (ptr_count - 1));
3412+
mouse_st->hold = btns[ptr_count];
34033413
want_feedback = true;
34043414
}
34053415
else if (is_brief)
@@ -3409,7 +3419,7 @@ static void input_overlay_poll_mouse(settings_t *settings,
34093419
/* New input. Check for double tap */
34103420
if ( dtap_to_drag
34113421
&& now_usec - last_up_usec < dtap_usec)
3412-
mouse_st->hold = (1 << (old_peak_ptr_count - 1));
3422+
mouse_st->hold = btns[old_peak_ptr_count];
34133423

34143424
last_down_usec = now_usec;
34153425
}
@@ -3425,7 +3435,7 @@ static void input_overlay_poll_mouse(settings_t *settings,
34253435
}
34263436
else
34273437
{
3428-
mouse_st->click = (1 << (peak_ptr_count - 1));
3438+
mouse_st->click = btns[peak_ptr_count];
34293439
click_end_usec = now_usec + click_dur_usec;
34303440
}
34313441

@@ -3435,14 +3445,19 @@ static void input_overlay_poll_mouse(settings_t *settings,
34353445
}
34363446
else
34373447
{
3438-
/* If dragging 2+ fingers, hold RMB or MMB */
3448+
/* Swiping. Stop gesture checks and possibly hold a button */
34393449
if (ptr_count > 1)
34403450
{
3441-
mouse_st->hold = (1 << (ptr_count - 1));
3442-
if (hold_to_drag)
3451+
if (hold_to_drag && !alt_2touch)
3452+
{
3453+
mouse_st->hold = btns[ptr_count];
34433454
want_feedback = true;
3455+
}
3456+
else if (alt_2touch && !hold_to_drag
3457+
&& ptr_count == 2)
3458+
mouse_st->hold = btns[alt_2touch];
34443459
}
3445-
skip_buttons = true;
3460+
check_gestures = false;
34463461
}
34473462
}
34483463

@@ -3455,9 +3470,9 @@ static void input_overlay_poll_mouse(settings_t *settings,
34553470
}
34563471

34573472
if (!ptr_count)
3458-
skip_buttons = false; /* Reset button checks */
3473+
check_gestures = true;
34593474
else if (is_long)
3460-
skip_buttons = true; /* End of button checks */
3475+
check_gestures = false;
34613476

34623477
/* Remove stale clicks */
34633478
if (mouse_st->click && now_usec > click_end_usec)

input/input_overlay.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,16 @@ enum overlay_lightgun_action
161161
OVERLAY_LIGHTGUN_ACTION_END
162162
};
163163

164+
enum overlay_mouse_button
165+
{
166+
OVERLAY_MOUSE_BTN_NONE = 0,
167+
OVERLAY_MOUSE_BTN_LMB,
168+
OVERLAY_MOUSE_BTN_RMB,
169+
OVERLAY_MOUSE_BTN_MMB,
170+
171+
OVERLAY_MOUSE_BTN_END
172+
};
173+
164174
/* Overlay driver acts as a medium between input drivers
165175
* and video driver.
166176
*

intl/msg_hash_lbl.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2142,6 +2142,10 @@ MSG_HASH(
21422142
MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD,
21432143
"input_overlay_mouse_swipe_threshold"
21442144
)
2145+
MSG_HASH(
2146+
MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
2147+
"input_overlay_mouse_alt_two_touch_input"
2148+
)
21452149
MSG_HASH(
21462150
MENU_ENUM_LABEL_INPUT_OVERLAY_DPAD_DIAGONAL_SENSITIVITY,
21472151
"input_overlay_dpad_diagonal_sensitivity"

intl/msg_hash_us.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5885,6 +5885,14 @@ MSG_HASH(
58855885
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD,
58865886
"Swipe Threshold"
58875887
)
5888+
MSG_HASH(
5889+
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
5890+
"Alt 2-Touch Input"
5891+
)
5892+
MSG_HASH(
5893+
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
5894+
"Use second touch as a mouse button while controlling the cursor."
5895+
)
58885896
MSG_HASH(
58895897
MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD,
58905898
"Adjust the allowable drift range when detecting a long press or tap. Expressed as a percentage of the smaller screen dimension."

menu/cbs/menu_cbs_sublabel.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -926,6 +926,7 @@ DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_mouse_hold_msec,
926926
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_mouse_dtap_to_drag, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_DTAP_TO_DRAG)
927927
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_mouse_dtap_msec, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_DTAP_MSEC)
928928
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_mouse_swipe_threshold, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD)
929+
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_input_overlay_mouse_alt_two_touch_input, MENU_ENUM_SUBLABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT)
929930
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_public_announce, MENU_ENUM_SUBLABEL_NETPLAY_PUBLIC_ANNOUNCE)
930931
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_ip_address, MENU_ENUM_SUBLABEL_NETPLAY_IP_ADDRESS)
931932
DEFAULT_SUBLABEL_MACRO(action_bind_sublabel_netplay_tcp_udp_port, MENU_ENUM_SUBLABEL_NETPLAY_TCP_UDP_PORT)
@@ -3994,6 +3995,9 @@ int menu_cbs_init_bind_sublabel(menu_file_list_cbs_t *cbs,
39943995
case MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD:
39953996
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_mouse_swipe_threshold);
39963997
break;
3998+
case MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT:
3999+
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_input_overlay_mouse_alt_two_touch_input);
4000+
break;
39974001
case MENU_ENUM_LABEL_AUDIO_DSP_PLUGIN:
39984002
BIND_ACTION_SUBLABEL(cbs, action_bind_sublabel_audio_dsp_plugin);
39994003
break;

menu/menu_displaylist.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10681,6 +10681,10 @@ unsigned menu_displaylist_build_list(
1068110681
MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_SWIPE_THRESHOLD,
1068210682
PARSE_ONLY_FLOAT, false) == 0)
1068310683
count++;
10684+
if (MENU_DISPLAYLIST_PARSE_SETTINGS_ENUM(list,
10685+
MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
10686+
PARSE_ONLY_UINT, false) == 0)
10687+
count++;
1068410688
break;
1068510689
#endif
1068610690
case DISPLAYLIST_LATENCY_SETTINGS_LIST:

menu/menu_setting.c

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5515,6 +5515,31 @@ static size_t setting_get_string_representation_overlay_lightgun_action(
55155515
}
55165516
return 0;
55175517
}
5518+
5519+
static size_t setting_get_string_representation_overlay_mouse_btn(
5520+
rarch_setting_t *setting, char *s, size_t len)
5521+
{
5522+
if (setting)
5523+
{
5524+
switch (*setting->value.target.unsigned_integer)
5525+
{
5526+
case OVERLAY_MOUSE_BTN_NONE:
5527+
return strlcpy(s, msg_hash_to_str(
5528+
MENU_ENUM_LABEL_VALUE_NONE), len);
5529+
case OVERLAY_MOUSE_BTN_LMB:
5530+
return strlcpy(s, msg_hash_to_str(
5531+
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_LEFT), len);
5532+
case OVERLAY_MOUSE_BTN_RMB:
5533+
return strlcpy(s, msg_hash_to_str(
5534+
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_RIGHT), len);
5535+
case OVERLAY_MOUSE_BTN_MMB:
5536+
return strlcpy(s, msg_hash_to_str(
5537+
MENU_ENUM_LABEL_VALUE_INPUT_MOUSE_MIDDLE), len);
5538+
}
5539+
}
5540+
5541+
return 0;
5542+
}
55185543
#endif
55195544

55205545
/* A protected driver is such that the user cannot set to "null" using the UI.
@@ -18171,6 +18196,23 @@ static bool setting_append_list(
1817118196
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint;
1817218197
menu_settings_list_current_add_range(list, list_info, 0.0, 10.0, 0.1, true, true);
1817318198

18199+
CONFIG_UINT(
18200+
list, list_info,
18201+
&settings->uints.input_overlay_mouse_alt_two_touch_input,
18202+
MENU_ENUM_LABEL_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
18203+
MENU_ENUM_LABEL_VALUE_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
18204+
DEFAULT_INPUT_OVERLAY_MOUSE_ALT_TWO_TOUCH_INPUT,
18205+
&group_info,
18206+
&subgroup_info,
18207+
parent_group,
18208+
general_write_handler,
18209+
general_read_handler);
18210+
(*list)[list_info->index - 1].action_ok = &setting_action_ok_uint;
18211+
(*list)[list_info->index - 1].get_string_representation =
18212+
&setting_get_string_representation_overlay_mouse_btn;
18213+
menu_settings_list_current_add_range(list, list_info,
18214+
OVERLAY_MOUSE_BTN_NONE, OVERLAY_MOUSE_BTN_END - 1, 1, true, true);
18215+
1817418216
END_SUB_GROUP(list, list_info, parent_group);
1817518217

1817618218
END_GROUP(list, list_info, parent_group);

0 commit comments

Comments
 (0)