From a26d08d3bc5f5ae718e381b05ee2e3af75b1b0c1 Mon Sep 17 00:00:00 2001 From: Peter Hutterer Date: Thu, 25 Jan 2024 14:01:45 +1000 Subject: [PATCH] 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: --- src/core/meta-pad-action-mapper.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/core/meta-pad-action-mapper.c b/src/core/meta-pad-action-mapper.c index 82e25b2f1..fca9b8651 100644 --- a/src/core/meta-pad-action-mapper.c +++ b/src/core/meta-pad-action-mapper.c @@ -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; }