oxwm

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