oxwm

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