Add map-to-focused-window tablet setting

This commit is contained in:
Ivan Molodetskikh
2026-04-30 19:53:34 +03:00
parent adb5b3cd2c
commit 5f6f131b24
4 changed files with 56 additions and 19 deletions
+8 -1
View File
@@ -90,6 +90,7 @@ input {
// off
map-to-output "eDP-1"
// map-to-focused-output
// map-to-focused-window
// left-handed
// calibration-matrix 1.0 0.0 0.0 0.0 1.0 0.0
}
@@ -282,10 +283,16 @@ Valid output names are the same as the ones used for output configuration.
<sup>Since: 0.1.7</sup> When a tablet is not mapped to any output, it will map to the union of all connected outputs, without aspect ratio correction.
Setting specific to `tablet`:
Settings specific to `tablet`:
- `map-to-focused-output`: <sup>Since: 26.04</sup> will map the tablet to the focused output, takes precedence over `map-to-output`.
- `map-to-focused-window`: <sup>Since: next release</sup> will map the tablet to the focused window's geometry, takes precedence over `map-to-focused-output` and `map-to-output`.
Falls back to those when no window is focused (for example, in the overview).
When the tablet is also mapped to a specific output via `map-to-output`, the `map-to-focused-window` flag will map the tablet to the active window on that output.
If the tablet isn't mapped to any specific output, it will map the tablet to the current focused window regardless of where it is.
### General Settings
These settings are not specific to a particular input device.
+2
View File
@@ -366,6 +366,8 @@ pub struct Tablet {
#[knuffel(child)]
pub map_to_focused_output: bool,
#[knuffel(child)]
pub map_to_focused_window: bool,
#[knuffel(child)]
pub left_handed: bool,
}
+2
View File
@@ -720,6 +720,7 @@ mod tests {
tablet {
map-to-output "eDP-1"
map-to-focused-output
map-to-focused-window
calibration-matrix 1.0 2.0 3.0 \
4.0 5.0 6.0
}
@@ -1113,6 +1114,7 @@ mod tests {
"eDP-1",
),
map_to_focused_output: true,
map_to_focused_window: true,
left_handed: false,
},
touch: Touch {
+44 -18
View File
@@ -297,26 +297,52 @@ impl State {
let device_output = event.device().output(self);
let device_output = device_output.filter(|output| self.niri.output_exists(output));
let device_output = device_output.as_ref();
let (target_geo, keep_ratio, px, transform) =
if let Some(output) = device_output.or_else(|| self.niri.output_for_tablet()) {
let geo = self.niri.global_space.output_geometry(output).unwrap();
(
geo.to_f64(),
true,
1. / output.current_scale().fractional_scale(),
output.current_transform(),
)
} else {
let geo = self.global_bounding_rectangle()?.to_f64();
let mapped_output = device_output.or_else(|| self.niri.output_for_tablet());
// FIXME: this 1 px size should ideally somehow be computed for the rightmost output
// corresponding to the position on the right when clamping.
let output = self.niri.global_space.outputs().next().unwrap();
let scale = output.current_scale().fractional_scale();
// If the tablet is configured to map to the focused window, use that window's geometry on
// the mapped output (or on the focused output if no specific output is mapped).
let map_to_focused_window = self.niri.config.borrow().input.tablet.map_to_focused_window;
// But only if the keyboard focus is on the layout, so that it doesn't trigger on the lock
// screen and such.
let window_target = if map_to_focused_window && self.niri.keyboard_focus.is_layout() {
let output = mapped_output.or_else(|| self.niri.layout.active_output());
output.and_then(|output| {
let monitor = self.niri.layout.monitor_for_output(output)?;
let mut rect = monitor.active_window_visual_rectangle()?;
let output_geo = self.niri.global_space.output_geometry(output)?;
rect.loc += output_geo.loc.to_f64();
Some((rect, output))
})
} else {
None
};
// Do not keep ratio for the unified mode as this is what OpenTabletDriver expects.
(geo, false, 1. / scale, Transform::Normal)
};
let (target_geo, keep_ratio, px, transform) = if let Some((rect, output)) = window_target {
(
rect,
true,
1. / output.current_scale().fractional_scale(),
output.current_transform(),
)
} else if let Some(output) = mapped_output {
let geo = self.niri.global_space.output_geometry(output).unwrap();
(
geo.to_f64(),
true,
1. / output.current_scale().fractional_scale(),
output.current_transform(),
)
} else {
let geo = self.global_bounding_rectangle()?.to_f64();
// FIXME: this 1 px size should ideally somehow be computed for the rightmost output
// corresponding to the position on the right when clamping.
let output = self.niri.global_space.outputs().next().unwrap();
let scale = output.current_scale().fractional_scale();
// Do not keep ratio for the unified mode as this is what OpenTabletDriver expects.
(geo, false, 1. / scale, Transform::Normal)
};
let mut pos = {
let size = transform.invert().transform_size(target_geo.size);