-
Notifications
You must be signed in to change notification settings - Fork 87
/
Copy pathmain.rs
107 lines (94 loc) · 3.32 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
//! penrose :: minimal configuration
//!
//! This file will give you a functional if incredibly minimal window manager that
//! has multiple workspaces and simple client / workspace movement.
use penrose::{
builtin::{
actions::{
exit,
floating::{sink_focused, MouseDragHandler, MouseResizeHandler},
modify_with, send_layout_message, spawn,
},
layout::messages::{ExpandMain, IncMain, ShrinkMain},
},
core::{
bindings::{
click_handler, parse_keybindings_with_xmodmap, KeyEventHandler, MouseEventHandler,
MouseState,
},
Config, WindowManager,
},
map,
x11rb::RustConn,
Result,
};
use std::collections::HashMap;
use tracing_subscriber::{self, prelude::*};
fn raw_key_bindings() -> HashMap<String, Box<dyn KeyEventHandler<RustConn>>> {
let mut raw_bindings = map! {
map_keys: |k: &str| k.to_string();
"M-j" => modify_with(|cs| cs.focus_down()),
"M-k" => modify_with(|cs| cs.focus_up()),
"M-S-j" => modify_with(|cs| cs.swap_down()),
"M-S-k" => modify_with(|cs| cs.swap_up()),
"M-S-q" => modify_with(|cs| cs.kill_focused()),
"M-Tab" => modify_with(|cs| cs.toggle_tag()),
"M-bracketright" => modify_with(|cs| cs.next_screen()),
"M-bracketleft" => modify_with(|cs| cs.previous_screen()),
"M-grave" => modify_with(|cs| cs.next_layout()),
"M-S-grave" => modify_with(|cs| cs.previous_layout()),
"M-S-Up" => send_layout_message(|| IncMain(1)),
"M-S-Down" => send_layout_message(|| IncMain(-1)),
"M-S-Right" => send_layout_message(|| ExpandMain),
"M-S-Left" => send_layout_message(|| ShrinkMain),
"M-semicolon" => spawn("dmenu_run"),
"M-Return" => spawn("st"),
"M-A-Escape" => exit(),
};
for tag in &["1", "2", "3", "4", "5", "6", "7", "8", "9"] {
raw_bindings.extend([
(
format!("M-{tag}"),
modify_with(move |client_set| client_set.focus_tag(tag)),
),
(
format!("M-S-{tag}"),
modify_with(move |client_set| client_set.move_focused_to_tag(tag)),
),
]);
}
raw_bindings
}
fn mouse_bindings() -> HashMap<MouseState, Box<dyn MouseEventHandler<RustConn>>> {
use penrose::core::bindings::{
ModifierKey::{Meta, Shift},
MouseButton::{Left, Middle, Right},
};
map! {
map_keys: |(button, modifiers)| MouseState { button, modifiers };
(Left, vec![Shift, Meta]) => MouseDragHandler::boxed_default(),
(Right, vec![Shift, Meta]) => MouseResizeHandler::boxed_default(),
(Middle, vec![Shift, Meta]) => click_handler(sink_focused()),
}
}
fn main() -> Result<()> {
tracing_subscriber::fmt()
.with_env_filter("info")
.finish()
.init();
let conn = RustConn::new()?;
let key_bindings = parse_keybindings_with_xmodmap(raw_key_bindings())?;
let wm = WindowManager::new(Config::default(), key_bindings, mouse_bindings(), conn)?;
wm.run()
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn bindings_parse_correctly_with_xmodmap() {
let res = parse_keybindings_with_xmodmap(raw_key_bindings());
if let Err(e) = res {
panic!("{e}");
}
}
}