| @@ -147,6 +147,8 @@ pub struct WindowManager { |
| 147 |
display: *mut x11::xlib::Display, |
147 |
display: *mut x11::xlib::Display, |
| 148 |
font: crate::bar::font::Font, |
148 |
font: crate::bar::font::Font, |
| 149 |
keychord_state: keyboard::handlers::KeychordState, |
149 |
keychord_state: keyboard::handlers::KeychordState, |
|
|
150 |
+ current_key: usize, |
|
|
151 |
+ keyboard_mapping: Option<keyboard::KeyboardMapping>, |
| 150 |
error_message: Option<String>, |
152 |
error_message: Option<String>, |
| 151 |
overlay: ErrorOverlay, |
153 |
overlay: ErrorOverlay, |
| 152 |
keybind_overlay: KeybindOverlay, |
154 |
keybind_overlay: KeybindOverlay, |
| @@ -303,6 +305,8 @@ impl WindowManager { |
| 303 |
display, |
305 |
display, |
| 304 |
font, |
306 |
font, |
| 305 |
keychord_state: keyboard::handlers::KeychordState::Idle, |
307 |
keychord_state: keyboard::handlers::KeychordState::Idle, |
|
|
308 |
+ current_key: 0, |
|
|
309 |
+ keyboard_mapping: None, |
| 306 |
error_message: None, |
310 |
error_message: None, |
| 307 |
overlay, |
311 |
overlay, |
| 308 |
keybind_overlay, |
312 |
keybind_overlay, |
| @@ -509,7 +513,7 @@ impl WindowManager { |
| 509 |
pub fn run(&mut self) -> WmResult<bool> { |
513 |
pub fn run(&mut self) -> WmResult<bool> { |
| 510 |
println!("oxwm started on display {}", self.screen_number); |
514 |
println!("oxwm started on display {}", self.screen_number); |
| 511 |
|
515 |
|
| 512 |
- keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
516 |
+ self.grab_keys()?; |
| 513 |
self.update_bar()?; |
517 |
self.update_bar()?; |
| 514 |
|
518 |
|
| 515 |
let mut last_bar_update = std::time::Instant::now(); |
519 |
let mut last_bar_update = std::time::Instant::now(); |
| @@ -1253,98 +1257,13 @@ impl WindowManager { |
| 1253 |
Ok(()) |
1257 |
Ok(()) |
| 1254 |
} |
1258 |
} |
| 1255 |
|
1259 |
|
| 1256 |
- fn grab_next_keys(&self, candidates: &[usize], keys_pressed: usize) -> WmResult<()> { |
1260 |
+ fn grab_keys(&mut self) -> WmResult<()> { |
| 1257 |
- use std::collections::HashMap; |
1261 |
+ self.keyboard_mapping = Some(keyboard::grab_keys( |
| 1258 |
- use x11rb::protocol::xproto::Keycode; |
1262 |
+ &self.connection, |
| 1259 |
- |
1263 |
+ self.root, |
| 1260 |
- let setup = self.connection.setup(); |
1264 |
+ &self.config.keybindings, |
| 1261 |
- let min_keycode = setup.min_keycode; |
1265 |
+ self.current_key, |
| 1262 |
- let max_keycode = setup.max_keycode; |
1266 |
+ )?); |
| 1263 |
- |
|
|
| 1264 |
- let keyboard_mapping = self |
|
|
| 1265 |
- .connection |
|
|
| 1266 |
- .get_keyboard_mapping(min_keycode, max_keycode - min_keycode + 1)? |
|
|
| 1267 |
- .reply()?; |
|
|
| 1268 |
- |
|
|
| 1269 |
- let mut keysym_to_keycode: HashMap<keyboard::keysyms::Keysym, Vec<Keycode>> = |
|
|
| 1270 |
- HashMap::new(); |
|
|
| 1271 |
- let keysyms_per_keycode = keyboard_mapping.keysyms_per_keycode; |
|
|
| 1272 |
- |
|
|
| 1273 |
- for keycode in min_keycode..=max_keycode { |
|
|
| 1274 |
- let index = (keycode - min_keycode) as usize * keysyms_per_keycode as usize; |
|
|
| 1275 |
- for i in 0..keysyms_per_keycode as usize { |
|
|
| 1276 |
- if let Some(&keysym) = keyboard_mapping.keysyms.get(index + i) { |
|
|
| 1277 |
- if keysym != 0 { |
|
|
| 1278 |
- keysym_to_keycode |
|
|
| 1279 |
- .entry(keysym) |
|
|
| 1280 |
- .or_insert_with(Vec::new) |
|
|
| 1281 |
- .push(keycode); |
|
|
| 1282 |
- } |
|
|
| 1283 |
- } |
|
|
| 1284 |
- } |
|
|
| 1285 |
- } |
|
|
| 1286 |
- |
|
|
| 1287 |
- let mut grabbed_keys: HashSet<(u16, Keycode)> = HashSet::new(); |
|
|
| 1288 |
- |
|
|
| 1289 |
- let ignore_modifiers = [ |
|
|
| 1290 |
- 0, |
|
|
| 1291 |
- u16::from(ModMask::LOCK), |
|
|
| 1292 |
- u16::from(ModMask::M2), |
|
|
| 1293 |
- u16::from(ModMask::LOCK | ModMask::M2), |
|
|
| 1294 |
- ]; |
|
|
| 1295 |
- |
|
|
| 1296 |
- for &candidate_index in candidates { |
|
|
| 1297 |
- let binding = &self.config.keybindings[candidate_index]; |
|
|
| 1298 |
- if keys_pressed < binding.keys.len() { |
|
|
| 1299 |
- let next_key = &binding.keys[keys_pressed]; |
|
|
| 1300 |
- let modifier_mask = keyboard::handlers::modifiers_to_mask(&next_key.modifiers); |
|
|
| 1301 |
- |
|
|
| 1302 |
- if let Some(keycodes) = keysym_to_keycode.get(&next_key.keysym) { |
|
|
| 1303 |
- if let Some(&keycode) = keycodes.first() { |
|
|
| 1304 |
- for &ignore_mask in &ignore_modifiers { |
|
|
| 1305 |
- let grab_mask = modifier_mask | ignore_mask; |
|
|
| 1306 |
- let key_tuple = (grab_mask, keycode); |
|
|
| 1307 |
- |
|
|
| 1308 |
- if grabbed_keys.insert(key_tuple) { |
|
|
| 1309 |
- self.connection.grab_key( |
|
|
| 1310 |
- false, |
|
|
| 1311 |
- self.root, |
|
|
| 1312 |
- grab_mask.into(), |
|
|
| 1313 |
- keycode, |
|
|
| 1314 |
- GrabMode::ASYNC, |
|
|
| 1315 |
- GrabMode::ASYNC, |
|
|
| 1316 |
- )?; |
|
|
| 1317 |
- } |
|
|
| 1318 |
- } |
|
|
| 1319 |
- } |
|
|
| 1320 |
- } |
|
|
| 1321 |
- } |
|
|
| 1322 |
- } |
|
|
| 1323 |
- |
|
|
| 1324 |
- if let Some(keycodes) = keysym_to_keycode.get(&keyboard::keysyms::XK_ESCAPE) { |
|
|
| 1325 |
- if let Some(&keycode) = keycodes.first() { |
|
|
| 1326 |
- for &ignore_mask in &ignore_modifiers { |
|
|
| 1327 |
- self.connection.grab_key( |
|
|
| 1328 |
- false, |
|
|
| 1329 |
- self.root, |
|
|
| 1330 |
- ModMask::from(ignore_mask), |
|
|
| 1331 |
- keycode, |
|
|
| 1332 |
- GrabMode::ASYNC, |
|
|
| 1333 |
- GrabMode::ASYNC, |
|
|
| 1334 |
- )?; |
|
|
| 1335 |
- } |
|
|
| 1336 |
- } |
|
|
| 1337 |
- } |
|
|
| 1338 |
- |
|
|
| 1339 |
- self.connection.flush()?; |
|
|
| 1340 |
- Ok(()) |
|
|
| 1341 |
- } |
|
|
| 1342 |
- |
|
|
| 1343 |
- fn ungrab_chord_keys(&self) -> WmResult<()> { |
|
|
| 1344 |
- self.connection |
|
|
| 1345 |
- .ungrab_key(x11rb::protocol::xproto::Grab::ANY, self.root, ModMask::ANY)?; |
|
|
| 1346 |
- keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
|
|
| 1347 |
- self.connection.flush()?; |
|
|
| 1348 |
Ok(()) |
1267 |
Ok(()) |
| 1349 |
} |
1268 |
} |
| 1350 |
|
1269 |
|
| @@ -2797,21 +2716,8 @@ impl WindowManager { |
| 2797 |
&& !self.keybind_overlay.should_suppress_input() |
2716 |
&& !self.keybind_overlay.should_suppress_input() |
| 2798 |
{ |
2717 |
{ |
| 2799 |
use crate::keyboard::keysyms; |
2718 |
use crate::keyboard::keysyms; |
| 2800 |
- let keyboard_mapping = self |
2719 |
+ if let Some(mapping) = &self.keyboard_mapping { |
| 2801 |
- .connection |
2720 |
+ let keysym = mapping.keycode_to_keysym(e.detail); |
| 2802 |
- .get_keyboard_mapping( |
|
|
| 2803 |
- self.connection.setup().min_keycode, |
|
|
| 2804 |
- self.connection.setup().max_keycode |
|
|
| 2805 |
- - self.connection.setup().min_keycode |
|
|
| 2806 |
- + 1, |
|
|
| 2807 |
- )? |
|
|
| 2808 |
- .reply()?; |
|
|
| 2809 |
- |
|
|
| 2810 |
- let min_keycode = self.connection.setup().min_keycode; |
|
|
| 2811 |
- let keysyms_per_keycode = keyboard_mapping.keysyms_per_keycode; |
|
|
| 2812 |
- let index = (e.detail - min_keycode) as usize * keysyms_per_keycode as usize; |
|
|
| 2813 |
- |
|
|
| 2814 |
- if let Some(&keysym) = keyboard_mapping.keysyms.get(index) { |
|
|
| 2815 |
if keysym == keysyms::XK_ESCAPE || keysym == keysyms::XK_Q { |
2721 |
if keysym == keysyms::XK_ESCAPE || keysym == keysyms::XK_Q { |
| 2816 |
if let Err(error) = self.keybind_overlay.hide(&self.connection) { |
2722 |
if let Err(error) = self.keybind_overlay.hide(&self.connection) { |
| 2817 |
eprintln!("Failed to hide keybind overlay: {:?}", error); |
2723 |
eprintln!("Failed to hide keybind overlay: {:?}", error); |
| @@ -2938,17 +2844,22 @@ impl WindowManager { |
| 2938 |
} |
2844 |
} |
| 2939 |
} |
2845 |
} |
| 2940 |
Event::KeyPress(event) => { |
2846 |
Event::KeyPress(event) => { |
|
|
2847 |
+ let Some(mapping) = &self.keyboard_mapping else { |
|
|
2848 |
+ return Ok(None); |
|
|
2849 |
+ }; |
|
|
2850 |
+ |
| 2941 |
let result = keyboard::handle_key_press( |
2851 |
let result = keyboard::handle_key_press( |
| 2942 |
event, |
2852 |
event, |
| 2943 |
&self.config.keybindings, |
2853 |
&self.config.keybindings, |
| 2944 |
&self.keychord_state, |
2854 |
&self.keychord_state, |
| 2945 |
- &self.connection, |
2855 |
+ mapping, |
| 2946 |
- )?; |
2856 |
+ ); |
| 2947 |
|
2857 |
|
| 2948 |
match result { |
2858 |
match result { |
| 2949 |
keyboard::handlers::KeychordResult::Completed(action, arg) => { |
2859 |
keyboard::handlers::KeychordResult::Completed(action, arg) => { |
| 2950 |
self.keychord_state = keyboard::handlers::KeychordState::Idle; |
2860 |
self.keychord_state = keyboard::handlers::KeychordState::Idle; |
| 2951 |
- self.ungrab_chord_keys()?; |
2861 |
+ self.current_key = 0; |
|
|
2862 |
+ self.grab_keys()?; |
| 2952 |
self.update_bar()?; |
2863 |
self.update_bar()?; |
| 2953 |
|
2864 |
|
| 2954 |
match action { |
2865 |
match action { |
| @@ -2989,25 +2900,19 @@ impl WindowManager { |
| 2989 |
} |
2900 |
} |
| 2990 |
} |
2901 |
} |
| 2991 |
keyboard::handlers::KeychordResult::InProgress(candidates) => { |
2902 |
keyboard::handlers::KeychordResult::InProgress(candidates) => { |
| 2992 |
- let keys_pressed = match &self.keychord_state { |
2903 |
+ self.current_key += 1; |
| 2993 |
- keyboard::handlers::KeychordState::Idle => 1, |
|
|
| 2994 |
- keyboard::handlers::KeychordState::InProgress { |
|
|
| 2995 |
- keys_pressed, .. |
|
|
| 2996 |
- } => keys_pressed + 1, |
|
|
| 2997 |
- }; |
|
|
| 2998 |
- |
|
|
| 2999 |
self.keychord_state = keyboard::handlers::KeychordState::InProgress { |
2904 |
self.keychord_state = keyboard::handlers::KeychordState::InProgress { |
| 3000 |
candidates: candidates.clone(), |
2905 |
candidates: candidates.clone(), |
| 3001 |
- keys_pressed, |
2906 |
+ keys_pressed: self.current_key, |
| 3002 |
}; |
2907 |
}; |
| 3003 |
- |
2908 |
+ self.grab_keys()?; |
| 3004 |
- self.grab_next_keys(&candidates, keys_pressed)?; |
|
|
| 3005 |
self.update_bar()?; |
2909 |
self.update_bar()?; |
| 3006 |
} |
2910 |
} |
| 3007 |
keyboard::handlers::KeychordResult::Cancelled |
2911 |
keyboard::handlers::KeychordResult::Cancelled |
| 3008 |
| keyboard::handlers::KeychordResult::None => { |
2912 |
| keyboard::handlers::KeychordResult::None => { |
| 3009 |
self.keychord_state = keyboard::handlers::KeychordState::Idle; |
2913 |
self.keychord_state = keyboard::handlers::KeychordState::Idle; |
| 3010 |
- self.ungrab_chord_keys()?; |
2914 |
+ self.current_key = 0; |
|
|
2915 |
+ self.grab_keys()?; |
| 3011 |
self.update_bar()?; |
2916 |
self.update_bar()?; |
| 3012 |
} |
2917 |
} |
| 3013 |
} |
2918 |
} |
| @@ -3069,12 +2974,20 @@ impl WindowManager { |
| 3069 |
} else if event.child != x11rb::NONE { |
2974 |
} else if event.child != x11rb::NONE { |
| 3070 |
self.focus(Some(event.child))?; |
2975 |
self.focus(Some(event.child))?; |
| 3071 |
self.update_tab_bars()?; |
2976 |
self.update_tab_bars()?; |
|
|
2977 |
+ self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; |
| 3072 |
|
2978 |
|
| 3073 |
if event.detail == ButtonIndex::M1.into() { |
2979 |
if event.detail == ButtonIndex::M1.into() { |
| 3074 |
self.drag_window(event.child)?; |
2980 |
self.drag_window(event.child)?; |
| 3075 |
} else if event.detail == ButtonIndex::M3.into() { |
2981 |
} else if event.detail == ButtonIndex::M3.into() { |
| 3076 |
self.resize_window_with_mouse(event.child)?; |
2982 |
self.resize_window_with_mouse(event.child)?; |
| 3077 |
} |
2983 |
} |
|
|
2984 |
+ } else if self.windows.contains(&event.event) { |
|
|
2985 |
+ // child is NONE but event.event is a managed window (click on border/frame) |
|
|
2986 |
+ self.focus(Some(event.event))?; |
|
|
2987 |
+ self.update_tab_bars()?; |
|
|
2988 |
+ self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; |
|
|
2989 |
+ } else { |
|
|
2990 |
+ self.connection.allow_events(Allow::REPLAY_POINTER, event.time)?; |
| 3078 |
} |
2991 |
} |
| 3079 |
} |
2992 |
} |
| 3080 |
} |
2993 |
} |
| @@ -3257,7 +3170,7 @@ impl WindowManager { |
| 3257 |
} |
3170 |
} |
| 3258 |
Event::MappingNotify(event) => { |
3171 |
Event::MappingNotify(event) => { |
| 3259 |
if event.request == x11rb::protocol::xproto::Mapping::KEYBOARD { |
3172 |
if event.request == x11rb::protocol::xproto::Mapping::KEYBOARD { |
| 3260 |
- keyboard::setup_keybinds(&self.connection, self.root, &self.config.keybindings)?; |
3173 |
+ self.grab_keys()?; |
| 3261 |
} |
3174 |
} |
| 3262 |
} |
3175 |
} |
| 3263 |
Event::ConfigureNotify(event) => { |
3176 |
Event::ConfigureNotify(event) => { |