#![allow(clippy::too_many_arguments)]
#[allow(unused_imports)]
use std::borrow::Cow;
#[allow(unused_imports)]
use std::convert::TryInto;
#[allow(unused_imports)]
use crate::utils::RawFdContainer;
#[allow(unused_imports)]
use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
use std::io::IoSlice;
use crate::connection::RequestConnection;
#[allow(unused_imports)]
use crate::connection::Connection as X11Connection;
#[allow(unused_imports)]
use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
use crate::errors::ConnectionError;
#[allow(unused_imports)]
use crate::errors::ReplyOrIdError;
use std::future::Future;
use std::pin::Pin;
#[allow(unused_imports)]
use super::xfixes;
#[allow(unused_imports)]
use super::xproto;
pub use x11rb_protocol::protocol::damage::*;
async fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
let info = conn.extension_information(X11_EXTENSION_NAME).await?;
let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
Ok(info.major_opcode)
}
pub async fn query_version<Conn>(conn: &Conn, client_major_version: u32, client_minor_version: u32) -> Result<Cookie<'_, Conn, QueryVersionReply>, ConnectionError>
where
Conn: RequestConnection + ?Sized,
{
let request0 = QueryVersionRequest {
client_major_version,
client_minor_version,
};
let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
let slices = bytes.iter().map(|b| IoSlice::new(b)).collect::<Vec<_>>();
conn.send_request_with_reply(&slices, fds).await
}
pub async fn create<Conn>(conn: &Conn, damage: Damage, drawable: xproto::Drawable, level: ReportLevel) -> Result<VoidCookie<'_, Conn>, ConnectionError>
where
Conn: RequestConnection + ?Sized,
{
let request0 = CreateRequest {
damage,
drawable,
level,
};
let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
let slices = bytes.iter().map(|b| IoSlice::new(b)).collect::<Vec<_>>();
conn.send_request_without_reply(&slices, fds).await
}
pub async fn destroy<Conn>(conn: &Conn, damage: Damage) -> Result<VoidCookie<'_, Conn>, ConnectionError>
where
Conn: RequestConnection + ?Sized,
{
let request0 = DestroyRequest {
damage,
};
let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
let slices = bytes.iter().map(|b| IoSlice::new(b)).collect::<Vec<_>>();
conn.send_request_without_reply(&slices, fds).await
}
pub async fn subtract<Conn, A, B>(conn: &Conn, damage: Damage, repair: A, parts: B) -> Result<VoidCookie<'_, Conn>, ConnectionError>
where
Conn: RequestConnection + ?Sized,
A: Into<xfixes::Region> + Send,
B: Into<xfixes::Region> + Send,
{
let repair: xfixes::Region = repair.into();
let parts: xfixes::Region = parts.into();
let request0 = SubtractRequest {
damage,
repair,
parts,
};
let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
let slices = bytes.iter().map(|b| IoSlice::new(b)).collect::<Vec<_>>();
conn.send_request_without_reply(&slices, fds).await
}
pub async fn add<Conn>(conn: &Conn, drawable: xproto::Drawable, region: xfixes::Region) -> Result<VoidCookie<'_, Conn>, ConnectionError>
where
Conn: RequestConnection + ?Sized,
{
let request0 = AddRequest {
drawable,
region,
};
let (bytes, fds) = request0.serialize(major_opcode(conn).await?);
let slices = bytes.iter().map(|b| IoSlice::new(b)).collect::<Vec<_>>();
conn.send_request_without_reply(&slices, fds).await
}
pub trait ConnectionExt: RequestConnection {
fn damage_query_version(&self, client_major_version: u32, client_minor_version: u32) -> Pin<Box<dyn Future<Output = Result<Cookie<'_, Self, QueryVersionReply>, ConnectionError>> + Send + '_>>
{
Box::pin(query_version(self, client_major_version, client_minor_version))
}
fn damage_create(&self, damage: Damage, drawable: xproto::Drawable, level: ReportLevel) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
{
Box::pin(create(self, damage, drawable, level))
}
fn damage_destroy(&self, damage: Damage) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
{
Box::pin(destroy(self, damage))
}
fn damage_subtract<A, B>(&self, damage: Damage, repair: A, parts: B) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
where
A: Into<xfixes::Region> + Send + 'static,
B: Into<xfixes::Region> + Send + 'static,
{
Box::pin(subtract(self, damage, repair, parts))
}
fn damage_add(&self, drawable: xproto::Drawable, region: xfixes::Region) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
{
Box::pin(add(self, drawable, region))
}
}
impl<C: RequestConnection + ?Sized> ConnectionExt for C {}