Add map-to-focused-window tablet setting
Browse files at this commit5f6f131b24826a01374d5cd87b281bd7ea181537Parent: adb5b3c4 changed files +56 -19
- docs/wiki/Configuration:-Input.md +8 -1
- niri-config/src/input.rs +2 -0
- niri-config/src/lib.rs +2 -0
- src/input/mod.rs +44 -18
docs/wiki/Configuration:-Input.mdmodified+8 -1
| @@ -90,6 +90,7 @@ input { | |||
| 90 | // off | 90 | // off |
| 91 | map-to-output "eDP-1" | 91 | map-to-output "eDP-1" |
| 92 | // map-to-focused-output | 92 | // map-to-focused-output |
| 93 | + // map-to-focused-window | ||
| 93 | // left-handed | 94 | // left-handed |
| 94 | // calibration-matrix 1.0 0.0 0.0 0.0 1.0 0.0 | 95 | // calibration-matrix 1.0 0.0 0.0 0.0 1.0 0.0 |
| 95 | } | 96 | } |
| @@ -282,10 +283,16 @@ Valid output names are the same as the ones used for output configuration. | |||
| 282 | 283 | ||
| 283 | <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. | 284 | <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. |
| 284 | 285 | ||
| 285 | -Setting specific to `tablet`: | 286 | +Settings specific to `tablet`: |
| 286 | 287 | ||
| 287 | - `map-to-focused-output`: <sup>Since: 26.04</sup> will map the tablet to the focused output, takes precedence over `map-to-output`. | 288 | - `map-to-focused-output`: <sup>Since: 26.04</sup> will map the tablet to the focused output, takes precedence over `map-to-output`. |
| 288 | 289 | ||
| 290 | +- `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`. | ||
| 291 | +Falls back to those when no window is focused (for example, in the overview). | ||
| 292 | + | ||
| 293 | + 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. | ||
| 294 | + 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. | ||
| 295 | + | ||
| 289 | ### General Settings | 296 | ### General Settings |
| 290 | 297 | ||
| 291 | These settings are not specific to a particular input device. | 298 | These settings are not specific to a particular input device. |
niri-config/src/input.rsmodified+2 -0
| @@ -366,6 +366,8 @@ pub struct Tablet { | |||
| 366 | #[knuffel(child)] | 366 | #[knuffel(child)] |
| 367 | pub map_to_focused_output: bool, | 367 | pub map_to_focused_output: bool, |
| 368 | #[knuffel(child)] | 368 | #[knuffel(child)] |
| 369 | + pub map_to_focused_window: bool, | ||
| 370 | + #[knuffel(child)] | ||
| 369 | pub left_handed: bool, | 371 | pub left_handed: bool, |
| 370 | } | 372 | } |
| 371 | 373 | ||
niri-config/src/lib.rsmodified+2 -0
| @@ -720,6 +720,7 @@ mod tests { | |||
| 720 | tablet { | 720 | tablet { |
| 721 | map-to-output "eDP-1" | 721 | map-to-output "eDP-1" |
| 722 | map-to-focused-output | 722 | map-to-focused-output |
| 723 | + map-to-focused-window | ||
| 723 | calibration-matrix 1.0 2.0 3.0 \ | 724 | calibration-matrix 1.0 2.0 3.0 \ |
| 724 | 4.0 5.0 6.0 | 725 | 4.0 5.0 6.0 |
| 725 | } | 726 | } |
| @@ -1113,6 +1114,7 @@ mod tests { | |||
| 1113 | "eDP-1", | 1114 | "eDP-1", |
| 1114 | ), | 1115 | ), |
| 1115 | map_to_focused_output: true, | 1116 | map_to_focused_output: true, |
| 1117 | + map_to_focused_window: true, | ||
| 1116 | left_handed: false, | 1118 | left_handed: false, |
| 1117 | }, | 1119 | }, |
| 1118 | touch: Touch { | 1120 | touch: Touch { |
src/input/mod.rsmodified+44 -18
| @@ -297,26 +297,52 @@ impl State { | |||
| 297 | let device_output = event.device().output(self); | 297 | let device_output = event.device().output(self); |
| 298 | let device_output = device_output.filter(|output| self.niri.output_exists(output)); | 298 | let device_output = device_output.filter(|output| self.niri.output_exists(output)); |
| 299 | let device_output = device_output.as_ref(); | 299 | let device_output = device_output.as_ref(); |
| 300 | - let (target_geo, keep_ratio, px, transform) = | 300 | + let mapped_output = device_output.or_else(|| self.niri.output_for_tablet()); |
| 301 | - if let Some(output) = device_output.or_else(|| self.niri.output_for_tablet()) { | 301 | + |
| 302 | - let geo = self.niri.global_space.output_geometry(output).unwrap(); | 302 | + // If the tablet is configured to map to the focused window, use that window's geometry on |
| 303 | - ( | 303 | + // the mapped output (or on the focused output if no specific output is mapped). |
| 304 | - geo.to_f64(), | 304 | + let map_to_focused_window = self.niri.config.borrow().input.tablet.map_to_focused_window; |
| 305 | - true, | 305 | + // But only if the keyboard focus is on the layout, so that it doesn't trigger on the lock |
| 306 | - 1. / output.current_scale().fractional_scale(), | 306 | + // screen and such. |
| 307 | - output.current_transform(), | 307 | + let window_target = if map_to_focused_window && self.niri.keyboard_focus.is_layout() { |
| 308 | - ) | 308 | + let output = mapped_output.or_else(|| self.niri.layout.active_output()); |
| 309 | - } else { | 309 | + output.and_then(|output| { |
| 310 | - let geo = self.global_bounding_rectangle()?.to_f64(); | 310 | + let monitor = self.niri.layout.monitor_for_output(output)?; |
| 311 | + let mut rect = monitor.active_window_visual_rectangle()?; | ||
| 312 | + let output_geo = self.niri.global_space.output_geometry(output)?; | ||
| 313 | + rect.loc += output_geo.loc.to_f64(); | ||
| 314 | + Some((rect, output)) | ||
| 315 | + }) | ||
| 316 | + } else { | ||
| 317 | + None | ||
| 318 | + }; | ||
| 311 | 319 | ||
| 312 | - // FIXME: this 1 px size should ideally somehow be computed for the rightmost output | 320 | + let (target_geo, keep_ratio, px, transform) = if let Some((rect, output)) = window_target { |
| 313 | - // corresponding to the position on the right when clamping. | 321 | + ( |
| 314 | - let output = self.niri.global_space.outputs().next().unwrap(); | 322 | + rect, |
| 315 | - let scale = output.current_scale().fractional_scale(); | 323 | + true, |
| 324 | + 1. / output.current_scale().fractional_scale(), | ||
| 325 | + output.current_transform(), | ||
| 326 | + ) | ||
| 327 | + } else if let Some(output) = mapped_output { | ||
| 328 | + let geo = self.niri.global_space.output_geometry(output).unwrap(); | ||
| 329 | + ( | ||
| 330 | + geo.to_f64(), | ||
| 331 | + true, | ||
| 332 | + 1. / output.current_scale().fractional_scale(), | ||
| 333 | + output.current_transform(), | ||
| 334 | + ) | ||
| 335 | + } else { | ||
| 336 | + let geo = self.global_bounding_rectangle()?.to_f64(); | ||
| 316 | 337 | ||
| 317 | - // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects. | 338 | + // FIXME: this 1 px size should ideally somehow be computed for the rightmost output |
| 318 | - (geo, false, 1. / scale, Transform::Normal) | 339 | + // corresponding to the position on the right when clamping. |
| 319 | - }; | 340 | + let output = self.niri.global_space.outputs().next().unwrap(); |
| 341 | + let scale = output.current_scale().fractional_scale(); | ||
| 342 | + | ||
| 343 | + // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects. | ||
| 344 | + (geo, false, 1. / scale, Transform::Normal) | ||
| 345 | + }; | ||
| 320 | 346 | ||
| 321 | let mut pos = { | 347 | let mut pos = { |
| 322 | let size = transform.invert().transform_size(target_geo.size); | 348 | let size = transform.invert().transform_size(target_geo.size); |