Skip to content

Commit

Permalink
input: Allow multiple keyboards to have different configurations
Browse files Browse the repository at this point in the history
This patch checks for additional configuration sections so keyboards can
be matched by name or with udev properties. Running wayfire with '-d' will
log the sections that are being checked, for reference. This allows multiple
keyboards 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.

Fixes #2481.
  • Loading branch information
soreau committed Nov 6, 2024
1 parent 288fcce commit 91db71d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 14 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 @@ -71,7 +71,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);
LOGD("Checking for config section [", name, "] ",
pd.property_name, " (", pd.description, ")");
section = config.get_section(name);
Expand All @@ -86,7 +86,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;
LOGD("Checking for config section [", name, "]");
section = config.get_section(name);
if (section)
Expand All @@ -96,7 +96,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));

return config.get_section(name);
}
Expand Down
2 changes: 1 addition & 1 deletion src/core/seat/input-manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ void wf::input_manager_t::configure_input_device(wlr_input_device *dev)
{
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
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

0 comments on commit 91db71d

Please sign in to comment.