use crate::base::{self, BaseError, BaseEvent, GeEvent, Raw, Reply, WiredIn, WiredOut, Xid};
use crate::ext;
use crate::ffi::base::*;
use crate::ffi::ext::*;
use crate::lat1_str::{Lat1Str, Lat1String, Lat1StrF};
use crate::xproto;
use crate::randr;
use crate::render;
use crate::xfixes;
use crate::shape;
use crate::sync;
use crate::xproto::PropEl;
use bitflags::bitflags;
use libc::{self, iovec};
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
use std::os::unix::io::RawFd;
pub const XNAME: &str = "Present";
pub const MAJOR_VERSION: u32 = 1;
pub const MINOR_VERSION: u32 = 2;
pub const VERSION_STRING: &str = "1.2";
pub(crate) static mut FFI_EXT: xcb_extension_t = xcb_extension_t {
name: "Present\0".as_ptr() as *const _,
global_id: 0,
};
pub fn prefetch_extension_data(conn: &base::Connection) {
unsafe {
xcb_prefetch_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
}
}
pub fn get_extension_data(conn: &base::Connection) -> std::option::Option<ext::ExtensionData> {
unsafe {
let reply = xcb_get_extension_data(conn.get_raw_conn(), &mut FFI_EXT as *mut _);
assert!(!reply.is_null(), "Could not fetch Present extension data");
let reply = xproto::QueryExtensionReply::from_raw(reply);
if !reply.present() {
std::mem::forget(reply);
return None;
}
let res = ext::ExtensionData{
ext: ext::Extension::Present,
major_opcode: reply.major_opcode(),
first_event: reply.first_event(),
first_error: reply.first_error(),
};
std::mem::forget(reply);
Some(res)
}
}
pub struct GenericEvent {
raw: *mut xcb_generic_event_t,
}
impl base::Raw<xcb_generic_event_t> for GenericEvent {
unsafe fn from_raw(raw: *mut xcb_generic_event_t) -> Self { GenericEvent { raw } }
fn as_raw(&self) -> *mut xcb_generic_event_t {
self.raw
}
}
impl base::BaseEvent for GenericEvent {
const EXTENSION: std::option::Option<ext::Extension> = Some(ext::Extension::Present);
const NUMBER: u32 = 0;
}
impl GenericEvent {
pub fn new(event_base: u8,
extension: u8,
length: u32,
evtype: u16,
event: EventXid,
) -> GenericEvent {
unsafe {
let ptr = libc::malloc(32) as *mut u8;
let wire_buf = std::slice::from_raw_parts_mut(ptr, 32);
let mut wire_off = 0usize;
let response_type = event_base;
let sequence = 0u16;
wire_off += response_type.serialize(&mut wire_buf[wire_off ..]);
wire_off += extension.serialize(&mut wire_buf[wire_off ..]);
wire_off += sequence.serialize(&mut wire_buf[wire_off ..]);
wire_off += length.serialize(&mut wire_buf[wire_off ..]);
wire_off += evtype.serialize(&mut wire_buf[wire_off ..]);
wire_off += 2usize;
event.serialize(&mut wire_buf[wire_off ..]);
GenericEvent::from_raw(ptr as *mut xcb_generic_event_t)
}
}
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn extension(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn evtype(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn event(&self) -> EventXid {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const EventXid;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for GenericEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("GenericEvent")
.field("response_type", &self.response_type())
.field("extension", &self.extension())
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("evtype", &self.evtype())
.field("pad", &2)
.field("event", &self.event())
.finish()
}
}
impl base::WiredOut for GenericEvent {
fn wire_len(&self) -> usize {
32usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for GenericEvent {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize {
32
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_generic_event_t;
std::ptr::copy(ptr as *const xcb_generic_event_t, raw, sz);
GenericEvent { raw }
}
}
impl Drop for GenericEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for GenericEvent {}
unsafe impl Sync for GenericEvent {}
pub struct ConfigureNotifyEvent {
raw: *mut xcb_ge_generic_event_t,
}
impl base::Raw<xcb_ge_generic_event_t> for ConfigureNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_ge_generic_event_t) -> Self { ConfigureNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_ge_generic_event_t {
self.raw
}
}
impl base::GeEvent for ConfigureNotifyEvent {
const EXTENSION: ext::Extension = ext::Extension::Present;
const NUMBER: u32 = 0;
}
impl ConfigureNotifyEvent {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn extension(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn event_type(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn event(&self) -> EventXid {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const EventXid;
base::value_from_ptr(ptr)
}
}
pub fn window(&self) -> xproto::Window {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Window;
base::value_from_ptr(ptr)
}
}
pub fn x(&self) -> i16 {
unsafe {
let offset = 20usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn y(&self) -> i16 {
unsafe {
let offset = 22usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn width(&self) -> u16 {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn height(&self) -> u16 {
unsafe {
let offset = 26usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn off_x(&self) -> i16 {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn off_y(&self) -> i16 {
unsafe {
let offset = 30usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn full_sequence(&self) -> u32 {
unsafe {
let offset = 32usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn pixmap_width(&self) -> u16 {
unsafe {
let offset = 36usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn pixmap_height(&self) -> u16 {
unsafe {
let offset = 38usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn pixmap_flags(&self) -> u32 {
unsafe {
let offset = 40usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for ConfigureNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ConfigureNotifyEvent")
.field("response_type", &self.response_type())
.field("extension", &self.extension())
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("event_type", &self.event_type())
.field("pad", &2)
.field("event", &self.event())
.field("window", &self.window())
.field("x", &self.x())
.field("y", &self.y())
.field("width", &self.width())
.field("height", &self.height())
.field("off_x", &self.off_x())
.field("off_y", &self.off_y())
.field("full_sequence", &self.full_sequence())
.field("pixmap_width", &self.pixmap_width())
.field("pixmap_height", &self.pixmap_height())
.field("pixmap_flags", &self.pixmap_flags())
.finish()
}
}
impl base::WiredOut for ConfigureNotifyEvent {
fn wire_len(&self) -> usize {
32 + 4 * self.length() as usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for ConfigureNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
32 + 4 * (*(ptr.add(4) as *const u32) as usize)
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_ge_generic_event_t;
std::ptr::copy(ptr as *const xcb_ge_generic_event_t, raw, sz);
ConfigureNotifyEvent { raw }
}
}
impl Drop for ConfigureNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for ConfigureNotifyEvent {}
unsafe impl Sync for ConfigureNotifyEvent {}
pub struct CompleteNotifyEvent {
raw: *mut xcb_ge_generic_event_t,
}
impl base::Raw<xcb_ge_generic_event_t> for CompleteNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_ge_generic_event_t) -> Self { CompleteNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_ge_generic_event_t {
self.raw
}
}
impl base::GeEvent for CompleteNotifyEvent {
const EXTENSION: ext::Extension = ext::Extension::Present;
const NUMBER: u32 = 1;
}
impl CompleteNotifyEvent {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn extension(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn event_type(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn kind(&self) -> CompleteKind {
unsafe {
let offset = 10usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, CompleteKind>(val)
}
}
pub fn mode(&self) -> CompleteMode {
unsafe {
let offset = 11usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
let val = base::value_from_ptr(ptr) as u32;
std::mem::transmute::<u32, CompleteMode>(val)
}
}
pub fn event(&self) -> EventXid {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const EventXid;
base::value_from_ptr(ptr)
}
}
pub fn window(&self) -> xproto::Window {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Window;
base::value_from_ptr(ptr)
}
}
pub fn serial(&self) -> u32 {
unsafe {
let offset = 20usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn ust(&self) -> u64 {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const u64;
base::value_from_ptr(ptr)
}
}
pub fn full_sequence(&self) -> u32 {
unsafe {
let offset = 32usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn msc(&self) -> u64 {
unsafe {
let offset = 36usize;
let ptr = self.wire_ptr().add(offset) as *const u64;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for CompleteNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("CompleteNotifyEvent")
.field("response_type", &self.response_type())
.field("extension", &self.extension())
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("event_type", &self.event_type())
.field("kind", &self.kind())
.field("mode", &self.mode())
.field("event", &self.event())
.field("window", &self.window())
.field("serial", &self.serial())
.field("ust", &self.ust())
.field("full_sequence", &self.full_sequence())
.field("msc", &self.msc())
.finish()
}
}
impl base::WiredOut for CompleteNotifyEvent {
fn wire_len(&self) -> usize {
32 + 4 * self.length() as usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for CompleteNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
32 + 4 * (*(ptr.add(4) as *const u32) as usize)
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_ge_generic_event_t;
std::ptr::copy(ptr as *const xcb_ge_generic_event_t, raw, sz);
CompleteNotifyEvent { raw }
}
}
impl Drop for CompleteNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for CompleteNotifyEvent {}
unsafe impl Sync for CompleteNotifyEvent {}
pub struct IdleNotifyEvent {
raw: *mut xcb_ge_generic_event_t,
}
impl base::Raw<xcb_ge_generic_event_t> for IdleNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_ge_generic_event_t) -> Self { IdleNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_ge_generic_event_t {
self.raw
}
}
impl base::GeEvent for IdleNotifyEvent {
const EXTENSION: ext::Extension = ext::Extension::Present;
const NUMBER: u32 = 2;
}
impl IdleNotifyEvent {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn extension(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn event_type(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn event(&self) -> EventXid {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const EventXid;
base::value_from_ptr(ptr)
}
}
pub fn window(&self) -> xproto::Window {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Window;
base::value_from_ptr(ptr)
}
}
pub fn serial(&self) -> u32 {
unsafe {
let offset = 20usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn pixmap(&self) -> xproto::Pixmap {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Pixmap;
base::value_from_ptr(ptr)
}
}
pub fn idle_fence(&self) -> sync::Fence {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const sync::Fence;
base::value_from_ptr(ptr)
}
}
pub fn full_sequence(&self) -> u32 {
unsafe {
let offset = 32usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
}
impl std::fmt::Debug for IdleNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("IdleNotifyEvent")
.field("response_type", &self.response_type())
.field("extension", &self.extension())
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("event_type", &self.event_type())
.field("pad", &2)
.field("event", &self.event())
.field("window", &self.window())
.field("serial", &self.serial())
.field("pixmap", &self.pixmap())
.field("idle_fence", &self.idle_fence())
.field("full_sequence", &self.full_sequence())
.finish()
}
}
impl base::WiredOut for IdleNotifyEvent {
fn wire_len(&self) -> usize {
32 + 4 * self.length() as usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for IdleNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
32 + 4 * (*(ptr.add(4) as *const u32) as usize)
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_ge_generic_event_t;
std::ptr::copy(ptr as *const xcb_ge_generic_event_t, raw, sz);
IdleNotifyEvent { raw }
}
}
impl Drop for IdleNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for IdleNotifyEvent {}
unsafe impl Sync for IdleNotifyEvent {}
pub struct RedirectNotifyEvent {
raw: *mut xcb_ge_generic_event_t,
}
impl base::Raw<xcb_ge_generic_event_t> for RedirectNotifyEvent {
unsafe fn from_raw(raw: *mut xcb_ge_generic_event_t) -> Self { RedirectNotifyEvent { raw } }
fn as_raw(&self) -> *mut xcb_ge_generic_event_t {
self.raw
}
}
impl base::GeEvent for RedirectNotifyEvent {
const EXTENSION: ext::Extension = ext::Extension::Present;
const NUMBER: u32 = 3;
}
impl RedirectNotifyEvent {
fn wire_ptr(&self) -> *const u8 { self.raw as *const u8 }
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn extension(&self) -> u8 {
unsafe {
let offset = 1usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn event_type(&self) -> u16 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn update_window(&self) -> bool {
let val = unsafe { *(self.wire_ptr().add(10usize)) };
val != 0
}
pub fn event(&self) -> EventXid {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const EventXid;
base::value_from_ptr(ptr)
}
}
pub fn event_window(&self) -> xproto::Window {
unsafe {
let offset = 16usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Window;
base::value_from_ptr(ptr)
}
}
pub fn window(&self) -> xproto::Window {
unsafe {
let offset = 20usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Window;
base::value_from_ptr(ptr)
}
}
pub fn pixmap(&self) -> xproto::Pixmap {
unsafe {
let offset = 24usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Pixmap;
base::value_from_ptr(ptr)
}
}
pub fn serial(&self) -> u32 {
unsafe {
let offset = 28usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn full_sequence(&self) -> u32 {
unsafe {
let offset = 32usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn valid_region(&self) -> xfixes::Region {
unsafe {
let offset = 36usize;
let ptr = self.wire_ptr().add(offset) as *const xfixes::Region;
base::value_from_ptr(ptr)
}
}
pub fn update_region(&self) -> xfixes::Region {
unsafe {
let offset = 40usize;
let ptr = self.wire_ptr().add(offset) as *const xfixes::Region;
base::value_from_ptr(ptr)
}
}
pub fn valid_rect(&self) -> xproto::Rectangle {
unsafe {
let offset = 44usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Rectangle;
base::value_from_ptr(ptr)
}
}
pub fn update_rect(&self) -> xproto::Rectangle {
unsafe {
let offset = 52usize;
let ptr = self.wire_ptr().add(offset) as *const xproto::Rectangle;
base::value_from_ptr(ptr)
}
}
pub fn x_off(&self) -> i16 {
unsafe {
let offset = 60usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn y_off(&self) -> i16 {
unsafe {
let offset = 62usize;
let ptr = self.wire_ptr().add(offset) as *const i16;
base::value_from_ptr(ptr)
}
}
pub fn target_crtc(&self) -> randr::Crtc {
unsafe {
let offset = 64usize;
let ptr = self.wire_ptr().add(offset) as *const randr::Crtc;
base::value_from_ptr(ptr)
}
}
pub fn wait_fence(&self) -> sync::Fence {
unsafe {
let offset = 68usize;
let ptr = self.wire_ptr().add(offset) as *const sync::Fence;
base::value_from_ptr(ptr)
}
}
pub fn idle_fence(&self) -> sync::Fence {
unsafe {
let offset = 72usize;
let ptr = self.wire_ptr().add(offset) as *const sync::Fence;
base::value_from_ptr(ptr)
}
}
pub fn options(&self) -> u32 {
unsafe {
let offset = 76usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn target_msc(&self) -> u64 {
unsafe {
let offset = 84usize;
let ptr = self.wire_ptr().add(offset) as *const u64;
base::value_from_ptr(ptr)
}
}
pub fn divisor(&self) -> u64 {
unsafe {
let offset = 92usize;
let ptr = self.wire_ptr().add(offset) as *const u64;
base::value_from_ptr(ptr)
}
}
pub fn remainder(&self) -> u64 {
unsafe {
let offset = 100usize;
let ptr = self.wire_ptr().add(offset) as *const u64;
base::value_from_ptr(ptr)
}
}
pub fn notifies(&self) -> &[Notify] {
unsafe {
let offset = 108usize;
assert_eq!((self.wire_len() as usize - offset) % std::mem::size_of::<Notify>(), 0);
let len = (self.wire_len() as usize - offset) / std::mem::size_of::<Notify>();
std::slice::from_raw_parts(self.wire_ptr().add(offset) as *const Notify, len)
}
}
}
impl std::fmt::Debug for RedirectNotifyEvent {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("RedirectNotifyEvent")
.field("response_type", &self.response_type())
.field("extension", &self.extension())
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("event_type", &self.event_type())
.field("update_window", &self.update_window())
.field("pad", &1)
.field("event", &self.event())
.field("event_window", &self.event_window())
.field("window", &self.window())
.field("pixmap", &self.pixmap())
.field("serial", &self.serial())
.field("full_sequence", &self.full_sequence())
.field("valid_region", &self.valid_region())
.field("update_region", &self.update_region())
.field("valid_rect", &self.valid_rect())
.field("update_rect", &self.update_rect())
.field("x_off", &self.x_off())
.field("y_off", &self.y_off())
.field("target_crtc", &self.target_crtc())
.field("wait_fence", &self.wait_fence())
.field("idle_fence", &self.idle_fence())
.field("options", &self.options())
.field("pad", &4)
.field("target_msc", &self.target_msc())
.field("divisor", &self.divisor())
.field("remainder", &self.remainder())
.field("notifies", &self.notifies())
.finish()
}
}
impl base::WiredOut for RedirectNotifyEvent {
fn wire_len(&self) -> usize {
32 + 4 * self.length() as usize
}
fn serialize(&self, wire_buf: &mut[u8]) -> usize {
debug_assert!(wire_buf.len() >= self.wire_len());
let raw_slice = unsafe { std::slice::from_raw_parts(self.raw as *const u8, self.wire_len()) };
wire_buf[0 .. self.wire_len()].copy_from_slice(raw_slice);
self.wire_len()
}
}
impl base::WiredIn for RedirectNotifyEvent {
type Params = ();
unsafe fn compute_wire_len(ptr: *const u8, _params: ()) -> usize {
32 + 4 * (*(ptr.add(4) as *const u32) as usize)
}
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
let sz = Self::compute_wire_len(ptr, ());
*offset += sz;
let raw = libc::malloc(sz) as *mut xcb_ge_generic_event_t;
std::ptr::copy(ptr as *const xcb_ge_generic_event_t, raw, sz);
RedirectNotifyEvent { raw }
}
}
impl Drop for RedirectNotifyEvent {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl Send for RedirectNotifyEvent {}
unsafe impl Sync for RedirectNotifyEvent {}
#[derive(Debug)]
pub enum Event {
Generic(GenericEvent),
ConfigureNotify(ConfigureNotifyEvent),
CompleteNotify(CompleteNotifyEvent),
IdleNotify(IdleNotifyEvent),
RedirectNotify(RedirectNotifyEvent),
}
impl Event {
pub fn as_raw(&self) -> *mut xcb_generic_event_t {
match self {
Self::Generic(e) => e.as_raw(),
Self::ConfigureNotify(e) => e.as_raw() as *mut xcb_generic_event_t,
Self::CompleteNotify(e) => e.as_raw() as *mut xcb_generic_event_t,
Self::IdleNotify(e) => e.as_raw() as *mut xcb_generic_event_t,
Self::RedirectNotify(e) => e.as_raw() as *mut xcb_generic_event_t,
}
}
}
impl base::ResolveWireEvent for Event {
unsafe fn resolve_wire_event(first_event: u8, raw: *mut xcb_generic_event_t) -> std::option::Option<Self> {
debug_assert!(!raw.is_null());
let response_type = (*raw).response_type & 0x7F;
debug_assert!(response_type != 0, "This is not an event but an error!");
debug_assert!(response_type != XCB_GE_GENERIC, "This is a GE_GENERIC event!");
match response_type - first_event {
0 => Some(Event::Generic(GenericEvent::from_raw(raw))),
_ => None,
}
}
}
impl base::ResolveWireGeEvent for Event {
unsafe fn resolve_wire_ge_event(raw: *mut xcb_ge_generic_event_t) -> Self{
debug_assert!(!raw.is_null());
debug_assert!(((*raw).response_type & 0x7F) == XCB_GE_GENERIC);
let event_type = (*raw).event_type;
match event_type {
0 => Event::ConfigureNotify(ConfigureNotifyEvent::from_raw(raw)),
1 => Event::CompleteNotify(CompleteNotifyEvent::from_raw(raw)),
2 => Event::IdleNotify(IdleNotifyEvent::from_raw(raw)),
3 => Event::RedirectNotify(RedirectNotifyEvent::from_raw(raw)),
_ => panic!("Could not resolve GE event for present: {}", event_type),
}
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum EventEnum {
ConfigureNotify = 0,
CompleteNotify = 1,
IdleNotify = 2,
RedirectNotify = 3,
}
bitflags! {
pub struct EventMask: u32 {
const NO_EVENT = 0x00000000;
const CONFIGURE_NOTIFY = 0x00000001;
const COMPLETE_NOTIFY = 0x00000002;
const IDLE_NOTIFY = 0x00000004;
const REDIRECT_NOTIFY = 0x00000008;
}
}
bitflags! {
pub struct Option: u32 {
const NONE = 0x00000000;
const ASYNC = 0x00000001;
const COPY = 0x00000002;
const UST = 0x00000004;
const SUBOPTIMAL = 0x00000008;
}
}
bitflags! {
pub struct Capability: u32 {
const NONE = 0x00000000;
const ASYNC = 0x00000001;
const FENCE = 0x00000002;
const UST = 0x00000004;
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum CompleteKind {
Pixmap = 0,
NotifyMsc = 1,
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
#[repr(u32)]
pub enum CompleteMode {
Copy = 0,
Flip = 1,
Skip = 2,
SuboptimalCopy = 3,
}
#[derive(Copy, Clone, Debug)]
#[repr(C)]
pub struct Notify {
pub window: xproto::Window,
pub serial: u32,
}
#[test]
fn test_sizeof_notify() {
assert_eq!(std::mem::size_of::<Notify>(), 8);
}
impl base::WiredOut for Notify {
fn wire_len(&self) -> usize { 8 }
fn serialize(&self, wire_buf: &mut [u8]) -> usize {
let me = unsafe {
std::slice::from_raw_parts(self as *const Notify as _, 8)
};
(&mut wire_buf[..me.len()]).copy_from_slice(me);
8
}
}
impl base::WiredIn for Notify {
type Params = ();
unsafe fn compute_wire_len(_ptr: *const u8, _params: ()) -> usize { 8 }
unsafe fn unserialize(ptr: *const u8, _params: (), offset: &mut usize) -> Self {
*offset += 8;
*(ptr as *const Notify)
}
}
#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
#[repr(C)]
pub struct EventXid {
res_id: u32,
}
impl base::Xid for EventXid {
fn none() -> Self { EventXid { res_id: 0 } }
fn resource_id(&self) -> u32 { self.res_id }
}
impl base::XidNew for EventXid {
unsafe fn new(res_id: u32) -> Self { EventXid { res_id } }
}
#[test]
fn test_sizeof_event_xid() {
assert_eq!(std::mem::size_of::<EventXid>(), 4);
}
pub(crate) fn request_name(opcode: u16) -> std::option::Option<&'static str> {
match opcode {
0 => Some("present::QueryVersion"),
1 => Some("present::Pixmap"),
2 => Some("present::NotifyMsc"),
3 => Some("present::SelectInput"),
4 => Some("present::QueryCapabilities"),
_ => None,
}
}
pub struct QueryVersionReply {
raw: *const u8,
}
impl QueryVersionReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn major_version(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn minor_version(&self) -> u32 {
unsafe {
let offset = 12usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for QueryVersionReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryVersionReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryVersionReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("major_version", &self.major_version())
.field("minor_version", &self.minor_version())
.finish()
}
}
impl Drop for QueryVersionReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryVersionReply {}
unsafe impl std::marker::Sync for QueryVersionReply {}
#[derive(Debug)]
pub struct QueryVersionCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryVersionCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryVersionCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryVersionCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryVersionCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryVersionCookie {
type Reply = QueryVersionReply;
}
impl base::Cookie for QueryVersionCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryVersionCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryVersionCookieUnchecked {
type Reply = QueryVersionReply;
}
#[derive(Clone, Debug)]
pub struct QueryVersion {
pub major_version: u32,
pub minor_version: u32,
}
unsafe impl base::RawRequest for QueryVersion {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 0,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 12];
self.major_version.serialize(&mut buf0[4 .. ]);
self.minor_version.serialize(&mut buf0[8 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 12;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryVersion {
type Cookie = QueryVersionCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryVersion {
type Reply = QueryVersionReply;
type Cookie = QueryVersionCookie;
type CookieUnchecked = QueryVersionCookieUnchecked;
}
#[derive(Clone, Debug)]
pub struct Pixmap<'a> {
pub window: xproto::Window,
pub pixmap: xproto::Pixmap,
pub serial: u32,
pub valid: xfixes::Region,
pub update: xfixes::Region,
pub x_off: i16,
pub y_off: i16,
pub target_crtc: randr::Crtc,
pub wait_fence: sync::Fence,
pub idle_fence: sync::Fence,
pub options: u32,
pub target_msc: u64,
pub divisor: u64,
pub remainder: u64,
pub notifies: &'a [Notify],
}
unsafe impl<'a> base::RawRequest for Pixmap<'a> {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 4,
ext: (&mut FFI_EXT) as *mut _,
opcode: 1,
isvoid: 1,
};
let mut sections: [iovec; 6] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 6];
let buf0: &mut [u8] = &mut [0; 72];
self.window.serialize(&mut buf0[4 .. ]);
self.pixmap.serialize(&mut buf0[8 .. ]);
self.serial.serialize(&mut buf0[12 .. ]);
self.valid.serialize(&mut buf0[16 .. ]);
self.update.serialize(&mut buf0[20 .. ]);
self.x_off.serialize(&mut buf0[24 .. ]);
self.y_off.serialize(&mut buf0[26 .. ]);
self.target_crtc.serialize(&mut buf0[28 .. ]);
self.wait_fence.serialize(&mut buf0[32 .. ]);
self.idle_fence.serialize(&mut buf0[36 .. ]);
self.options.serialize(&mut buf0[40 .. ]);
self.target_msc.serialize(&mut buf0[48 .. ]);
self.divisor.serialize(&mut buf0[56 .. ]);
self.remainder.serialize(&mut buf0[64 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 72;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
sections[4].iov_base = self.notifies.as_ptr() as *mut _;
sections[4].iov_len = self.notifies.len() * std::mem::size_of::<Notify>();
sections[5].iov_len = base::align_pad(sections[4].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl<'a> base::Request for Pixmap<'a> {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl<'a> base::RequestWithoutReply for Pixmap<'a> {
}
#[derive(Clone, Debug)]
pub struct NotifyMsc {
pub window: xproto::Window,
pub serial: u32,
pub target_msc: u64,
pub divisor: u64,
pub remainder: u64,
}
unsafe impl base::RawRequest for NotifyMsc {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 2,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 40];
self.window.serialize(&mut buf0[4 .. ]);
self.serial.serialize(&mut buf0[8 .. ]);
self.target_msc.serialize(&mut buf0[16 .. ]);
self.divisor.serialize(&mut buf0[24 .. ]);
self.remainder.serialize(&mut buf0[32 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 40;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for NotifyMsc {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for NotifyMsc {
}
#[derive(Clone, Debug)]
pub struct SelectInput {
pub eid: EventXid,
pub window: xproto::Window,
pub event_mask: EventMask,
}
unsafe impl base::RawRequest for SelectInput {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 3,
isvoid: 1,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 16];
self.eid.serialize(&mut buf0[4 .. ]);
self.window.serialize(&mut buf0[8 .. ]);
self.event_mask.bits().serialize(&mut buf0[12 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 16;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for SelectInput {
type Cookie = base::VoidCookie;
const IS_VOID: bool = true;
}
impl base::RequestWithoutReply for SelectInput {
}
pub struct QueryCapabilitiesReply {
raw: *const u8,
}
impl QueryCapabilitiesReply {
fn wire_ptr(&self) -> *const u8 {
self.raw
}
fn wire_len(&self) -> usize {
(32 + self.length() * 4) as _
}
pub fn response_type(&self) -> u8 {
unsafe {
let offset = 0usize;
let ptr = self.wire_ptr().add(offset) as *const u8;
base::value_from_ptr(ptr)
}
}
pub fn sequence(&self) -> u16 {
unsafe {
let offset = 2usize;
let ptr = self.wire_ptr().add(offset) as *const u16;
base::value_from_ptr(ptr)
}
}
pub fn length(&self) -> u32 {
unsafe {
let offset = 4usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
pub fn capabilities(&self) -> u32 {
unsafe {
let offset = 8usize;
let ptr = self.wire_ptr().add(offset) as *const u32;
base::value_from_ptr(ptr)
}
}
}
impl base::Reply for QueryCapabilitiesReply {
unsafe fn from_raw(raw: *const u8) -> Self {
Self { raw }
}
unsafe fn into_raw(self) -> *const u8 {
let raw = self.raw;
std::mem::forget(self);
raw
}
}
impl std::fmt::Debug for QueryCapabilitiesReply {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("QueryCapabilitiesReply")
.field("response_type", &self.response_type())
.field("pad", &1)
.field("sequence", &self.sequence())
.field("length", &self.length())
.field("capabilities", &self.capabilities())
.finish()
}
}
impl Drop for QueryCapabilitiesReply {
fn drop(&mut self) {
unsafe { libc::free(self.raw as *mut _); }
}
}
unsafe impl std::marker::Send for QueryCapabilitiesReply {}
unsafe impl std::marker::Sync for QueryCapabilitiesReply {}
#[derive(Debug)]
pub struct QueryCapabilitiesCookie {
seq: u64,
}
#[derive(Debug)]
pub struct QueryCapabilitiesCookieUnchecked {
seq: u64,
}
impl base::Cookie for QueryCapabilitiesCookie {
unsafe fn from_sequence(seq: u64) -> Self {
QueryCapabilitiesCookie { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieChecked for QueryCapabilitiesCookie {
}
unsafe impl base::CookieWithReplyChecked for QueryCapabilitiesCookie {
type Reply = QueryCapabilitiesReply;
}
impl base::Cookie for QueryCapabilitiesCookieUnchecked {
unsafe fn from_sequence(seq: u64) -> Self {
QueryCapabilitiesCookieUnchecked { seq }
}
fn sequence(&self) -> u64 {
self.seq
}
}
unsafe impl base::CookieWithReplyUnchecked for QueryCapabilitiesCookieUnchecked {
type Reply = QueryCapabilitiesReply;
}
#[derive(Clone, Debug)]
pub struct QueryCapabilities {
pub target: u32,
}
unsafe impl base::RawRequest for QueryCapabilities {
fn raw_request(&self, c: &base::Connection, checked: bool) -> u64 { unsafe {
let mut protocol_request = xcb_protocol_request_t {
count: 2,
ext: (&mut FFI_EXT) as *mut _,
opcode: 4,
isvoid: 0,
};
let mut sections: [iovec; 4] = [iovec {
iov_base: std::ptr::null_mut(),
iov_len: 0,
}; 4];
let buf0: &mut [u8] = &mut [0; 8];
self.target.serialize(&mut buf0[4 .. ]);
sections[2].iov_base = buf0.as_mut_ptr() as *mut _;
sections[2].iov_len = 8;
sections[3].iov_len = base::align_pad(sections[2].iov_len, 4);
let flags = if checked { base::RequestFlags::CHECKED } else { base::RequestFlags::NONE };
xcb_send_request64(
c.get_raw_conn(),
flags.bits() as _,
sections.as_mut_ptr().add(2),
&mut protocol_request as *mut _,
)
}
}}
impl base::Request for QueryCapabilities {
type Cookie = QueryCapabilitiesCookie;
const IS_VOID: bool = false;
}
impl base::RequestWithReply for QueryCapabilities {
type Reply = QueryCapabilitiesReply;
type Cookie = QueryCapabilitiesCookie;
type CookieUnchecked = QueryCapabilitiesCookieUnchecked;
}