#![warn(missing_docs)]
#[macro_use]
extern crate bitflags;
#[cfg(not(feature = "native_lib"))]
#[macro_use]
extern crate downcast_rs as downcast;
extern crate libc;
extern crate nix;
#[cfg(feature = "eventloop")]
extern crate calloop;
#[cfg(feature = "eventloop")]
extern crate mio;
extern crate wayland_commons;
#[cfg_attr(feature = "native_lib", macro_use)]
extern crate wayland_sys;
mod display;
mod event_queue;
mod globals;
mod proxy;
pub use display::{ConnectError, Display, ProtocolError};
pub use event_queue::{EventQueue, QueueToken, ReadEventsGuard};
pub use globals::{GlobalError, GlobalEvent, GlobalImplementor, GlobalManager};
pub use imp::ProxyMap;
pub use proxy::{HandledBy, NewProxy, Proxy};
#[cfg(feature = "cursor")]
pub mod cursor;
#[cfg(feature = "egl")]
pub mod egl;
pub mod sinks;
pub use anonymous_object::AnonymousObject;
pub use wayland_commons::{Interface, MessageGroup, NoMessage};
#[cfg(not(feature = "native_lib"))]
#[path = "rust_imp/mod.rs"]
mod imp;
#[cfg(feature = "native_lib")]
#[path = "native_lib/mod.rs"]
mod imp;
pub mod sys {
pub use wayland_sys::{client, common};
}
pub mod protocol {
#![allow(dead_code, non_camel_case_types, unused_unsafe, unused_variables)]
#![allow(non_upper_case_globals, non_snake_case, unused_imports)]
#![allow(missing_docs)]
#![cfg_attr(feature = "cargo-clippy", allow(clippy))]
pub(crate) use wayland_commons::map::{Object, ObjectMetadata};
pub(crate) use wayland_commons::wire::{Argument, ArgumentType, Message, MessageDesc};
pub(crate) use wayland_commons::{Interface, MessageGroup};
pub(crate) use wayland_sys as sys;
pub(crate) use {AnonymousObject, HandledBy, NewProxy, Proxy, ProxyMap};
include!(concat!(env!("OUT_DIR"), "/wayland_api.rs"));
}
mod anonymous_object {
use super::{Interface, NoMessage, Proxy};
#[derive(Clone, Eq, PartialEq)]
pub struct AnonymousObject(Proxy<AnonymousObject>);
impl Interface for AnonymousObject {
type Request = NoMessage;
type Event = NoMessage;
const NAME: &'static str = "<anonymous>";
const VERSION: u32 = 0;
fn c_interface() -> *const ::sys::common::wl_interface {
::std::ptr::null()
}
}
impl AsRef<Proxy<AnonymousObject>> for AnonymousObject {
#[inline]
fn as_ref(&self) -> &Proxy<Self> {
&self.0
}
}
impl From<Proxy<AnonymousObject>> for AnonymousObject {
#[inline]
fn from(proxy: Proxy<Self>) -> Self {
AnonymousObject(proxy)
}
}
impl From<AnonymousObject> for Proxy<AnonymousObject> {
#[inline]
fn from(value: AnonymousObject) -> Self {
value.0
}
}
}
#[cfg(feature = "eventloop")]
impl ::mio::event::Evented for EventQueue {
fn register(
&self,
poll: &::mio::Poll,
token: ::mio::Token,
interest: ::mio::Ready,
opts: ::mio::PollOpt,
) -> ::std::io::Result<()> {
let fd = self.inner.get_connection_fd();
::mio::unix::EventedFd(&fd).register(poll, token, interest, opts)
}
fn reregister(
&self,
poll: &::mio::Poll,
token: ::mio::Token,
interest: ::mio::Ready,
opts: ::mio::PollOpt,
) -> ::std::io::Result<()> {
let fd = self.inner.get_connection_fd();
::mio::unix::EventedFd(&fd).reregister(poll, token, interest, opts)
}
fn deregister(&self, poll: &::mio::Poll) -> ::std::io::Result<()> {
let fd = self.inner.get_connection_fd();
::mio::unix::EventedFd(&fd).deregister(poll)
}
}
#[cfg(feature = "eventloop")]
impl ::calloop::EventSource for EventQueue {
type Event = ();
fn interest(&self) -> ::mio::Ready {
::mio::Ready::readable()
}
fn pollopts(&self) -> ::mio::PollOpt {
::mio::PollOpt::edge()
}
fn make_dispatcher<Data: 'static, F: FnMut((), &mut Data) + 'static>(
&self,
_callback: F,
) -> ::std::rc::Rc<::std::cell::RefCell<::calloop::EventDispatcher<Data>>> {
struct Dispatcher {
inner: ::std::rc::Rc<::imp::EventQueueInner>,
}
impl<Data> ::calloop::EventDispatcher<Data> for Dispatcher {
fn ready(&mut self, _ready: ::mio::Ready, _data: &mut Data) {
if let Err(()) = self.inner.prepare_read() {
self.inner.dispatch_pending().unwrap();
} else {
match self.inner.read_events() {
Ok(_) => {
self.inner.dispatch_pending().unwrap();
}
Err(e) => match e.kind() {
::std::io::ErrorKind::WouldBlock => {}
_ => {
panic!("Failed to read from wayland socket: {}", e);
}
},
}
}
}
}
::std::rc::Rc::new(::std::cell::RefCell::new(Dispatcher {
inner: self.inner.clone(),
}))
}
}