1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
// This file contains generated code. Do not edit directly.
// To regenerate this, run 'make'.

//! Bindings to the `Damage` X11 extension.

#![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::*;

/// Get the major opcode of this extension
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)
}

/// Negotiate the version of the DAMAGE extension.
///
/// This negotiates the version of the DAMAGE extension.  It must precede any other
/// request using the DAMAGE extension.  Failure to do so will cause a BadRequest
/// error for those requests.
///
/// # Fields
///
/// * `client_major_version` - The major version supported by the client.
/// * `client_minor_version` - The minor version supported by the client.
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 = [IoSlice::new(&bytes[0])];
    assert_eq!(slices.len(), bytes.len());
    conn.send_request_with_reply(&slices, fds).await
}
/// Creates a Damage object to monitor changes to a drawable..
///
/// This creates a Damage object to monitor changes to a drawable, and specifies
/// the level of detail to be reported for changes.
///
/// We call changes made to pixel contents of windows and pixmaps 'damage'
/// throughout this extension.
///
/// Damage accumulates as drawing occurs in the drawable.  Each drawing operation
/// 'damages' one or more rectangular areas within the drawable.  The rectangles
/// are guaranteed to include the set of pixels modified by each operation, but
/// may include significantly more than just those pixels.  The desire is for
/// the damage to strike a balance between the number of rectangles reported and
/// the extraneous area included.  A reasonable goal is for each primitive
/// object drawn (line, string, rectangle) to be represented as a single
/// rectangle and for the damage area of the operation to be the union of these
/// rectangles.
///
/// The DAMAGE extension allows applications to either receive the raw
/// rectangles as a stream of events, or to have them partially processed within
/// the X server to reduce the amount of data transmitted as well as reduce the
/// processing latency once the repaint operation has started.
///
/// The Damage object holds any accumulated damage region and reflects the
/// relationship between the drawable selected for damage notification and the
/// drawable for which damage is tracked.
///
/// # Fields
///
/// * `damage` - The ID with which you will refer to the new Damage object, created by
/// `xcb_generate_id`.
/// * `drawable` - The ID of the drawable to be monitored.
/// * `level` - The level of detail to be provided in Damage events.
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 = [IoSlice::new(&bytes[0])];
    assert_eq!(slices.len(), bytes.len());
    conn.send_request_without_reply(&slices, fds).await
}
/// Destroys a previously created Damage object..
///
/// This destroys a Damage object and requests the X server stop reporting
/// the changes it was tracking.
///
/// # Fields
///
/// * `damage` - The ID you provided to `xcb_create_damage`.
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 = [IoSlice::new(&bytes[0])];
    assert_eq!(slices.len(), bytes.len());
    conn.send_request_without_reply(&slices, fds).await
}
/// Remove regions from a previously created Damage object..
///
/// This updates the regions of damage recorded in a a Damage object.
/// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
/// for details.
///
/// # Fields
///
/// * `damage` - The ID you provided to `xcb_create_damage`.
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 = [IoSlice::new(&bytes[0])];
    assert_eq!(slices.len(), bytes.len());
    conn.send_request_without_reply(&slices, fds).await
}
/// Add a region to a previously created Damage object..
///
/// This updates the regions of damage recorded in a a Damage object.
/// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
/// for details.
///
/// # Fields
///
/// * `damage` - The ID you provided to `xcb_create_damage`.
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 = [IoSlice::new(&bytes[0])];
    assert_eq!(slices.len(), bytes.len());
    conn.send_request_without_reply(&slices, fds).await
}
/// Extension trait defining the requests of this extension.
pub trait ConnectionExt: RequestConnection {
    /// Negotiate the version of the DAMAGE extension.
    ///
    /// This negotiates the version of the DAMAGE extension.  It must precede any other
    /// request using the DAMAGE extension.  Failure to do so will cause a BadRequest
    /// error for those requests.
    ///
    /// # Fields
    ///
    /// * `client_major_version` - The major version supported by the client.
    /// * `client_minor_version` - The minor version supported by the client.
    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))
    }
    /// Creates a Damage object to monitor changes to a drawable..
    ///
    /// This creates a Damage object to monitor changes to a drawable, and specifies
    /// the level of detail to be reported for changes.
    ///
    /// We call changes made to pixel contents of windows and pixmaps 'damage'
    /// throughout this extension.
    ///
    /// Damage accumulates as drawing occurs in the drawable.  Each drawing operation
    /// 'damages' one or more rectangular areas within the drawable.  The rectangles
    /// are guaranteed to include the set of pixels modified by each operation, but
    /// may include significantly more than just those pixels.  The desire is for
    /// the damage to strike a balance between the number of rectangles reported and
    /// the extraneous area included.  A reasonable goal is for each primitive
    /// object drawn (line, string, rectangle) to be represented as a single
    /// rectangle and for the damage area of the operation to be the union of these
    /// rectangles.
    ///
    /// The DAMAGE extension allows applications to either receive the raw
    /// rectangles as a stream of events, or to have them partially processed within
    /// the X server to reduce the amount of data transmitted as well as reduce the
    /// processing latency once the repaint operation has started.
    ///
    /// The Damage object holds any accumulated damage region and reflects the
    /// relationship between the drawable selected for damage notification and the
    /// drawable for which damage is tracked.
    ///
    /// # Fields
    ///
    /// * `damage` - The ID with which you will refer to the new Damage object, created by
    /// `xcb_generate_id`.
    /// * `drawable` - The ID of the drawable to be monitored.
    /// * `level` - The level of detail to be provided in Damage events.
    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))
    }
    /// Destroys a previously created Damage object..
    ///
    /// This destroys a Damage object and requests the X server stop reporting
    /// the changes it was tracking.
    ///
    /// # Fields
    ///
    /// * `damage` - The ID you provided to `xcb_create_damage`.
    fn damage_destroy(&self, damage: Damage) -> Pin<Box<dyn Future<Output = Result<VoidCookie<'_, Self>, ConnectionError>> + Send + '_>>
    {
        Box::pin(destroy(self, damage))
    }
    /// Remove regions from a previously created Damage object..
    ///
    /// This updates the regions of damage recorded in a a Damage object.
    /// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
    /// for details.
    ///
    /// # Fields
    ///
    /// * `damage` - The ID you provided to `xcb_create_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))
    }
    /// Add a region to a previously created Damage object..
    ///
    /// This updates the regions of damage recorded in a a Damage object.
    /// See <https://www.x.org/releases/current/doc/damageproto/damageproto.txt>
    /// for details.
    ///
    /// # Fields
    ///
    /// * `damage` - The ID you provided to `xcb_create_damage`.
    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 {}