oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git
7,787 bytes raw
1
#![allow(dead_code)]
2
3
pub type Keysym = u32;
4
pub const XK_ESCAPE: Keysym = 0xff1b;
5
pub const XK_RETURN: Keysym = 0xff0d;
6
pub const XK_SPACE: Keysym = 0x0020;
7
pub const XK_TAB: Keysym = 0xff09;
8
pub const XK_BACKSPACE: Keysym = 0xff08;
9
pub const XK_DELETE: Keysym = 0xffff;
10
pub const XK_F1: Keysym = 0xffbe;
11
pub const XK_F2: Keysym = 0xffbf;
12
pub const XK_F3: Keysym = 0xffc0;
13
pub const XK_F4: Keysym = 0xffc1;
14
pub const XK_F5: Keysym = 0xffc2;
15
pub const XK_F6: Keysym = 0xffc3;
16
pub const XK_F7: Keysym = 0xffc4;
17
pub const XK_F8: Keysym = 0xffc5;
18
pub const XK_F9: Keysym = 0xffc6;
19
pub const XK_F10: Keysym = 0xffc7;
20
pub const XK_F11: Keysym = 0xffc8;
21
pub const XK_F12: Keysym = 0xffc9;
22
pub const XK_A: Keysym = 0x0061;
23
pub const XK_B: Keysym = 0x0062;
24
pub const XK_C: Keysym = 0x0063;
25
pub const XK_D: Keysym = 0x0064;
26
pub const XK_E: Keysym = 0x0065;
27
pub const XK_F: Keysym = 0x0066;
28
pub const XK_G: Keysym = 0x0067;
29
pub const XK_H: Keysym = 0x0068;
30
pub const XK_I: Keysym = 0x0069;
31
pub const XK_J: Keysym = 0x006a;
32
pub const XK_K: Keysym = 0x006b;
33
pub const XK_L: Keysym = 0x006c;
34
pub const XK_M: Keysym = 0x006d;
35
pub const XK_N: Keysym = 0x006e;
36
pub const XK_O: Keysym = 0x006f;
37
pub const XK_P: Keysym = 0x0070;
38
pub const XK_Q: Keysym = 0x0071;
39
pub const XK_R: Keysym = 0x0072;
40
pub const XK_S: Keysym = 0x0073;
41
pub const XK_T: Keysym = 0x0074;
42
pub const XK_U: Keysym = 0x0075;
43
pub const XK_V: Keysym = 0x0076;
44
pub const XK_W: Keysym = 0x0077;
45
pub const XK_X: Keysym = 0x0078;
46
pub const XK_Y: Keysym = 0x0079;
47
pub const XK_Z: Keysym = 0x007a;
48
pub const XK_0: Keysym = 0x0030;
49
pub const XK_1: Keysym = 0x0031;
50
pub const XK_2: Keysym = 0x0032;
51
pub const XK_3: Keysym = 0x0033;
52
pub const XK_4: Keysym = 0x0034;
53
pub const XK_5: Keysym = 0x0035;
54
pub const XK_6: Keysym = 0x0036;
55
pub const XK_7: Keysym = 0x0037;
56
pub const XK_8: Keysym = 0x0038;
57
pub const XK_9: Keysym = 0x0039;
58
pub const XK_LEFT: Keysym = 0xff51;
59
pub const XK_UP: Keysym = 0xff52;
60
pub const XK_RIGHT: Keysym = 0xff53;
61
pub const XK_DOWN: Keysym = 0xff54;
62
pub const XK_HOME: Keysym = 0xff50;
63
pub const XK_END: Keysym = 0xff57;
64
pub const XK_PAGE_UP: Keysym = 0xff55;
65
pub const XK_PAGE_DOWN: Keysym = 0xff56;
66
pub const XK_INSERT: Keysym = 0xff63;
67
pub const XK_MINUS: Keysym = 0x002d;
68
pub const XK_EQUAL: Keysym = 0x003d;
69
pub const XK_LEFT_BRACKET: Keysym = 0x005b;
70
pub const XK_RIGHT_BRACKET: Keysym = 0x005d;
71
pub const XK_SEMICOLON: Keysym = 0x003b;
72
pub const XK_APOSTROPHE: Keysym = 0x0027;
73
pub const XK_GRAVE: Keysym = 0x0060;
74
pub const XK_BACKSLASH: Keysym = 0x005c;
75
pub const XK_COMMA: Keysym = 0x002c;
76
pub const XK_PERIOD: Keysym = 0x002e;
77
pub const XK_SLASH: Keysym = 0x002f;
78
pub const XK_PRINT: Keysym = 0xff61;
79
80
pub const XF86_AUDIO_RAISE_VOLUME: Keysym = 0x1008ff13;
81
pub const XF86_AUDIO_LOWER_VOLUME: Keysym = 0x1008ff11;
82
pub const XF86_AUDIO_MUTE: Keysym = 0x1008ff12;
83
pub const XF86_MON_BRIGHTNESS_UP: Keysym = 0x1008ff02;
84
pub const XF86_MON_BRIGHTNESS_DOWN: Keysym = 0x1008ff03;
85
86
pub fn keysym_from_str(s: &str) -> Option<Keysym> {
87
    match s {
88
        "Return" => Some(XK_RETURN),
89
        "Escape" => Some(XK_ESCAPE),
90
        "Space" => Some(XK_SPACE),
91
        "Tab" => Some(XK_TAB),
92
        "Backspace" => Some(XK_BACKSPACE),
93
        "Delete" => Some(XK_DELETE),
94
        "F1" => Some(XK_F1),
95
        "F2" => Some(XK_F2),
96
        "F3" => Some(XK_F3),
97
        "F4" => Some(XK_F4),
98
        "F5" => Some(XK_F5),
99
        "F6" => Some(XK_F6),
100
        "F7" => Some(XK_F7),
101
        "F8" => Some(XK_F8),
102
        "F9" => Some(XK_F9),
103
        "F10" => Some(XK_F10),
104
        "F11" => Some(XK_F11),
105
        "F12" => Some(XK_F12),
106
        "A" => Some(XK_A),
107
        "B" => Some(XK_B),
108
        "C" => Some(XK_C),
109
        "D" => Some(XK_D),
110
        "E" => Some(XK_E),
111
        "F" => Some(XK_F),
112
        "G" => Some(XK_G),
113
        "H" => Some(XK_H),
114
        "I" => Some(XK_I),
115
        "J" => Some(XK_J),
116
        "K" => Some(XK_K),
117
        "L" => Some(XK_L),
118
        "M" => Some(XK_M),
119
        "N" => Some(XK_N),
120
        "O" => Some(XK_O),
121
        "P" => Some(XK_P),
122
        "Q" => Some(XK_Q),
123
        "R" => Some(XK_R),
124
        "S" => Some(XK_S),
125
        "T" => Some(XK_T),
126
        "U" => Some(XK_U),
127
        "V" => Some(XK_V),
128
        "W" => Some(XK_W),
129
        "X" => Some(XK_X),
130
        "Y" => Some(XK_Y),
131
        "Z" => Some(XK_Z),
132
        "0" => Some(XK_0),
133
        "1" => Some(XK_1),
134
        "2" => Some(XK_2),
135
        "3" => Some(XK_3),
136
        "4" => Some(XK_4),
137
        "5" => Some(XK_5),
138
        "6" => Some(XK_6),
139
        "7" => Some(XK_7),
140
        "8" => Some(XK_8),
141
        "9" => Some(XK_9),
142
        "Left" => Some(XK_LEFT),
143
        "Right" => Some(XK_RIGHT),
144
        "Up" => Some(XK_UP),
145
        "Down" => Some(XK_DOWN),
146
        "Home" => Some(XK_HOME),
147
        "End" => Some(XK_END),
148
        "PageUp" => Some(XK_PAGE_UP),
149
        "PageDown" => Some(XK_PAGE_DOWN),
150
        "Insert" => Some(XK_INSERT),
151
        "Minus" => Some(XK_MINUS),
152
        "Equal" => Some(XK_EQUAL),
153
        "BracketLeft" => Some(XK_LEFT_BRACKET),
154
        "BracketRight" => Some(XK_RIGHT_BRACKET),
155
        "Semicolon" => Some(XK_SEMICOLON),
156
        "Apostrophe" => Some(XK_APOSTROPHE),
157
        "Grave" => Some(XK_GRAVE),
158
        "Backslash" => Some(XK_BACKSLASH),
159
        "Comma" => Some(XK_COMMA),
160
        "Period" => Some(XK_PERIOD),
161
        "Slash" => Some(XK_SLASH),
162
        "AudioRaiseVolume" => Some(XF86_AUDIO_RAISE_VOLUME),
163
        "AudioLowerVolume" => Some(XF86_AUDIO_LOWER_VOLUME),
164
        "AudioMute" => Some(XF86_AUDIO_MUTE),
165
        "MonBrightnessUp" => Some(XF86_MON_BRIGHTNESS_UP),
166
        "MonBrightnessDown" => Some(XF86_MON_BRIGHTNESS_DOWN),
167
        _ => None,
168
    }
169
}
170
171
pub fn format_keysym(keysym: Keysym) -> String {
172
    match keysym {
173
        XK_RETURN => "Return".to_string(),
174
        XK_ESCAPE => "Esc".to_string(),
175
        XK_SPACE => "Space".to_string(),
176
        XK_TAB => "Tab".to_string(),
177
        XK_BACKSPACE => "Backspace".to_string(),
178
        XK_DELETE => "Del".to_string(),
179
        XK_LEFT => "Left".to_string(),
180
        XK_RIGHT => "Right".to_string(),
181
        XK_UP => "Up".to_string(),
182
        XK_DOWN => "Down".to_string(),
183
        XK_HOME => "Home".to_string(),
184
        XK_END => "End".to_string(),
185
        XK_PAGE_UP => "PgUp".to_string(),
186
        XK_PAGE_DOWN => "PgDn".to_string(),
187
        XK_INSERT => "Ins".to_string(),
188
        XK_F1 => "F1".to_string(),
189
        XK_F2 => "F2".to_string(),
190
        XK_F3 => "F3".to_string(),
191
        XK_F4 => "F4".to_string(),
192
        XK_F5 => "F5".to_string(),
193
        XK_F6 => "F6".to_string(),
194
        XK_F7 => "F7".to_string(),
195
        XK_F8 => "F8".to_string(),
196
        XK_F9 => "F9".to_string(),
197
        XK_F10 => "F10".to_string(),
198
        XK_F11 => "F11".to_string(),
199
        XK_F12 => "F12".to_string(),
200
        XK_SLASH => "/".to_string(),
201
        XK_COMMA => ",".to_string(),
202
        XK_PERIOD => ".".to_string(),
203
        XK_MINUS => "-".to_string(),
204
        XK_EQUAL => "=".to_string(),
205
        XK_GRAVE => "`".to_string(),
206
        XK_LEFT_BRACKET => "[".to_string(),
207
        XK_RIGHT_BRACKET => "]".to_string(),
208
        XK_SEMICOLON => ";".to_string(),
209
        XK_APOSTROPHE => "'".to_string(),
210
        XK_BACKSLASH => "\\".to_string(),
211
        XK_PRINT => "Print".to_string(),
212
        XF86_AUDIO_RAISE_VOLUME => "Vol+".to_string(),
213
        XF86_AUDIO_LOWER_VOLUME => "Vol-".to_string(),
214
        XF86_AUDIO_MUTE => "Mute".to_string(),
215
        XF86_MON_BRIGHTNESS_UP => "Bright+".to_string(),
216
        XF86_MON_BRIGHTNESS_DOWN => "Bright-".to_string(),
217
        XK_A..=XK_Z => {
218
            let ch = (keysym - XK_A + b'A' as u32) as u8 as char;
219
            ch.to_string()
220
        }
221
        XK_0..=XK_9 => {
222
            let ch = (keysym - XK_0 + b'0' as u32) as u8 as char;
223
            ch.to_string()
224
        }
225
        _ => format!("0x{:x}", keysym),
226
    }
227
}