tony / oxwm

Branch: 7443210
Switch branches/tags
master
tonybtw Finished killing windows dymanically and correctly b5923a9 2025-09-29
67 lines · 1.6 KB Raw Blame History
1 use crate::keyboard::keycodes;
2 use anyhow::Result;
3 use x11rb::connection::Connection;
4 use x11rb::protocol::xproto::*;
5
6 #[derive(Debug)]
7 pub enum KeyAction {
8 SpawnTerminal,
9 CloseWindow,
10 CycleWindow,
11 Quit,
12 None,
13 }
14
15 pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()> {
16 connection.grab_key(
17 false,
18 root,
19 ModMask::M1.into(),
20 keycodes::RETURN,
21 GrabMode::ASYNC,
22 GrabMode::ASYNC,
23 )?;
24
25 connection.grab_key(
26 false,
27 root,
28 (ModMask::M1 | ModMask::SHIFT).into(),
29 keycodes::Q,
30 GrabMode::ASYNC,
31 GrabMode::ASYNC,
32 )?;
33
34 connection.grab_key(
35 false,
36 root,
37 ModMask::M1.into(),
38 keycodes::Q,
39 GrabMode::ASYNC,
40 GrabMode::ASYNC,
41 )?;
42
43 connection.grab_key(
44 false,
45 root,
46 ModMask::M1.into(),
47 keycodes::J,
48 GrabMode::ASYNC,
49 GrabMode::ASYNC,
50 )?;
51
52 Ok(())
53 }
54
55 pub fn handle_key_press(event: KeyPressEvent) -> Result<KeyAction> {
56 println!("KeyPress: detail={}, state={:?}", event.detail, event.state);
57 let action = match (event.detail, event.state) {
58 (keycodes::RETURN, state) if state.contains(KeyButMask::MOD1) => KeyAction::SpawnTerminal,
59 (keycodes::Q, state) if state.contains(KeyButMask::MOD1 | KeyButMask::SHIFT) => {
60 KeyAction::CloseWindow
61 }
62 (keycodes::Q, state) if state.contains(KeyButMask::MOD1) => KeyAction::Quit,
63 (keycodes::J, state) if state.contains(KeyButMask::MOD1) => KeyAction::CycleWindow,
64 _ => KeyAction::None,
65 };
66 Ok(action)
67 }