Skip to content

Commit

Permalink
Fixes clicks outside key bounds (#2637)
Browse files Browse the repository at this point in the history
  • Loading branch information
keianhzo authored and bluemarvin committed Jan 23, 2020
1 parent 8a2f86a commit 9ab6581
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -880,6 +880,18 @@ private void onBufferDraw() {
mDirtyRect.setEmpty();
}

/**
* We use our own Key.isInside implementation {@link Keyboard#isInside} as that one assumes that the
* motion event is inside the key if it is an edge key.
*/
public boolean isInside(Key key, int x, int y) {
if ((x >= key.x) && (x < key.x + key.width) && (y >= key.y) && (y < key.y + key.height)) {
return true;
} else {
return false;
}
}

private int getKeyIndices(int x, int y, int[] allKeys) {
final Key[] keys = mKeys;
int primaryIndex = NOT_A_KEY;
Expand All @@ -891,7 +903,7 @@ private int getKeyIndices(int x, int y, int[] allKeys) {
for (int i = 0; i < keyCount; i++) {
final Key key = keys[nearestKeyIndices[i]];
int dist = 0;
boolean isInside = key.isInside(x,y);
boolean isInside = isInside(key, x,y);
if (isInside) {
primaryIndex = nearestKeyIndices[i];
}
Expand Down

0 comments on commit 9ab6581

Please sign in to comment.