mirror of
https://github.com/brl/mutter.git
synced 2025-01-08 10:42:33 +00:00
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:
parent
947c636275
commit
a26d08d3bc
@ -611,6 +611,7 @@ meta_pad_action_mapper_get_action_direction (MetaPadActionMapper *mapper,
|
||||
MetaPadDirection inc_dir, dec_dir;
|
||||
uint32_t number;
|
||||
double value;
|
||||
gboolean detect_wraparound = FALSE;
|
||||
|
||||
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);
|
||||
inc_dir = META_PAD_DIRECTION_CW;
|
||||
dec_dir = META_PAD_DIRECTION_CCW;
|
||||
detect_wraparound = TRUE;
|
||||
break;
|
||||
case CLUTTER_PAD_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 &&
|
||||
value >= 0 && mapper->last_pad_action_info.value >= 0)
|
||||
{
|
||||
*direction = (value - mapper->last_pad_action_info.value) > 0 ?
|
||||
inc_dir : dec_dir;
|
||||
double delta = value - mapper->last_pad_action_info.value;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user