• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 void
86 filter_restart(struct motion_filter *filter,
87 	       void *data, uint64_t time);
88 
89 void
90 filter_destroy(struct motion_filter *filter);
91 
92 bool
93 filter_set_speed(struct motion_filter *filter,
94 		 double speed);
95 double
96 filter_get_speed(struct motion_filter *filter);
97 
98 enum libinput_config_accel_profile
99 filter_get_type(struct motion_filter *filter);
100 
101 typedef double (*accel_profile_func_t)(struct motion_filter *filter,
102 				       void *data,
103 				       double velocity,
104 				       uint64_t time);
105 
106 /* Pointer acceleration types */
107 struct motion_filter *
108 create_pointer_accelerator_filter_flat(int dpi);
109 
110 struct motion_filter *
111 create_pointer_accelerator_filter_linear(int dpi, bool use_velocity_averaging);
112 
113 struct motion_filter *
114 create_pointer_accelerator_filter_linear_low_dpi(int dpi, bool use_velocity_averaging);
115 
116 struct motion_filter *
117 create_pointer_accelerator_filter_touchpad(int dpi,
118 	uint64_t event_delta_smooth_threshold,
119 	uint64_t event_delta_smooth_value,
120 	bool use_velocity_averaging);
121 
122 struct motion_filter *
123 create_pointer_accelerator_filter_touchpad_flat(int dpi);
124 
125 struct motion_filter *
126 create_pointer_accelerator_filter_lenovo_x230(int dpi, bool use_velocity_averaging);
127 
128 struct motion_filter *
129 create_pointer_accelerator_filter_trackpoint(double multiplier, bool use_velocity_averaging);
130 
131 struct motion_filter *
132 create_pointer_accelerator_filter_tablet(int xres, int yres);
133 
134 /*
135  * Pointer acceleration profiles.
136  */
137 
138 double
139 pointer_accel_profile_linear_low_dpi(struct motion_filter *filter,
140 				     void *data,
141 				     double speed_in,
142 				     uint64_t time);
143 double
144 pointer_accel_profile_linear(struct motion_filter *filter,
145 			     void *data,
146 			     double speed_in,
147 			     uint64_t time);
148 double
149 touchpad_accel_profile_linear(struct motion_filter *filter,
150 			      void *data,
151 			      double speed_in,
152 			      uint64_t time);
153 double
154 touchpad_lenovo_x230_accel_profile(struct motion_filter *filter,
155 				      void *data,
156 				      double speed_in,
157 				      uint64_t time);
158 double
159 trackpoint_accel_profile(struct motion_filter *filter,
160 			 void *data,
161 			 double velocity,
162 			 uint64_t time);
163 #endif /* FILTER_H */
164