Skip to content

Commit

Permalink
input: Allow multiple keyboards and mice to have different configurat…
Browse files Browse the repository at this point in the history
…ions

This patch checks for additional configuration sections so keyboards and
mice can be matched by name or with udev properties. Running wayfire with
'-d input-devices' will log the sections that are being checked, for reference.
This allows multiple keyboards and mice to be configured differently,
whereas before, all keyboards used the common configuration in the [input]
section. To be clear, no additional configuration is required. If no matching
configuration section is found for the device, [input] options will be used.
  • Loading branch information
soreau committed Dec 25, 2024
1 parent 5e54a7a commit d2a11a7
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 83 deletions.
2 changes: 1 addition & 1 deletion src/api/wayfire/config-backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class config_backend_t
* described in input-device.xml
*/
virtual std::shared_ptr<config::section_t> get_input_device_section(
wlr_input_device *device);
std::string const & prefix, wlr_input_device *device);

virtual ~config_backend_t() = default;

Expand Down
8 changes: 4 additions & 4 deletions src/core/plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static struct udev_property_and_desc
};

std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_section(
wlr_input_device *device)
std::string const & prefix, wlr_input_device *device)
{
auto& config = wf::get_core().config;
std::shared_ptr<wf::config::section_t> section;
Expand All @@ -65,7 +65,7 @@ std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_sectio
continue;
}

std::string name = std::string("input-device:") + nonull(value);
std::string name = prefix + ":" + nonull(value);
LOGC(INPUT_DEVICES, "Checking for config section [", name, "] ",
pd.property_name, " (", pd.description, ")");
section = config.get_section(name);
Expand All @@ -80,7 +80,7 @@ std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_sectio
}

std::string name = nonull(device->name);
name = "input-device:" + name;
name = prefix + ":" + name;
LOGC(INPUT_DEVICES, "Checking for config section [", name, "]");
section = config.get_section(name);
if (section)
Expand All @@ -90,7 +90,7 @@ std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_sectio
}

config.merge_section(
config.get_section("input-device")->clone_with_name(name));
config.get_section(prefix)->clone_with_name(name));

LOGC(INPUT_DEVICES, "Using config section [", name, "]");
return config.get_section(name);
Expand Down
4 changes: 1 addition & 3 deletions src/core/seat/input-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void wf::input_manager_t::configure_input_device(std::unique_ptr<wf::input_devic
auto dev = device->get_wlr_handle();
auto cursor = wf::get_core().get_wlr_cursor();
auto section =
wf::get_core().config_backend->get_input_device_section(dev);
wf::get_core().config_backend->get_input_device_section("input-device", dev);

auto mapped_output = section->get_option("output")->get_value_str();
if (mapped_output.empty())
Expand Down Expand Up @@ -152,8 +152,6 @@ void load_locked_mods_from_config(xkb_mod_mask_t& locked_mods)

wf::input_manager_t::input_manager_t()
{
wf::pointing_device_t::config.load();

load_locked_mods_from_config(locked_mods);

input_device_created.set_callback([&] (void *data)
Expand Down
20 changes: 12 additions & 8 deletions src/core/seat/keyboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,14 +121,18 @@ void wf::keyboard_t::setup_listeners()
wf::keyboard_t::keyboard_t(wlr_input_device *dev) :
handle(wlr_keyboard_from_input_device(dev)), device(dev)
{
model.load_option("input/xkb_model");
variant.load_option("input/xkb_variant");
layout.load_option("input/xkb_layout");
options.load_option("input/xkb_options");
rules.load_option("input/xkb_rules");

repeat_rate.load_option("input/kb_repeat_rate");
repeat_delay.load_option("input/kb_repeat_delay");
auto section =
wf::get_core().config_backend->get_input_device_section("input", dev);
auto section_name = section->get_name();

model.load_option(section_name + "/xkb_model");
variant.load_option(section_name + "/xkb_variant");
layout.load_option(section_name + "/xkb_layout");
options.load_option(section_name + "/xkb_options");
rules.load_option(section_name + "/xkb_rules");

repeat_rate.load_option(section_name + "/kb_repeat_rate");
repeat_delay.load_option(section_name + "/kb_repeat_delay");

// When the configuration options change, mark them as dirty.
// They are applied at the config-reloaded signal.
Expand Down
5 changes: 2 additions & 3 deletions src/core/seat/pointer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -355,9 +355,8 @@ void wf::pointer_t::handle_pointer_axis(wlr_pointer_axis_event *ev,
}

/* Calculate speed settings */
double mult = ev->source == WL_POINTER_AXIS_SOURCE_FINGER ?
wf::pointing_device_t::config.touchpad_scroll_speed :
wf::pointing_device_t::config.mouse_scroll_speed;
wf::pointing_device_t *pd = (wf::pointing_device_t*)ev->pointer->base.data;
double mult = pd->get_scroll_speed(&ev->pointer->base, ev->source == WL_POINTER_AXIS_SOURCE_FINGER);

ev->delta *= mult;
ev->delta_discrete *= mult;
Expand Down
102 changes: 59 additions & 43 deletions src/core/seat/pointing-device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,32 +3,37 @@
wf::pointing_device_t::pointing_device_t(wlr_input_device *dev) :
input_device_impl_t(dev)
{
dev->data = this;
load_options();
update_options();
}

wf::pointing_device_t::config_t wf::pointing_device_t::config;
void wf::pointing_device_t::config_t::load()
void wf::pointing_device_t::load_options()
{
left_handed_mode.load_option("input/left_handed_mode");
middle_emulation.load_option("input/middle_emulation");

mouse_scroll_speed.load_option("input/mouse_scroll_speed");
mouse_cursor_speed.load_option("input/mouse_cursor_speed");
touchpad_cursor_speed.load_option("input/touchpad_cursor_speed");
touchpad_scroll_speed.load_option("input/touchpad_scroll_speed");

mouse_natural_scroll_enabled.load_option("input/mouse_natural_scroll");
touchpad_tap_enabled.load_option("input/tap_to_click");
touchpad_dwt_enabled.load_option("input/disable_touchpad_while_typing");
touchpad_dwmouse_enabled.load_option("input/disable_touchpad_while_mouse");
touchpad_natural_scroll_enabled.load_option("input/natural_scroll");
touchpad_drag_lock_enabled.load_option("input/drag_lock");

mouse_accel_profile.load_option("input/mouse_accel_profile");
touchpad_accel_profile.load_option("input/touchpad_accel_profile");

touchpad_click_method.load_option("input/click_method");
touchpad_scroll_method.load_option("input/scroll_method");
auto section =
wf::get_core().config_backend->get_input_device_section("input", get_wlr_handle());
auto section_name = section->get_name();

left_handed_mode.load_option(section_name + "/left_handed_mode");
middle_emulation.load_option(section_name + "/middle_emulation");

mouse_scroll_speed.load_option(section_name + "/mouse_scroll_speed");
mouse_cursor_speed.load_option(section_name + "/mouse_cursor_speed");
touchpad_cursor_speed.load_option(section_name + "/touchpad_cursor_speed");
touchpad_scroll_speed.load_option(section_name + "/touchpad_scroll_speed");

mouse_natural_scroll_enabled.load_option(section_name + "/mouse_natural_scroll");
touchpad_tap_enabled.load_option(section_name + "/tap_to_click");
touchpad_dwt_enabled.load_option(section_name + "/disable_touchpad_while_typing");
touchpad_dwmouse_enabled.load_option(section_name + "/disable_touchpad_while_mouse");
touchpad_natural_scroll_enabled.load_option(section_name + "/natural_scroll");
touchpad_drag_lock_enabled.load_option(section_name + "/drag_lock");

mouse_accel_profile.load_option(section_name + "/mouse_accel_profile");
touchpad_accel_profile.load_option(section_name + "/touchpad_accel_profile");

touchpad_click_method.load_option(section_name + "/click_method");
touchpad_scroll_method.load_option(section_name + "/scroll_method");
}

static void set_libinput_accel_profile(libinput_device *dev, std::string name)
Expand Down Expand Up @@ -63,93 +68,104 @@ void wf::pointing_device_t::update_options()
auto dev = wlr_libinput_get_device_handle(get_wlr_handle());
assert(dev);

libinput_device_config_left_handed_set(dev, config.left_handed_mode);
libinput_device_config_left_handed_set(dev, left_handed_mode);

libinput_device_config_middle_emulation_set_enabled(dev,
config.middle_emulation ?
middle_emulation ?
LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);

/* we are configuring a touchpad */
if (libinput_device_config_tap_get_finger_count(dev) > 0)
{
libinput_device_config_accel_set_speed(dev,
config.touchpad_cursor_speed);
touchpad_cursor_speed);

set_libinput_accel_profile(dev, config.touchpad_accel_profile);
set_libinput_accel_profile(dev, touchpad_accel_profile);
libinput_device_config_tap_set_enabled(dev,
config.touchpad_tap_enabled ?
touchpad_tap_enabled ?
LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED);

if ((std::string)config.touchpad_click_method == "default")
if ((std::string)touchpad_click_method == "default")
{
libinput_device_config_click_set_method(dev,
libinput_device_config_click_get_default_method(dev));
} else if ((std::string)config.touchpad_click_method == "none")
} else if ((std::string)touchpad_click_method == "none")
{
libinput_device_config_click_set_method(dev,
LIBINPUT_CONFIG_CLICK_METHOD_NONE);
} else if ((std::string)config.touchpad_click_method == "button-areas")
} else if ((std::string)touchpad_click_method == "button-areas")
{
libinput_device_config_click_set_method(dev,
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
} else if ((std::string)config.touchpad_click_method == "clickfinger")
} else if ((std::string)touchpad_click_method == "clickfinger")
{
libinput_device_config_click_set_method(dev,
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
}

if ((std::string)config.touchpad_scroll_method == "default")
if ((std::string)touchpad_scroll_method == "default")
{
libinput_device_config_scroll_set_method(dev,
libinput_device_config_scroll_get_default_method(dev));
} else if ((std::string)config.touchpad_scroll_method == "none")
} else if ((std::string)touchpad_scroll_method == "none")
{
libinput_device_config_scroll_set_method(dev,
LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
} else if ((std::string)config.touchpad_scroll_method == "two-finger")
} else if ((std::string)touchpad_scroll_method == "two-finger")
{
libinput_device_config_scroll_set_method(dev,
LIBINPUT_CONFIG_SCROLL_2FG);
} else if ((std::string)config.touchpad_scroll_method == "edge")
} else if ((std::string)touchpad_scroll_method == "edge")
{
libinput_device_config_scroll_set_method(dev,
LIBINPUT_CONFIG_SCROLL_EDGE);
} else if ((std::string)config.touchpad_scroll_method == "on-button-down")
} else if ((std::string)touchpad_scroll_method == "on-button-down")
{
libinput_device_config_scroll_set_method(dev,
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
}

libinput_device_config_dwt_set_enabled(dev,
config.touchpad_dwt_enabled ?
touchpad_dwt_enabled ?
LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED);

libinput_device_config_send_events_set_mode(dev,
config.touchpad_dwmouse_enabled ?
touchpad_dwmouse_enabled ?
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE :
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);

libinput_device_config_tap_set_drag_lock_enabled(dev,
config.touchpad_drag_lock_enabled ?
touchpad_drag_lock_enabled ?
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED :
LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);

if (libinput_device_config_scroll_has_natural_scroll(dev) > 0)
{
libinput_device_config_scroll_set_natural_scroll_enabled(dev,
(bool)config.touchpad_natural_scroll_enabled);
(bool)touchpad_natural_scroll_enabled);
}
} else
{
libinput_device_config_accel_set_speed(dev,
config.mouse_cursor_speed);
set_libinput_accel_profile(dev, config.mouse_accel_profile);
mouse_cursor_speed);
set_libinput_accel_profile(dev, mouse_accel_profile);

if (libinput_device_config_scroll_has_natural_scroll(dev) > 0)
{
libinput_device_config_scroll_set_natural_scroll_enabled(dev,
(bool)config.mouse_natural_scroll_enabled);
(bool)mouse_natural_scroll_enabled);
}
}
}

double wf::pointing_device_t::get_scroll_speed(wlr_input_device *dev, bool touchpad)
{
if ((touchpad && (dev->type != WLR_INPUT_DEVICE_TABLET_PAD)) ||
(!touchpad && (dev->type != WLR_INPUT_DEVICE_POINTER)))
{
return 1.0;
}

return touchpad ? touchpad_scroll_speed : mouse_scroll_speed;
}
41 changes: 20 additions & 21 deletions src/core/seat/pointing-device.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,28 @@ struct pointing_device_t : public input_device_impl_t
pointing_device_t(wlr_input_device *dev);
virtual ~pointing_device_t() = default;

void load_options();
void update_options() override;

static struct config_t
{
wf::option_wrapper_t<bool> left_handed_mode;
wf::option_wrapper_t<bool> middle_emulation;
wf::option_wrapper_t<double> mouse_cursor_speed;
wf::option_wrapper_t<double> mouse_scroll_speed;
wf::option_wrapper_t<std::string> tablet_motion_mode;
wf::option_wrapper_t<double> touchpad_cursor_speed;
wf::option_wrapper_t<double> touchpad_scroll_speed;
wf::option_wrapper_t<std::string> touchpad_click_method;
wf::option_wrapper_t<std::string> touchpad_scroll_method;
wf::option_wrapper_t<std::string> touchpad_accel_profile;
wf::option_wrapper_t<std::string> mouse_accel_profile;
wf::option_wrapper_t<bool> touchpad_tap_enabled;
wf::option_wrapper_t<bool> touchpad_dwt_enabled;
wf::option_wrapper_t<bool> touchpad_dwmouse_enabled;
wf::option_wrapper_t<bool> touchpad_natural_scroll_enabled;
wf::option_wrapper_t<bool> mouse_natural_scroll_enabled;
wf::option_wrapper_t<bool> touchpad_drag_lock_enabled;
void load();
} config;
double get_scroll_speed(wlr_input_device *dev, bool touchpad);

wf::option_wrapper_t<bool> left_handed_mode;
wf::option_wrapper_t<bool> middle_emulation;
wf::option_wrapper_t<double> mouse_cursor_speed;
wf::option_wrapper_t<double> mouse_scroll_speed;
wf::option_wrapper_t<std::string> tablet_motion_mode;
wf::option_wrapper_t<double> touchpad_cursor_speed;
wf::option_wrapper_t<double> touchpad_scroll_speed;
wf::option_wrapper_t<std::string> touchpad_click_method;
wf::option_wrapper_t<std::string> touchpad_scroll_method;
wf::option_wrapper_t<std::string> touchpad_accel_profile;
wf::option_wrapper_t<std::string> mouse_accel_profile;
wf::option_wrapper_t<bool> touchpad_tap_enabled;
wf::option_wrapper_t<bool> touchpad_dwt_enabled;
wf::option_wrapper_t<bool> touchpad_dwmouse_enabled;
wf::option_wrapper_t<bool> touchpad_natural_scroll_enabled;
wf::option_wrapper_t<bool> mouse_natural_scroll_enabled;
wf::option_wrapper_t<bool> touchpad_drag_lock_enabled;
};
}

Expand Down

0 comments on commit d2a11a7

Please sign in to comment.