Implement stub mutter-x11-interop
Browse files at this commit883763c17224c69094340d3abc2f9e4cb656966aParent: 9063a5d8 changed files +154 -2
- Cargo.lock +2 -0
- Cargo.toml +2 -0
- resources/mutter-x11-interop.xml +18 -0
- src/handlers/mod.rs +6 -2
- src/niri.rs +5 -0
- src/protocols/mod.rs +3 -0
- src/protocols/mutter_x11_interop.rs +93 -0
- src/protocols/raw.rs +25 -0
Cargo.lockmodified+2 -0
| @@ -2260,6 +2260,8 @@ dependencies = [ | |||
| 2260 | "tracing-subscriber", | 2260 | "tracing-subscriber", |
| 2261 | "tracy-client", | 2261 | "tracy-client", |
| 2262 | "url", | 2262 | "url", |
| 2263 | + "wayland-backend", | ||
| 2264 | + "wayland-scanner", | ||
| 2263 | "xcursor", | 2265 | "xcursor", |
| 2264 | "xshell", | 2266 | "xshell", |
| 2265 | "zbus", | 2267 | "zbus", |
Cargo.tomlmodified+2 -0
| @@ -78,6 +78,8 @@ tracing-subscriber.workspace = true | |||
| 78 | tracing.workspace = true | 78 | tracing.workspace = true |
| 79 | tracy-client.workspace = true | 79 | tracy-client.workspace = true |
| 80 | url = { version = "2.5.2", optional = true } | 80 | url = { version = "2.5.2", optional = true } |
| 81 | +wayland-backend = "0.3.6" | ||
| 82 | +wayland-scanner = "0.31.4" | ||
| 81 | xcursor = "0.3.6" | 83 | xcursor = "0.3.6" |
| 82 | zbus = { version = "~3.15.2", optional = true } | 84 | zbus = { version = "~3.15.2", optional = true } |
| 83 | 85 | ||
resources/mutter-x11-interop.xmladded+18 -0
| @@ -0,0 +1,18 @@ | |||
| 1 | +<?xml version="1.0" encoding="UTF-8"?> | ||
| 2 | +<protocol name="mutter_x11_interop"> | ||
| 3 | + <description summary="X11 interoperability helper"> | ||
| 4 | + This protocol is intended to be used by the portal backend to map Wayland | ||
| 5 | + dialogs as modal dialogs on top of X11 windows. | ||
| 6 | + </description> | ||
| 7 | + | ||
| 8 | + <interface name="mutter_x11_interop" version="1"> | ||
| 9 | + <description summary="X11 interoperability helper"/> | ||
| 10 | + | ||
| 11 | + <request name="destroy" type="destructor"/> | ||
| 12 | + | ||
| 13 | + <request name="set_x11_parent"> | ||
| 14 | + <arg name="surface" type="object" interface="wl_surface"/> | ||
| 15 | + <arg name="xwindow" type="uint"/> | ||
| 16 | + </request> | ||
| 17 | + </interface> | ||
| 18 | +</protocol> | ||
src/handlers/mod.rsmodified+6 -2
| @@ -69,12 +69,13 @@ use crate::protocols::foreign_toplevel::{ | |||
| 69 | self, ForeignToplevelHandler, ForeignToplevelManagerState, | 69 | self, ForeignToplevelHandler, ForeignToplevelManagerState, |
| 70 | }; | 70 | }; |
| 71 | use crate::protocols::gamma_control::{GammaControlHandler, GammaControlManagerState}; | 71 | use crate::protocols::gamma_control::{GammaControlHandler, GammaControlManagerState}; |
| 72 | +use crate::protocols::mutter_x11_interop::MutterX11InteropHandler; | ||
| 72 | use crate::protocols::output_management::{OutputManagementHandler, OutputManagementManagerState}; | 73 | use crate::protocols::output_management::{OutputManagementHandler, OutputManagementManagerState}; |
| 73 | use crate::protocols::screencopy::{Screencopy, ScreencopyHandler, ScreencopyManagerState}; | 74 | use crate::protocols::screencopy::{Screencopy, ScreencopyHandler, ScreencopyManagerState}; |
| 74 | use crate::utils::{output_size, send_scale_transform}; | 75 | use crate::utils::{output_size, send_scale_transform}; |
| 75 | use crate::{ | 76 | use crate::{ |
| 76 | - delegate_foreign_toplevel, delegate_gamma_control, delegate_output_management, | 77 | + delegate_foreign_toplevel, delegate_gamma_control, delegate_mutter_x11_interop, |
| 77 | - delegate_screencopy, | 78 | + delegate_output_management, delegate_screencopy, |
| 78 | }; | 79 | }; |
| 79 | 80 | ||
| 80 | impl SeatHandler for State { | 81 | impl SeatHandler for State { |
| @@ -580,3 +581,6 @@ impl OutputManagementHandler for State { | |||
| 580 | } | 581 | } |
| 581 | } | 582 | } |
| 582 | delegate_output_management!(State); | 583 | delegate_output_management!(State); |
| 584 | + | ||
| 585 | +impl MutterX11InteropHandler for State {} | ||
| 586 | +delegate_mutter_x11_interop!(State); | ||
src/niri.rsmodified+5 -0
| @@ -118,6 +118,7 @@ use crate::ipc::server::IpcServer; | |||
| 118 | use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement}; | 118 | use crate::layout::{Layout, LayoutElement as _, MonitorRenderElement}; |
| 119 | use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState}; | 119 | use crate::protocols::foreign_toplevel::{self, ForeignToplevelManagerState}; |
| 120 | use crate::protocols::gamma_control::GammaControlManagerState; | 120 | use crate::protocols::gamma_control::GammaControlManagerState; |
| 121 | +use crate::protocols::mutter_x11_interop::MutterX11InteropManagerState; | ||
| 121 | use crate::protocols::output_management::OutputManagementManagerState; | 122 | use crate::protocols::output_management::OutputManagementManagerState; |
| 122 | use crate::protocols::screencopy::{Screencopy, ScreencopyBuffer, ScreencopyManagerState}; | 123 | use crate::protocols::screencopy::{Screencopy, ScreencopyBuffer, ScreencopyManagerState}; |
| 123 | use crate::pw_utils::{Cast, PipeWire}; | 124 | use crate::pw_utils::{Cast, PipeWire}; |
| @@ -233,6 +234,7 @@ pub struct Niri { | |||
| 233 | pub security_context_state: SecurityContextState, | 234 | pub security_context_state: SecurityContextState, |
| 234 | pub gamma_control_manager_state: GammaControlManagerState, | 235 | pub gamma_control_manager_state: GammaControlManagerState, |
| 235 | pub activation_state: XdgActivationState, | 236 | pub activation_state: XdgActivationState, |
| 237 | + pub mutter_x11_interop_state: MutterX11InteropManagerState, | ||
| 236 | 238 | ||
| 237 | pub seat: Seat<State>, | 239 | pub seat: Seat<State>, |
| 238 | /// Scancodes of the keys to suppress. | 240 | /// Scancodes of the keys to suppress. |
| @@ -1602,6 +1604,8 @@ impl Niri { | |||
| 1602 | is_tty && !client.get_data::<ClientState>().unwrap().restricted | 1604 | is_tty && !client.get_data::<ClientState>().unwrap().restricted |
| 1603 | }); | 1605 | }); |
| 1604 | let activation_state = XdgActivationState::new::<State>(&display_handle); | 1606 | let activation_state = XdgActivationState::new::<State>(&display_handle); |
| 1607 | + let mutter_x11_interop_state = | ||
| 1608 | + MutterX11InteropManagerState::new::<State, _>(&display_handle, move |_| true); | ||
| 1605 | 1609 | ||
| 1606 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); | 1610 | let mut seat: Seat<State> = seat_state.new_wl_seat(&display_handle, backend.seat_name()); |
| 1607 | seat.add_keyboard( | 1611 | seat.add_keyboard( |
| @@ -1764,6 +1768,7 @@ impl Niri { | |||
| 1764 | security_context_state, | 1768 | security_context_state, |
| 1765 | gamma_control_manager_state, | 1769 | gamma_control_manager_state, |
| 1766 | activation_state, | 1770 | activation_state, |
| 1771 | + mutter_x11_interop_state, | ||
| 1767 | 1772 | ||
| 1768 | seat, | 1773 | seat, |
| 1769 | keyboard_focus: KeyboardFocus::Layout { surface: None }, | 1774 | keyboard_focus: KeyboardFocus::Layout { surface: None }, |
src/protocols/mod.rsmodified+3 -0
| @@ -1,4 +1,7 @@ | |||
| 1 | pub mod foreign_toplevel; | 1 | pub mod foreign_toplevel; |
| 2 | pub mod gamma_control; | 2 | pub mod gamma_control; |
| 3 | +pub mod mutter_x11_interop; | ||
| 3 | pub mod output_management; | 4 | pub mod output_management; |
| 4 | pub mod screencopy; | 5 | pub mod screencopy; |
| 6 | + | ||
| 7 | +pub mod raw; | ||
src/protocols/mutter_x11_interop.rsadded+93 -0
| @@ -0,0 +1,93 @@ | |||
| 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 | +} | ||
src/protocols/raw.rsadded+25 -0
| @@ -0,0 +1,25 @@ | |||
| 1 | +pub mod mutter_x11_interop { | ||
| 2 | + pub mod v1 { | ||
| 3 | + pub use self::generated::server; | ||
| 4 | + | ||
| 5 | + mod generated { | ||
| 6 | + pub mod server { | ||
| 7 | + #![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)] | ||
| 8 | + #![allow(non_upper_case_globals, non_snake_case, unused_imports)] | ||
| 9 | + #![allow(missing_docs, clippy::all)] | ||
| 10 | + | ||
| 11 | + use smithay::reexports::wayland_server; | ||
| 12 | + use wayland_server::protocol::*; | ||
| 13 | + | ||
| 14 | + pub mod __interfaces { | ||
| 15 | + use smithay::reexports::wayland_server; | ||
| 16 | + use wayland_server::protocol::__interfaces::*; | ||
| 17 | + wayland_scanner::generate_interfaces!("resources/mutter-x11-interop.xml"); | ||
| 18 | + } | ||
| 19 | + use self::__interfaces::*; | ||
| 20 | + | ||
| 21 | + wayland_scanner::generate_server_code!("resources/mutter-x11-interop.xml"); | ||
| 22 | + } | ||
| 23 | + } | ||
| 24 | + } | ||
| 25 | +} | ||