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.
This commit is contained in:
Jules Aguillon 2022-11-13 14:43:53 +01:00
parent b102ad9078
commit e213834f67

View File

@ -117,11 +117,14 @@ final class Config
} }
layout = layoutId_of_string(_prefs.getString("layout", "none")); layout = layoutId_of_string(_prefs.getString("layout", "none"));
second_layout = layoutId_of_string(_prefs.getString("second_layout", "none")); second_layout = layoutId_of_string(_prefs.getString("second_layout", "none"));
// The swipe distance is defined relatively to the "exact physical pixels // The baseline for the swipe distance correspond to approximately the
// per inch of the screen", which isn't affected by the scaling settings. // width of a key in portrait mode, as most layouts have 10 columns.
// Take the mean of both dimensions as an approximation of the diagonal. // Multipled by the DPI ratio because most swipes are made in the diagonals.
float physical_scaling = (dm.widthPixels + dm.heightPixels) / (dm.xdpi + dm.ydpi); // The option value uses an unnamed scale where the baseline is around 25.
swipe_dist_px = Float.valueOf(_prefs.getString("swipe_dist", "15")) * physical_scaling;; 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); vibrateEnabled = _prefs.getBoolean("vibrate_enabled", vibrateEnabled);
longPressTimeout = _prefs.getInt("longpress_timeout", (int)longPressTimeout); longPressTimeout = _prefs.getInt("longpress_timeout", (int)longPressTimeout);
longPressInterval = _prefs.getInt("longpress_interval", (int)longPressInterval); longPressInterval = _prefs.getInt("longpress_interval", (int)longPressInterval);