tony / oxwm

Branch: ed1cbf5
Switch branches/tags
master
tonybtw keybinds... ed1cbf5 2025-09-28
55 lines · 1.5 KB Raw Blame History
1 use crate::keyboard;
2 use anyhow::Result;
3 use x11rb::connection::Connection;
4 use x11rb::protocol::xproto::*;
5
6 pub fn setup_keybinds(connection: &impl Connection, root: Window) -> Result<()> {
7 connection.grab_key(
8 false,
9 root,
10 ModMask::M4.into(),
11 keyboard::RETURN,
12 GrabMode::ASYNC,
13 GrabMode::ASYNC,
14 )?;
15 connection.grab_key(
16 false,
17 root,
18 (ModMask::M1 | ModMask::SHIFT).into(),
19 keyboard::Q,
20 GrabMode::ASYNC,
21 GrabMode::ASYNC,
22 )?;
23
24 connection.grab_key(
25 false,
26 root,
27 ModMask::M4.into(),
28 keyboard::Q,
29 GrabMode::ASYNC,
30 GrabMode::ASYNC,
31 )?;
32
33 Ok(())
34 }
35
36 pub fn handle_key_press(connection: &impl Connection, event: KeyPressEvent) -> Result<()> {
37 println!("KeyPress: detail={}, state={:?}", event.detail, event.state);
38
39 match (event.detail, event.state) {
40 (keyboard::RETURN, state) if state.contains(KeyButMask::MOD1) => {
41 println!("Spawning terminal");
42 std::process::Command::new("xterm").spawn()?;
43 }
44 (keyboard::Q, state) if state.contains(KeyButMask::MOD1 | KeyButMask::SHIFT) => {
45 println!("Closing focused window");
46 let focus_reply = connection.get_input_focus()?.reply()?;
47 if focus_reply.focus != x11rb::NONE && focus_reply.focus != event.root {
48 connection.kill_client(focus_reply.focus)?;
49 connection.flush()?;
50 }
51 }
52 _ => {}
53 }
54 Ok(())
55 }