2
0
mirror of https://github.com/KDE/kdeconnect-android synced 2025-08-31 22:25:08 +00:00

Make remote input sensitivity consistant across device DPIs

Summary:
KDEConnect's Remote Input feature does not take display DPI into account, resulting in inconsistent mouse sensitivities for devices with different DPIs.
This revision aims to fix that by dividing the mouse delta with the relative DPI of the current device. By doing so, the same amount of finger movement should produce the same amount of cursor movement, regardless of the device's DPI.

Addresses the following bug:
BUG: 391029

Reviewers: #kde_connect, nicolasfella

Reviewed By: #kde_connect, nicolasfella

Subscribers: sredman, nicolasfella, kdeconnect

Tags: #kde_connect

Differential Revision: https://phabricator.kde.org/D13925
This commit is contained in:
Chansol Yang
2018-07-07 22:27:42 +02:00
committed by Nicolas Fella
parent 4f3f24dc9f
commit 212069c425

View File

@@ -45,12 +45,14 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
private final static float MinDistanceToSendScroll = 2.5f; // touch gesture scroll
private final static float MinDistanceToSendGenericScroll = 0.1f; // real mouse scroll wheel event
private final static float StandardDpi = 240.0f; // = hdpi
private float mPrevX;
private float mPrevY;
private float mCurrentX;
private float mCurrentY;
private float mCurrentSensitivity;
private float displayDpiMultiplier;
private int scrollDirection = 1;
boolean isScrolling = false;
@@ -112,6 +114,10 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
doubleTapAction = ClickType.fromString(doubleTapSetting);
tripleTapAction = ClickType.fromString(tripleTapSetting);
//Technically xdpi and ydpi should be handled separately,
//but since ydpi is usually almost equal to xdpi, only xdpi is used for the multiplier.
displayDpiMultiplier = StandardDpi / getResources().getDisplayMetrics().xdpi;
switch (sensitivitySetting) {
case "slowest":
mCurrentSensitivity = 0.2f;
@@ -215,7 +221,10 @@ public class MousePadActivity extends AppCompatActivity implements GestureDetect
Device device = service.getDevice(deviceId);
MousePadPlugin mousePadPlugin = device.getPlugin(MousePadPlugin.class);
if (mousePadPlugin == null) return;
mousePadPlugin.sendMouseDelta(mCurrentX - mPrevX, mCurrentY - mPrevY, mCurrentSensitivity);
mousePadPlugin.sendMouseDelta(
(mCurrentX - mPrevX) * displayDpiMultiplier,
(mCurrentY - mPrevY) * displayDpiMultiplier,
mCurrentSensitivity);
mPrevX = mCurrentX;
mPrevY = mCurrentY;
});