forge
Explore
Log in

Don't you dare go Hollow

Make tablet without specific output map to union of outputs

Browse files at this commit

cb0ebd35ce237a23a32aeb50ec475645db00bcacIvan MolodetskikhParent: 29cf80a
src/input/mod.rsmodified+51 -31
@@ -216,17 +216,16 @@ impl State {
216 }216 }
217 217
218 /// Computes the rectangle that covers all outputs in global space.218 /// Computes the rectangle that covers all outputs in global space.
219- fn global_bounding_rectangle(&self) -> Rectangle<i32, Logical> {219+ fn global_bounding_rectangle(&self) -> Option<Rectangle<i32, Logical>> {
220- self.niri220+ self.niri.global_space.outputs().fold(
221- .global_space221+ None,
222- .outputs()222+ |acc: Option<Rectangle<i32, Logical>>, output| {
223- .fold(None, |acc: Option<Rectangle<i32, Logical>>, output| {
224 self.niri223 self.niri
225 .global_space224 .global_space
226 .output_geometry(output)225 .output_geometry(output)
227 .map(|geo| acc.map(|acc| acc.merge(geo)).unwrap_or(geo))226 .map(|geo| acc.map(|acc| acc.merge(geo)).unwrap_or(geo))
228- })227+ },
229- .unwrap_or_else(Default::default)228+ )
230 }229 }
231 230
232 /// Computes the cursor position for the tablet event.231 /// Computes the cursor position for the tablet event.
@@ -240,33 +239,52 @@ impl State {
240 where239 where
241 I::Device: 'static,240 I::Device: 'static,
242 {241 {
243- let output = self.niri.output_for_tablet()?;242+ let (target_geo, keep_ratio, px) = if let Some(output) = self.niri.output_for_tablet() {
244- let output_geo = self.niri.global_space.output_geometry(output).unwrap();243+ (
244+ self.niri.global_space.output_geometry(output).unwrap(),
245+ true,
246+ 1. / output.current_scale().fractional_scale(),
247+ )
248+ } else {
249+ let geo = self.global_bounding_rectangle()?;
245 250
246- let mut pos = event.position_transformed(output_geo.size);251+ // FIXME: this 1 px size should ideally somehow be computed for the rightmost output
247- pos.x /= output_geo.size.w as f64;252+ // corresponding to the position on the right when clamping.
248- pos.y /= output_geo.size.h as f64;253+ let output = self.niri.global_space.outputs().next().unwrap();
254+ let scale = output.current_scale().fractional_scale();
249 255
250- let device = event.device();256+ // Do not keep ratio for the unified mode as this is what OpenTabletDriver expects.
251- if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() {257+ (geo, false, 1. / scale)
252- if let Some(data) = self.niri.tablets.get(device) {
253- // This code does the same thing as mutter with "keep aspect ratio" enabled.
254- let output_aspect_ratio = output_geo.size.w as f64 / output_geo.size.h as f64;
255- let ratio = data.aspect_ratio / output_aspect_ratio;
256-
257- if ratio > 1. {
258- pos.x *= ratio;
259- } else {
260- pos.y /= ratio;
261- }
262- }
263 };258 };
264 259
265- pos.x *= output_geo.size.w as f64;260+ let mut pos = event.position_transformed(target_geo.size);
266- pos.y *= output_geo.size.h as f64;261+
267- pos.x = pos.x.clamp(0.0, output_geo.size.w as f64 - 1.);262+ if keep_ratio {
268- pos.y = pos.y.clamp(0.0, output_geo.size.h as f64 - 1.);263+ pos.x /= target_geo.size.w as f64;
269- Some(pos + output_geo.loc.to_f64())264+ pos.y /= target_geo.size.h as f64;
265+
266+ let device = event.device();
267+ if let Some(device) = (&device as &dyn Any).downcast_ref::<input::Device>() {
268+ if let Some(data) = self.niri.tablets.get(device) {
269+ // This code does the same thing as mutter with "keep aspect ratio" enabled.
270+ let output_aspect_ratio = target_geo.size.w as f64 / target_geo.size.h as f64;
271+ let ratio = data.aspect_ratio / output_aspect_ratio;
272+
273+ if ratio > 1. {
274+ pos.x *= ratio;
275+ } else {
276+ pos.y /= ratio;
277+ }
278+ }
279+ };
280+
281+ pos.x *= target_geo.size.w as f64;
282+ pos.y *= target_geo.size.h as f64;
283+ }
284+
285+ pos.x = pos.x.clamp(0.0, target_geo.size.w as f64 - px);
286+ pos.y = pos.y.clamp(0.0, target_geo.size.h as f64 - px);
287+ Some(pos + target_geo.loc.to_f64())
270 }288 }
271 289
272 fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {290 fn on_keyboard<I: InputBackend>(&mut self, event: I::KeyboardKeyEvent) {
@@ -1097,7 +1115,9 @@ impl State {
1097 &mut self,1115 &mut self,
1098 event: I::PointerMotionAbsoluteEvent,1116 event: I::PointerMotionAbsoluteEvent,
1099 ) {1117 ) {
1100- let output_geo = self.global_bounding_rectangle();1118+ let Some(output_geo) = self.global_bounding_rectangle() else {
1119+ return;
1120+ };
1101 1121
1102 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();1122 let pos = event.position_transformed(output_geo.size) + output_geo.loc.to_f64();
1103 1123
src/niri.rsmodified+1 -3
@@ -2183,9 +2183,7 @@ impl Niri {
2183 pub fn output_for_tablet(&self) -> Option<&Output> {2183 pub fn output_for_tablet(&self) -> Option<&Output> {
2184 let config = self.config.borrow();2184 let config = self.config.borrow();
2185 let map_to_output = config.input.tablet.map_to_output.as_ref();2185 let map_to_output = config.input.tablet.map_to_output.as_ref();
2186- map_to_output2186+ map_to_output.and_then(|name| self.output_by_name.get(name))
2187- .and_then(|name| self.output_by_name.get(name))
2188- .or_else(|| self.global_space.outputs().next())
2189 }2187 }
2190 2188
2191 pub fn output_for_touch(&self) -> Option<&Output> {2189 pub fn output_for_touch(&self) -> Option<&Output> {
wiki/Configuration:-Input.mdmodified+2 -0
@@ -168,6 +168,8 @@ input {
168 168
169 Valid output names are the same as the ones used for output configuration.169 Valid output names are the same as the ones used for output configuration.
170 170
171+<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.
172+
171 ### General Settings173 ### General Settings
172 174
173 These settings are not specific to a particular input device.175 These settings are not specific to a particular input device.