azul_winit/platform_impl/linux/x11/util/
mod.rs1mod atom;
5mod client_msg;
6mod cursor;
7mod format;
8mod geometry;
9mod hint;
10mod icon;
11mod input;
12pub mod keys;
13mod memory;
14pub mod modifiers;
15mod randr;
16mod window_property;
17mod wm;
18
19pub use self::{
20 atom::*, client_msg::*, format::*, geometry::*, hint::*, icon::*, input::*, memory::*,
21 randr::*, window_property::*, wm::*,
22};
23
24use std::{
25 mem::{self, MaybeUninit},
26 ops::BitAnd,
27 os::raw::*,
28 ptr,
29};
30
31use super::{ffi, XConnection, XError};
32
33pub fn maybe_change<T: PartialEq>(field: &mut Option<T>, value: T) -> bool {
34 let wrapped = Some(value);
35 if *field != wrapped {
36 *field = wrapped;
37 true
38 } else {
39 false
40 }
41}
42
43pub fn has_flag<T>(bitset: T, flag: T) -> bool
44where
45 T: Copy + PartialEq + BitAnd<T, Output = T>,
46{
47 bitset & flag == flag
48}
49
50#[must_use = "This request was made asynchronously, and is still in the output buffer. You must explicitly choose to either `.flush()` (empty the output buffer, sending the request now) or `.queue()` (wait to send the request, allowing you to continue to add more requests without additional round-trips). For more information, see the documentation for `util::flush_requests`."]
51pub struct Flusher<'a> {
52 xconn: &'a XConnection,
53}
54
55impl<'a> Flusher<'a> {
56 pub fn new(xconn: &'a XConnection) -> Self {
57 Flusher { xconn }
58 }
59
60 pub fn flush(self) -> Result<(), XError> {
62 self.xconn.flush_requests()
63 }
64
65 pub fn sync(self) -> Result<(), XError> {
67 self.xconn.sync_with_server()
68 }
69
70 pub fn queue(self) {}
72}
73
74impl XConnection {
75 pub fn flush_requests(&self) -> Result<(), XError> {
85 unsafe { (self.xlib.XFlush)(self.display) };
86 self.check_errors()
90 }
91
92 pub fn sync_with_server(&self) -> Result<(), XError> {
93 unsafe { (self.xlib.XSync)(self.display, ffi::False) };
94 self.check_errors()
96 }
97}