forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB66583cdIvan Molodetskikh1 year ago2489 commits

backend_ext.rs51 lines, 1.7 KiBHistoryRawDownload
1use ::input as libinput;
2use smithay::backend::input;
3use smithay::backend::winit::WinitVirtualDevice;
4use smithay::output::Output;
5
6use crate::niri::State;
7use crate::protocols::virtual_pointer::VirtualPointer;
8
9pub trait NiriInputBackend: input::InputBackend<Device = Self::NiriDevice> {
10 type NiriDevice: NiriInputDevice;
11}
12impl<T: input::InputBackend> NiriInputBackend for T
13where
14 Self::Device: NiriInputDevice,
15{
16 type NiriDevice = Self::Device;
17}
18
19pub trait NiriInputDevice: input::Device {
20 // FIXME: this should maybe be per-event, not per-device,
21 // but it's not clear that this matters in practice?
22 // it might be more obvious once we implement it for libinput
23 fn output(&self, state: &State) -> Option<Output>;
24}
25
26impl NiriInputDevice for libinput::Device {
27 fn output(&self, _state: &State) -> Option<Output> {
28 // FIXME: Allow specifying the output per-device?
29 None
30 }
31}
32
33impl NiriInputDevice for WinitVirtualDevice {
34 fn output(&self, _state: &State) -> Option<Output> {
35 // FIXME: we should be returning the single output that the winit backend creates,
36 // but for now, that will cause issues because the output is normally upside down,
37 // so we apply Transform::Flipped180 to it and that would also cause
38 // the cursor position to be flipped, which is not what we want.
39 //
40 // instead, we just return None and rely on the fact that it has only one output.
41 // doing so causes the cursor to be placed in *global* output coordinates,
42 // which are not flipped, and happen to be what we want.
43 None
44 }
45}
46
47impl NiriInputDevice for VirtualPointer {
48 fn output(&self, _: &State) -> Option<Output> {
49 self.output().cloned()
50 }
51}