From 7f700e08ac8ac95c395b54c86b40d2fc79242310 Mon Sep 17 00:00:00 2001 From: Brian Ashworth Date: Thu, 7 Mar 2019 03:37:49 -0500 Subject: ipc: describe libinput device configuration This adds the device configurations to the ipc response for libinput devices. Only supported configuration options for the device will be added. This also moves `libinput_send_events` inside a new `libinput` object that contains the rest of the configuration options. sway-ipc(7) has been updated to reflect the changes and document the new additions. --- sway/ipc-json.c | 198 +++++++++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 183 insertions(+), 15 deletions(-) (limited to 'sway/ipc-json.c') diff --git a/sway/ipc-json.c b/sway/ipc-json.c index 20dcafb1..e9564b04 100644 --- a/sway/ipc-json.c +++ b/sway/ipc-json.c @@ -617,6 +617,187 @@ json_object *ipc_json_describe_node_recursive(struct sway_node *node) { return object; } +static json_object *describe_libinput_device(struct libinput_device *device) { + json_object *object = json_object_new_object(); + + const char *events = "unknown"; + switch (libinput_device_config_send_events_get_mode(device)) { + case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: + events = "enabled"; + break; + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: + events = "disabled_on_external_mouse"; + break; + case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: + events = "disabled"; + break; + } + json_object_object_add(object, "send_events", + json_object_new_string(events)); + + if (libinput_device_config_tap_get_finger_count(device) > 0) { + const char *tap = "unknown"; + switch (libinput_device_config_tap_get_enabled(device)) { + case LIBINPUT_CONFIG_TAP_ENABLED: + tap = "enabled"; + break; + case LIBINPUT_CONFIG_TAP_DISABLED: + tap = "disabled"; + break; + } + json_object_object_add(object, "tap", json_object_new_string(tap)); + + const char *button_map = "unknown"; + switch (libinput_device_config_tap_get_button_map(device)) { + case LIBINPUT_CONFIG_TAP_MAP_LRM: + button_map = "lrm"; + break; + case LIBINPUT_CONFIG_TAP_MAP_LMR: + button_map = "lmr"; + break; + } + json_object_object_add(object, "tap_button_map", + json_object_new_string(button_map)); + + const char* drag = "unknown"; + switch (libinput_device_config_tap_get_drag_enabled(device)) { + case LIBINPUT_CONFIG_DRAG_ENABLED: + drag = "enabled"; + break; + case LIBINPUT_CONFIG_DRAG_DISABLED: + drag = "disabled"; + break; + } + json_object_object_add(object, "tap_drag", + json_object_new_string(drag)); + + const char *drag_lock = "unknown"; + switch (libinput_device_config_tap_get_drag_lock_enabled(device)) { + case LIBINPUT_CONFIG_DRAG_LOCK_ENABLED: + drag_lock = "enabled"; + break; + case LIBINPUT_CONFIG_DRAG_LOCK_DISABLED: + drag_lock = "disabled"; + break; + } + json_object_object_add(object, "tap_drag_lock", + json_object_new_string(drag_lock)); + } + + if (libinput_device_config_accel_is_available(device)) { + double accel = libinput_device_config_accel_get_speed(device); + json_object_object_add(object, "accel_speed", + json_object_new_double(accel)); + + const char *accel_profile = "unknown"; + switch (libinput_device_config_accel_get_profile(device)) { + case LIBINPUT_CONFIG_ACCEL_PROFILE_NONE: + accel_profile = "none"; + break; + case LIBINPUT_CONFIG_ACCEL_PROFILE_FLAT: + accel_profile = "flat"; + break; + case LIBINPUT_CONFIG_ACCEL_PROFILE_ADAPTIVE: + accel_profile = "adaptive"; + break; + } + json_object_object_add(object, "accel_profile", + json_object_new_string(accel_profile)); + } + + if (libinput_device_config_scroll_has_natural_scroll(device)) { + const char *natural_scroll = "disabled"; + if (libinput_device_config_scroll_get_natural_scroll_enabled(device)) { + natural_scroll = "enabled"; + } + json_object_object_add(object, "natural_scroll", + json_object_new_string(natural_scroll)); + } + + if (libinput_device_config_left_handed_is_available(device)) { + const char *left_handed = "disabled"; + if (libinput_device_config_left_handed_get(device) != 0) { + left_handed = "enabled"; + } + json_object_object_add(object, "left_handed", + json_object_new_string(left_handed)); + } + + uint32_t click_methods = libinput_device_config_click_get_methods(device); + if ((click_methods & ~LIBINPUT_CONFIG_CLICK_METHOD_NONE) != 0) { + const char *click_method = "unknown"; + switch (libinput_device_config_click_get_method(device)) { + case LIBINPUT_CONFIG_CLICK_METHOD_NONE: + click_method = "none"; + break; + case LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS: + click_method = "button_areas"; + break; + case LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER: + click_method = "clickfinger"; + break; + } + json_object_object_add(object, "click_method", + json_object_new_string(click_method)); + } + + if (libinput_device_config_middle_emulation_is_available(device)) { + const char *middle_emulation = "unknown"; + switch (libinput_device_config_middle_emulation_get_enabled(device)) { + case LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED: + middle_emulation = "enabled"; + break; + case LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED: + middle_emulation = "disabled"; + break; + } + json_object_object_add(object, "middle_emulation", + json_object_new_string(middle_emulation)); + } + + uint32_t scroll_methods = libinput_device_config_scroll_get_methods(device); + if ((scroll_methods & ~LIBINPUT_CONFIG_SCROLL_NO_SCROLL) != 0) { + const char *scroll_method = "unknown"; + switch (libinput_device_config_scroll_get_method(device)) { + case LIBINPUT_CONFIG_SCROLL_NO_SCROLL: + scroll_method = "none"; + break; + case LIBINPUT_CONFIG_SCROLL_2FG: + scroll_method = "two_finger"; + break; + case LIBINPUT_CONFIG_SCROLL_EDGE: + scroll_method = "edge"; + break; + case LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN: + scroll_method = "on_button_down"; + break; + } + json_object_object_add(object, "scroll_method", + json_object_new_string(scroll_method)); + + if ((scroll_methods & LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN) != 0) { + uint32_t button = libinput_device_config_scroll_get_button(device); + json_object_object_add(object, "scroll_button", + json_object_new_int(button)); + } + } + + if (libinput_device_config_dwt_is_available(device)) { + const char *dwt = "unknown"; + switch (libinput_device_config_dwt_get_enabled(device)) { + case LIBINPUT_CONFIG_DWT_ENABLED: + dwt = "enabled"; + break; + case LIBINPUT_CONFIG_DWT_DISABLED: + dwt = "disabled"; + break; + } + json_object_object_add(object, "dwt", json_object_new_string(dwt)); + } + + return object; +} + json_object *ipc_json_describe_input(struct sway_input_device *device) { if (!(sway_assert(device, "Device must not be null"))) { return NULL; @@ -660,21 +841,8 @@ json_object *ipc_json_describe_input(struct sway_input_device *device) { if (wlr_input_device_is_libinput(device->wlr_device)) { struct libinput_device *libinput_dev; libinput_dev = wlr_libinput_get_device_handle(device->wlr_device); - - const char *events = "unknown"; - switch (libinput_device_config_send_events_get_mode(libinput_dev)) { - case LIBINPUT_CONFIG_SEND_EVENTS_ENABLED: - events = "enabled"; - break; - case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE: - events = "disabled_on_external_mouse"; - break; - case LIBINPUT_CONFIG_SEND_EVENTS_DISABLED: - events = "disabled"; - break; - } - json_object_object_add(object, "libinput_send_events", - json_object_new_string(events)); + json_object_object_add(object, "libinput", + describe_libinput_device(libinput_dev)); } return object; -- cgit v1.2.3-54-g00ecf