Skip to content

Commit

Permalink
Support additional libinput config options (#91)
Browse files Browse the repository at this point in the history
Adds the possibility to configure disabling the input device while typing and
allows for choosing the click method, both of which are useful for touchpads.
  • Loading branch information
flaviozavan authored Sep 25, 2021
1 parent d546af6 commit e861fe1
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 2 deletions.
5 changes: 5 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,9 @@ command = "amixer -q sset Master 3%+"
# - left-handed : If true, switch left and right buttons. Defaults to false.
# - natural-scroll : If true, switch the scrolling direction from default style (scroll down => go down)
# to so-called "natural" style (scroll down => go up). Defaults to false.
# - disable-while-typing : If true, disables the device while typing. Defaults to false
# - click-method : Method for determining which button is being clicked.
# One of "none", "areas" or "fingers". Defaults to "none"

[[libinput-config]]
# Example libinput-config for a popular trackball:
Expand All @@ -241,6 +244,8 @@ scroll-button = 8
middle-emulation = true
left-handed = false
natural-scroll = false
disable-while-typing = false
click-method = "none"

### DEBUG ###
# Vivarium debug options included for completion. You will want to leave these with their
Expand Down
4 changes: 4 additions & 0 deletions config/viv_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ struct viv_libinput_config the_libinput_configs[] = {
.left_handed = 0,
// Invert scroll direction
.natural_scroll = 0,
// Disable while typing (usually touchpad only)
.disable_while_typing = LIBINPUT_CONFIG_DWT_DISABLED,
// Method used for registering the type of click (usually touchpad only)
.click_method = LIBINPUT_CONFIG_CLICK_METHOD_NONE,
},
TERMINATE_LIBINPUT_CONFIG_LIST(),
};
Expand Down
2 changes: 2 additions & 0 deletions include/viv_config_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ struct viv_libinput_config {
enum libinput_config_middle_emulation_state middle_emulation;
int left_handed;
int natural_scroll;
enum libinput_config_dwt_state disable_while_typing;
enum libinput_config_click_method click_method;
};

#endif
2 changes: 2 additions & 0 deletions src/viv_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ static void configure_libinput_device(struct libinput_device *device, struct viv
libinput_device_config_middle_emulation_set_enabled(device, config->middle_emulation);
libinput_device_config_left_handed_set(device, config->left_handed);
libinput_device_config_scroll_set_natural_scroll_enabled(device, config->natural_scroll);
libinput_device_config_dwt_set_enabled(device, config->disable_while_typing);
libinput_device_config_click_set_method(device, config->click_method);
}

static void try_configure_libinput_device(struct wlr_input_device *device, struct viv_libinput_config *libinput_configs) {
Expand Down
29 changes: 27 additions & 2 deletions src/viv_toml_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ static struct string_map_pair scroll_method_map[] = {
NULL_STRING_MAP_PAIR,
};

static struct string_map_pair click_method_map[] = {
{"none", LIBINPUT_CONFIG_CLICK_METHOD_NONE},
{"areas", LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS},
{"fingers", LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER},
NULL_STRING_MAP_PAIR,
};

static struct string_map_pair damage_tracking_mode_map[] = {
{"none", VIV_DAMAGE_TRACKING_NONE},
{"frame", VIV_DAMAGE_TRACKING_FRAME},
Expand Down Expand Up @@ -469,9 +476,27 @@ static void parse_libinput_config_table(toml_table_t *libinput_table, struct viv
libinput_config->natural_scroll = (uint32_t)natural_scroll.u.i;
}

wlr_log(WLR_DEBUG, "Parsed [[libinput-config]] for device \"%s\", scroll method %d, scroll button %d, middle emulation %d, left handed %d, natural scroll %d",
toml_datum_t disable_while_typing = toml_bool_in(libinput_table, "disable-while-typing");
if (disable_while_typing.ok) {
libinput_config->disable_while_typing = disable_while_typing.u.i ? LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED;
}

toml_datum_t click_method = toml_string_in(libinput_table, "click-method");
if (click_method.ok) {
enum libinput_config_click_method click_method_enum;
bool success = look_up_string_in_map(click_method.u.s, click_method_map, &click_method_enum);
if (!success) {
EXIT_WITH_FORMATTED_MESSAGE("Error parsing [[libinput-config]] for device \"%s\": click-method \"%s\" not recognised",
device_name.u.s, click_method.u.s);
} else {
libinput_config->click_method = click_method_enum;
}
free(click_method.u.s);
}

wlr_log(WLR_DEBUG, "Parsed [[libinput-config]] for device \"%s\", scroll method %d, scroll button %d, middle emulation %d, left handed %d, natural scroll %d, disable while typing %d, click method %d",
device_name.u.s, libinput_config->scroll_method, libinput_config->scroll_button,
libinput_config->middle_emulation, libinput_config->left_handed, libinput_config->natural_scroll);
libinput_config->middle_emulation, libinput_config->left_handed, libinput_config->natural_scroll, libinput_config->disable_while_typing, libinput_config->click_method);

libinput_config->device_name = device_name.u.s;
}
Expand Down
2 changes: 2 additions & 0 deletions tests/test_config.c
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ void test_config_toml_libinput_configs_match_defaults(void) {
TEST_ASSERT_EQUAL(default_li_config.middle_emulation, load_li_config.middle_emulation);
TEST_ASSERT_EQUAL(default_li_config.left_handed, load_li_config.left_handed);
TEST_ASSERT_EQUAL(default_li_config.natural_scroll, load_li_config.natural_scroll);
TEST_ASSERT_EQUAL(default_li_config.disable_while_typing, load_li_config.disable_while_typing);
TEST_ASSERT_EQUAL(default_li_config.click_method, load_li_config.click_method);

if (strlen(default_li_config.device_name) == 0) {
break;
Expand Down

0 comments on commit e861fe1

Please sign in to comment.