forge
Explore
Log in

Don't you dare go Hollow

niri

Clone
★ 0

0 watching0 forksRustGPL-3.012.1 MiB9d8f4f8Ivan Molodetskikh1 month ago2997 commits

backend_ext.rs58 lines, 1.9 KiBHistoryRawDownload
1use ::input as libinput;
2use smithay::backend::input;
3use smithay::backend::winit::WinitVirtualDevice;
4use smithay::output::Output;
5use smithay::wayland::virtual_keyboard::VirtualKeyboardDevice;
6use smithay::wayland::virtual_pointer::VirtualPointerDevice;
7
8use crate::niri::State;
9
10pub trait NiriInputBackend: input::InputBackend<Device = Self::NiriDevice> {
11 type NiriDevice: NiriInputDevice;
12}
13impl<T: input::InputBackend> NiriInputBackend for T
14where
15 Self::Device: NiriInputDevice,
16{
17 type NiriDevice = Self::Device;
18}
19
20pub trait NiriInputDevice: input::Device {
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>;
25}
26
27impl NiriInputDevice for libinput::Device {
28 fn output(&self, _state: &State) -> Option<Output> {
29 // FIXME: Allow specifying the output per-device?
30 None
31 }
32}
33
34impl NiriInputDevice for WinitVirtualDevice {
35 fn output(&self, _state: &State) -> Option<Output> {
36 // FIXME: we should be returning the single output that the winit backend creates,
37 // but for now, that will cause issues because the output is normally upside down,
38 // so we apply Transform::Flipped180 to it and that would also cause
39 // the cursor position to be flipped, which is not what we want.
40 //
41 // instead, we just return None and rely on the fact that it has only one output.
42 // doing so causes the cursor to be placed in *global* output coordinates,
43 // which are not flipped, and happen to be what we want.
44 None
45 }
46}
47
48impl NiriInputDevice for VirtualPointerDevice {
49 fn output(&self, _: &State) -> Option<Output> {
50 self.output()
51 }
52}
53
54impl NiriInputDevice for VirtualKeyboardDevice {
55 fn output(&self, _: &State) -> Option<Output> {
56 None
57 }
58}