use std::collections::HashMap;
use arbitrary_int::u11;
use bitbybit::bitfield;
use zbus::zvariant::{Structure, Value};
pub fn make_ibus_text(text: String) -> Value<'static> {
let st1 = Structure::from((
"IBusAttrList",
HashMap::<String, Value<'static>>::new(),
Vec::<Value<'static>>::new(),
));
let st2 = Structure::from((
"IBusText",
HashMap::<String, Value<'static>>::new(),
text,
Value::new(st1),
));
Value::new(st2)
}
#[bitfield(u32)]
pub struct IBusModifierState {
#[bit(0, rw)]
shift: bool,
#[bit(1, rw)]
lock: bool,
#[bit(2, rw)]
control: bool,
#[bit(3, rw)]
mod1: bool,
#[bit(4, rw)]
mod2: bool,
#[bit(5, rw)]
mod3: bool,
#[bit(6, rw)]
mod4: bool,
#[bit(7, rw)]
mod5: bool,
#[bit(8, rw)]
button1: bool,
#[bit(9, rw)]
button2: bool,
#[bit(10, rw)]
button3: bool,
#[bit(11, rw)]
button4: bool,
#[bit(12, rw)]
button5: bool,
#[bits(13..=23, rw)]
unused1: u11,
#[bit(24, rw)]
handled: bool,
#[bit(25, rw)]
forward: bool,
#[bit(26, rw)]
super_: bool,
#[bit(27, rw)]
hyper: bool,
#[bit(28, rw)]
meta: bool,
#[bit(29, rw)]
unused2: bool,
#[bit(30, rw)]
release: bool,
#[bit(31, rw)]
unused3: bool,
}
impl IBusModifierState {
pub fn has_special_modifiers(self) -> bool {
self.control() || self.mod1() || self.mod4() || self.super_() || self.meta() || self.hyper()
}
pub fn is_keyup(self) -> bool {
self.release()
}
pub fn is_keydown(self) -> bool {
!self.is_keyup()
}
}
#[cfg(test)]
mod test {
use super::*;
#[test]
fn ibus_text_zvariant_signature() {
let v = make_ibus_text("test".into());
assert_eq!(v.value_signature(), "(sa{sv}sv)");
}
}