1
0
Fork 0

core: Detect pad ring wraparound values

A ring will naturally go from 355 degrees to 5 degrees (or vice versa),
giving us the illusion of a direction change. Avoid this by assuming
that any change larger than 180 degrees is actually the equivalent
smaller change in the other direction.

Closes #1885

Part-of: <https://gitlab.gnome.org/GNOME/mutter/-/merge_requests/3545>
This commit is contained in:
Peter Hutterer 2024-01-25 14:01:45 +10:00 committed by Marge Bot
parent 947c636275
commit a26d08d3bc

View file

@ -611,6 +611,7 @@ meta_pad_action_mapper_get_action_direction (MetaPadActionMapper *mapper,
MetaPadDirection inc_dir, dec_dir; MetaPadDirection inc_dir, dec_dir;
uint32_t number; uint32_t number;
double value; double value;
gboolean detect_wraparound = FALSE;
switch (clutter_event_type (event)) switch (clutter_event_type (event))
{ {
@ -619,6 +620,7 @@ meta_pad_action_mapper_get_action_direction (MetaPadActionMapper *mapper,
clutter_event_get_pad_details (event, &number, NULL, NULL, &value); clutter_event_get_pad_details (event, &number, NULL, NULL, &value);
inc_dir = META_PAD_DIRECTION_CW; inc_dir = META_PAD_DIRECTION_CW;
dec_dir = META_PAD_DIRECTION_CCW; dec_dir = META_PAD_DIRECTION_CCW;
detect_wraparound = TRUE;
break; break;
case CLUTTER_PAD_STRIP: case CLUTTER_PAD_STRIP:
pad_feature = META_PAD_FEATURE_STRIP; pad_feature = META_PAD_FEATURE_STRIP;
@ -635,8 +637,17 @@ meta_pad_action_mapper_get_action_direction (MetaPadActionMapper *mapper,
mapper->last_pad_action_info.number == number && mapper->last_pad_action_info.number == number &&
value >= 0 && mapper->last_pad_action_info.value >= 0) value >= 0 && mapper->last_pad_action_info.value >= 0)
{ {
*direction = (value - mapper->last_pad_action_info.value) > 0 ? double delta = value - mapper->last_pad_action_info.value;
inc_dir : dec_dir;
if (detect_wraparound)
{
if (delta < -180.0)
delta += 360;
else if (delta > 180.0)
delta -= 360;
}
*direction = delta > 0 ? inc_dir : dec_dir;
has_direction = TRUE; has_direction = TRUE;
} }