x11rb/protocol/
sync.rs

1// This file contains generated code. Do not edit directly.
2// To regenerate this, run 'make'.
3
4//! Bindings to the `Sync` X11 extension.
5
6#![allow(clippy::too_many_arguments)]
7
8#[allow(unused_imports)]
9use std::borrow::Cow;
10#[allow(unused_imports)]
11use std::convert::TryInto;
12#[allow(unused_imports)]
13use crate::utils::RawFdContainer;
14#[allow(unused_imports)]
15use crate::x11_utils::{Request, RequestHeader, Serialize, TryParse, TryParseFd};
16use std::io::IoSlice;
17use crate::connection::RequestConnection;
18#[allow(unused_imports)]
19use crate::connection::Connection as X11Connection;
20#[allow(unused_imports)]
21use crate::cookie::{Cookie, CookieWithFds, VoidCookie};
22use crate::errors::ConnectionError;
23#[allow(unused_imports)]
24use crate::errors::ReplyOrIdError;
25#[allow(unused_imports)]
26use super::xproto;
27
28pub use x11rb_protocol::protocol::sync::*;
29
30/// Get the major opcode of this extension
31fn major_opcode<Conn: RequestConnection + ?Sized>(conn: &Conn) -> Result<u8, ConnectionError> {
32    let info = conn.extension_information(X11_EXTENSION_NAME)?;
33    let info = info.ok_or(ConnectionError::UnsupportedExtension)?;
34    Ok(info.major_opcode)
35}
36
37pub fn initialize<Conn>(conn: &Conn, desired_major_version: u8, desired_minor_version: u8) -> Result<Cookie<'_, Conn, InitializeReply>, ConnectionError>
38where
39    Conn: RequestConnection + ?Sized,
40{
41    let request0 = InitializeRequest {
42        desired_major_version,
43        desired_minor_version,
44    };
45    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
46    let slices = [IoSlice::new(&bytes[0])];
47    assert_eq!(slices.len(), bytes.len());
48    conn.send_request_with_reply(&slices, fds)
49}
50
51pub fn list_system_counters<Conn>(conn: &Conn) -> Result<Cookie<'_, Conn, ListSystemCountersReply>, ConnectionError>
52where
53    Conn: RequestConnection + ?Sized,
54{
55    let request0 = ListSystemCountersRequest;
56    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
57    let slices = [IoSlice::new(&bytes[0])];
58    assert_eq!(slices.len(), bytes.len());
59    conn.send_request_with_reply(&slices, fds)
60}
61
62pub fn create_counter<Conn>(conn: &Conn, id: Counter, initial_value: Int64) -> Result<VoidCookie<'_, Conn>, ConnectionError>
63where
64    Conn: RequestConnection + ?Sized,
65{
66    let request0 = CreateCounterRequest {
67        id,
68        initial_value,
69    };
70    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
71    let slices = [IoSlice::new(&bytes[0])];
72    assert_eq!(slices.len(), bytes.len());
73    conn.send_request_without_reply(&slices, fds)
74}
75
76pub fn destroy_counter<Conn>(conn: &Conn, counter: Counter) -> Result<VoidCookie<'_, Conn>, ConnectionError>
77where
78    Conn: RequestConnection + ?Sized,
79{
80    let request0 = DestroyCounterRequest {
81        counter,
82    };
83    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
84    let slices = [IoSlice::new(&bytes[0])];
85    assert_eq!(slices.len(), bytes.len());
86    conn.send_request_without_reply(&slices, fds)
87}
88
89pub fn query_counter<Conn>(conn: &Conn, counter: Counter) -> Result<Cookie<'_, Conn, QueryCounterReply>, ConnectionError>
90where
91    Conn: RequestConnection + ?Sized,
92{
93    let request0 = QueryCounterRequest {
94        counter,
95    };
96    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
97    let slices = [IoSlice::new(&bytes[0])];
98    assert_eq!(slices.len(), bytes.len());
99    conn.send_request_with_reply(&slices, fds)
100}
101
102pub fn await_<'c, 'input, Conn>(conn: &'c Conn, wait_list: &'input [Waitcondition]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
103where
104    Conn: RequestConnection + ?Sized,
105{
106    let request0 = AwaitRequest {
107        wait_list: Cow::Borrowed(wait_list),
108    };
109    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
110    let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
111    assert_eq!(slices.len(), bytes.len());
112    conn.send_request_without_reply(&slices, fds)
113}
114
115pub fn change_counter<Conn>(conn: &Conn, counter: Counter, amount: Int64) -> Result<VoidCookie<'_, Conn>, ConnectionError>
116where
117    Conn: RequestConnection + ?Sized,
118{
119    let request0 = ChangeCounterRequest {
120        counter,
121        amount,
122    };
123    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
124    let slices = [IoSlice::new(&bytes[0])];
125    assert_eq!(slices.len(), bytes.len());
126    conn.send_request_without_reply(&slices, fds)
127}
128
129pub fn set_counter<Conn>(conn: &Conn, counter: Counter, value: Int64) -> Result<VoidCookie<'_, Conn>, ConnectionError>
130where
131    Conn: RequestConnection + ?Sized,
132{
133    let request0 = SetCounterRequest {
134        counter,
135        value,
136    };
137    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
138    let slices = [IoSlice::new(&bytes[0])];
139    assert_eq!(slices.len(), bytes.len());
140    conn.send_request_without_reply(&slices, fds)
141}
142
143pub fn create_alarm<'c, 'input, Conn>(conn: &'c Conn, id: Alarm, value_list: &'input CreateAlarmAux) -> Result<VoidCookie<'c, Conn>, ConnectionError>
144where
145    Conn: RequestConnection + ?Sized,
146{
147    let request0 = CreateAlarmRequest {
148        id,
149        value_list: Cow::Borrowed(value_list),
150    };
151    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
152    let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
153    assert_eq!(slices.len(), bytes.len());
154    conn.send_request_without_reply(&slices, fds)
155}
156
157pub fn change_alarm<'c, 'input, Conn>(conn: &'c Conn, id: Alarm, value_list: &'input ChangeAlarmAux) -> Result<VoidCookie<'c, Conn>, ConnectionError>
158where
159    Conn: RequestConnection + ?Sized,
160{
161    let request0 = ChangeAlarmRequest {
162        id,
163        value_list: Cow::Borrowed(value_list),
164    };
165    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
166    let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
167    assert_eq!(slices.len(), bytes.len());
168    conn.send_request_without_reply(&slices, fds)
169}
170
171pub fn destroy_alarm<Conn>(conn: &Conn, alarm: Alarm) -> Result<VoidCookie<'_, Conn>, ConnectionError>
172where
173    Conn: RequestConnection + ?Sized,
174{
175    let request0 = DestroyAlarmRequest {
176        alarm,
177    };
178    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
179    let slices = [IoSlice::new(&bytes[0])];
180    assert_eq!(slices.len(), bytes.len());
181    conn.send_request_without_reply(&slices, fds)
182}
183
184pub fn query_alarm<Conn>(conn: &Conn, alarm: Alarm) -> Result<Cookie<'_, Conn, QueryAlarmReply>, ConnectionError>
185where
186    Conn: RequestConnection + ?Sized,
187{
188    let request0 = QueryAlarmRequest {
189        alarm,
190    };
191    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
192    let slices = [IoSlice::new(&bytes[0])];
193    assert_eq!(slices.len(), bytes.len());
194    conn.send_request_with_reply(&slices, fds)
195}
196
197pub fn set_priority<Conn>(conn: &Conn, id: u32, priority: i32) -> Result<VoidCookie<'_, Conn>, ConnectionError>
198where
199    Conn: RequestConnection + ?Sized,
200{
201    let request0 = SetPriorityRequest {
202        id,
203        priority,
204    };
205    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
206    let slices = [IoSlice::new(&bytes[0])];
207    assert_eq!(slices.len(), bytes.len());
208    conn.send_request_without_reply(&slices, fds)
209}
210
211pub fn get_priority<Conn>(conn: &Conn, id: u32) -> Result<Cookie<'_, Conn, GetPriorityReply>, ConnectionError>
212where
213    Conn: RequestConnection + ?Sized,
214{
215    let request0 = GetPriorityRequest {
216        id,
217    };
218    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
219    let slices = [IoSlice::new(&bytes[0])];
220    assert_eq!(slices.len(), bytes.len());
221    conn.send_request_with_reply(&slices, fds)
222}
223
224pub fn create_fence<Conn>(conn: &Conn, drawable: xproto::Drawable, fence: Fence, initially_triggered: bool) -> Result<VoidCookie<'_, Conn>, ConnectionError>
225where
226    Conn: RequestConnection + ?Sized,
227{
228    let request0 = CreateFenceRequest {
229        drawable,
230        fence,
231        initially_triggered,
232    };
233    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
234    let slices = [IoSlice::new(&bytes[0])];
235    assert_eq!(slices.len(), bytes.len());
236    conn.send_request_without_reply(&slices, fds)
237}
238
239pub fn trigger_fence<Conn>(conn: &Conn, fence: Fence) -> Result<VoidCookie<'_, Conn>, ConnectionError>
240where
241    Conn: RequestConnection + ?Sized,
242{
243    let request0 = TriggerFenceRequest {
244        fence,
245    };
246    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
247    let slices = [IoSlice::new(&bytes[0])];
248    assert_eq!(slices.len(), bytes.len());
249    conn.send_request_without_reply(&slices, fds)
250}
251
252pub fn reset_fence<Conn>(conn: &Conn, fence: Fence) -> Result<VoidCookie<'_, Conn>, ConnectionError>
253where
254    Conn: RequestConnection + ?Sized,
255{
256    let request0 = ResetFenceRequest {
257        fence,
258    };
259    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
260    let slices = [IoSlice::new(&bytes[0])];
261    assert_eq!(slices.len(), bytes.len());
262    conn.send_request_without_reply(&slices, fds)
263}
264
265pub fn destroy_fence<Conn>(conn: &Conn, fence: Fence) -> Result<VoidCookie<'_, Conn>, ConnectionError>
266where
267    Conn: RequestConnection + ?Sized,
268{
269    let request0 = DestroyFenceRequest {
270        fence,
271    };
272    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
273    let slices = [IoSlice::new(&bytes[0])];
274    assert_eq!(slices.len(), bytes.len());
275    conn.send_request_without_reply(&slices, fds)
276}
277
278pub fn query_fence<Conn>(conn: &Conn, fence: Fence) -> Result<Cookie<'_, Conn, QueryFenceReply>, ConnectionError>
279where
280    Conn: RequestConnection + ?Sized,
281{
282    let request0 = QueryFenceRequest {
283        fence,
284    };
285    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
286    let slices = [IoSlice::new(&bytes[0])];
287    assert_eq!(slices.len(), bytes.len());
288    conn.send_request_with_reply(&slices, fds)
289}
290
291pub fn await_fence<'c, 'input, Conn>(conn: &'c Conn, fence_list: &'input [Fence]) -> Result<VoidCookie<'c, Conn>, ConnectionError>
292where
293    Conn: RequestConnection + ?Sized,
294{
295    let request0 = AwaitFenceRequest {
296        fence_list: Cow::Borrowed(fence_list),
297    };
298    let (bytes, fds) = request0.serialize(major_opcode(conn)?);
299    let slices = [IoSlice::new(&bytes[0]), IoSlice::new(&bytes[1]), IoSlice::new(&bytes[2])];
300    assert_eq!(slices.len(), bytes.len());
301    conn.send_request_without_reply(&slices, fds)
302}
303
304/// Extension trait defining the requests of this extension.
305pub trait ConnectionExt: RequestConnection {
306    fn sync_initialize(&self, desired_major_version: u8, desired_minor_version: u8) -> Result<Cookie<'_, Self, InitializeReply>, ConnectionError>
307    {
308        initialize(self, desired_major_version, desired_minor_version)
309    }
310    fn sync_list_system_counters(&self) -> Result<Cookie<'_, Self, ListSystemCountersReply>, ConnectionError>
311    {
312        list_system_counters(self)
313    }
314    fn sync_create_counter(&self, id: Counter, initial_value: Int64) -> Result<VoidCookie<'_, Self>, ConnectionError>
315    {
316        create_counter(self, id, initial_value)
317    }
318    fn sync_destroy_counter(&self, counter: Counter) -> Result<VoidCookie<'_, Self>, ConnectionError>
319    {
320        destroy_counter(self, counter)
321    }
322    fn sync_query_counter(&self, counter: Counter) -> Result<Cookie<'_, Self, QueryCounterReply>, ConnectionError>
323    {
324        query_counter(self, counter)
325    }
326    fn sync_await_<'c, 'input>(&'c self, wait_list: &'input [Waitcondition]) -> Result<VoidCookie<'c, Self>, ConnectionError>
327    {
328        await_(self, wait_list)
329    }
330    fn sync_change_counter(&self, counter: Counter, amount: Int64) -> Result<VoidCookie<'_, Self>, ConnectionError>
331    {
332        change_counter(self, counter, amount)
333    }
334    fn sync_set_counter(&self, counter: Counter, value: Int64) -> Result<VoidCookie<'_, Self>, ConnectionError>
335    {
336        set_counter(self, counter, value)
337    }
338    fn sync_create_alarm<'c, 'input>(&'c self, id: Alarm, value_list: &'input CreateAlarmAux) -> Result<VoidCookie<'c, Self>, ConnectionError>
339    {
340        create_alarm(self, id, value_list)
341    }
342    fn sync_change_alarm<'c, 'input>(&'c self, id: Alarm, value_list: &'input ChangeAlarmAux) -> Result<VoidCookie<'c, Self>, ConnectionError>
343    {
344        change_alarm(self, id, value_list)
345    }
346    fn sync_destroy_alarm(&self, alarm: Alarm) -> Result<VoidCookie<'_, Self>, ConnectionError>
347    {
348        destroy_alarm(self, alarm)
349    }
350    fn sync_query_alarm(&self, alarm: Alarm) -> Result<Cookie<'_, Self, QueryAlarmReply>, ConnectionError>
351    {
352        query_alarm(self, alarm)
353    }
354    fn sync_set_priority(&self, id: u32, priority: i32) -> Result<VoidCookie<'_, Self>, ConnectionError>
355    {
356        set_priority(self, id, priority)
357    }
358    fn sync_get_priority(&self, id: u32) -> Result<Cookie<'_, Self, GetPriorityReply>, ConnectionError>
359    {
360        get_priority(self, id)
361    }
362    fn sync_create_fence(&self, drawable: xproto::Drawable, fence: Fence, initially_triggered: bool) -> Result<VoidCookie<'_, Self>, ConnectionError>
363    {
364        create_fence(self, drawable, fence, initially_triggered)
365    }
366    fn sync_trigger_fence(&self, fence: Fence) -> Result<VoidCookie<'_, Self>, ConnectionError>
367    {
368        trigger_fence(self, fence)
369    }
370    fn sync_reset_fence(&self, fence: Fence) -> Result<VoidCookie<'_, Self>, ConnectionError>
371    {
372        reset_fence(self, fence)
373    }
374    fn sync_destroy_fence(&self, fence: Fence) -> Result<VoidCookie<'_, Self>, ConnectionError>
375    {
376        destroy_fence(self, fence)
377    }
378    fn sync_query_fence(&self, fence: Fence) -> Result<Cookie<'_, Self, QueryFenceReply>, ConnectionError>
379    {
380        query_fence(self, fence)
381    }
382    fn sync_await_fence<'c, 'input>(&'c self, fence_list: &'input [Fence]) -> Result<VoidCookie<'c, Self>, ConnectionError>
383    {
384        await_fence(self, fence_list)
385    }
386}
387
388impl<C: RequestConnection + ?Sized> ConnectionExt for C {}
389
390/// A RAII-like wrapper around a [Counter].
391///
392/// Instances of this struct represent a Counter that is freed in `Drop`.
393///
394/// Any errors during `Drop` are silently ignored. Most likely an error here means that your
395/// X11 connection is broken and later requests will also fail.
396#[derive(Debug)]
397pub struct CounterWrapper<C: RequestConnection>(C, Counter);
398
399impl<C: RequestConnection> CounterWrapper<C>
400{
401    /// Assume ownership of the given resource and destroy it in `Drop`.
402    pub fn for_counter(conn: C, id: Counter) -> Self {
403        CounterWrapper(conn, id)
404    }
405
406    /// Get the XID of the wrapped resource
407    pub fn counter(&self) -> Counter {
408        self.1
409    }
410
411    /// Assume ownership of the XID of the wrapped resource
412    ///
413    /// This function destroys this wrapper without freeing the underlying resource.
414    pub fn into_counter(self) -> Counter {
415        let id = self.1;
416        std::mem::forget(self);
417        id
418    }
419}
420
421impl<'c, C: X11Connection> CounterWrapper<&'c C>
422{
423    /// Create a new Counter and return a Counter wrapper and a cookie.
424    ///
425    /// This is a thin wrapper around [create_counter] that allocates an id for the Counter.
426    /// This function returns the resulting `CounterWrapper` that owns the created Counter and frees
427    /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
428    /// [create_counter].
429    ///
430    /// Errors can come from the call to [X11Connection::generate_id] or [create_counter].
431    pub fn create_counter_and_get_cookie(conn: &'c C, initial_value: Int64) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
432    {
433        let id = conn.generate_id()?;
434        let cookie = create_counter(conn, id, initial_value)?;
435        Ok((Self::for_counter(conn, id), cookie))
436    }
437}
438impl<C: X11Connection> CounterWrapper<C>
439{
440    /// Create a new Counter and return a Counter wrapper
441    ///
442    /// This is a thin wrapper around [create_counter] that allocates an id for the Counter.
443    /// This function returns the resulting `CounterWrapper` that owns the created Counter and frees
444    /// it in `Drop`.
445    ///
446    /// Errors can come from the call to [X11Connection::generate_id] or [create_counter].
447    pub fn create_counter(conn: C, initial_value: Int64) -> Result<Self, ReplyOrIdError>
448    {
449        let id = conn.generate_id()?;
450        let _ = create_counter(&conn, id, initial_value)?;
451        Ok(Self::for_counter(conn, id))
452    }
453}
454
455impl<C: RequestConnection> From<&CounterWrapper<C>> for Counter {
456    fn from(from: &CounterWrapper<C>) -> Self {
457        from.1
458    }
459}
460
461impl<C: RequestConnection> Drop for CounterWrapper<C> {
462    fn drop(&mut self) {
463        let _ = destroy_counter(&self.0, self.1);
464    }
465}
466
467/// A RAII-like wrapper around a [Alarm].
468///
469/// Instances of this struct represent a Alarm that is freed in `Drop`.
470///
471/// Any errors during `Drop` are silently ignored. Most likely an error here means that your
472/// X11 connection is broken and later requests will also fail.
473#[derive(Debug)]
474pub struct AlarmWrapper<C: RequestConnection>(C, Alarm);
475
476impl<C: RequestConnection> AlarmWrapper<C>
477{
478    /// Assume ownership of the given resource and destroy it in `Drop`.
479    pub fn for_alarm(conn: C, id: Alarm) -> Self {
480        AlarmWrapper(conn, id)
481    }
482
483    /// Get the XID of the wrapped resource
484    pub fn alarm(&self) -> Alarm {
485        self.1
486    }
487
488    /// Assume ownership of the XID of the wrapped resource
489    ///
490    /// This function destroys this wrapper without freeing the underlying resource.
491    pub fn into_alarm(self) -> Alarm {
492        let id = self.1;
493        std::mem::forget(self);
494        id
495    }
496}
497
498impl<'c, C: X11Connection> AlarmWrapper<&'c C>
499{
500    /// Create a new Alarm and return a Alarm wrapper and a cookie.
501    ///
502    /// This is a thin wrapper around [create_alarm] that allocates an id for the Alarm.
503    /// This function returns the resulting `AlarmWrapper` that owns the created Alarm and frees
504    /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
505    /// [create_alarm].
506    ///
507    /// Errors can come from the call to [X11Connection::generate_id] or [create_alarm].
508    pub fn create_alarm_and_get_cookie(conn: &'c C, value_list: &CreateAlarmAux) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
509    {
510        let id = conn.generate_id()?;
511        let cookie = create_alarm(conn, id, value_list)?;
512        Ok((Self::for_alarm(conn, id), cookie))
513    }
514}
515impl<C: X11Connection> AlarmWrapper<C>
516{
517    /// Create a new Alarm and return a Alarm wrapper
518    ///
519    /// This is a thin wrapper around [create_alarm] that allocates an id for the Alarm.
520    /// This function returns the resulting `AlarmWrapper` that owns the created Alarm and frees
521    /// it in `Drop`.
522    ///
523    /// Errors can come from the call to [X11Connection::generate_id] or [create_alarm].
524    pub fn create_alarm(conn: C, value_list: &CreateAlarmAux) -> Result<Self, ReplyOrIdError>
525    {
526        let id = conn.generate_id()?;
527        let _ = create_alarm(&conn, id, value_list)?;
528        Ok(Self::for_alarm(conn, id))
529    }
530}
531
532impl<C: RequestConnection> From<&AlarmWrapper<C>> for Alarm {
533    fn from(from: &AlarmWrapper<C>) -> Self {
534        from.1
535    }
536}
537
538impl<C: RequestConnection> Drop for AlarmWrapper<C> {
539    fn drop(&mut self) {
540        let _ = destroy_alarm(&self.0, self.1);
541    }
542}
543
544/// A RAII-like wrapper around a [Fence].
545///
546/// Instances of this struct represent a Fence that is freed in `Drop`.
547///
548/// Any errors during `Drop` are silently ignored. Most likely an error here means that your
549/// X11 connection is broken and later requests will also fail.
550#[derive(Debug)]
551pub struct FenceWrapper<C: RequestConnection>(C, Fence);
552
553impl<C: RequestConnection> FenceWrapper<C>
554{
555    /// Assume ownership of the given resource and destroy it in `Drop`.
556    pub fn for_fence(conn: C, id: Fence) -> Self {
557        FenceWrapper(conn, id)
558    }
559
560    /// Get the XID of the wrapped resource
561    pub fn fence(&self) -> Fence {
562        self.1
563    }
564
565    /// Assume ownership of the XID of the wrapped resource
566    ///
567    /// This function destroys this wrapper without freeing the underlying resource.
568    pub fn into_fence(self) -> Fence {
569        let id = self.1;
570        std::mem::forget(self);
571        id
572    }
573}
574
575impl<'c, C: X11Connection> FenceWrapper<&'c C>
576{
577    /// Create a new Fence and return a Fence wrapper and a cookie.
578    ///
579    /// This is a thin wrapper around [create_fence] that allocates an id for the Fence.
580    /// This function returns the resulting `FenceWrapper` that owns the created Fence and frees
581    /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
582    /// [create_fence].
583    ///
584    /// Errors can come from the call to [X11Connection::generate_id] or [create_fence].
585    pub fn create_fence_and_get_cookie(conn: &'c C, drawable: xproto::Drawable, initially_triggered: bool) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
586    {
587        let fence = conn.generate_id()?;
588        let cookie = create_fence(conn, drawable, fence, initially_triggered)?;
589        Ok((Self::for_fence(conn, fence), cookie))
590    }
591}
592impl<C: X11Connection> FenceWrapper<C>
593{
594    /// Create a new Fence and return a Fence wrapper
595    ///
596    /// This is a thin wrapper around [create_fence] that allocates an id for the Fence.
597    /// This function returns the resulting `FenceWrapper` that owns the created Fence and frees
598    /// it in `Drop`.
599    ///
600    /// Errors can come from the call to [X11Connection::generate_id] or [create_fence].
601    pub fn create_fence(conn: C, drawable: xproto::Drawable, initially_triggered: bool) -> Result<Self, ReplyOrIdError>
602    {
603        let fence = conn.generate_id()?;
604        let _ = create_fence(&conn, drawable, fence, initially_triggered)?;
605        Ok(Self::for_fence(conn, fence))
606    }
607}
608
609impl<'c, C: X11Connection> FenceWrapper<&'c C>
610{
611    /// Create a new Fence and return a Fence wrapper and a cookie.
612    ///
613    /// This is a thin wrapper around [super::dri3::fence_from_fd] that allocates an id for the Fence.
614    /// This function returns the resulting `FenceWrapper` that owns the created Fence and frees
615    /// it in `Drop`. This also returns a `VoidCookie` that comes from the call to
616    /// [super::dri3::fence_from_fd].
617    ///
618    /// Errors can come from the call to [X11Connection::generate_id] or [super::dri3::fence_from_fd].
619    #[cfg(feature = "dri3")]
620    pub fn dri3_fence_from_fd_and_get_cookie<A>(conn: &'c C, drawable: xproto::Drawable, initially_triggered: bool, fence_fd: A) -> Result<(Self, VoidCookie<'c, C>), ReplyOrIdError>
621    where
622        A: Into<RawFdContainer>,
623    {
624        let fence = conn.generate_id()?;
625        let cookie = super::dri3::fence_from_fd(conn, drawable, fence, initially_triggered, fence_fd)?;
626        Ok((Self::for_fence(conn, fence), cookie))
627    }
628}
629impl<C: X11Connection> FenceWrapper<C>
630{
631    /// Create a new Fence and return a Fence wrapper
632    ///
633    /// This is a thin wrapper around [super::dri3::fence_from_fd] that allocates an id for the Fence.
634    /// This function returns the resulting `FenceWrapper` that owns the created Fence and frees
635    /// it in `Drop`.
636    ///
637    /// Errors can come from the call to [X11Connection::generate_id] or [super::dri3::fence_from_fd].
638    #[cfg(feature = "dri3")]
639    pub fn dri3_fence_from_fd<A>(conn: C, drawable: xproto::Drawable, initially_triggered: bool, fence_fd: A) -> Result<Self, ReplyOrIdError>
640    where
641        A: Into<RawFdContainer>,
642    {
643        let fence = conn.generate_id()?;
644        let _ = super::dri3::fence_from_fd(&conn, drawable, fence, initially_triggered, fence_fd)?;
645        Ok(Self::for_fence(conn, fence))
646    }
647}
648
649#[cfg(feature = "dri3")]
650#[allow(unused_imports)]
651use super::dri3;
652impl<C: RequestConnection> From<&FenceWrapper<C>> for Fence {
653    fn from(from: &FenceWrapper<C>) -> Self {
654        from.1
655    }
656}
657
658impl<C: RequestConnection> Drop for FenceWrapper<C> {
659    fn drop(&mut self) {
660        let _ = destroy_fence(&self.0, self.1);
661    }
662}