|
1 | | -pub use smithay::{ |
2 | | - backend::input::KeyState, |
3 | | - input::keyboard::{keysyms as KeySyms, Keysym, ModifiersState}, |
4 | | - output::{Mode, Output}, |
5 | | - reexports::{ |
6 | | - calloop::LoopHandle, |
7 | | - input::{ |
8 | | - AccelProfile, ClickMethod, Device as InputDevice, ScrollMethod, SendEventsMode, |
9 | | - TapButtonMap, |
10 | | - }, |
11 | | - }, |
12 | | - utils::{Logical, Physical, Point, Size, Transform}, |
| 1 | +use smithay::reexports::input::{ |
| 2 | + Device as InputDevice, DeviceConfigError, ScrollMethod, SendEventsMode, |
13 | 3 | }; |
14 | 4 | use tracing::warn; |
15 | 5 |
|
@@ -91,17 +81,38 @@ pub fn for_device(device: &InputDevice) -> InputConfig { |
91 | 81 | } |
92 | 82 | } |
93 | 83 |
|
| 84 | +// Get setting from `device_config` if present, then `default_config` |
| 85 | +// Returns `is_default` to indicate this is a default value. |
94 | 86 | fn get_config<'a, T: 'a, F: Fn(&'a InputConfig) -> Option<T>>( |
95 | 87 | device_config: Option<&'a InputConfig>, |
96 | 88 | default_config: &'a InputConfig, |
97 | 89 | f: F, |
98 | | -) -> Option<T> { |
99 | | - if let Some(device_config) = device_config { |
100 | | - if let Some(setting) = f(device_config) { |
101 | | - return Some(setting); |
102 | | - } |
| 90 | +) -> Option<(T, bool)> { |
| 91 | + if let Some(setting) = device_config.and_then(&f) { |
| 92 | + Some((setting, false)) |
| 93 | + } else if let Some(setting) = f(default_config) { |
| 94 | + Some((setting, true)) |
| 95 | + } else { |
| 96 | + None |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +fn config_set_error<T: std::fmt::Debug>( |
| 101 | + device: &InputDevice, |
| 102 | + setting: &str, |
| 103 | + value: T, |
| 104 | + err: DeviceConfigError, |
| 105 | + is_default: bool, |
| 106 | +) { |
| 107 | + if !(is_default && err == DeviceConfigError::Unsupported) { |
| 108 | + warn!( |
| 109 | + ?err, |
| 110 | + "Failed to apply {} {:?} for device {:?}.", |
| 111 | + setting, |
| 112 | + value, |
| 113 | + device.name(), |
| 114 | + ); |
103 | 115 | } |
104 | | - f(default_config) |
105 | 116 | } |
106 | 117 |
|
107 | 118 | pub fn update_device( |
@@ -130,152 +141,77 @@ pub fn update_device( |
130 | 141 | device.name(), |
131 | 142 | ); |
132 | 143 | } |
133 | | - if let Some(accel) = config!(|x| x.acceleration.as_ref()) { |
| 144 | + if let Some((accel, is_default)) = config!(|x| x.acceleration.as_ref()) { |
134 | 145 | if let Some(profile) = accel.profile { |
135 | 146 | if let Err(err) = device.config_accel_set_profile(profile) { |
136 | | - warn!( |
137 | | - ?err, |
138 | | - "Failed to apply acceleration profile {:?} for device {:?}.", |
139 | | - profile, |
140 | | - device.name(), |
141 | | - ); |
| 147 | + config_set_error(device, "acceleration profile", profile, err, is_default); |
142 | 148 | } |
143 | 149 | } |
144 | 150 | if let Err(err) = device.config_accel_set_speed(accel.speed) { |
145 | | - warn!( |
146 | | - ?err, |
147 | | - "Failed to apply acceleration speed {:?} for device {:?}.", |
148 | | - accel.speed, |
149 | | - device.name(), |
150 | | - ); |
| 151 | + config_set_error(device, "acceleration speed", accel.speed, err, is_default); |
151 | 152 | } |
152 | 153 | } |
153 | | - if let Some(matrix) = config!(|x| x.calibration) { |
| 154 | + if let Some((matrix, is_default)) = config!(|x| x.calibration) { |
154 | 155 | if let Err(err) = device.config_calibration_set_matrix(matrix) { |
155 | | - warn!( |
156 | | - ?err, |
157 | | - "Failed to apply calibration matrix {:?} for device {:?}.", |
158 | | - matrix, |
159 | | - device.name(), |
160 | | - ); |
| 156 | + config_set_error(device, "calibration matrix", matrix, err, is_default); |
161 | 157 | } |
162 | 158 | } |
163 | | - if let Some(method) = config!(|x| x.click_method) { |
| 159 | + if let Some((method, is_default)) = config!(|x| x.click_method) { |
164 | 160 | if let Err(err) = device.config_click_set_method(method) { |
165 | | - warn!( |
166 | | - ?err, |
167 | | - "Failed to apply click method {:?} for device {:?}.", |
168 | | - method, |
169 | | - device.name(), |
170 | | - ); |
| 161 | + config_set_error(device, "click method", method, err, is_default); |
171 | 162 | } |
172 | 163 | } |
173 | | - if let Some(dwt) = config!(|x| x.disable_while_typing) { |
| 164 | + if let Some((dwt, is_default)) = config!(|x| x.disable_while_typing) { |
174 | 165 | if let Err(err) = device.config_dwt_set_enabled(dwt) { |
175 | | - warn!( |
176 | | - ?err, |
177 | | - "Failed to apply disable-while-typing {:?} for device {:?}.", |
178 | | - dwt, |
179 | | - device.name(), |
180 | | - ); |
| 166 | + config_set_error(device, "disable-while-typing", dwt, err, is_default); |
181 | 167 | } |
182 | 168 | } |
183 | | - if let Some(left) = config!(|x| x.left_handed) { |
| 169 | + if let Some((left, is_default)) = config!(|x| x.left_handed) { |
184 | 170 | if let Err(err) = device.config_left_handed_set(left) { |
185 | | - warn!( |
186 | | - ?err, |
187 | | - "Failed to apply left-handed {:?} for device {:?}.", |
188 | | - left, |
189 | | - device.name(), |
190 | | - ); |
| 171 | + config_set_error(device, "left-handed", left, err, is_default); |
191 | 172 | } |
192 | 173 | } |
193 | | - if let Some(middle) = config!(|x| x.middle_button_emulation) { |
| 174 | + if let Some((middle, is_default)) = config!(|x| x.middle_button_emulation) { |
194 | 175 | if let Err(err) = device.config_middle_emulation_set_enabled(middle) { |
195 | | - warn!( |
196 | | - ?err, |
197 | | - "Failed to apply middle-button-emulation {:?} for device {:?}.", |
198 | | - middle, |
199 | | - device.name(), |
200 | | - ); |
| 176 | + config_set_error(device, "middle-button-emulation", middle, err, is_default); |
201 | 177 | } |
202 | 178 | } |
203 | | - if let Some(angle) = config!(|x| x.rotation_angle) { |
| 179 | + if let Some((angle, is_default)) = config!(|x| x.rotation_angle) { |
204 | 180 | if let Err(err) = device.config_rotation_set_angle(angle) { |
205 | | - warn!( |
206 | | - ?err, |
207 | | - "Failed to apply rotation-angle {:?} for device {:?}", |
208 | | - angle, |
209 | | - device.name(), |
210 | | - ); |
| 181 | + config_set_error(device, "rotation-angle", angle, err, is_default); |
211 | 182 | } |
212 | 183 | } |
213 | | - if let Some(scroll) = config!(|x| x.scroll_config.as_ref()) { |
| 184 | + if let Some((scroll, is_default)) = config!(|x| x.scroll_config.as_ref()) { |
214 | 185 | if let Some(method) = scroll.method { |
215 | 186 | if let Err(err) = device.config_scroll_set_method(method) { |
216 | | - warn!( |
217 | | - ?err, |
218 | | - "Failed to apply scroll method {:?} for device {:?}.", |
219 | | - method, |
220 | | - device.name(), |
221 | | - ); |
| 187 | + config_set_error(device, "scroll method", scroll, err, is_default); |
222 | 188 | } |
223 | 189 | } |
224 | 190 | if let Some(natural) = scroll.natural_scroll { |
225 | 191 | if let Err(err) = device.config_scroll_set_natural_scroll_enabled(natural) { |
226 | | - warn!( |
227 | | - ?err, |
228 | | - "Failed to apply natural scrolling {:?} for device {:?}.", |
229 | | - natural, |
230 | | - device.name(), |
231 | | - ); |
| 192 | + config_set_error(device, "natural scrolling", natural, err, is_default); |
232 | 193 | } |
233 | 194 | } |
234 | 195 | if let Some(button) = scroll.scroll_button { |
235 | 196 | if let Err(err) = device.config_scroll_set_button(button) { |
236 | | - warn!( |
237 | | - ?err, |
238 | | - "Failed to apply scroll button {:?} for device {:?}.", |
239 | | - button, |
240 | | - device.name(), |
241 | | - ); |
| 197 | + config_set_error(device, "scroll button", button, err, is_default); |
242 | 198 | } |
243 | 199 | } |
244 | 200 | } |
245 | | - if let Some(tap) = config!(|x| x.tap_config.as_ref()) { |
| 201 | + if let Some((tap, is_default)) = config!(|x| x.tap_config.as_ref()) { |
246 | 202 | if let Err(err) = device.config_tap_set_enabled(tap.enabled) { |
247 | | - warn!( |
248 | | - ?err, |
249 | | - "Failed to apply tap-to-click {:?} for device {:?}.", |
250 | | - tap.enabled, |
251 | | - device.name(), |
252 | | - ); |
| 203 | + config_set_error(device, "tap-to-click", tap.enabled, err, is_default); |
253 | 204 | } |
254 | 205 | if let Some(button_map) = tap.button_map { |
255 | 206 | if let Err(err) = device.config_tap_set_button_map(button_map) { |
256 | | - warn!( |
257 | | - ?err, |
258 | | - "Failed to apply button map {:?} for device {:?}.", |
259 | | - button_map, |
260 | | - device.name(), |
261 | | - ); |
| 207 | + config_set_error(device, "button map", button_map, err, is_default); |
262 | 208 | } |
263 | 209 | } |
264 | 210 | if let Err(err) = device.config_tap_set_drag_enabled(tap.drag) { |
265 | | - warn!( |
266 | | - ?err, |
267 | | - "Failed to apply tap-drag {:?} for device {:?}.", |
268 | | - tap.drag, |
269 | | - device.name(), |
270 | | - ); |
| 211 | + config_set_error(device, "tap-drag", tap.drag, err, is_default); |
271 | 212 | } |
272 | 213 | if let Err(err) = device.config_tap_set_drag_lock_enabled(tap.drag_lock) { |
273 | | - warn!( |
274 | | - ?err, |
275 | | - "Failed to apply tap-drag-lock {:?} for device {:?}.", |
276 | | - tap.drag_lock, |
277 | | - device.name(), |
278 | | - ); |
| 214 | + config_set_error(device, "tap-drag-lock", tap.drag_lock, err, is_default); |
279 | 215 | } |
280 | 216 | } |
281 | 217 | } |
0 commit comments