aboutsummaryrefslogtreecommitdiffstats
path: root/sway/input
diff options
context:
space:
mode:
authorLibravatar Brian Ashworth <bosrsf04@gmail.com>2020-09-02 19:26:39 -0400
committerLibravatar Simon Ser <contact@emersion.fr>2020-09-03 10:46:06 +0200
commit2ea5d2985ad18ec6cb9d9f4e8d05e3d91356a6bb (patch)
tree4301701ac756f63bf02ad2be8d331d41aa00554f /sway/input
parentUse wlr_output_event_commit (diff)
downloadsway-2ea5d2985ad18ec6cb9d9f4e8d05e3d91356a6bb.tar.gz
sway-2ea5d2985ad18ec6cb9d9f4e8d05e3d91356a6bb.tar.zst
sway-2ea5d2985ad18ec6cb9d9f4e8d05e3d91356a6bb.zip
input/libinput: remove input type property bias
This changes it so all libinput config options are set on any device that supports it. Previously, only a subset of libinput config options were being considered depending on the input type. Instead of trying to guess which properties the device may support, attempt to set any configured property regardless of the device type. All of the functions already have early returns in them for when the device does not actually support the property. This brings the configuration side inline with describe_libinput_device for the IPC side. This change was prompted by a tablet tool showing the calibration matrix property in the IPC message, but not being able to actually change it since that property was only being considered for the touch input type.
Diffstat (limited to 'sway/input')
-rw-r--r--sway/input/libinput.c134
1 files changed, 25 insertions, 109 deletions
diff --git a/sway/input/libinput.c b/sway/input/libinput.c
index 108fc7b2..54520f9e 100644
--- a/sway/input/libinput.c
+++ b/sway/input/libinput.c
@@ -186,17 +186,23 @@ static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) {
186 return changed; 186 return changed;
187} 187}
188 188
189static bool config_libinput_pointer(struct libinput_device *device, 189void sway_input_configure_libinput_device(struct sway_input_device *input_device) {
190 struct input_config *ic, const char *device_id) { 190 struct input_config *ic = input_device_get_config(input_device);
191 sway_log(SWAY_DEBUG, "config_libinput_pointer('%s' on '%s')", 191 if (!ic || !wlr_input_device_is_libinput(input_device->wlr_device)) {
192 ic->identifier, device_id); 192 return;
193 bool changed = false; 193 }
194 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;
195 if (ic->mapped_to_output && 201 if (ic->mapped_to_output &&
196 !output_by_name_or_id(ic->mapped_to_output)) { 202 !output_by_name_or_id(ic->mapped_to_output)) {
197 sway_log(SWAY_DEBUG, 203 sway_log(SWAY_DEBUG,
198 "Pointer '%s' is mapped to offline output '%s'; disabling input", 204 "%s '%s' is mapped to offline output '%s'; disabling input",
199 ic->identifier, ic->mapped_to_output); 205 ic->input_type, ic->identifier, ic->mapped_to_output);
200 changed |= set_send_events(device, 206 changed |= set_send_events(device,
201 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED); 207 LIBINPUT_CONFIG_SEND_EVENTS_DISABLED);
202 } else if (ic->send_events != INT_MIN) { 208 } else if (ic->send_events != INT_MIN) {
@@ -221,7 +227,6 @@ static bool config_libinput_pointer(struct libinput_device *device,
221 if (ic->drag_lock != INT_MIN) { 227 if (ic->drag_lock != INT_MIN) {
222 changed |= set_tap_drag_lock(device, ic->drag_lock); 228 changed |= set_tap_drag_lock(device, ic->drag_lock);
223 } 229 }
224
225 if (ic->pointer_accel != FLT_MIN) { 230 if (ic->pointer_accel != FLT_MIN) {
226 changed |= set_accel_speed(device, ic->pointer_accel); 231 changed |= set_accel_speed(device, ic->pointer_accel);
227 } 232 }
@@ -249,71 +254,26 @@ static bool config_libinput_pointer(struct libinput_device *device,
249 if (ic->dwt != INT_MIN) { 254 if (ic->dwt != INT_MIN) {
250 changed |= set_dwt(device, ic->dwt); 255 changed |= set_dwt(device, ic->dwt);
251 } 256 }
252 return changed;
253}
254
255static bool config_libinput_keyboard(struct libinput_device *device,
256 struct input_config *ic, const char *device_id) {
257 sway_log(SWAY_DEBUG, "config_libinput_keyboard('%s' on '%s')",
258 ic->identifier, device_id);
259 if (ic->send_events != INT_MIN) {
260 return set_send_events(device, ic->send_events);
261 }
262 return false;
263}
264
265static bool config_libinput_switch(struct libinput_device *device,
266 struct input_config *ic, const char *device_id) {
267 sway_log(SWAY_DEBUG, "config_libinput_switch('%s' on '%s')",
268 ic->identifier, device_id);
269 if (ic->send_events != INT_MIN) {
270 return set_send_events(device, ic->send_events);
271 }
272 return false;
273}
274
275static bool config_libinput_touch(struct libinput_device *device,
276 struct input_config *ic, const char *device_id) {
277 sway_log(SWAY_DEBUG, "config_libinput_touch('%s' on '%s')",
278 ic->identifier, device_id);
279 bool changed = false;
280 if (ic->send_events != INT_MIN) {
281 changed |= set_send_events(device, ic->send_events);
282 }
283 if (ic->calibration_matrix.configured) { 257 if (ic->calibration_matrix.configured) {
284 changed |= set_calibration_matrix(device, ic->calibration_matrix.matrix); 258 changed |= set_calibration_matrix(device, ic->calibration_matrix.matrix);
285 } 259 }
286 return changed;
287}
288 260
289void sway_input_configure_libinput_device(struct sway_input_device *device) {
290 struct input_config *ic = input_device_get_config(device);
291 if (!ic || !wlr_input_device_is_libinput(device->wlr_device)) {
292 return;
293 }
294 bool changed = false;
295 const char *device_id = device->identifier;
296 struct libinput_device *libinput_device =
297 wlr_libinput_get_device_handle(device->wlr_device);
298 if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
299 device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
300 changed = config_libinput_pointer(libinput_device, ic, device_id);
301 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
302 changed = config_libinput_keyboard(libinput_device, ic, device_id);
303 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
304 changed = config_libinput_switch(libinput_device, ic, device_id);
305 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
306 changed = config_libinput_touch(libinput_device, ic, device_id);
307 }
308 if (changed) { 261 if (changed) {
309 ipc_event_input("libinput_config", device); 262 ipc_event_input("libinput_config", input_device);
310 } 263 }
311} 264}
312 265
313static bool reset_libinput_pointer(struct libinput_device *device, 266void sway_input_reset_libinput_device(struct sway_input_device *input_device) {
314 const char *device_id) { 267 if (!wlr_input_device_is_libinput(input_device->wlr_device)) {
315 sway_log(SWAY_DEBUG, "reset_libinput_pointer(%s)", device_id); 268 return;
269 }
270
271 struct libinput_device *device =
272 wlr_libinput_get_device_handle(input_device->wlr_device);
273 sway_log(SWAY_DEBUG, "sway_input_reset_libinput_device(%s)",
274 input_device->identifier);
316 bool changed = false; 275 bool changed = false;
276
317 changed |= set_send_events(device, 277 changed |= set_send_events(device,
318 libinput_device_config_send_events_get_default_mode(device)); 278 libinput_device_config_send_events_get_default_mode(device));
319 changed |= set_tap(device, 279 changed |= set_tap(device,
@@ -343,56 +303,12 @@ static bool reset_libinput_pointer(struct libinput_device *device,
343 libinput_device_config_scroll_get_default_button(device)); 303 libinput_device_config_scroll_get_default_button(device));
344 changed |= set_dwt(device, 304 changed |= set_dwt(device,
345 libinput_device_config_dwt_get_default_enabled(device)); 305 libinput_device_config_dwt_get_default_enabled(device));
346 return changed;
347}
348
349static bool reset_libinput_keyboard(struct libinput_device *device,
350 const char *device_id) {
351 sway_log(SWAY_DEBUG, "reset_libinput_keyboard(%s)", device_id);
352 return set_send_events(device,
353 libinput_device_config_send_events_get_default_mode(device));
354}
355
356static bool reset_libinput_switch(struct libinput_device *device,
357 const char *device_id) {
358 sway_log(SWAY_DEBUG, "reset_libinput_switch(%s)", device_id);
359 return set_send_events(device,
360 libinput_device_config_send_events_get_default_mode(device));
361}
362
363static bool reset_libinput_touch(struct libinput_device *device,
364 const char *device_id) {
365 sway_log(SWAY_DEBUG, "reset_libinput_touch(%s)", device_id);
366 bool changed = false;
367
368 changed |= set_send_events(device,
369 libinput_device_config_send_events_get_default_mode(device));
370 306
371 float matrix[6]; 307 float matrix[6];
372 libinput_device_config_calibration_get_default_matrix(device, matrix); 308 libinput_device_config_calibration_get_default_matrix(device, matrix);
373 changed |= set_calibration_matrix(device, matrix); 309 changed |= set_calibration_matrix(device, matrix);
374 310
375 return changed;
376}
377
378void sway_input_reset_libinput_device(struct sway_input_device *device) {
379 if (!wlr_input_device_is_libinput(device->wlr_device)) {
380 return;
381 }
382 bool changed = false;
383 struct libinput_device *libinput_device =
384 wlr_libinput_get_device_handle(device->wlr_device);
385 if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
386 device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
387 changed = reset_libinput_pointer(libinput_device, device->identifier);
388 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
389 changed = reset_libinput_keyboard(libinput_device, device->identifier);
390 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
391 changed = reset_libinput_switch(libinput_device, device->identifier);
392 } else if (device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
393 changed = reset_libinput_touch(libinput_device, device->identifier);
394 }
395 if (changed) { 311 if (changed) {
396 ipc_event_input("libinput_config", device); 312 ipc_event_input("libinput_config", input_device);
397 } 313 }
398} 314}