use super::super::raw;
pub(crate) const US_POSITION: i64 = 1 << 0; pub(crate) const US_SIZE: i64 = 1 << 1;
pub(crate) const P_POSITION: i64 = 1 << 2; pub(crate) const P_SIZE: i64 = 1 << 3; pub(crate) const P_MIN_SIZE: i64 = 1 << 4; pub(crate) const P_MAX_SIZE: i64 = 1 << 5; pub(crate) const P_RESIZE_INC: i64 = 1 << 6; pub(crate) const P_ASPECT: i64 = 1 << 7; pub(crate) const P_BASE_SIZE: i64 = 1 << 8; pub(crate) const P_WIN_GRAVITY: i64 = 1 << 9;
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub(crate) struct XAtomsIcccm {
pub wm_normal_hints: u32,
pub wm_protocols: u32,
pub wm_delete_window: u32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct XSizeHints {
pub flags: i64,
pub x: i32,
pub y: i32,
pub width: i32,
pub height: i32,
pub min_width: i32,
pub min_height: i32,
pub max_width: i32,
pub max_height: i32,
pub width_inc: i32,
pub height_inc: i32,
pub aspect_min: XSizeRatio,
pub aspect_max: XSizeRatio,
pub base_width: i32,
pub base_height: i32,
pub win_gravity: i32,
}
#[repr(C)]
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) struct XSizeRatio {
pub num: i32,
pub den: i32,
}
#[repr(i32)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, PartialOrd, Ord, Hash)]
pub(crate) enum XWinGravity {
Forget = 0,
NorthWest = 1,
North = 2,
NorthEast = 3,
West = 4,
Center = 5,
East = 6,
SouthWest = 7,
South = 8,
SouthEast = 9,
Static = 10,
}
#[rustfmt::skip]
impl XSizeHints {
pub fn new() -> Self {
Self::default()
}
pub fn set_position(mut self, x: i16, y: i16) -> Self {
self.flags |= US_POSITION; self.x = x as i32; self.y = y as i32; self
}
pub fn set_size(mut self, w: u16, h: u16) -> Self {
self.flags |= US_SIZE; self.width = w as i32; self.height = h as i32; self
}
pub fn set_min_size(mut self, w: u16, h: u16) -> Self {
self.flags |= P_MIN_SIZE; self.min_width = w as i32; self.min_height = h as i32; self
}
pub fn set_max_size(mut self, w: u16, h: u16) -> Self {
self.flags |= P_MAX_SIZE; self.max_width = w as i32; self.max_height = h as i32; self
}
pub fn set_resize_inc(mut self, w: i32, h: i32) -> Self {
self.flags |= P_RESIZE_INC; self.width_inc = w; self.height_inc = h; self
}
pub fn set_base_size(mut self, w: i32, h: i32) -> Self {
self.flags |= P_BASE_SIZE; self.base_width = w; self.base_height = h; self
}
pub fn set_aspect(mut self, min_num: i32, min_den: i32, max_num: i32, max_den: i32) -> Self {
self.flags |= P_ASPECT;
self.aspect_min = XSizeRatio { num: min_num, den: min_den };
self.aspect_max = XSizeRatio { num: max_num, den: max_den };
self
}
pub fn set_gravity(mut self, g: XWinGravity) -> Self {
self.flags |= P_WIN_GRAVITY;
self.win_gravity = g as i32;
self
}
pub fn set_on(&self, conn: *mut raw::xcb_connection_t, win: u32, atom_normal_hints: u32) {
let arr = self.as_u32_array();
raw::change_property_u32(conn, win, atom_normal_hints,
raw::xcb_atom_enum_t::XCB_ATOM_WM_SIZE_HINTS as u32, &arr);
}
pub fn as_u32_array(&self) -> [u32; 20] {
[
self.flags as u32, self.x as u32,
self.y as u32,
self.width as u32,
self.height as u32,
self.min_width as u32,
self.min_height as u32,
self.max_width as u32,
self.max_height as u32,
self.width_inc as u32,
self.height_inc as u32,
self.aspect_min.num as u32,
self.aspect_min.den as u32,
self.aspect_max.num as u32,
self.aspect_max.den as u32,
self.base_width as u32,
self.base_height as u32,
self.win_gravity as u32,
0, 0,
]
}
}