From 8f989e9c70c892a42add20d27eabad461c2a6631 Mon Sep 17 00:00:00 2001 From: Scott Moreau Date: Tue, 5 Nov 2024 20:19:18 -0700 Subject: [PATCH] input: Allow multiple keyboards to have different configurations 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. --- src/api/wayfire/config-backend.hpp | 2 +- src/core/plugin.cpp | 8 ++++---- src/core/seat/input-manager.cpp | 2 +- src/core/seat/keyboard.cpp | 20 ++++++++++++-------- 4 files changed, 18 insertions(+), 14 deletions(-) diff --git a/src/api/wayfire/config-backend.hpp b/src/api/wayfire/config-backend.hpp index 8a47601e7..54db71bb6 100644 --- a/src/api/wayfire/config-backend.hpp +++ b/src/api/wayfire/config-backend.hpp @@ -49,7 +49,7 @@ class config_backend_t * described in input-device.xml */ virtual std::shared_ptr get_input_device_section( - wlr_input_device *device); + std::string const & prefix, wlr_input_device *device); virtual ~config_backend_t() = default; diff --git a/src/core/plugin.cpp b/src/core/plugin.cpp index afec20d2f..8dcec39ce 100644 --- a/src/core/plugin.cpp +++ b/src/core/plugin.cpp @@ -44,7 +44,7 @@ static struct udev_property_and_desc }; std::shared_ptr 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 section; @@ -71,7 +71,7 @@ std::shared_ptr 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); @@ -86,7 +86,7 @@ std::shared_ptr 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) @@ -96,7 +96,7 @@ std::shared_ptr 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); } diff --git a/src/core/seat/input-manager.cpp b/src/core/seat/input-manager.cpp index 1c81a414a..2af3cd659 100644 --- a/src/core/seat/input-manager.cpp +++ b/src/core/seat/input-manager.cpp @@ -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()) diff --git a/src/core/seat/keyboard.cpp b/src/core/seat/keyboard.cpp index ad3ab71b1..51a964dea 100644 --- a/src/core/seat/keyboard.cpp +++ b/src/core/seat/keyboard.cpp @@ -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.