fcitx5_dbus/utils/
key_event.rs

1use crate::utils::macros;
2use bitflags::bitflags;
3
4macros::dbus_type! {
5    pub struct KeyVal(u32);
6
7    pub struct KeyState(u32);
8
9    // pub struct KeyEvent {
10    //     val: KeyVal,
11    //     code: u32,
12    //     state: KeyState,
13    //     is_release: bool,
14    //     time: u32,
15    // }
16}
17
18impl KeyVal {
19    pub fn from_char(chr: char) -> Self {
20        Self(chr as u32)
21    }
22}
23
24macros::impl_const_members_in!(KeyVal =>
25    DELETE  => 0xff08
26    ENTER   => 0xff0d
27    LEFT    => 0xff51
28    RIGHT   => 0xff53
29    CHAR_A  => b'a' as u32
30    CHAR_B  => b'b' as u32
31    CHAR_C  => b'c' as u32
32    CHAR_D  => b'd' as u32
33    CHAR_E  => b'e' as u32
34    CHAR_F  => b'f' as u32
35    CHAR_G  => b'g' as u32
36    CHAR_H  => b'h' as u32
37    CHAR_I  => b'i' as u32
38    CHAR_J  => b'j' as u32
39    CHAR_K  => b'k' as u32
40    CHAR_L  => b'l' as u32
41    CHAR_M  => b'm' as u32
42    CHAR_N  => b'n' as u32
43    CHAR_O  => b'o' as u32
44    CHAR_P  => b'p' as u32
45    CHAR_Q  => b'q' as u32
46    CHAR_R  => b'r' as u32
47    CHAR_S  => b's' as u32
48    CHAR_T  => b't' as u32
49    CHAR_U  => b'u' as u32
50    CHAR_V  => b'v' as u32
51    CHAR_W  => b'w' as u32
52    CHAR_X  => b'x' as u32
53    CHAR_Y  => b'y' as u32
54    CHAR_Z  => b'z' as u32
55);
56
57// #[rustfmt::skip]
58// impl KeyEvent {
59//     pub fn new(val: KeyVal, code: u32, state: KeyState, is_release: bool, time: u32) -> Self {
60//         Self { val, code, state, is_release, time }
61//     }
62//     pub fn char(val: KeyVal) -> Self {
63//         Self { val, ..Self::default() }
64//     }
65//     pub fn char_with_modifier(val: KeyVal, state: KeyState) -> Self {
66//         Self { val, state, ..Self::default() }
67//     }
68// }
69
70#[rustfmt::skip]
71bitflags! { impl KeyState: u32 {
72    const NoState        = 0;
73    const Shift          = 1 << 0;
74    const CapsLock       = 1 << 1;
75    const Ctrl           = 1 << 2;
76    const Alt            = 1 << 3;
77    const Mod1           = Self::Alt.bits();
78    const Alt_Shift      = Self::Alt.bits() | Self::Shift.bits();
79    const Ctrl_Shift     = Self::Ctrl.bits() | Self::Shift.bits();
80    const Ctrl_Alt       = Self::Ctrl.bits() | Self::Alt.bits();
81    const Ctrl_Alt_Shift = Self::Ctrl.bits() | Self::Alt.bits() | Self::Shift.bits();
82    const NumLock        = 1 << 4;
83    const Mod2           = Self::NumLock.bits();
84    const Hyper          = 1 << 5;
85    const Mod3           = Self::Hyper.bits();
86    const Super          = 1 << 6;
87    const Mod5           = 1 << 7;
88    const MousePressed   = 1 << 8;
89    const HandledMask    = 1 << 24;
90    const IgnoredMask    = 1 << 25;
91    const Super2         = 1 << 26; // Gtk virtual Super
92    const Hyper2         = 1 << 27; // Gtk virtual Hyper
93    const Meta           = 1 << 28;
94
95    // Key state that used internally for virtual key board.
96    // @since fcitx5 5.1.0
97    const Virtual        = 1 << 29;
98
99    // Whether a Key Press is from key repetition.
100    // @since fcitx5 5.0.4
101    const Repeat         = 1 << 31;
102
103    const UsedMask       = 0x5c001fff;
104    const SimpleMask     = Self::Ctrl_Alt_Shift.bits() | Self::Super.bits() | Self::Super2.bits() | Self::Hyper.bits() | Self::Meta.bits();
105}}