tony / oxwm

Branch: 953e629
Switch branches/tags
master
emzywastaken move errors to `error` module 953e629 2025-10-14
195 lines · 6.5 KB Raw Blame History
1 pub mod bar;
2 pub mod errors;
3 pub mod keyboard;
4 pub mod layout;
5 pub mod window_manager;
6
7 pub mod prelude {
8 pub use crate::ColorScheme;
9 pub use crate::bar::{BlockCommand, BlockConfig};
10 pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes};
11 pub use x11rb::protocol::xproto::KeyButMask;
12 }
13
14 #[derive(Clone)]
15 pub struct Config {
16 // Appearance
17 pub border_width: u32,
18 pub border_focused: u32,
19 pub border_unfocused: u32,
20 pub font: String,
21
22 // Gaps
23 pub gaps_enabled: bool,
24 pub gap_inner_horizontal: u32,
25 pub gap_inner_vertical: u32,
26 pub gap_outer_horizontal: u32,
27 pub gap_outer_vertical: u32,
28
29 // Basics
30 pub terminal: String,
31 pub modkey: x11rb::protocol::xproto::KeyButMask,
32
33 // Tags
34 pub tags: Vec<String>,
35
36 // Keybindings
37 pub keybindings: Vec<crate::keyboard::handlers::Key>,
38
39 // Status bar
40 pub status_blocks: Vec<crate::bar::BlockConfig>,
41
42 // Bar color schemes
43 pub scheme_normal: ColorScheme,
44 pub scheme_occupied: ColorScheme,
45 pub scheme_selected: ColorScheme,
46 }
47
48 #[derive(Clone, Copy)]
49 pub struct ColorScheme {
50 pub foreground: u32,
51 pub background: u32,
52 pub underline: u32,
53 }
54
55 impl Default for Config {
56 fn default() -> Self {
57 use crate::keyboard::handlers::Key;
58 use crate::keyboard::{Arg, KeyAction, keycodes};
59 use x11rb::protocol::xproto::KeyButMask;
60
61 const MODKEY: KeyButMask = KeyButMask::MOD4;
62 const SHIFT: KeyButMask = KeyButMask::SHIFT;
63
64 const TERMINAL: &str = "st";
65
66 Self {
67 border_width: 2,
68 border_focused: 0x6dade3,
69 border_unfocused: 0xbbbbbb,
70 font: "monospace:size=12".to_string(),
71 gaps_enabled: false,
72 gap_inner_horizontal: 0,
73 gap_inner_vertical: 0,
74 gap_outer_horizontal: 0,
75 gap_outer_vertical: 0,
76 terminal: TERMINAL.to_string(),
77 modkey: MODKEY,
78 tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
79 .into_iter()
80 .map(String::from)
81 .collect(),
82 keybindings: vec![
83 Key::new(
84 &[MODKEY],
85 keycodes::RETURN,
86 KeyAction::Spawn,
87 Arg::Str(TERMINAL),
88 ),
89 Key::new(
90 &[MODKEY],
91 keycodes::D,
92 KeyAction::Spawn,
93 Arg::Array(&["sh", "-c", "dmenu_run"]),
94 ),
95 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
96 Key::new(
97 &[MODKEY, SHIFT],
98 keycodes::F,
99 KeyAction::ToggleFullScreen,
100 Arg::None,
101 ),
102 Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
103 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
104 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
105 Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
106 Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)),
107 Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)),
108 Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)),
109 Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)),
110 Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)),
111 Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)),
112 Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)),
113 Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)),
114 Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)),
115 Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)),
116 Key::new(
117 &[MODKEY, SHIFT],
118 keycodes::KEY_1,
119 KeyAction::MoveToTag,
120 Arg::Int(0),
121 ),
122 Key::new(
123 &[MODKEY, SHIFT],
124 keycodes::KEY_2,
125 KeyAction::MoveToTag,
126 Arg::Int(1),
127 ),
128 Key::new(
129 &[MODKEY, SHIFT],
130 keycodes::KEY_3,
131 KeyAction::MoveToTag,
132 Arg::Int(2),
133 ),
134 Key::new(
135 &[MODKEY, SHIFT],
136 keycodes::KEY_4,
137 KeyAction::MoveToTag,
138 Arg::Int(3),
139 ),
140 Key::new(
141 &[MODKEY, SHIFT],
142 keycodes::KEY_5,
143 KeyAction::MoveToTag,
144 Arg::Int(4),
145 ),
146 Key::new(
147 &[MODKEY, SHIFT],
148 keycodes::KEY_6,
149 KeyAction::MoveToTag,
150 Arg::Int(5),
151 ),
152 Key::new(
153 &[MODKEY, SHIFT],
154 keycodes::KEY_7,
155 KeyAction::MoveToTag,
156 Arg::Int(6),
157 ),
158 Key::new(
159 &[MODKEY, SHIFT],
160 keycodes::KEY_8,
161 KeyAction::MoveToTag,
162 Arg::Int(7),
163 ),
164 Key::new(
165 &[MODKEY, SHIFT],
166 keycodes::KEY_9,
167 KeyAction::MoveToTag,
168 Arg::Int(8),
169 ),
170 ],
171 status_blocks: vec![crate::bar::BlockConfig {
172 format: " {}",
173 command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P"),
174 interval_secs: 1,
175 color: 0x0db9d7,
176 underline: true,
177 }],
178 scheme_normal: ColorScheme {
179 foreground: 0xbbbbbb,
180 background: 0x1a1b26,
181 underline: 0x444444,
182 },
183 scheme_occupied: ColorScheme {
184 foreground: 0x0db9d7,
185 background: 0x1a1b26,
186 underline: 0x0db9d7,
187 },
188 scheme_selected: ColorScheme {
189 foreground: 0x0db9d7,
190 background: 0x1a1b26,
191 underline: 0xad8ee6,
192 },
193 }
194 }
195 }