abouttreesummaryrefslogcommitdiff
path: root/srcs/juloo.keyboard2
diff options
context:
space:
mode:
authorJules Aguillon2022-04-02 16:01:48 +0200
committerJules Aguillon2022-04-02 16:16:24 +0200
commit2b6c2b98e09ab6eed11c14bc142d6caece769ab8 (patch)
tree8b3999b5ca05a2f31e7c87c4645a05bb5bca3ced /srcs/juloo.keyboard2
parent281f779121527c1d8d9136320fcf231422fbdefd (diff)
downloadunexpected-keyboard-2b6c2b98e09ab6eed11c14bc142d6caece769ab8.tar.gz
unexpected-keyboard-2b6c2b98e09ab6eed11c14bc142d6caece769ab8.zip
Compute the swipe distance from the physical dpi
The previous computation was very different depending on the device's screen and accessibility options. Given that the keyboard is supposed to fill all the space in one dimension, the dpi unit makes little sense. The formula doesn't mean anything in particular, it takes into account both dimensions (x and y) and should be close to the dpi in the diagonals (which is the direction of swipe). This changes the actual value, on a 1920x1080 480dpi screen, the value is increased by 20%.
Diffstat (limited to 'srcs/juloo.keyboard2')
-rw-r--r--srcs/juloo.keyboard2/Config.java8
1 files changed, 5 insertions, 3 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java
index aa583de..76aa4e0 100644
--- a/srcs/juloo.keyboard2/Config.java
+++ b/srcs/juloo.keyboard2/Config.java
@@ -23,7 +23,6 @@ final class Config
// From preferences
public int layout; // Or '-1' for the system defaults
- private float swipe_dist_dp;
public float swipe_dist_px;
public boolean vibrateEnabled;
public long vibrateDuration;
@@ -103,8 +102,11 @@ final class Config
keyboardHeightPercent = prefs.getInt("keyboard_height", 35);
}
layout = layoutId_of_string(prefs.getString("layout", "system"));
- swipe_dist_dp = Float.valueOf(prefs.getString("swipe_dist", "15"));
- swipe_dist_px = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, swipe_dist_dp, dm);
+ // The swipe distance is defined relatively to the "exact physical pixels
+ // per inch of the screen", which isn't affected by the scaling settings.
+ // Take the mean of both dimensions as an approximation of the diagonal.
+ float physical_scaling = (dm.widthPixels + dm.heightPixels) / (dm.xdpi + dm.ydpi);
+ swipe_dist_px = Float.valueOf(prefs.getString("swipe_dist", "15")) * physical_scaling;;
vibrateEnabled = prefs.getBoolean("vibrate_enabled", vibrateEnabled);
vibrateDuration = prefs.getInt("vibrate_duration", (int)vibrateDuration);
longPressTimeout = prefs.getInt("longpress_timeout", (int)longPressTimeout);