Automatically calculate swipe zones #1116
Draft
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Using the information of what swipes are available for a key, we can calculate swipe zones without relying on explicit
SwipeNWay
.The algorithm assigns each
SwipeDirection
a "precise direction" vector - for example(+1, -1)
forTOP_RIGHT
. It then uses a dot product to calculate a cosine of an angle between the swipe and this precise direction. The biggest cosine (that is, the smallest angle) that has an action attached wins, but only if the cosine is positive (that is, if the angle is in the ±90 degree range).This new behavior differs from the old one in a few notable ways, though:
It is no longer possible to reduce the swipe zone size by utilizing
SwipeNWay.EIGHT_WAY
, but then only setting the four cardinal directions. This behavior was fairly obscure, and AFAIK no layout was using it intentionally.Some swipe zones are now bigger than before. Notably, if
TOP
,BOTTOM
, andLEFT
all have actions attached to them, then swiping right would trigger the closest of theTOP
andBOTTOM
actions - which wasn't happening withSwipeNWay.FOUR_WAY_CROSS
. On the other hand, theTWO_WAY_*
values do have this behaviour - swiping right on aTWO_WAY_VERTICAL
would trigger one of the actions.I'm still not sure if I like point 2 so far. It also looks like it would break the "ghost keys" feature. Point 1, I am okay with.
The end goal of this PR is to eliminate the need to set
swipeType
in keyboard definitions, in all or most cases. A more conservative approach to that would be to just calculateKeyItemC.swipeType
in the constructor based on which swipes are set. I might just end up doing that instead, in a separate PR.