wayland_bridge/
dispatcher.rsuse crate::alpha_compositing::*;
use crate::aura_shell::*;
use crate::compositor::*;
use crate::data_device_manager::*;
use crate::display::*;
use crate::linux_dmabuf::*;
use crate::object::*;
use crate::output::*;
use crate::pointer_constraints::*;
use crate::registry::*;
use crate::relative_pointer::*;
use crate::seat::*;
use crate::secure_output::*;
use crate::shm::*;
use crate::subcompositor::*;
use crate::viewporter::*;
use crate::xdg_shell::*;
use anyhow::{Error, Result};
use fuchsia_sync::Mutex;
use std::io::Read;
use std::sync::Arc;
use wayland_server_protocol::{
WlCompositor, WlDataDeviceManager, WlOutput, WlSeat, WlShm, WlSubcompositor,
};
use wp_viewporter_server_protocol::WpViewporter;
use xdg_shell_server_protocol::XdgWmBase;
use zaura_shell_server_protocol::ZauraShell;
use zcr_alpha_compositing_v1_server_protocol::ZcrAlphaCompositingV1;
use zcr_secure_output_v1_server_protocol::ZcrSecureOutputV1;
use zwp_linux_dmabuf_v1_server_protocol::ZwpLinuxDmabufV1;
use zwp_pointer_constraints_v1_server_protocol::ZwpPointerConstraintsV1;
use zwp_relative_pointer_v1_server_protocol::ZwpRelativePointerManagerV1;
fn read_file_into_vmo(filename: &str) -> Result<zx::Vmo> {
let mut file = std::fs::File::open(filename)?;
let keymap_len = file.metadata()?.len();
let mut buffer = Vec::new();
file.read_to_end(&mut buffer)?;
let vmo = zx::Vmo::create(keymap_len)?;
vmo.write(&buffer, 0)?;
Ok(vmo)
}
pub struct WaylandDispatcher {
pub display: Display,
}
impl WaylandDispatcher {
pub fn new_local(client: Arc<Mutex<Box<dyn LocalViewProducerClient>>>) -> Result<Self, Error> {
let registry = WaylandDispatcher::new_registry()?;
let display = Display::new_local(registry, client)?;
Ok(WaylandDispatcher { display })
}
pub fn new() -> Result<Self, Error> {
let registry = WaylandDispatcher::new_registry()?;
let display = Display::new(registry)?;
Ok(WaylandDispatcher { display })
}
fn new_registry() -> Result<Registry, Error> {
let mut registry = RegistryBuilder::new();
registry.add_global(WlCompositor, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(Compositor::new())))
});
registry.add_global(WlSubcompositor, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(Subcompositor::new())))
});
registry.add_global(WlOutput, move |id, _, client| {
let output = Output::new();
let display_info = client.display().display_info();
Output::post_output_info(id, client, &display_info)?;
Output::post_output_done(id, client)?;
Ok(Box::new(RequestDispatcher::new(output)))
});
{
registry.add_global(WlSeat, move |id, version, client| {
let vmo = read_file_into_vmo("/pkg/data/keymap.xkb")?;
let seat = Seat::new(version, vmo);
seat.post_seat_info(id, version, client)?;
Ok(Box::new(RequestDispatcher::new(seat)))
});
}
registry.add_global(WlShm, move |id, _, client| {
let shm = Shm::new();
shm.post_formats(id, client)?;
Ok(Box::new(RequestDispatcher::new(shm)))
});
registry.add_global(WlDataDeviceManager, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(DataDeviceManager::new())))
});
registry.add_global(XdgWmBase, move |_, _, _| {
let xdg_shell = XdgShell::new();
Ok(Box::new(RequestDispatcher::new(xdg_shell)))
});
registry.add_global(ZwpLinuxDmabufV1, move |id, version, client| {
let linux_dmabuf = LinuxDmabuf::new(version);
linux_dmabuf.post_formats(id, client)?;
Ok(Box::new(RequestDispatcher::new(linux_dmabuf)))
});
registry.add_global(ZcrAlphaCompositingV1, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(AlphaCompositing::new())))
});
registry.add_global(ZcrSecureOutputV1, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(SecureOutput::new())))
});
registry.add_global(WpViewporter, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(Viewporter::new())))
});
registry.add_global(ZauraShell, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(AuraShell::new())))
});
registry.add_global(ZwpRelativePointerManagerV1, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(RelativePointerManager)))
});
registry.add_global(ZwpPointerConstraintsV1, move |_, _, _| {
Ok(Box::new(RequestDispatcher::new(PointerConstraints)))
});
Ok(registry.build())
}
}