diff options
| author | Jules Aguillon | 2022-11-13 14:43:53 +0100 |
|---|---|---|
| committer | Jules Aguillon | 2022-11-13 14:43:53 +0100 |
| commit | e213834f674223ca3f63cb7c57698b7b17ba6fde (patch) | |
| tree | a683b466d59f4e73f85c2c657c485ba7714a99d5 /srcs/juloo.keyboard2 | |
| parent | b102ad90781487dd00a8147330eb0c430f0ba503 (diff) | |
| download | unexpected-keyboard-e213834f674223ca3f63cb7c57698b7b17ba6fde.tar.gz unexpected-keyboard-e213834f674223ca3f63cb7c57698b7b17ba6fde.zip | |
Don't depend on dpi values in swipe distance
The dpi values "xdpi" and "ydpi" can have wildly different values on
different devices.
The new computation defines a baseline and only take into account the
dpi values as a ratio.
On a 480dpi screen (in both directions), this decrease the value by
about 18%. This new distance felt better during testing.
Diffstat (limited to 'srcs/juloo.keyboard2')
| -rw-r--r-- | srcs/juloo.keyboard2/Config.java | 13 |
1 files changed, 8 insertions, 5 deletions
diff --git a/srcs/juloo.keyboard2/Config.java b/srcs/juloo.keyboard2/Config.java index 6c1dced..e6bd1f8 100644 --- a/srcs/juloo.keyboard2/Config.java +++ b/srcs/juloo.keyboard2/Config.java @@ -117,11 +117,14 @@ final class Config } layout = layoutId_of_string(_prefs.getString("layout", "none")); second_layout = layoutId_of_string(_prefs.getString("second_layout", "none")); - // 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;; + // The baseline for the swipe distance correspond to approximately the + // width of a key in portrait mode, as most layouts have 10 columns. + // Multipled by the DPI ratio because most swipes are made in the diagonals. + // The option value uses an unnamed scale where the baseline is around 25. + float dpi_ratio = Math.max(dm.xdpi, dm.ydpi) / Math.min(dm.xdpi, dm.ydpi); + float swipe_scaling = Math.min(dm.widthPixels, dm.heightPixels) / 10.f * dpi_ratio; + float swipe_dist_value = Float.valueOf(_prefs.getString("swipe_dist", "15")); + swipe_dist_px = swipe_dist_value / 25.f * swipe_scaling; vibrateEnabled = _prefs.getBoolean("vibrate_enabled", vibrateEnabled); longPressTimeout = _prefs.getInt("longpress_timeout", (int)longPressTimeout); longPressInterval = _prefs.getInt("longpress_interval", (int)longPressInterval); |
