diff options
Diffstat (limited to 'sway/input/libinput.c')
-rw-r--r-- | sway/input/libinput.c | 124 |
1 files changed, 108 insertions, 16 deletions
diff --git a/sway/input/libinput.c b/sway/input/libinput.c index 54520f9e..0266c7a9 100644 --- a/sway/input/libinput.c +++ b/sway/input/libinput.c | |||
@@ -1,5 +1,6 @@ | |||
1 | #include <float.h> | 1 | #include <float.h> |
2 | #include <libinput.h> | 2 | #include <libinput.h> |
3 | #include <libudev.h> | ||
3 | #include <limits.h> | 4 | #include <limits.h> |
4 | #include <wlr/backend/libinput.h> | 5 | #include <wlr/backend/libinput.h> |
5 | #include "log.h" | 6 | #include "log.h" |
@@ -78,6 +79,16 @@ static bool set_accel_speed(struct libinput_device *device, double speed) { | |||
78 | return true; | 79 | return true; |
79 | } | 80 | } |
80 | 81 | ||
82 | static bool set_rotation_angle(struct libinput_device *device, double angle) { | ||
83 | if (!libinput_device_config_rotation_is_available(device) || | ||
84 | libinput_device_config_rotation_get_angle(device) == angle) { | ||
85 | return false; | ||
86 | } | ||
87 | sway_log(SWAY_DEBUG, "rotation_set_angle(%f)", angle); | ||
88 | log_status(libinput_device_config_rotation_set_angle(device, angle)); | ||
89 | return true; | ||
90 | } | ||
91 | |||
81 | static bool set_accel_profile(struct libinput_device *device, | 92 | static bool set_accel_profile(struct libinput_device *device, |
82 | enum libinput_config_accel_profile profile) { | 93 | enum libinput_config_accel_profile profile) { |
83 | if (!libinput_device_config_accel_is_available(device) || | 94 | if (!libinput_device_config_accel_is_available(device) || |
@@ -155,6 +166,18 @@ static bool set_scroll_button(struct libinput_device *dev, uint32_t button) { | |||
155 | return true; | 166 | return true; |
156 | } | 167 | } |
157 | 168 | ||
169 | static bool set_scroll_button_lock(struct libinput_device *dev, | ||
170 | enum libinput_config_scroll_button_lock_state lock) { | ||
171 | uint32_t scroll = libinput_device_config_scroll_get_methods(dev); | ||
172 | if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 || | ||
173 | libinput_device_config_scroll_get_button_lock(dev) == lock) { | ||
174 | return false; | ||
175 | } | ||
176 | sway_log(SWAY_DEBUG, "scroll_set_button_lock(%" PRIu32 ")", lock); | ||
177 | log_status(libinput_device_config_scroll_set_button_lock(dev, lock)); | ||
178 | return true; | ||
179 | } | ||
180 | |||
158 | static bool set_dwt(struct libinput_device *device, bool dwt) { | 181 | static bool set_dwt(struct libinput_device *device, bool dwt) { |
159 | if (!libinput_device_config_dwt_is_available(device) || | 182 | if (!libinput_device_config_dwt_is_available(device) || |
160 | libinput_device_config_dwt_get_enabled(device) == dwt) { | 183 | libinput_device_config_dwt_get_enabled(device) == dwt) { |
@@ -165,6 +188,16 @@ static bool set_dwt(struct libinput_device *device, bool dwt) { | |||
165 | return true; | 188 | return true; |
166 | } | 189 | } |
167 | 190 | ||
191 | static bool set_dwtp(struct libinput_device *device, bool dwtp) { | ||
192 | if (!libinput_device_config_dwtp_is_available(device) || | ||
193 | libinput_device_config_dwtp_get_enabled(device) == dwtp) { | ||
194 | return false; | ||
195 | } | ||
196 | sway_log(SWAY_DEBUG, "dwtp_set_enabled(%d)", dwtp); | ||
197 | log_status(libinput_device_config_dwtp_set_enabled(device, dwtp)); | ||
198 | return true; | ||
199 | } | ||
200 | |||
168 | static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) { | 201 | static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) { |
169 | if (!libinput_device_config_calibration_has_matrix(dev)) { | 202 | if (!libinput_device_config_calibration_has_matrix(dev)) { |
170 | return false; | 203 | return false; |
@@ -186,35 +219,38 @@ static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) { | |||
186 | return changed; | 219 | return changed; |
187 | } | 220 | } |
188 | 221 | ||
189 | void sway_input_configure_libinput_device(struct sway_input_device *input_device) { | 222 | static bool configure_send_events(struct libinput_device *device, |
190 | struct input_config *ic = input_device_get_config(input_device); | 223 | struct input_config *ic) { |
191 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
192 | return; | ||
193 | } | ||
194 | |||
195 | struct libinput_device *device = | ||
196 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
197 | sway_log(SWAY_DEBUG, "sway_input_configure_libinput_device('%s' on '%s')", | ||
198 | ic->identifier, input_device->identifier); | ||
199 | |||
200 | bool changed = false; | ||
201 | if (ic->mapped_to_output && | 224 | if (ic->mapped_to_output && |
225 | strcmp("*", ic->mapped_to_output) != 0 && | ||
202 | !output_by_name_or_id(ic->mapped_to_output)) { | 226 | !output_by_name_or_id(ic->mapped_to_output)) { |
203 | sway_log(SWAY_DEBUG, | 227 | sway_log(SWAY_DEBUG, |
204 | "%s '%s' is mapped to offline output '%s'; disabling input", | 228 | "%s '%s' is mapped to offline output '%s'; disabling input", |
205 | ic->input_type, ic->identifier, ic->mapped_to_output); | 229 | ic->input_type, ic->identifier, ic->mapped_to_output); |
206 | changed |= set_send_events(device, | 230 | return set_send_events(device, LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); |
207 | LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); | ||
208 | } else if (ic->send_events != INT_MIN) { | 231 | } else if (ic->send_events != INT_MIN) { |
209 | changed |= set_send_events(device, ic->send_events); | 232 | return set_send_events(device, ic->send_events); |
210 | } else { | 233 | } else { |
211 | // Have to reset to the default mode here, otherwise if ic->send_events | 234 | // Have to reset to the default mode here, otherwise if ic->send_events |
212 | // is unset and a mapped output just came online after being disabled, | 235 | // is unset and a mapped output just came online after being disabled, |
213 | // we'd remain stuck sending no events. | 236 | // we'd remain stuck sending no events. |
214 | changed |= set_send_events(device, | 237 | return set_send_events(device, |
215 | libinput_device_config_send_events_get_default_mode(device)); | 238 | libinput_device_config_send_events_get_default_mode(device)); |
216 | } | 239 | } |
240 | } | ||
241 | |||
242 | bool sway_input_configure_libinput_device(struct sway_input_device *input_device) { | ||
243 | struct input_config *ic = input_device_get_config(input_device); | ||
244 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
245 | return false; | ||
246 | } | ||
217 | 247 | ||
248 | struct libinput_device *device = | ||
249 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
250 | sway_log(SWAY_DEBUG, "sway_input_configure_libinput_device('%s' on '%s')", | ||
251 | ic->identifier, input_device->identifier); | ||
252 | |||
253 | bool changed = configure_send_events(device, ic); | ||
218 | if (ic->tap != INT_MIN) { | 254 | if (ic->tap != INT_MIN) { |
219 | changed |= set_tap(device, ic->tap); | 255 | changed |= set_tap(device, ic->tap); |
220 | } | 256 | } |
@@ -230,6 +266,9 @@ void sway_input_configure_libinput_device(struct sway_input_device *input_device | |||
230 | if (ic->pointer_accel != FLT_MIN) { | 266 | if (ic->pointer_accel != FLT_MIN) { |
231 | changed |= set_accel_speed(device, ic->pointer_accel); | 267 | changed |= set_accel_speed(device, ic->pointer_accel); |
232 | } | 268 | } |
269 | if (ic->rotation_angle != FLT_MIN) { | ||
270 | changed |= set_rotation_angle(device, ic->rotation_angle); | ||
271 | } | ||
233 | if (ic->accel_profile != INT_MIN) { | 272 | if (ic->accel_profile != INT_MIN) { |
234 | changed |= set_accel_profile(device, ic->accel_profile); | 273 | changed |= set_accel_profile(device, ic->accel_profile); |
235 | } | 274 | } |
@@ -251,13 +290,33 @@ void sway_input_configure_libinput_device(struct sway_input_device *input_device | |||
251 | if (ic->scroll_button != INT_MIN) { | 290 | if (ic->scroll_button != INT_MIN) { |
252 | changed |= set_scroll_button(device, ic->scroll_button); | 291 | changed |= set_scroll_button(device, ic->scroll_button); |
253 | } | 292 | } |
293 | if (ic->scroll_button_lock != INT_MIN) { | ||
294 | changed |= set_scroll_button_lock(device, ic->scroll_button_lock); | ||
295 | } | ||
254 | if (ic->dwt != INT_MIN) { | 296 | if (ic->dwt != INT_MIN) { |
255 | changed |= set_dwt(device, ic->dwt); | 297 | changed |= set_dwt(device, ic->dwt); |
256 | } | 298 | } |
299 | if (ic->dwtp != INT_MIN) { | ||
300 | changed |= set_dwtp(device, ic->dwtp); | ||
301 | } | ||
257 | if (ic->calibration_matrix.configured) { | 302 | if (ic->calibration_matrix.configured) { |
258 | changed |= set_calibration_matrix(device, ic->calibration_matrix.matrix); | 303 | changed |= set_calibration_matrix(device, ic->calibration_matrix.matrix); |
259 | } | 304 | } |
260 | 305 | ||
306 | return changed; | ||
307 | } | ||
308 | |||
309 | void sway_input_configure_libinput_device_send_events( | ||
310 | struct sway_input_device *input_device) { | ||
311 | struct input_config *ic = input_device_get_config(input_device); | ||
312 | if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) { | ||
313 | return; | ||
314 | } | ||
315 | |||
316 | struct libinput_device *device = | ||
317 | wlr_libinput_get_device_handle(input_device->wlr_device); | ||
318 | bool changed = configure_send_events(device, ic); | ||
319 | |||
261 | if (changed) { | 320 | if (changed) { |
262 | ipc_event_input("libinput_config", input_device); | 321 | ipc_event_input("libinput_config", input_device); |
263 | } | 322 | } |
@@ -286,6 +345,8 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | |||
286 | libinput_device_config_tap_get_default_drag_lock_enabled(device)); | 345 | libinput_device_config_tap_get_default_drag_lock_enabled(device)); |
287 | changed |= set_accel_speed(device, | 346 | changed |= set_accel_speed(device, |
288 | libinput_device_config_accel_get_default_speed(device)); | 347 | libinput_device_config_accel_get_default_speed(device)); |
348 | changed |= set_rotation_angle(device, | ||
349 | libinput_device_config_rotation_get_default_angle(device)); | ||
289 | changed |= set_accel_profile(device, | 350 | changed |= set_accel_profile(device, |
290 | libinput_device_config_accel_get_default_profile(device)); | 351 | libinput_device_config_accel_get_default_profile(device)); |
291 | changed |= set_natural_scroll(device, | 352 | changed |= set_natural_scroll(device, |
@@ -303,6 +364,8 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | |||
303 | libinput_device_config_scroll_get_default_button(device)); | 364 | libinput_device_config_scroll_get_default_button(device)); |
304 | changed |= set_dwt(device, | 365 | changed |= set_dwt(device, |
305 | libinput_device_config_dwt_get_default_enabled(device)); | 366 | libinput_device_config_dwt_get_default_enabled(device)); |
367 | changed |= set_dwtp(device, | ||
368 | libinput_device_config_dwtp_get_default_enabled(device)); | ||
306 | 369 | ||
307 | float matrix[6]; | 370 | float matrix[6]; |
308 | libinput_device_config_calibration_get_default_matrix(device, matrix); | 371 | libinput_device_config_calibration_get_default_matrix(device, matrix); |
@@ -312,3 +375,32 @@ void sway_input_reset_libinput_device(struct sway_input_device *input_device) { | |||
312 | ipc_event_input("libinput_config", input_device); | 375 | ipc_event_input("libinput_config", input_device); |
313 | } | 376 | } |
314 | } | 377 | } |
378 | |||
379 | bool sway_libinput_device_is_builtin(struct sway_input_device *sway_device) { | ||
380 | if (!wlr_input_device_is_libinput(sway_device->wlr_device)) { | ||
381 | return false; | ||
382 | } | ||
383 | |||
384 | struct libinput_device *device = | ||
385 | wlr_libinput_get_device_handle(sway_device->wlr_device); | ||
386 | struct udev_device *udev_device = | ||
387 | libinput_device_get_udev_device(device); | ||
388 | if (!udev_device) { | ||
389 | return false; | ||
390 | } | ||
391 | |||
392 | const char *id_path = udev_device_get_property_value(udev_device, "ID_PATH"); | ||
393 | if (!id_path) { | ||
394 | return false; | ||
395 | } | ||
396 | |||
397 | const char prefix_platform[] = "platform-"; | ||
398 | if (strncmp(id_path, prefix_platform, strlen(prefix_platform)) != 0) { | ||
399 | return false; | ||
400 | } | ||
401 | |||
402 | const char prefix_pci[] = "pci-"; | ||
403 | const char infix_platform[] = "-platform-"; | ||
404 | return (strncmp(id_path, prefix_pci, strlen(prefix_pci)) == 0) && | ||
405 | strstr(id_path, infix_platform); | ||
406 | } | ||