oxwm

https://git.tonybtw.com/oxwm.git git://git.tonybtw.com/oxwm.git
11,064 bytes raw
1
use std::path::PathBuf;
2
3
pub mod bar;
4
pub mod client;
5
pub mod config;
6
pub mod errors;
7
pub mod keyboard;
8
pub mod layout;
9
pub mod monitor;
10
pub mod overlay;
11
pub mod signal;
12
pub mod size_hints;
13
pub mod tab_bar;
14
pub mod window_manager;
15
16
pub mod prelude {
17
    pub use crate::ColorScheme;
18
    pub use crate::LayoutSymbolOverride;
19
    pub use crate::WindowRule;
20
    pub use crate::bar::{BlockCommand, BlockConfig};
21
    pub use crate::keyboard::{Arg, KeyAction, handlers::KeyBinding, keysyms};
22
    pub use x11rb::protocol::xproto::KeyButMask;
23
}
24
25
#[derive(Debug, Clone)]
26
pub struct LayoutSymbolOverride {
27
    pub name: String,
28
    pub symbol: String,
29
}
30
31
#[derive(Debug, Clone)]
32
pub struct WindowRule {
33
    pub class: Option<String>,
34
    pub instance: Option<String>,
35
    pub title: Option<String>,
36
    pub tags: Option<u32>,
37
    pub is_floating: Option<bool>,
38
    pub monitor: Option<usize>,
39
}
40
41
impl WindowRule {
42
    pub fn matches(&self, class: &str, instance: &str, title: &str) -> bool {
43
        let class_matches = self
44
            .class
45
            .as_ref()
46
            .is_none_or(|c| class.contains(c.as_str()));
47
        let instance_matches = self
48
            .instance
49
            .as_ref()
50
            .is_none_or(|i| instance.contains(i.as_str()));
51
        let title_matches = self
52
            .title
53
            .as_ref()
54
            .is_none_or(|t| title.contains(t.as_str()));
55
        class_matches && instance_matches && title_matches
56
    }
57
}
58
59
#[derive(Debug, Clone)]
60
pub struct Config {
61
    // Meta
62
    pub path: Option<PathBuf>,
63
64
    // Appearance
65
    pub border_width: u32,
66
    pub border_focused: u32,
67
    pub border_unfocused: u32,
68
    pub font: String,
69
70
    // Gaps
71
    pub gaps_enabled: bool,
72
    pub smartgaps_enabled: bool,
73
    pub gap_inner_horizontal: u32,
74
    pub gap_inner_vertical: u32,
75
    pub gap_outer_horizontal: u32,
76
    pub gap_outer_vertical: u32,
77
78
    // Basics
79
    pub terminal: String,
80
    pub modkey: x11rb::protocol::xproto::KeyButMask,
81
82
    // Tags
83
    pub tags: Vec<String>,
84
85
    // Layout symbol overrides
86
    pub layout_symbols: Vec<LayoutSymbolOverride>,
87
88
    // Keybindings
89
    pub keybindings: Vec<crate::keyboard::handlers::Key>,
90
    pub tag_back_and_forth: bool,
91
92
    // Window rules
93
    pub window_rules: Vec<WindowRule>,
94
95
    // Status bar
96
    pub status_blocks: Vec<crate::bar::BlockConfig>,
97
98
    // Bar color schemes
99
    pub scheme_normal: ColorScheme,
100
    pub scheme_occupied: ColorScheme,
101
    pub scheme_selected: ColorScheme,
102
    pub scheme_urgent: ColorScheme,
103
104
    pub autostart: Vec<String>,
105
    pub auto_tile: bool,
106
}
107
108
#[derive(Debug, Clone, Copy)]
109
pub struct ColorScheme {
110
    pub foreground: u32,
111
    pub background: u32,
112
    pub underline: u32,
113
}
114
115
impl Default for Config {
116
    fn default() -> Self {
117
        use crate::keyboard::handlers::KeyBinding;
118
        use crate::keyboard::{Arg, KeyAction, keysyms};
119
        use x11rb::protocol::xproto::KeyButMask;
120
121
        const MODKEY: KeyButMask = KeyButMask::MOD4;
122
        const SHIFT: KeyButMask = KeyButMask::SHIFT;
123
124
        const TERMINAL: &str = "st";
125
126
        Self {
127
            path: None,
128
            border_width: 2,
129
            border_focused: 0x6dade3,
130
            border_unfocused: 0xbbbbbb,
131
            font: "monospace:size=10".to_string(),
132
            gaps_enabled: false,
133
            smartgaps_enabled: true,
134
            gap_inner_horizontal: 0,
135
            gap_inner_vertical: 0,
136
            gap_outer_horizontal: 0,
137
            gap_outer_vertical: 0,
138
            terminal: TERMINAL.to_string(),
139
            modkey: MODKEY,
140
            tags: vec!["1", "2", "3", "4", "5", "6", "7", "8", "9"]
141
                .into_iter()
142
                .map(String::from)
143
                .collect(),
144
            layout_symbols: vec![],
145
            keybindings: vec![
146
                KeyBinding::single_key(
147
                    vec![MODKEY],
148
                    keysyms::XK_RETURN,
149
                    KeyAction::Spawn,
150
                    Arg::Str(TERMINAL.to_string()),
151
                ),
152
                KeyBinding::single_key(
153
                    vec![MODKEY],
154
                    keysyms::XK_D,
155
                    KeyAction::Spawn,
156
                    Arg::Array(vec![
157
                        "sh".to_string(),
158
                        "-c".to_string(),
159
                        "dmenu_run -l 10".to_string(),
160
                    ]),
161
                ),
162
                KeyBinding::single_key(
163
                    vec![MODKEY],
164
                    keysyms::XK_Q,
165
                    KeyAction::KillClient,
166
                    Arg::None,
167
                ),
168
                KeyBinding::single_key(
169
                    vec![MODKEY],
170
                    keysyms::XK_N,
171
                    KeyAction::CycleLayout,
172
                    Arg::None,
173
                ),
174
                KeyBinding::single_key(
175
                    vec![MODKEY, SHIFT],
176
                    keysyms::XK_F,
177
                    KeyAction::ToggleFullScreen,
178
                    Arg::None,
179
                ),
180
                KeyBinding::single_key(
181
                    vec![MODKEY],
182
                    keysyms::XK_A,
183
                    KeyAction::ToggleGaps,
184
                    Arg::None,
185
                ),
186
                KeyBinding::single_key(
187
                    vec![MODKEY, SHIFT],
188
                    keysyms::XK_Q,
189
                    KeyAction::Quit,
190
                    Arg::None,
191
                ),
192
                KeyBinding::single_key(
193
                    vec![MODKEY, SHIFT],
194
                    keysyms::XK_R,
195
                    KeyAction::Restart,
196
                    Arg::None,
197
                ),
198
                KeyBinding::single_key(
199
                    vec![MODKEY],
200
                    keysyms::XK_F,
201
                    KeyAction::ToggleFloating,
202
                    Arg::None,
203
                ),
204
                KeyBinding::single_key(
205
                    vec![MODKEY],
206
                    keysyms::XK_J,
207
                    KeyAction::FocusStack,
208
                    Arg::Int(-1),
209
                ),
210
                KeyBinding::single_key(
211
                    vec![MODKEY],
212
                    keysyms::XK_K,
213
                    KeyAction::FocusStack,
214
                    Arg::Int(1),
215
                ),
216
                KeyBinding::single_key(
217
                    vec![MODKEY],
218
                    keysyms::XK_1,
219
                    KeyAction::ViewTag,
220
                    Arg::Int(0),
221
                ),
222
                KeyBinding::single_key(
223
                    vec![MODKEY],
224
                    keysyms::XK_2,
225
                    KeyAction::ViewTag,
226
                    Arg::Int(1),
227
                ),
228
                KeyBinding::single_key(
229
                    vec![MODKEY],
230
                    keysyms::XK_3,
231
                    KeyAction::ViewTag,
232
                    Arg::Int(2),
233
                ),
234
                KeyBinding::single_key(
235
                    vec![MODKEY],
236
                    keysyms::XK_4,
237
                    KeyAction::ViewTag,
238
                    Arg::Int(3),
239
                ),
240
                KeyBinding::single_key(
241
                    vec![MODKEY],
242
                    keysyms::XK_5,
243
                    KeyAction::ViewTag,
244
                    Arg::Int(4),
245
                ),
246
                KeyBinding::single_key(
247
                    vec![MODKEY],
248
                    keysyms::XK_6,
249
                    KeyAction::ViewTag,
250
                    Arg::Int(5),
251
                ),
252
                KeyBinding::single_key(
253
                    vec![MODKEY],
254
                    keysyms::XK_7,
255
                    KeyAction::ViewTag,
256
                    Arg::Int(6),
257
                ),
258
                KeyBinding::single_key(
259
                    vec![MODKEY],
260
                    keysyms::XK_8,
261
                    KeyAction::ViewTag,
262
                    Arg::Int(7),
263
                ),
264
                KeyBinding::single_key(
265
                    vec![MODKEY],
266
                    keysyms::XK_9,
267
                    KeyAction::ViewTag,
268
                    Arg::Int(8),
269
                ),
270
                KeyBinding::single_key(
271
                    vec![MODKEY, SHIFT],
272
                    keysyms::XK_1,
273
                    KeyAction::MoveToTag,
274
                    Arg::Int(0),
275
                ),
276
                KeyBinding::single_key(
277
                    vec![MODKEY, SHIFT],
278
                    keysyms::XK_2,
279
                    KeyAction::MoveToTag,
280
                    Arg::Int(1),
281
                ),
282
                KeyBinding::single_key(
283
                    vec![MODKEY, SHIFT],
284
                    keysyms::XK_3,
285
                    KeyAction::MoveToTag,
286
                    Arg::Int(2),
287
                ),
288
                KeyBinding::single_key(
289
                    vec![MODKEY, SHIFT],
290
                    keysyms::XK_4,
291
                    KeyAction::MoveToTag,
292
                    Arg::Int(3),
293
                ),
294
                KeyBinding::single_key(
295
                    vec![MODKEY, SHIFT],
296
                    keysyms::XK_5,
297
                    KeyAction::MoveToTag,
298
                    Arg::Int(4),
299
                ),
300
                KeyBinding::single_key(
301
                    vec![MODKEY, SHIFT],
302
                    keysyms::XK_6,
303
                    KeyAction::MoveToTag,
304
                    Arg::Int(5),
305
                ),
306
                KeyBinding::single_key(
307
                    vec![MODKEY, SHIFT],
308
                    keysyms::XK_7,
309
                    KeyAction::MoveToTag,
310
                    Arg::Int(6),
311
                ),
312
                KeyBinding::single_key(
313
                    vec![MODKEY, SHIFT],
314
                    keysyms::XK_8,
315
                    KeyAction::MoveToTag,
316
                    Arg::Int(7),
317
                ),
318
                KeyBinding::single_key(
319
                    vec![MODKEY, SHIFT],
320
                    keysyms::XK_9,
321
                    KeyAction::MoveToTag,
322
                    Arg::Int(8),
323
                ),
324
            ],
325
            tag_back_and_forth: false,
326
            window_rules: vec![],
327
            status_blocks: vec![crate::bar::BlockConfig {
328
                format: "{}".to_string(),
329
                command: crate::bar::BlockCommand::DateTime("%a, %b %d - %-I:%M %P".to_string()),
330
                interval_secs: 1,
331
                color: 0x0db9d7,
332
                underline: true,
333
            }],
334
            scheme_normal: ColorScheme {
335
                foreground: 0xbbbbbb,
336
                background: 0x1a1b26,
337
                underline: 0x444444,
338
            },
339
            scheme_occupied: ColorScheme {
340
                foreground: 0x0db9d7,
341
                background: 0x1a1b26,
342
                underline: 0x0db9d7,
343
            },
344
            scheme_selected: ColorScheme {
345
                foreground: 0x0db9d7,
346
                background: 0x1a1b26,
347
                underline: 0xad8ee6,
348
            },
349
            scheme_urgent: ColorScheme {
350
                foreground: 0xff5555,
351
                background: 0x1a1b26,
352
                underline: 0xff5555,
353
            },
354
            autostart: vec![],
355
            auto_tile: false,
356
        }
357
    }
358
}