tony / oxwm

Branch: 4001329
Switch branches/tags
master
tonybtw added sane defaults 4001329 2025-10-11
205 lines · 6.6 KB Raw Blame History
1 pub mod bar;
2 pub mod keyboard;
3 pub mod layout;
4 pub mod window_manager;
5
6 pub mod prelude {
7 pub use crate::ColorScheme;
8 pub use crate::bar::{BlockCommand, BlockConfig};
9 pub use crate::keyboard::{Arg, KeyAction, handlers::Key, keycodes};
10 pub use x11rb::protocol::xproto::KeyButMask;
11 }
12
13 #[derive(Clone)]
14 pub struct Config {
15 // Appearance
16 pub border_width: u32,
17 pub border_focused: u32,
18 pub border_unfocused: u32,
19 pub font: String,
20
21 // Gaps
22 pub gaps_enabled: bool,
23 pub gap_inner_horizontal: u32,
24 pub gap_inner_vertical: u32,
25 pub gap_outer_horizontal: u32,
26 pub gap_outer_vertical: u32,
27
28 // Basics
29 pub terminal: String,
30 pub modkey: x11rb::protocol::xproto::KeyButMask,
31
32 // Tags
33 pub tags: Vec<String>,
34
35 // Keybindings
36 pub keybindings: Vec<crate::keyboard::handlers::Key>,
37
38 // Status bar
39 pub status_blocks: Vec<crate::bar::BlockConfig>,
40
41 // Bar color schemes
42 pub scheme_normal: ColorScheme,
43 pub scheme_occupied: ColorScheme,
44 pub scheme_selected: ColorScheme,
45 }
46
47 #[derive(Clone, Copy)]
48 pub struct ColorScheme {
49 pub foreground: u32,
50 pub background: u32,
51 pub underline: u32,
52 }
53
54 impl Default for Config {
55 fn default() -> Self {
56 use crate::keyboard::handlers::Key;
57 use crate::keyboard::{Arg, KeyAction, keycodes};
58 use x11rb::protocol::xproto::KeyButMask;
59
60 const MODKEY: KeyButMask = KeyButMask::MOD4;
61 const SHIFT: KeyButMask = KeyButMask::SHIFT;
62
63 // Detect terminal
64 let terminal = detect_terminal();
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,
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 // Launch terminal
84 Key::new(
85 &[MODKEY],
86 keycodes::RETURN,
87 KeyAction::Spawn,
88 Arg::Str("xterm"),
89 ),
90 // Window management
91 Key::new(&[MODKEY], keycodes::Q, KeyAction::KillClient, Arg::None),
92 Key::new(
93 &[MODKEY, SHIFT],
94 keycodes::F,
95 KeyAction::ToggleFullScreen,
96 Arg::None,
97 ),
98 Key::new(&[MODKEY], keycodes::A, KeyAction::ToggleGaps, Arg::None),
99 // WM controls
100 Key::new(&[MODKEY, SHIFT], keycodes::Q, KeyAction::Quit, Arg::None),
101 Key::new(&[MODKEY, SHIFT], keycodes::R, KeyAction::Restart, Arg::None),
102 // Focus
103 Key::new(&[MODKEY], keycodes::J, KeyAction::FocusStack, Arg::Int(-1)),
104 Key::new(&[MODKEY], keycodes::K, KeyAction::FocusStack, Arg::Int(1)),
105 // View tags
106 Key::new(&[MODKEY], keycodes::KEY_1, KeyAction::ViewTag, Arg::Int(0)),
107 Key::new(&[MODKEY], keycodes::KEY_2, KeyAction::ViewTag, Arg::Int(1)),
108 Key::new(&[MODKEY], keycodes::KEY_3, KeyAction::ViewTag, Arg::Int(2)),
109 Key::new(&[MODKEY], keycodes::KEY_4, KeyAction::ViewTag, Arg::Int(3)),
110 Key::new(&[MODKEY], keycodes::KEY_5, KeyAction::ViewTag, Arg::Int(4)),
111 Key::new(&[MODKEY], keycodes::KEY_6, KeyAction::ViewTag, Arg::Int(5)),
112 Key::new(&[MODKEY], keycodes::KEY_7, KeyAction::ViewTag, Arg::Int(6)),
113 Key::new(&[MODKEY], keycodes::KEY_8, KeyAction::ViewTag, Arg::Int(7)),
114 Key::new(&[MODKEY], keycodes::KEY_9, KeyAction::ViewTag, Arg::Int(8)),
115 // Move windows to tags
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::new(),
172 scheme_normal: ColorScheme {
173 foreground: 0xbbbbbb,
174 background: 0x1a1b26,
175 underline: 0x444444,
176 },
177 scheme_occupied: ColorScheme {
178 foreground: 0x0db9d7,
179 background: 0x1a1b26,
180 underline: 0x0db9d7,
181 },
182 scheme_selected: ColorScheme {
183 foreground: 0x0db9d7,
184 background: 0x1a1b26,
185 underline: 0xad8ee6,
186 },
187 }
188 }
189 }
190
191 fn detect_terminal() -> String {
192 let terminals = ["alacritty", "kitty", "st", "xterm", "urxvt", "termite"];
193
194 for term in &terminals {
195 if std::process::Command::new("which")
196 .arg(term)
197 .output()
198 .map(|o| o.status.success())
199 .unwrap_or(false)
200 {
201 return term.to_string();
202 }
203 }
204 "xterm".to_string()
205 }