Skip to content

Commit d2a11a7

Browse files
committed
input: Allow multiple keyboards and mice to have different configurations
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.
1 parent 5e54a7a commit d2a11a7

File tree

7 files changed

+99
-83
lines changed

7 files changed

+99
-83
lines changed

src/api/wayfire/config-backend.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ class config_backend_t
4949
* described in input-device.xml
5050
*/
5151
virtual std::shared_ptr<config::section_t> get_input_device_section(
52-
wlr_input_device *device);
52+
std::string const & prefix, wlr_input_device *device);
5353

5454
virtual ~config_backend_t() = default;
5555

src/core/plugin.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ static struct udev_property_and_desc
4444
};
4545

4646
std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_section(
47-
wlr_input_device *device)
47+
std::string const & prefix, wlr_input_device *device)
4848
{
4949
auto& config = wf::get_core().config;
5050
std::shared_ptr<wf::config::section_t> section;
@@ -65,7 +65,7 @@ std::shared_ptr<config::section_t> wf::config_backend_t::get_input_device_sectio
6565
continue;
6666
}
6767

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

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

9292
config.merge_section(
93-
config.get_section("input-device")->clone_with_name(name));
93+
config.get_section(prefix)->clone_with_name(name));
9494

9595
LOGC(INPUT_DEVICES, "Using config section [", name, "]");
9696
return config.get_section(name);

src/core/seat/input-manager.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ void wf::input_manager_t::configure_input_device(std::unique_ptr<wf::input_devic
6060
auto dev = device->get_wlr_handle();
6161
auto cursor = wf::get_core().get_wlr_cursor();
6262
auto section =
63-
wf::get_core().config_backend->get_input_device_section(dev);
63+
wf::get_core().config_backend->get_input_device_section("input-device", dev);
6464

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

153153
wf::input_manager_t::input_manager_t()
154154
{
155-
wf::pointing_device_t::config.load();
156-
157155
load_locked_mods_from_config(locked_mods);
158156

159157
input_device_created.set_callback([&] (void *data)

src/core/seat/keyboard.cpp

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -121,14 +121,18 @@ void wf::keyboard_t::setup_listeners()
121121
wf::keyboard_t::keyboard_t(wlr_input_device *dev) :
122122
handle(wlr_keyboard_from_input_device(dev)), device(dev)
123123
{
124-
model.load_option("input/xkb_model");
125-
variant.load_option("input/xkb_variant");
126-
layout.load_option("input/xkb_layout");
127-
options.load_option("input/xkb_options");
128-
rules.load_option("input/xkb_rules");
129-
130-
repeat_rate.load_option("input/kb_repeat_rate");
131-
repeat_delay.load_option("input/kb_repeat_delay");
124+
auto section =
125+
wf::get_core().config_backend->get_input_device_section("input", dev);
126+
auto section_name = section->get_name();
127+
128+
model.load_option(section_name + "/xkb_model");
129+
variant.load_option(section_name + "/xkb_variant");
130+
layout.load_option(section_name + "/xkb_layout");
131+
options.load_option(section_name + "/xkb_options");
132+
rules.load_option(section_name + "/xkb_rules");
133+
134+
repeat_rate.load_option(section_name + "/kb_repeat_rate");
135+
repeat_delay.load_option(section_name + "/kb_repeat_delay");
132136

133137
// When the configuration options change, mark them as dirty.
134138
// They are applied at the config-reloaded signal.

src/core/seat/pointer.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -355,9 +355,8 @@ void wf::pointer_t::handle_pointer_axis(wlr_pointer_axis_event *ev,
355355
}
356356

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

362361
ev->delta *= mult;
363362
ev->delta_discrete *= mult;

src/core/seat/pointing-device.cpp

Lines changed: 59 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,37 @@
33
wf::pointing_device_t::pointing_device_t(wlr_input_device *dev) :
44
input_device_impl_t(dev)
55
{
6+
dev->data = this;
7+
load_options();
68
update_options();
79
}
810

9-
wf::pointing_device_t::config_t wf::pointing_device_t::config;
10-
void wf::pointing_device_t::config_t::load()
11+
void wf::pointing_device_t::load_options()
1112
{
12-
left_handed_mode.load_option("input/left_handed_mode");
13-
middle_emulation.load_option("input/middle_emulation");
14-
15-
mouse_scroll_speed.load_option("input/mouse_scroll_speed");
16-
mouse_cursor_speed.load_option("input/mouse_cursor_speed");
17-
touchpad_cursor_speed.load_option("input/touchpad_cursor_speed");
18-
touchpad_scroll_speed.load_option("input/touchpad_scroll_speed");
19-
20-
mouse_natural_scroll_enabled.load_option("input/mouse_natural_scroll");
21-
touchpad_tap_enabled.load_option("input/tap_to_click");
22-
touchpad_dwt_enabled.load_option("input/disable_touchpad_while_typing");
23-
touchpad_dwmouse_enabled.load_option("input/disable_touchpad_while_mouse");
24-
touchpad_natural_scroll_enabled.load_option("input/natural_scroll");
25-
touchpad_drag_lock_enabled.load_option("input/drag_lock");
26-
27-
mouse_accel_profile.load_option("input/mouse_accel_profile");
28-
touchpad_accel_profile.load_option("input/touchpad_accel_profile");
29-
30-
touchpad_click_method.load_option("input/click_method");
31-
touchpad_scroll_method.load_option("input/scroll_method");
13+
auto section =
14+
wf::get_core().config_backend->get_input_device_section("input", get_wlr_handle());
15+
auto section_name = section->get_name();
16+
17+
left_handed_mode.load_option(section_name + "/left_handed_mode");
18+
middle_emulation.load_option(section_name + "/middle_emulation");
19+
20+
mouse_scroll_speed.load_option(section_name + "/mouse_scroll_speed");
21+
mouse_cursor_speed.load_option(section_name + "/mouse_cursor_speed");
22+
touchpad_cursor_speed.load_option(section_name + "/touchpad_cursor_speed");
23+
touchpad_scroll_speed.load_option(section_name + "/touchpad_scroll_speed");
24+
25+
mouse_natural_scroll_enabled.load_option(section_name + "/mouse_natural_scroll");
26+
touchpad_tap_enabled.load_option(section_name + "/tap_to_click");
27+
touchpad_dwt_enabled.load_option(section_name + "/disable_touchpad_while_typing");
28+
touchpad_dwmouse_enabled.load_option(section_name + "/disable_touchpad_while_mouse");
29+
touchpad_natural_scroll_enabled.load_option(section_name + "/natural_scroll");
30+
touchpad_drag_lock_enabled.load_option(section_name + "/drag_lock");
31+
32+
mouse_accel_profile.load_option(section_name + "/mouse_accel_profile");
33+
touchpad_accel_profile.load_option(section_name + "/touchpad_accel_profile");
34+
35+
touchpad_click_method.load_option(section_name + "/click_method");
36+
touchpad_scroll_method.load_option(section_name + "/scroll_method");
3237
}
3338

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

66-
libinput_device_config_left_handed_set(dev, config.left_handed_mode);
71+
libinput_device_config_left_handed_set(dev, left_handed_mode);
6772

6873
libinput_device_config_middle_emulation_set_enabled(dev,
69-
config.middle_emulation ?
74+
middle_emulation ?
7075
LIBINPUT_CONFIG_MIDDLE_EMULATION_ENABLED :
7176
LIBINPUT_CONFIG_MIDDLE_EMULATION_DISABLED);
7277

7378
/* we are configuring a touchpad */
7479
if (libinput_device_config_tap_get_finger_count(dev) > 0)
7580
{
7681
libinput_device_config_accel_set_speed(dev,
77-
config.touchpad_cursor_speed);
82+
touchpad_cursor_speed);
7883

79-
set_libinput_accel_profile(dev, config.touchpad_accel_profile);
84+
set_libinput_accel_profile(dev, touchpad_accel_profile);
8085
libinput_device_config_tap_set_enabled(dev,
81-
config.touchpad_tap_enabled ?
86+
touchpad_tap_enabled ?
8287
LIBINPUT_CONFIG_TAP_ENABLED : LIBINPUT_CONFIG_TAP_DISABLED);
8388

84-
if ((std::string)config.touchpad_click_method == "default")
89+
if ((std::string)touchpad_click_method == "default")
8590
{
8691
libinput_device_config_click_set_method(dev,
8792
libinput_device_config_click_get_default_method(dev));
88-
} else if ((std::string)config.touchpad_click_method == "none")
93+
} else if ((std::string)touchpad_click_method == "none")
8994
{
9095
libinput_device_config_click_set_method(dev,
9196
LIBINPUT_CONFIG_CLICK_METHOD_NONE);
92-
} else if ((std::string)config.touchpad_click_method == "button-areas")
97+
} else if ((std::string)touchpad_click_method == "button-areas")
9398
{
9499
libinput_device_config_click_set_method(dev,
95100
LIBINPUT_CONFIG_CLICK_METHOD_BUTTON_AREAS);
96-
} else if ((std::string)config.touchpad_click_method == "clickfinger")
101+
} else if ((std::string)touchpad_click_method == "clickfinger")
97102
{
98103
libinput_device_config_click_set_method(dev,
99104
LIBINPUT_CONFIG_CLICK_METHOD_CLICKFINGER);
100105
}
101106

102-
if ((std::string)config.touchpad_scroll_method == "default")
107+
if ((std::string)touchpad_scroll_method == "default")
103108
{
104109
libinput_device_config_scroll_set_method(dev,
105110
libinput_device_config_scroll_get_default_method(dev));
106-
} else if ((std::string)config.touchpad_scroll_method == "none")
111+
} else if ((std::string)touchpad_scroll_method == "none")
107112
{
108113
libinput_device_config_scroll_set_method(dev,
109114
LIBINPUT_CONFIG_SCROLL_NO_SCROLL);
110-
} else if ((std::string)config.touchpad_scroll_method == "two-finger")
115+
} else if ((std::string)touchpad_scroll_method == "two-finger")
111116
{
112117
libinput_device_config_scroll_set_method(dev,
113118
LIBINPUT_CONFIG_SCROLL_2FG);
114-
} else if ((std::string)config.touchpad_scroll_method == "edge")
119+
} else if ((std::string)touchpad_scroll_method == "edge")
115120
{
116121
libinput_device_config_scroll_set_method(dev,
117122
LIBINPUT_CONFIG_SCROLL_EDGE);
118-
} else if ((std::string)config.touchpad_scroll_method == "on-button-down")
123+
} else if ((std::string)touchpad_scroll_method == "on-button-down")
119124
{
120125
libinput_device_config_scroll_set_method(dev,
121126
LIBINPUT_CONFIG_SCROLL_ON_BUTTON_DOWN);
122127
}
123128

124129
libinput_device_config_dwt_set_enabled(dev,
125-
config.touchpad_dwt_enabled ?
130+
touchpad_dwt_enabled ?
126131
LIBINPUT_CONFIG_DWT_ENABLED : LIBINPUT_CONFIG_DWT_DISABLED);
127132

128133
libinput_device_config_send_events_set_mode(dev,
129-
config.touchpad_dwmouse_enabled ?
134+
touchpad_dwmouse_enabled ?
130135
LIBINPUT_CONFIG_SEND_EVENTS_DISABLED_ON_EXTERNAL_MOUSE :
131136
LIBINPUT_CONFIG_SEND_EVENTS_ENABLED);
132137

133138
libinput_device_config_tap_set_drag_lock_enabled(dev,
134-
config.touchpad_drag_lock_enabled ?
139+
touchpad_drag_lock_enabled ?
135140
LIBINPUT_CONFIG_DRAG_LOCK_ENABLED :
136141
LIBINPUT_CONFIG_DRAG_LOCK_DISABLED);
137142

138143
if (libinput_device_config_scroll_has_natural_scroll(dev) > 0)
139144
{
140145
libinput_device_config_scroll_set_natural_scroll_enabled(dev,
141-
(bool)config.touchpad_natural_scroll_enabled);
146+
(bool)touchpad_natural_scroll_enabled);
142147
}
143148
} else
144149
{
145150
libinput_device_config_accel_set_speed(dev,
146-
config.mouse_cursor_speed);
147-
set_libinput_accel_profile(dev, config.mouse_accel_profile);
151+
mouse_cursor_speed);
152+
set_libinput_accel_profile(dev, mouse_accel_profile);
148153

149154
if (libinput_device_config_scroll_has_natural_scroll(dev) > 0)
150155
{
151156
libinput_device_config_scroll_set_natural_scroll_enabled(dev,
152-
(bool)config.mouse_natural_scroll_enabled);
157+
(bool)mouse_natural_scroll_enabled);
153158
}
154159
}
155160
}
161+
162+
double wf::pointing_device_t::get_scroll_speed(wlr_input_device *dev, bool touchpad)
163+
{
164+
if ((touchpad && (dev->type != WLR_INPUT_DEVICE_TABLET_PAD)) ||
165+
(!touchpad && (dev->type != WLR_INPUT_DEVICE_POINTER)))
166+
{
167+
return 1.0;
168+
}
169+
170+
return touchpad ? touchpad_scroll_speed : mouse_scroll_speed;
171+
}

src/core/seat/pointing-device.hpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,28 @@ struct pointing_device_t : public input_device_impl_t
1010
pointing_device_t(wlr_input_device *dev);
1111
virtual ~pointing_device_t() = default;
1212

13+
void load_options();
1314
void update_options() override;
1415

15-
static struct config_t
16-
{
17-
wf::option_wrapper_t<bool> left_handed_mode;
18-
wf::option_wrapper_t<bool> middle_emulation;
19-
wf::option_wrapper_t<double> mouse_cursor_speed;
20-
wf::option_wrapper_t<double> mouse_scroll_speed;
21-
wf::option_wrapper_t<std::string> tablet_motion_mode;
22-
wf::option_wrapper_t<double> touchpad_cursor_speed;
23-
wf::option_wrapper_t<double> touchpad_scroll_speed;
24-
wf::option_wrapper_t<std::string> touchpad_click_method;
25-
wf::option_wrapper_t<std::string> touchpad_scroll_method;
26-
wf::option_wrapper_t<std::string> touchpad_accel_profile;
27-
wf::option_wrapper_t<std::string> mouse_accel_profile;
28-
wf::option_wrapper_t<bool> touchpad_tap_enabled;
29-
wf::option_wrapper_t<bool> touchpad_dwt_enabled;
30-
wf::option_wrapper_t<bool> touchpad_dwmouse_enabled;
31-
wf::option_wrapper_t<bool> touchpad_natural_scroll_enabled;
32-
wf::option_wrapper_t<bool> mouse_natural_scroll_enabled;
33-
wf::option_wrapper_t<bool> touchpad_drag_lock_enabled;
34-
void load();
35-
} config;
16+
double get_scroll_speed(wlr_input_device *dev, bool touchpad);
17+
18+
wf::option_wrapper_t<bool> left_handed_mode;
19+
wf::option_wrapper_t<bool> middle_emulation;
20+
wf::option_wrapper_t<double> mouse_cursor_speed;
21+
wf::option_wrapper_t<double> mouse_scroll_speed;
22+
wf::option_wrapper_t<std::string> tablet_motion_mode;
23+
wf::option_wrapper_t<double> touchpad_cursor_speed;
24+
wf::option_wrapper_t<double> touchpad_scroll_speed;
25+
wf::option_wrapper_t<std::string> touchpad_click_method;
26+
wf::option_wrapper_t<std::string> touchpad_scroll_method;
27+
wf::option_wrapper_t<std::string> touchpad_accel_profile;
28+
wf::option_wrapper_t<std::string> mouse_accel_profile;
29+
wf::option_wrapper_t<bool> touchpad_tap_enabled;
30+
wf::option_wrapper_t<bool> touchpad_dwt_enabled;
31+
wf::option_wrapper_t<bool> touchpad_dwmouse_enabled;
32+
wf::option_wrapper_t<bool> touchpad_natural_scroll_enabled;
33+
wf::option_wrapper_t<bool> mouse_natural_scroll_enabled;
34+
wf::option_wrapper_t<bool> touchpad_drag_lock_enabled;
3635
};
3736
}
3837

0 commit comments

Comments
 (0)