1 /* 2 * Copyright © 2012 Jonas Ådahl 3 * Copyright © 2014-2015 Red Hat, Inc. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 22 * DEALINGS IN THE SOFTWARE. 23 */ 24 25 #ifndef FILTER_H 26 #define FILTER_H 27 28 #include "config.h" 29 30 #include <stdbool.h> 31 #include <stdint.h> 32 33 #include "libinput-private.h" 34 35 struct motion_filter; 36 37 /** 38 * Accelerate the given coordinates. 39 * Takes a set of unaccelerated deltas and accelerates them based on the 40 * current and previous motion. 41 * 42 * This is a superset of filter_dispatch_constant() 43 * 44 * @param filter The device's motion filter 45 * @param unaccelerated The unaccelerated delta in the device's dpi 46 * resolution as specified during filter creation. If a device has uneven 47 * resolution for x and y, one axis needs to be scaled to match the 48 * originally provided resolution. 49 * @param data Custom data 50 * @param time The time of the delta 51 * 52 * @return A set of normalized coordinates that can be used for pixel 53 * movement. The normalized coordinates are scaled to the default dpi range, 54 * i.e. regardless of the resolution of the underlying device, the returned 55 * values always reflect a 1000dpi mouse. 56 * 57 * @see filter_dispatch_constant 58 */ 59 struct normalized_coords 60 filter_dispatch(struct motion_filter *filter, 61 const struct device_float_coords *unaccelerated, 62 void *data, uint64_t time); 63 64 /** 65 * Apply constant motion filters, but no acceleration. 66 * 67 * Takes a set of unaccelerated deltas and applies any constant filters to 68 * it but does not accelerate the delta in the conventional sense. 69 * 70 * @param filter The device's motion filter 71 * @param unaccelerated The unaccelerated delta in the device's dpi 72 * resolution as specified during filter creation. If a device has uneven 73 * resolution for x and y, one axis needs to be scaled to match the 74 * originally provided resolution. 75 * @param data Custom data 76 * @param time The time of the delta 77 * 78 * @see filter_dispatch 79 */ 80 struct normalized_coords 81 filter_dispatch_constant(struct motion_filter *filter, 82 const struct device_float_coords *unaccelerated, 83 void *data, uint64_t time); 84 85 /** 86 * Apply a scroll filter. 87 * Depending on the device, and the acceleration profile, 88 * this filter allows the user to accelerate the scroll movement. 89 * 90 * Takes a set of unaccelerated deltas and applies the scroll filter to it. 91 * 92 * @param filter The device's motion filter 93 * @param unaccelerated The unaccelerated delta in the device's dpi 94 * resolution as specified during filter creation. If a device has uneven 95 * resolution for x and y, one axis needs to be scaled to match the 96 * originally provided resolution. 97 * @param data Custom data 98 * @param time The time of the delta 99 * 100 * @see filter_dispatch 101 */ 102 struct normalized_coords 103 filter_dispatch_scroll(struct motion_filter *filter, 104 const struct device_float_coords *unaccelerated, 105 void *data, uint64_t time); 106 107 void 108 filter_restart(struct motion_filter *filter, 109 void *data, uint64_t time); 110 111 void 112 filter_destroy(struct motion_filter *filter); 113 114 bool 115 filter_set_speed(struct motion_filter *filter, 116 double speed); 117 double 118 filter_get_speed(struct motion_filter *filter); 119 120 enum libinput_config_accel_profile 121 filter_get_type(struct motion_filter *filter); 122 123 typedef double (*accel_profile_func_t)(struct motion_filter *filter, 124 void *data, 125 double velocity, 126 uint64_t time); 127 128 bool 129 filter_set_accel_config(struct motion_filter *filter, 130 struct libinput_config_accel *accel_config); 131 132 /* Pointer acceleration types */ 133 struct motion_filter * 134 create_pointer_accelerator_filter_flat(int dpi); 135 136 struct motion_filter * 137 create_pointer_accelerator_filter_linear(int dpi, bool use_velocity_averaging); 138 139 struct motion_filter * 140 create_pointer_accelerator_filter_linear_low_dpi(int dpi, bool use_velocity_averaging); 141 142 struct motion_filter * 143 create_pointer_accelerator_filter_touchpad(int dpi, 144 uint64_t event_delta_smooth_threshold, 145 uint64_t event_delta_smooth_value, 146 bool use_velocity_averaging); 147 148 struct motion_filter * 149 create_pointer_accelerator_filter_touchpad_flat(int dpi); 150 151 struct motion_filter * 152 create_pointer_accelerator_filter_lenovo_x230(int dpi, bool use_velocity_averaging); 153 154 struct motion_filter * 155 create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocity_averaging); 156 157 struct motion_filter * 158 create_pointer_accelerator_filter_trackpoint_flat(double multiplier); 159 160 struct motion_filter * 161 create_pointer_accelerator_filter_tablet(int xres, int yres); 162 163 struct motion_filter * 164 create_custom_accelerator_filter(void); 165 166 /* 167 * Pointer acceleration profiles. 168 */ 169 170 double 171 pointer_accel_profile_linear_low_dpi(struct motion_filter *filter, 172 void *data, 173 double speed_in, 174 uint64_t time); 175 double 176 pointer_accel_profile_linear(struct motion_filter *filter, 177 void *data, 178 double speed_in, 179 uint64_t time); 180 double 181 touchpad_accel_profile_linear(struct motion_filter *filter, 182 void *data, 183 double speed_in, 184 uint64_t time); 185 double 186 touchpad_lenovo_x230_accel_profile(struct motion_filter *filter, 187 void *data, 188 double speed_in, 189 uint64_t time); 190 double 191 trackpoint_accel_profile(struct motion_filter *filter, 192 void *data, 193 double velocity, 194 uint64_t time); 195 double 196 custom_accel_profile_fallback(struct motion_filter *filter, 197 void *data, 198 double speed_in, 199 uint64_t time); 200 double 201 custom_accel_profile_motion(struct motion_filter *filter, 202 void *data, 203 double speed_in, 204 uint64_t time); 205 double 206 custom_accel_profile_scroll(struct motion_filter *filter, 207 void *data, 208 double speed_in, 209 uint64_t time); 210 #endif /* FILTER_H */ 211