mirror of
https://github.com/swaywm/sway.git
synced 2024-11-10 20:44:01 +01:00
ipc: add input::libinput_config event
This adds a libinput_config change type to the input event for when the libinput config for a device changes In order for this to be possible to track, the libinput config code had to be refactored. It is now extracted into a separate file to isolate it from the rest of the input management code.
This commit is contained in:
parent
6effca7b61
commit
1a16262903
9
include/sway/input/libinput.h
Normal file
9
include/sway/input/libinput.h
Normal file
@ -0,0 +1,9 @@
|
||||
#ifndef _SWAY_INPUT_LIBINPUT_H
|
||||
#define _SWAY_INPUT_LIBINPUT_H
|
||||
#include "sway/input/input-manager.h"
|
||||
|
||||
void sway_input_configure_libinput_device(struct sway_input_device *device);
|
||||
|
||||
void sway_input_reset_libinput_device(struct sway_input_device *device);
|
||||
|
||||
#endif
|
@ -1,16 +1,14 @@
|
||||
#define _POSIX_C_SOURCE 200809L
|
||||
#include <ctype.h>
|
||||
#include <float.h>
|
||||
#include <limits.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <libinput.h>
|
||||
#include <math.h>
|
||||
#include <wlr/backend/libinput.h>
|
||||
#include <wlr/types/wlr_input_inhibitor.h>
|
||||
#include <wlr/types/wlr_virtual_keyboard_v1.h>
|
||||
#include "sway/config.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/input/libinput.h"
|
||||
#include "sway/input/seat.h"
|
||||
#include "sway/ipc-server.h"
|
||||
#include "sway/server.h"
|
||||
@ -173,401 +171,6 @@ void input_manager_verify_fallback_seat(void) {
|
||||
}
|
||||
}
|
||||
|
||||
static void log_libinput_config_status(enum libinput_config_status status) {
|
||||
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
|
||||
sway_log(SWAY_ERROR, "Failed to apply libinput config: %s",
|
||||
libinput_config_status_to_str(status));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_config_keyboard(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct input_config *ic = input_device_get_config(input_device);
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!ic || !wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
sway_log(SWAY_DEBUG, "input_manager_libinput_config_keyboard(%s)",
|
||||
ic->identifier);
|
||||
|
||||
if (ic->send_events != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_keyboard(%s) send_events_set_mode(%d)",
|
||||
ic->identifier, ic->send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, ic->send_events));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_reset_keyboard(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
|
||||
uint32_t send_events =
|
||||
libinput_device_config_send_events_get_default_mode(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_keyboard(%s) send_events_set_mode(%d)",
|
||||
input_device->identifier, send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, send_events));
|
||||
}
|
||||
|
||||
static void input_manager_libinput_config_switch(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct input_config *ic = input_device_get_config(input_device);
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!ic || !wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
sway_log(SWAY_DEBUG, "input_manager_libinput_config_switch(%s)",
|
||||
ic->identifier);
|
||||
|
||||
if (ic->send_events != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_switch(%s) send_events_set_mode(%d)",
|
||||
ic->identifier, ic->send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, ic->send_events));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_reset_switch(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
|
||||
uint32_t send_events =
|
||||
libinput_device_config_send_events_get_default_mode(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_switch(%s) send_events_set_mode(%d)",
|
||||
input_device->identifier, send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, send_events));
|
||||
}
|
||||
|
||||
static void input_manager_libinput_config_touch(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct input_config *ic = input_device_get_config(input_device);
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!ic || !wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
sway_log(SWAY_DEBUG, "input_manager_libinput_config_touch(%s)",
|
||||
ic->identifier);
|
||||
|
||||
if (ic->send_events != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_touch(%s) send_events_set_mode(%d)",
|
||||
ic->identifier, ic->send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, ic->send_events));
|
||||
}
|
||||
float *m = ic->calibration_matrix.matrix;
|
||||
if (ic->calibration_matrix.configured) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_touch(%s) calibration_set_matrix(%f %f %f %f %f %f)",
|
||||
ic->identifier, m[0], m[1], m[2], m[3], m[4], m[5]);
|
||||
log_libinput_config_status(libinput_device_config_calibration_set_matrix(
|
||||
libinput_device, ic->calibration_matrix.matrix));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_reset_touch(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
|
||||
uint32_t send_events =
|
||||
libinput_device_config_send_events_get_default_mode(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_touch(%s) send_events_set_mode(%d)",
|
||||
input_device->identifier, send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, send_events));
|
||||
|
||||
if (libinput_device_config_calibration_has_matrix(libinput_device)) {
|
||||
float m[6];
|
||||
libinput_device_config_calibration_get_default_matrix(libinput_device, m);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_touch(%s) calibration_set_matrix("
|
||||
"%f %f %f %f %f %f)", input_device->identifier, m[0], m[1],
|
||||
m[2], m[3], m[4], m[5]);
|
||||
log_libinput_config_status(libinput_device_config_calibration_set_matrix(
|
||||
libinput_device, m));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_config_pointer(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
struct input_config *ic = input_device_get_config(input_device);
|
||||
struct libinput_device *libinput_device;
|
||||
|
||||
if (!ic || !wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
libinput_device = wlr_libinput_get_device_handle(wlr_device);
|
||||
sway_log(SWAY_DEBUG, "input_manager_libinput_config_pointer(%s)",
|
||||
ic->identifier);
|
||||
|
||||
if (ic->accel_profile != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) accel_set_profile(%d)",
|
||||
ic->identifier, ic->accel_profile);
|
||||
log_libinput_config_status(libinput_device_config_accel_set_profile(
|
||||
libinput_device, ic->accel_profile));
|
||||
}
|
||||
if (ic->click_method != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) click_set_method(%d)",
|
||||
ic->identifier, ic->click_method);
|
||||
log_libinput_config_status(libinput_device_config_click_set_method(
|
||||
libinput_device, ic->click_method));
|
||||
}
|
||||
if (ic->drag != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_config_pointer(%s) tap_set_drag_enabled(%d)",
|
||||
ic->identifier, ic->drag);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_drag_enabled(
|
||||
libinput_device, ic->drag));
|
||||
}
|
||||
if (ic->drag_lock != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_config_pointer(%s) tap_set_drag_lock_enabled(%d)",
|
||||
ic->identifier, ic->drag_lock);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_tap_set_drag_lock_enabled(
|
||||
libinput_device, ic->drag_lock));
|
||||
}
|
||||
if (ic->dwt != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) dwt_set_enabled(%d)",
|
||||
ic->identifier, ic->dwt);
|
||||
log_libinput_config_status(libinput_device_config_dwt_set_enabled(
|
||||
libinput_device, ic->dwt));
|
||||
}
|
||||
if (ic->left_handed != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_config_pointer(%s) left_handed_set_enabled(%d)",
|
||||
ic->identifier, ic->left_handed);
|
||||
log_libinput_config_status(libinput_device_config_left_handed_set(
|
||||
libinput_device, ic->left_handed));
|
||||
}
|
||||
if (ic->middle_emulation != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_config_pointer(%s) middle_emulation_set_enabled(%d)",
|
||||
ic->identifier, ic->middle_emulation);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_middle_emulation_set_enabled(
|
||||
libinput_device, ic->middle_emulation));
|
||||
}
|
||||
if (ic->natural_scroll != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_config_pointer(%s) natural_scroll_set_enabled(%d)",
|
||||
ic->identifier, ic->natural_scroll);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_scroll_set_natural_scroll_enabled(
|
||||
libinput_device, ic->natural_scroll));
|
||||
}
|
||||
if (ic->pointer_accel != FLT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) accel_set_speed(%f)",
|
||||
ic->identifier, ic->pointer_accel);
|
||||
log_libinput_config_status(libinput_device_config_accel_set_speed(
|
||||
libinput_device, ic->pointer_accel));
|
||||
}
|
||||
if (ic->scroll_button != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) scroll_set_button(%d)",
|
||||
ic->identifier, ic->scroll_button);
|
||||
log_libinput_config_status(libinput_device_config_scroll_set_button(
|
||||
libinput_device, ic->scroll_button));
|
||||
}
|
||||
if (ic->scroll_method != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) scroll_set_method(%d)",
|
||||
ic->identifier, ic->scroll_method);
|
||||
log_libinput_config_status(libinput_device_config_scroll_set_method(
|
||||
libinput_device, ic->scroll_method));
|
||||
}
|
||||
if (ic->send_events != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) send_events_set_mode(%d)",
|
||||
ic->identifier, ic->send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, ic->send_events));
|
||||
}
|
||||
if (ic->tap != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) tap_set_enabled(%d)",
|
||||
ic->identifier, ic->tap);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_enabled(
|
||||
libinput_device, ic->tap));
|
||||
}
|
||||
if (ic->tap_button_map != INT_MIN) {
|
||||
sway_log(SWAY_DEBUG, "libinput_config_pointer(%s) tap_set_button_map(%d)",
|
||||
ic->identifier, ic->tap_button_map);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_button_map(
|
||||
libinput_device, ic->tap_button_map));
|
||||
}
|
||||
}
|
||||
|
||||
static void input_manager_libinput_reset_pointer(
|
||||
struct sway_input_device *input_device) {
|
||||
struct wlr_input_device *wlr_device = input_device->wlr_device;
|
||||
|
||||
if (!wlr_input_device_is_libinput(wlr_device)) {
|
||||
return;
|
||||
}
|
||||
|
||||
struct libinput_device *libinput_device =
|
||||
wlr_libinput_get_device_handle(wlr_device);
|
||||
|
||||
uint32_t send_events =
|
||||
libinput_device_config_send_events_get_default_mode(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) send_events_set_mode(%d)",
|
||||
input_device->identifier, send_events);
|
||||
log_libinput_config_status(libinput_device_config_send_events_set_mode(
|
||||
libinput_device, send_events));
|
||||
|
||||
if (libinput_device_config_tap_get_finger_count(libinput_device) > 0) {
|
||||
enum libinput_config_tap_state tap =
|
||||
libinput_device_config_tap_get_default_enabled(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) tap_set_enabled(%d)",
|
||||
input_device->identifier, tap);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_enabled(
|
||||
libinput_device, tap));
|
||||
|
||||
enum libinput_config_tap_button_map tap_button_map =
|
||||
libinput_device_config_tap_get_button_map(libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) tap_set_button_map(%d)",
|
||||
input_device->identifier, tap_button_map);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_button_map(
|
||||
libinput_device, tap_button_map));
|
||||
|
||||
enum libinput_config_drag_state drag =
|
||||
libinput_device_config_tap_get_default_drag_enabled(libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) tap_set_drag_enabled(%d)",
|
||||
input_device->identifier, drag);
|
||||
log_libinput_config_status(libinput_device_config_tap_set_drag_enabled(
|
||||
libinput_device, drag));
|
||||
|
||||
enum libinput_config_drag_lock_state drag_lock =
|
||||
libinput_device_config_tap_get_default_drag_lock_enabled(
|
||||
libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) tap_set_drag_lock_enabled(%d)",
|
||||
input_device->identifier, drag_lock);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_tap_set_drag_lock_enabled(
|
||||
libinput_device, drag_lock));
|
||||
}
|
||||
|
||||
if (libinput_device_config_accel_is_available(libinput_device)) {
|
||||
double pointer_accel =
|
||||
libinput_device_config_accel_get_default_speed(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) accel_set_speed(%f)",
|
||||
input_device->identifier, pointer_accel);
|
||||
log_libinput_config_status(libinput_device_config_accel_set_speed(
|
||||
libinput_device, pointer_accel));
|
||||
|
||||
enum libinput_config_accel_profile accel_profile =
|
||||
libinput_device_config_accel_get_default_profile(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) accel_set_profile(%d)",
|
||||
input_device->identifier, accel_profile);
|
||||
log_libinput_config_status(libinput_device_config_accel_set_profile(
|
||||
libinput_device, accel_profile));
|
||||
}
|
||||
|
||||
if (libinput_device_config_scroll_has_natural_scroll(libinput_device)) {
|
||||
int natural_scroll =
|
||||
libinput_device_config_scroll_get_default_natural_scroll_enabled(
|
||||
libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) natural_scroll_set_enabled(%d)",
|
||||
input_device->identifier, natural_scroll);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_scroll_set_natural_scroll_enabled(
|
||||
libinput_device, natural_scroll));
|
||||
}
|
||||
|
||||
if (libinput_device_config_left_handed_is_available(libinput_device)) {
|
||||
int left_handed =
|
||||
libinput_device_config_left_handed_get_default(libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) left_handed_set_enabled(%d)",
|
||||
input_device->identifier, left_handed);
|
||||
log_libinput_config_status(libinput_device_config_left_handed_set(
|
||||
libinput_device, left_handed));
|
||||
}
|
||||
|
||||
uint32_t click = libinput_device_config_click_get_methods(libinput_device);
|
||||
if ((click & ~LIBINPUT_CONFIG_CLICK_METHOD_NONE) != 0) {
|
||||
enum libinput_config_click_method click_method =
|
||||
libinput_device_config_click_get_default_method(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) click_set_method(%d)",
|
||||
input_device->identifier, click_method);
|
||||
log_libinput_config_status(libinput_device_config_click_set_method(
|
||||
libinput_device, click_method));
|
||||
}
|
||||
|
||||
if (libinput_device_config_middle_emulation_is_available(libinput_device)) {
|
||||
enum libinput_config_middle_emulation_state middle_emulation =
|
||||
libinput_device_config_middle_emulation_get_default_enabled(
|
||||
libinput_device);
|
||||
sway_log(SWAY_DEBUG,
|
||||
"libinput_reset_pointer(%s) middle_emulation_set_enabled(%d)",
|
||||
input_device->identifier, middle_emulation);
|
||||
log_libinput_config_status(
|
||||
libinput_device_config_middle_emulation_set_enabled(
|
||||
libinput_device, middle_emulation));
|
||||
}
|
||||
|
||||
uint32_t scroll = libinput_device_config_scroll_get_methods(libinput_device);
|
||||
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) != 0) {
|
||||
enum libinput_config_scroll_method scroll_method =
|
||||
libinput_device_config_scroll_get_default_method(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) scroll_set_method(%d)",
|
||||
input_device->identifier, scroll_method);
|
||||
log_libinput_config_status(libinput_device_config_scroll_set_method(
|
||||
libinput_device, scroll_method));
|
||||
|
||||
uint32_t scroll_button =
|
||||
libinput_device_config_scroll_get_default_button(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) scroll_set_button(%d)",
|
||||
input_device->identifier, scroll_button);
|
||||
log_libinput_config_status(libinput_device_config_scroll_set_button(
|
||||
libinput_device, scroll_button));
|
||||
}
|
||||
|
||||
if (libinput_device_config_dwt_is_available(libinput_device)) {
|
||||
enum libinput_config_dwt_state dwt =
|
||||
libinput_device_config_dwt_get_default_enabled(libinput_device);
|
||||
sway_log(SWAY_DEBUG, "libinput_reset_pointer(%s) dwt_set_enabled(%d)",
|
||||
input_device->identifier, dwt);
|
||||
log_libinput_config_status(libinput_device_config_dwt_set_enabled(
|
||||
libinput_device, dwt));
|
||||
}
|
||||
}
|
||||
|
||||
static void handle_device_destroy(struct wl_listener *listener, void *data) {
|
||||
struct wlr_input_device *device = data;
|
||||
|
||||
@ -614,16 +217,7 @@ static void handle_new_input(struct wl_listener *listener, void *data) {
|
||||
|
||||
apply_input_type_config(input_device);
|
||||
|
||||
if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
input_manager_libinput_config_pointer(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
|
||||
input_manager_libinput_config_keyboard(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
|
||||
input_manager_libinput_config_switch(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
input_manager_libinput_config_touch(input_device);
|
||||
}
|
||||
sway_input_configure_libinput_device(input_device);
|
||||
|
||||
wl_signal_add(&device->events.destroy, &input_device->device_destroy);
|
||||
input_device->device_destroy.notify = handle_device_destroy;
|
||||
@ -775,17 +369,7 @@ void input_manager_apply_input_config(struct input_config *input_config) {
|
||||
if (strcmp(input_device->identifier, input_config->identifier) == 0
|
||||
|| wildcard
|
||||
|| type_matches) {
|
||||
if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
input_manager_libinput_config_pointer(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
|
||||
input_manager_libinput_config_keyboard(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
|
||||
input_manager_libinput_config_switch(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
input_manager_libinput_config_touch(input_device);
|
||||
}
|
||||
|
||||
sway_input_configure_libinput_device(input_device);
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_configure_device(seat, input_device);
|
||||
@ -795,17 +379,7 @@ void input_manager_apply_input_config(struct input_config *input_config) {
|
||||
}
|
||||
|
||||
void input_manager_reset_input(struct sway_input_device *input_device) {
|
||||
if (input_device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
input_device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
input_manager_libinput_reset_pointer(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
|
||||
input_manager_libinput_reset_keyboard(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
|
||||
input_manager_libinput_reset_switch(input_device);
|
||||
} else if (input_device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
input_manager_libinput_reset_touch(input_device);
|
||||
}
|
||||
|
||||
sway_input_reset_libinput_device(input_device);
|
||||
struct sway_seat *seat = NULL;
|
||||
wl_list_for_each(seat, &server.input->seats, link) {
|
||||
seat_reset_device(seat, input_device);
|
||||
|
382
sway/input/libinput.c
Normal file
382
sway/input/libinput.c
Normal file
@ -0,0 +1,382 @@
|
||||
#include <float.h>
|
||||
#include <libinput.h>
|
||||
#include <limits.h>
|
||||
#include <wlr/backend/libinput.h>
|
||||
#include "log.h"
|
||||
#include "sway/config.h"
|
||||
#include "sway/input/input-manager.h"
|
||||
#include "sway/ipc-server.h"
|
||||
|
||||
static void log_status(enum libinput_config_status status) {
|
||||
if (status != LIBINPUT_CONFIG_STATUS_SUCCESS) {
|
||||
sway_log(SWAY_ERROR, "Failed to apply libinput config: %s",
|
||||
libinput_config_status_to_str(status));
|
||||
}
|
||||
}
|
||||
|
||||
static bool set_send_events(struct libinput_device *device, uint32_t mode) {
|
||||
if ((libinput_device_config_send_events_get_mode(device) & mode) == 0) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "send_events_set_mode(%d)", mode);
|
||||
log_status(libinput_device_config_send_events_set_mode(device, mode));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_tap(struct libinput_device *device,
|
||||
enum libinput_config_tap_state tap) {
|
||||
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
|
||||
libinput_device_config_tap_get_enabled(device) == tap) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "tap_set_enabled(%d)", tap);
|
||||
log_status(libinput_device_config_tap_set_enabled(device, tap));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_tap_button_map(struct libinput_device *device,
|
||||
enum libinput_config_tap_button_map map) {
|
||||
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
|
||||
libinput_device_config_tap_get_button_map(device) == map) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "tap_set_button_map(%d)", map);
|
||||
log_status(libinput_device_config_tap_set_button_map(device, map));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_tap_drag(struct libinput_device *device,
|
||||
enum libinput_config_drag_state drag) {
|
||||
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
|
||||
libinput_device_config_tap_get_drag_enabled(device) == drag) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "tap_set_drag_enabled(%d)", drag);
|
||||
log_status(libinput_device_config_tap_set_drag_enabled(device, drag));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_tap_drag_lock(struct libinput_device *device,
|
||||
enum libinput_config_drag_lock_state lock) {
|
||||
if (libinput_device_config_tap_get_finger_count(device) <= 0 ||
|
||||
libinput_device_config_tap_get_drag_lock_enabled(device) == lock) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "tap_set_drag_lock_enabled(%d)", lock);
|
||||
log_status(libinput_device_config_tap_set_drag_lock_enabled(device, lock));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_accel_speed(struct libinput_device *device, double speed) {
|
||||
if (!libinput_device_config_accel_is_available(device) ||
|
||||
libinput_device_config_accel_get_speed(device) == speed) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "accel_set_speed(%f)", speed);
|
||||
log_status(libinput_device_config_accel_set_speed(device, speed));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_accel_profile(struct libinput_device *device,
|
||||
enum libinput_config_accel_profile profile) {
|
||||
if (!libinput_device_config_accel_is_available(device) ||
|
||||
libinput_device_config_accel_get_profile(device) == profile) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "accel_set_profile(%d)", profile);
|
||||
log_status(libinput_device_config_accel_set_profile(device, profile));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_natural_scroll(struct libinput_device *d, bool n) {
|
||||
if (!libinput_device_config_scroll_has_natural_scroll(d) ||
|
||||
libinput_device_config_scroll_get_natural_scroll_enabled(d) == n) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "scroll_set_natural_scroll(%d)", n);
|
||||
log_status(libinput_device_config_scroll_set_natural_scroll_enabled(d, n));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_left_handed(struct libinput_device *device, bool left) {
|
||||
if (!libinput_device_config_left_handed_is_available(device) ||
|
||||
libinput_device_config_left_handed_get(device) == left) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "left_handed_set(%d)", left);
|
||||
log_status(libinput_device_config_left_handed_set(device, left));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_click_method(struct libinput_device *device,
|
||||
enum libinput_config_click_method method) {
|
||||
uint32_t click = libinput_device_config_click_get_methods(device);
|
||||
if ((click & ~LIBINPUT_CONFIG_CLICK_METHOD_NONE) == 0 ||
|
||||
libinput_device_config_click_get_method(device) == method) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "click_set_method(%d)", method);
|
||||
log_status(libinput_device_config_click_set_method(device, method));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_middle_emulation(struct libinput_device *dev,
|
||||
enum libinput_config_middle_emulation_state mid) {
|
||||
if (!libinput_device_config_middle_emulation_is_available(dev) ||
|
||||
libinput_device_config_middle_emulation_get_enabled(dev) == mid) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "middle_emulation_set_enabled(%d)", mid);
|
||||
log_status(libinput_device_config_left_handed_set(dev, mid));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_scroll_method(struct libinput_device *device,
|
||||
enum libinput_config_scroll_method method) {
|
||||
uint32_t scroll = libinput_device_config_scroll_get_methods(device);
|
||||
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
|
||||
libinput_device_config_scroll_get_method(device) == method) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "scroll_set_method(%d)", method);
|
||||
log_status(libinput_device_config_scroll_set_method(device, method));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_scroll_button(struct libinput_device *dev, uint32_t button) {
|
||||
uint32_t scroll = libinput_device_config_scroll_get_methods(dev);
|
||||
if ((scroll & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) == 0 ||
|
||||
libinput_device_config_scroll_get_button(dev) == button) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "scroll_set_button(%d)", button);
|
||||
log_status(libinput_device_config_scroll_set_button(dev, button));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_dwt(struct libinput_device *device, bool dwt) {
|
||||
if (!libinput_device_config_dwt_is_available(device) ||
|
||||
libinput_device_config_dwt_get_enabled(device) == dwt) {
|
||||
return false;
|
||||
}
|
||||
sway_log(SWAY_DEBUG, "dwt_set_enabled(%d)", dwt);
|
||||
log_status(libinput_device_config_dwt_set_enabled(device, dwt));
|
||||
return true;
|
||||
}
|
||||
|
||||
static bool set_calibration_matrix(struct libinput_device *dev, float mat[6]) {
|
||||
if (!libinput_device_config_calibration_has_matrix(dev)) {
|
||||
return false;
|
||||
}
|
||||
bool changed = false;
|
||||
float current[6];
|
||||
libinput_device_config_calibration_get_matrix(dev, current);
|
||||
for (int i = 0; i < 6; i++) {
|
||||
if (current[i] != mat[i]) {
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (changed) {
|
||||
sway_log(SWAY_DEBUG, "calibration_set_matrix(%f, %f, %f, %f, %f, %f)",
|
||||
mat[0], mat[1], mat[2], mat[3], mat[4], mat[5]);
|
||||
log_status(libinput_device_config_calibration_set_matrix(dev, mat));
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
static bool config_libinput_pointer(struct libinput_device *device,
|
||||
struct input_config *ic, const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "config_libinput_pointer('%s' on '%s')",
|
||||
ic->identifier, device_id);
|
||||
bool changed = false;
|
||||
if (ic->send_events != INT_MIN) {
|
||||
changed |= set_send_events(device, ic->send_events);
|
||||
}
|
||||
if (ic->tap != INT_MIN) {
|
||||
changed |= set_tap(device, ic->tap);
|
||||
}
|
||||
if (ic->tap_button_map != INT_MIN) {
|
||||
changed |= set_tap_button_map(device, ic->tap_button_map);
|
||||
}
|
||||
if (ic->drag != INT_MIN) {
|
||||
changed |= set_tap_drag(device, ic->drag);
|
||||
}
|
||||
if (ic->drag_lock != INT_MIN) {
|
||||
changed |= set_tap_drag_lock(device, ic->drag_lock);
|
||||
}
|
||||
|
||||
if (ic->pointer_accel != FLT_MIN) {
|
||||
changed |= set_accel_speed(device, ic->pointer_accel);
|
||||
}
|
||||
if (ic->accel_profile != INT_MIN) {
|
||||
changed |= set_accel_profile(device, ic->accel_profile);
|
||||
}
|
||||
if (ic->natural_scroll != INT_MIN) {
|
||||
changed |= set_natural_scroll(device, ic->natural_scroll);
|
||||
}
|
||||
if (ic->left_handed != INT_MIN) {
|
||||
changed |= set_left_handed(device, ic->left_handed);
|
||||
}
|
||||
if (ic->click_method != INT_MIN) {
|
||||
changed |= set_click_method(device, ic->click_method);
|
||||
}
|
||||
if (ic->middle_emulation != INT_MIN) {
|
||||
changed |= set_middle_emulation(device, ic->middle_emulation);
|
||||
}
|
||||
if (ic->scroll_method != INT_MIN) {
|
||||
changed |= set_scroll_method(device, ic->scroll_method);
|
||||
}
|
||||
if (ic->scroll_button != INT_MIN) {
|
||||
changed |= set_scroll_button(device, ic->scroll_button);
|
||||
}
|
||||
if (ic->dwt != INT_MIN) {
|
||||
changed |= set_dwt(device, ic->dwt);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
static bool config_libinput_keyboard(struct libinput_device *device,
|
||||
struct input_config *ic, const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "config_libinput_keyboard('%s' on '%s')",
|
||||
ic->identifier, device_id);
|
||||
if (ic->send_events != INT_MIN) {
|
||||
return set_send_events(device, ic->send_events);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool config_libinput_switch(struct libinput_device *device,
|
||||
struct input_config *ic, const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "config_libinput_switch('%s' on '%s')",
|
||||
ic->identifier, device_id);
|
||||
if (ic->send_events != INT_MIN) {
|
||||
return set_send_events(device, ic->send_events);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool config_libinput_touch(struct libinput_device *device,
|
||||
struct input_config *ic, const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "config_libinput_touch('%s' on '%s')",
|
||||
ic->identifier, device_id);
|
||||
bool changed = false;
|
||||
if (ic->send_events != INT_MIN) {
|
||||
changed |= set_send_events(device, ic->send_events);
|
||||
}
|
||||
if (ic->calibration_matrix.configured) {
|
||||
changed |= set_calibration_matrix(device, ic->calibration_matrix.matrix);
|
||||
}
|
||||
return changed;
|
||||
}
|
||||
|
||||
void sway_input_configure_libinput_device(struct sway_input_device *device) {
|
||||
struct input_config *ic = input_device_get_config(device);
|
||||
if (!ic || !wlr_input_device_is_libinput(device->wlr_device)) {
|
||||
return;
|
||||
}
|
||||
bool changed = false;
|
||||
const char *device_id = device->identifier;
|
||||
struct libinput_device *libinput_device =
|
||||
wlr_libinput_get_device_handle(device->wlr_device);
|
||||
if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
changed = config_libinput_pointer(libinput_device, ic, device_id);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
|
||||
changed = config_libinput_keyboard(libinput_device, ic, device_id);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
|
||||
changed = config_libinput_switch(libinput_device, ic, device_id);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
changed = config_libinput_touch(libinput_device, ic, device_id);
|
||||
}
|
||||
if (changed) {
|
||||
ipc_event_input("libinput_config", device);
|
||||
}
|
||||
}
|
||||
|
||||
static bool reset_libinput_pointer(struct libinput_device *device,
|
||||
const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "reset_libinput_pointer(%s)", device_id);
|
||||
bool changed = false;
|
||||
changed |= set_send_events(device,
|
||||
libinput_device_config_send_events_get_default_mode(device));
|
||||
changed |= set_tap(device,
|
||||
libinput_device_config_tap_get_default_enabled(device));
|
||||
changed |= set_tap_button_map(device,
|
||||
libinput_device_config_tap_get_button_map(device));
|
||||
changed |= set_tap_drag(device,
|
||||
libinput_device_config_tap_get_default_drag_enabled(device));
|
||||
changed |= set_tap_drag_lock(device,
|
||||
libinput_device_config_tap_get_default_drag_lock_enabled(device));
|
||||
changed |= set_accel_speed(device,
|
||||
libinput_device_config_accel_get_default_speed(device));
|
||||
changed |= set_accel_profile(device,
|
||||
libinput_device_config_accel_get_default_profile(device));
|
||||
changed |= set_natural_scroll(device,
|
||||
libinput_device_config_scroll_get_default_natural_scroll_enabled(
|
||||
device));
|
||||
changed |= set_left_handed(device,
|
||||
libinput_device_config_left_handed_get_default(device));
|
||||
changed |= set_click_method(device,
|
||||
libinput_device_config_click_get_default_method(device));
|
||||
changed |= set_middle_emulation(device,
|
||||
libinput_device_config_middle_emulation_get_default_enabled(device));
|
||||
changed |= set_scroll_method(device,
|
||||
libinput_device_config_scroll_get_default_method(device));
|
||||
changed |= set_scroll_button(device,
|
||||
libinput_device_config_scroll_get_default_button(device));
|
||||
changed |= set_dwt(device,
|
||||
libinput_device_config_dwt_get_default_enabled(device));
|
||||
return changed;
|
||||
}
|
||||
|
||||
static bool reset_libinput_keyboard(struct libinput_device *device,
|
||||
const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "reset_libinput_keyboard(%s)", device_id);
|
||||
return set_send_events(device,
|
||||
libinput_device_config_send_events_get_default_mode(device));
|
||||
}
|
||||
|
||||
static bool reset_libinput_switch(struct libinput_device *device,
|
||||
const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "reset_libinput_switch(%s)", device_id);
|
||||
return set_send_events(device,
|
||||
libinput_device_config_send_events_get_default_mode(device));
|
||||
}
|
||||
|
||||
static bool reset_libinput_touch(struct libinput_device *device,
|
||||
const char *device_id) {
|
||||
sway_log(SWAY_DEBUG, "reset_libinput_touch(%s)", device_id);
|
||||
bool changed = false;
|
||||
|
||||
changed |= set_send_events(device,
|
||||
libinput_device_config_send_events_get_default_mode(device));
|
||||
|
||||
float matrix[6];
|
||||
libinput_device_config_calibration_get_matrix(device, matrix);
|
||||
changed |= set_calibration_matrix(device, matrix);
|
||||
|
||||
return changed;
|
||||
}
|
||||
|
||||
void sway_input_reset_libinput_device(struct sway_input_device *device) {
|
||||
if (!wlr_input_device_is_libinput(device->wlr_device)) {
|
||||
return;
|
||||
}
|
||||
bool changed = false;
|
||||
struct libinput_device *libinput_device =
|
||||
wlr_libinput_get_device_handle(device->wlr_device);
|
||||
if (device->wlr_device->type == WLR_INPUT_DEVICE_POINTER ||
|
||||
device->wlr_device->type == WLR_INPUT_DEVICE_TABLET_TOOL) {
|
||||
changed = reset_libinput_pointer(libinput_device, device->identifier);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_KEYBOARD) {
|
||||
changed = reset_libinput_keyboard(libinput_device, device->identifier);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_SWITCH) {
|
||||
changed = reset_libinput_switch(libinput_device, device->identifier);
|
||||
} else if (device->wlr_device->type == WLR_INPUT_DEVICE_TOUCH) {
|
||||
changed = reset_libinput_touch(libinput_device, device->identifier);
|
||||
}
|
||||
if (changed) {
|
||||
ipc_event_input("libinput_config", device);
|
||||
}
|
||||
}
|
@ -21,6 +21,9 @@ sway_sources = files(
|
||||
'desktop/xdg_shell.c',
|
||||
|
||||
'input/input-manager.c',
|
||||
'input/cursor.c',
|
||||
'input/keyboard.c',
|
||||
'input/libinput.c',
|
||||
'input/seat.c',
|
||||
'input/seatop_default.c',
|
||||
'input/seatop_down.c',
|
||||
@ -28,8 +31,6 @@ sway_sources = files(
|
||||
'input/seatop_move_tiling.c',
|
||||
'input/seatop_resize_floating.c',
|
||||
'input/seatop_resize_tiling.c',
|
||||
'input/cursor.c',
|
||||
'input/keyboard.c',
|
||||
'input/switch.c',
|
||||
|
||||
'config/bar.c',
|
||||
|
@ -1731,6 +1731,8 @@ The following change types are currently available:
|
||||
: (Keyboards only) The keymap for the keyboard has changed
|
||||
|- xkb_layout
|
||||
: (Keyboards only) The effective layout in the keymap has changed
|
||||
|- libinput_config
|
||||
: (libinput device only) A libinput config option for the device changed
|
||||
|
||||
*Example Event:*
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user