niri
Clone
https://git.tahinli.com/Tahinli/niri.git
0 watching·0 forks·Rust·GPL-3.0·12.1 MiB·055a94d·Ivan Molodetskikh·1 year ago·2247 commits
| 1 | use mutter_x11_interop::MutterX11Interop; |
| 2 | use smithay::reexports::wayland_server::{ |
| 3 | Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, |
| 4 | }; |
| 5 | |
| 6 | use super::raw::mutter_x11_interop::v1::server::mutter_x11_interop; |
| 7 | |
| 8 | const VERSION: u32 = 1; |
| 9 | |
| 10 | pub struct MutterX11InteropManagerState {} |
| 11 | |
| 12 | pub struct MutterX11InteropManagerGlobalData { |
| 13 | filter: Box<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>, |
| 14 | } |
| 15 | |
| 16 | pub trait MutterX11InteropHandler {} |
| 17 | |
| 18 | impl MutterX11InteropManagerState { |
| 19 | pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self |
| 20 | where |
| 21 | D: GlobalDispatch<MutterX11Interop, MutterX11InteropManagerGlobalData>, |
| 22 | D: Dispatch<MutterX11Interop, ()>, |
| 23 | D: MutterX11InteropHandler, |
| 24 | D: 'static, |
| 25 | F: for<'c> Fn(&'c Client) -> bool + Send + Sync + 'static, |
| 26 | { |
| 27 | let global_data = MutterX11InteropManagerGlobalData { |
| 28 | filter: Box::new(filter), |
| 29 | }; |
| 30 | display.create_global::<D, MutterX11Interop, _>(VERSION, global_data); |
| 31 | |
| 32 | Self {} |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | impl<D> GlobalDispatch<MutterX11Interop, MutterX11InteropManagerGlobalData, D> |
| 37 | for MutterX11InteropManagerState |
| 38 | where |
| 39 | D: GlobalDispatch<MutterX11Interop, MutterX11InteropManagerGlobalData>, |
| 40 | D: Dispatch<MutterX11Interop, ()>, |
| 41 | D: MutterX11InteropHandler, |
| 42 | D: 'static, |
| 43 | { |
| 44 | fn bind( |
| 45 | _state: &mut D, |
| 46 | _handle: &DisplayHandle, |
| 47 | _client: &Client, |
| 48 | manager: New<MutterX11Interop>, |
| 49 | _manager_state: &MutterX11InteropManagerGlobalData, |
| 50 | data_init: &mut DataInit<'_, D>, |
| 51 | ) { |
| 52 | data_init.init(manager, ()); |
| 53 | } |
| 54 | |
| 55 | fn can_view(client: Client, global_data: &MutterX11InteropManagerGlobalData) -> bool { |
| 56 | (global_data.filter)(&client) |
| 57 | } |
| 58 | } |
| 59 | |
| 60 | impl<D> Dispatch<MutterX11Interop, (), D> for MutterX11InteropManagerState |
| 61 | where |
| 62 | D: Dispatch<MutterX11Interop, ()>, |
| 63 | D: MutterX11InteropHandler, |
| 64 | D: 'static, |
| 65 | { |
| 66 | fn request( |
| 67 | _state: &mut D, |
| 68 | _client: &Client, |
| 69 | _resource: &MutterX11Interop, |
| 70 | request: <MutterX11Interop as Resource>::Request, |
| 71 | _data: &(), |
| 72 | _dhandle: &DisplayHandle, |
| 73 | _data_init: &mut DataInit<'_, D>, |
| 74 | ) { |
| 75 | match request { |
| 76 | mutter_x11_interop::Request::Destroy => (), |
| 77 | mutter_x11_interop::Request::SetX11Parent { .. } => (), |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | #[macro_export] |
| 83 | macro_rules! delegate_mutter_x11_interop { |
| 84 | ($(@<$( $lt:tt $( : $clt:tt $(+ $dlt:tt )* )? ),+>)? $ty: ty) => { |
| 85 | smithay::reexports::wayland_server::delegate_global_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ |
| 86 | $crate::protocols::raw::mutter_x11_interop::v1::server::mutter_x11_interop::MutterX11Interop: $crate::protocols::mutter_x11_interop::MutterX11InteropManagerGlobalData |
| 87 | ] => $crate::protocols::mutter_x11_interop::MutterX11InteropManagerState); |
| 88 | |
| 89 | smithay::reexports::wayland_server::delegate_dispatch!($(@< $( $lt $( : $clt $(+ $dlt )* )? ),+ >)? $ty: [ |
| 90 | $crate::protocols::raw::mutter_x11_interop::v1::server::mutter_x11_interop::MutterX11Interop: () |
| 91 | ] => $crate::protocols::mutter_x11_interop::MutterX11InteropManagerState); |
| 92 | }; |
| 93 | } |