diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..106d52c --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,4 @@ +[root] +name = "xlib" +version = "0.1.0" + diff --git a/src/xlib.rs b/src/xlib.rs index d1faa7f..58e9c45 100644 --- a/src/xlib.rs +++ b/src/xlib.rs @@ -11,6 +11,7 @@ #![allow(non_camel_case_types)] use libc::*; +use std::mem; pub type XID = c_ulong; @@ -733,7 +734,44 @@ pub struct XClientMessageEvent { pub window: Window, pub message_type: Atom, pub format: c_int, - pub data: union_unnamed2, + pub data: [int32_t, ..5], +} + +impl XClientMessageEvent { + pub fn get_b(&self) -> Option<&[int8_t, ..20]> { + match self.format { + 8 => Some(unsafe { mem::transmute_copy(&self.data) }), + _ => None + } + } + + pub fn get_s(&self) -> Option<&[int16_t, ..10]> { + match self.format { + 16 => Some(unsafe { mem::transmute_copy(&self.data) }), + _ => None + } + } + + pub fn get_l(&self) -> Option<&[int32_t, ..5]> { + match self.format { + 32 => Some(unsafe { mem::transmute_copy(&self.data) }), + _ => None + } + } + + pub fn set_b(&mut self, v: &[int8_t, ..20]) { + self.format = 8; + self.data = unsafe { mem::transmute_copy(&v) }; + } + + pub fn set_s(&mut self, v: &[int16_t, ..10]) { + self.format = 16; + self.data = unsafe { mem::transmute_copy(&v) }; + } + pub fn set_l(&mut self, v: &[int32_t, ..5]) { + self.format = 32; + self.data = unsafe { mem::transmute_copy(v) }; + } } #[repr(C)]