From 2b6c2b98e09ab6eed11c14bc142d6caece769ab8 Mon Sep 17 00:00:00 2001 From: Jules Aguillon Date: Sat, 2 Apr 2022 16:01:48 +0200 Subject: [PATCH] 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%. --- srcs/juloo.keyboard2/Config.java | 8 +++++--- 1 file 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);