oxwm

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