Skip to content

Commit f337a27

Browse files
committed
implement WinitVirtualDevice::output() to the one single virtual output
1 parent 2f1d143 commit f337a27

File tree

3 files changed

+23
-12
lines changed

3 files changed

+23
-12
lines changed

src/backend/winit.rs

+5
Original file line numberDiff line numberDiff line change
@@ -268,4 +268,9 @@ impl Winit {
268268
pub fn ipc_outputs(&self) -> Arc<Mutex<IpcOutputMap>> {
269269
self.ipc_outputs.clone()
270270
}
271+
272+
// FIXME: If/when the winit backend supports multiple outputs, then this method makes no sense.
273+
pub fn single_output(&self) -> &Output {
274+
&self.output
275+
}
271276
}

src/input/backend_ext.rs

+16-10
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ use smithay::backend::input;
33
use smithay::backend::winit::WinitVirtualDevice;
44
use smithay::output::Output;
55

6+
use crate::backend::Backend;
7+
use crate::niri::State;
68
use crate::protocols::virtual_pointer::VirtualPointer;
79

810
pub trait NiriInputBackend: input::InputBackend<Device = Self::NiriDevice> {
@@ -16,29 +18,33 @@ where
1618
}
1719

1820
pub trait NiriInputDevice: input::Device {
19-
// FIXME: should this be per-event? logically yes,
20-
// but right now we only use it for virtual pointers, which have static outputs.
21-
fn output(&self) -> Option<Output>;
21+
// FIXME: this should maybe be per-event, not per-device,
22+
// but it's not clear that this matters in practice?
23+
// it might be more obvious once we implement it for libinput
24+
fn output(&self, state: &State) -> Option<Output>;
2225
}
2326

2427
impl NiriInputDevice for libinput::Device {
25-
fn output(&self) -> Option<Output> {
28+
fn output(&self, _state: &State) -> Option<Output> {
2629
// FIXME: Allow specifying the output per-device?
27-
// In that case, change the method to take a reference to our state or config or something
28-
// (because we can't easily change the libinput Device struct)
2930
None
3031
}
3132
}
3233

3334
impl NiriInputDevice for WinitVirtualDevice {
34-
fn output(&self) -> Option<Output> {
35-
// here it's actually *correct* to return None, because there is only one output.
36-
None
35+
fn output(&self, state: &State) -> Option<Output> {
36+
match state.backend {
37+
Backend::Winit(ref winit) => Some(winit.single_output().clone()),
38+
// returning None over panicking here because it's not worth panicking over
39+
// and also, foreseeably, someone might want to, at some point, use `WinitInputBackend`
40+
// for dirty hacks or mocking or whatever, in which case this will be useful.
41+
_ => None,
42+
}
3743
}
3844
}
3945

4046
impl NiriInputDevice for VirtualPointer {
41-
fn output(&self) -> Option<Output> {
47+
fn output(&self, _: &State) -> Option<Output> {
4248
self.output().cloned()
4349
}
4450
}

src/input/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -268,7 +268,7 @@ impl State {
268268
where
269269
I::Device: 'static,
270270
{
271-
let device_output = event.device().output();
271+
let device_output = event.device().output(self);
272272
let device_output = device_output.as_ref();
273273
let (target_geo, keep_ratio, px, transform) =
274274
if let Some(output) = device_output.or_else(|| self.niri.output_for_tablet()) {
@@ -2373,7 +2373,7 @@ impl State {
23732373
evt: &impl AbsolutePositionEvent<I>,
23742374
fallback_output: Option<&Output>,
23752375
) -> Option<Point<f64, Logical>> {
2376-
let output = evt.device().output();
2376+
let output = evt.device().output(self);
23772377
let output = output.as_ref().or(fallback_output)?;
23782378
let output_geo = self.niri.global_space.output_geometry(output).unwrap();
23792379
let transform = output.current_transform();

0 commit comments

Comments
 (0)