1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
use std::collections::BTreeSet;
use std::fmt;
use std::process::Command;
use wm::client::{TagSet, ClientSet, current_tagset};
use wm::kbd::*;
use wm::layout::LayoutMessage;
use wm::layout::grid::Grid;
use wm::layout::monocle::Monocle;
use wm::layout::spiral::Spiral;
use wm::layout::stack::{DStack, HStack, VStack};
use wm::window_system::{Wm, WmConfig, WmCommand};
use xcb::xproto::{MOD_MASK_LOCK, MOD_MASK_2};
pub static IGNORED_MODS_VEC: [u16; 3] = [0, MOD_MASK_LOCK as u16, MOD_MASK_2 as u16];
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
pub enum Tag {
Web,
Work2,
Work3,
Work4,
Work5,
Media,
Chat,
Logs,
Mon,
}
impl Default for Tag {
fn default() -> Tag {
Tag::Work2
}
}
impl fmt::Display for Tag {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", match *self {
Tag::Web => "web",
Tag::Work2 => "work2",
Tag::Work3 => "work3",
Tag::Work4 => "work4",
Tag::Work5 => "work5",
Tag::Media => "media",
Tag::Chat => "chat",
Tag::Logs => "logs",
Tag::Mon => "mon",
})
}
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub enum Mode {
Normal,
Setup,
}
impl Default for Mode {
fn default() -> Mode {
Mode::Normal
}
}
pub fn generate_config() -> WmConfig {
WmConfig {
f_color: (0x5353, 0x5d5d, 0x6c6c),
u_color: (0x0000, 0x0000, 0x0000),
border_width: 1,
}
}
pub fn setup_wm(wm: &mut Wm) {
let modkey = if cfg!(feature = "no-xephyr") {
MOD4
} else {
ALTGR
};
wm.setup_bindings(vec![
bind!(10, modkey, Mode::Normal, push_tagset!(0;; current_tagset)),
bind!(11, modkey, Mode::Normal, push_tagset!(1;; current_tagset)),
bind!(12, modkey, Mode::Normal, push_tagset!(2;; current_tagset)),
bind!(13, modkey, Mode::Normal, push_tagset!(3;; current_tagset)),
bind!(14, modkey, Mode::Normal, push_tagset!(4;; current_tagset)),
bind!(15, modkey, Mode::Normal, push_tagset!(5;; current_tagset)),
bind!(16, modkey, Mode::Normal, push_tagset!(6;; current_tagset)),
bind!(17, modkey, Mode::Normal, push_tagset!(7;; current_tagset)),
bind!(18, modkey, Mode::Normal, push_tagset!(8;; current_tagset)),
bind!(10,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Web)),
bind!(11,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Work2)),
bind!(12,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Work3)),
bind!(13,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Work4)),
bind!(14,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Work5)),
bind!(15,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Media)),
bind!(16,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Chat)),
bind!(17,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Logs)),
bind!(18,
modkey + CTRL + SHIFT,
Mode::Normal,
toggle_tag!(Tag::Mon)),
bind!(10, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Web)),
bind!(11, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Work2)),
bind!(12, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Work3)),
bind!(13, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Work4)),
bind!(14, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Work5)),
bind!(15, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Media)),
bind!(16, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Chat)),
bind!(17, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Logs)),
bind!(18, modkey + SHIFT, Mode::Normal, move_to_tag!(Tag::Mon)),
bind!(43, modkey, Mode::Normal, focus!(ClientSet::focus_left)),
bind!(44, modkey, Mode::Normal, focus!(ClientSet::focus_bottom)),
bind!(45, modkey, Mode::Normal, focus!(ClientSet::focus_top)),
bind!(46, modkey, Mode::Normal, focus!(ClientSet::focus_right)),
bind!(35, modkey, Mode::Normal, focus!(ClientSet::focus_next)),
bind!(61, modkey, Mode::Normal, focus!(ClientSet::focus_prev)),
bind!(43,
modkey + SHIFT,
Mode::Normal,
swap!(ClientSet::swap_left)),
bind!(44,
modkey + SHIFT,
Mode::Normal,
swap!(ClientSet::swap_bottom)),
bind!(45, modkey + SHIFT, Mode::Normal, swap!(ClientSet::swap_top)),
bind!(46,
modkey + SHIFT,
Mode::Normal,
swap!(ClientSet::swap_right)),
bind!(35,
modkey + SHIFT,
Mode::Normal,
swap!(ClientSet::swap_next)),
bind!(61,
modkey + SHIFT,
Mode::Normal,
swap!(ClientSet::swap_prev)),
bind!(44,
modkey + CTRL,
Mode::Normal,
edit_layout!(LayoutMessage::MasterFactorRel(-5),
LayoutMessage::ColumnRel(-1))),
bind!(45,
modkey + CTRL,
Mode::Normal,
edit_layout!(LayoutMessage::MasterFactorRel(5),
LayoutMessage::ColumnRel(1))),
bind!(55, modkey, Mode::Normal, change_layout!(VStack::default())),
bind!(56, modkey, Mode::Normal, change_layout!(HStack::default())),
bind!(57, modkey, Mode::Normal, change_layout!(DStack::default())),
bind!(58, modkey, Mode::Normal, change_layout!(Grid::default())),
bind!(59, modkey, Mode::Normal, change_layout!(Spiral::default())),
bind!(60, modkey, Mode::Normal, change_layout!(Monocle::default())),
bind!(65,
modkey,
Mode::Normal,
|_, s| if s.change_screen(|cur, len| (cur + 1) % len) {
WmCommand::Focus
} else {
WmCommand::NoCommand
}),
bind!(24, modkey + CTRL, Mode::Normal, |_, _| WmCommand::Quit),
bind!(42,
modkey,
Mode::Normal,
|c, s| if s.tag_stack_mut().view_prev() {
println!("{}", current_tagset(c, s));
WmCommand::Redraw
} else {
WmCommand::NoCommand
}),
bind!(31, modkey, Mode::Normal, |_, _| {
let _ = Command::new("st").spawn();
WmCommand::NoCommand
}),
bind!(54, modkey, Mode::Normal, |c, s| {
s.tag_stack()
.current()
.and_then(|t| c.get_focused_window(t.get_tags()))
.map(WmCommand::Kill)
.unwrap_or(WmCommand::NoCommand)
}),
bind!(36,
modkey,
Mode::Normal,
|_, _| WmCommand::ModeSwitch(Mode::Setup)),
bind!(36,
modkey,
Mode::Setup,
|_, _| WmCommand::ModeSwitch(Mode::Normal)),
bind!(10,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Web;; current_tagset)),
bind!(11,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Work2;; current_tagset)),
bind!(12,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Work3;; current_tagset)),
bind!(13,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Work4;; current_tagset)),
bind!(14,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Work5;; current_tagset)),
bind!(15,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Media;; current_tagset)),
bind!(16,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Chat;; current_tagset)),
bind!(17,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Logs;; current_tagset)),
bind!(18,
modkey,
Mode::Setup,
toggle_show_tag!(Tag::Mon;; current_tagset))]);
wm.setup_matching(Box::new(|props, _| if props.name == "Mozilla Firefox" {
Some((set![Tag::Web], true))
} else {
None
}));
wm.setup_screen_matching(Box::new(|screen, _, index| {
if index == 0 && screen.area.offset_y == 0 {
screen.area.offset_y = 20;
screen.area.height -= 20;
}
if screen.tag_stack.is_clean() {
let tagsets = vec![TagSet::new(set![Tag::Web], DStack::default()),
TagSet::new(set![Tag::Work2], VStack::default()),
TagSet::new(set![Tag::Work3], VStack::default()),
TagSet::new(set![Tag::Work4], Spiral::default()),
TagSet::new(set![Tag::Work5], Grid::default()),
TagSet::new(set![Tag::Media], Monocle::default()),
TagSet::new(set![Tag::Chat], HStack::default()),
TagSet::new(set![Tag::Logs], HStack::default()),
TagSet::new(set![Tag::Mon], HStack::default())];
screen.tag_stack.setup(tagsets, 1);
}
}));
wm.setup_urgency_callback(Box::new(|_| {
info!("this the default urgency callback.");
}));
}