Skip to content
This repository was archived by the owner on Aug 3, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 39 additions & 1 deletion src/xlib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#![allow(non_camel_case_types)]

use libc::*;
use std::mem;

pub type XID = c_ulong;

Expand Down Expand Up @@ -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)]
Expand Down