| 1 | use mutter_x11_interop::MutterX11Interop; |
| 2 | use smithay::reexports::wayland_server::{ |
| 3 | Client, DataInit, Dispatch, DisplayHandle, GlobalDispatch, New, Resource, |
| 4 | }; |
| 5 | use smithay::wayland::{Dispatch2, GlobalData, GlobalDispatch2}; |
| 6 | |
| 7 | use super::raw::mutter_x11_interop::v1::server::mutter_x11_interop; |
| 8 | |
| 9 | const VERSION: u32 = 1; |
| 10 | |
| 11 | pub struct MutterX11InteropManagerState {} |
| 12 | |
| 13 | pub struct MutterX11InteropManagerGlobalData { |
| 14 | filter: Box<dyn for<'c> Fn(&'c Client) -> bool + Send + Sync>, |
| 15 | } |
| 16 | |
| 17 | pub trait MutterX11InteropHandler {} |
| 18 | |
| 19 | impl MutterX11InteropManagerState { |
| 20 | pub fn new<D, F>(display: &DisplayHandle, filter: F) -> Self |
| 21 | where |
| 22 | D: GlobalDispatch<MutterX11Interop, MutterX11InteropManagerGlobalData>, |
| 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> GlobalDispatch2<MutterX11Interop, D> for MutterX11InteropManagerGlobalData |
| 37 | where |
| 38 | D: Dispatch<MutterX11Interop, GlobalData>, |
| 39 | D: MutterX11InteropHandler, |
| 40 | { |
| 41 | fn bind( |
| 42 | &self, |
| 43 | _state: &mut D, |
| 44 | _handle: &DisplayHandle, |
| 45 | _client: &Client, |
| 46 | manager: New<MutterX11Interop>, |
| 47 | data_init: &mut DataInit<'_, D>, |
| 48 | ) { |
| 49 | data_init.init(manager, GlobalData); |
| 50 | } |
| 51 | |
| 52 | fn can_view(&self, client: &Client) -> bool { |
| 53 | (self.filter)(client) |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | impl<D> Dispatch2<MutterX11Interop, D> for GlobalData |
| 58 | where |
| 59 | D: MutterX11InteropHandler, |
| 60 | { |
| 61 | fn request( |
| 62 | &self, |
| 63 | _state: &mut D, |
| 64 | _client: &Client, |
| 65 | _resource: &MutterX11Interop, |
| 66 | request: <MutterX11Interop as Resource>::Request, |
| 67 | _dhandle: &DisplayHandle, |
| 68 | _data_init: &mut DataInit<'_, D>, |
| 69 | ) { |
| 70 | match request { |
| 71 | mutter_x11_interop::Request::Destroy => (), |
| 72 | mutter_x11_interop::Request::SetX11Parent { .. } => (), |
| 73 | } |
| 74 | } |
| 75 | } |