This repository was archived by the owner on Jun 19, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathprotocol.rs
87 lines (70 loc) · 2.66 KB
/
protocol.rs
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
pub mod i3bar_block;
pub mod i3bar_event;
use crate::config::SharedConfig;
use crate::errors::*;
use crate::themes::Color;
use i3bar_block::I3BarBlock;
pub fn init(never_pause: bool) {
if never_pause {
println!("{{\"version\": 1, \"click_events\": true, \"stop_signal\": 0}}\n[");
} else {
println!("{{\"version\": 1, \"click_events\": true}}\n[");
}
}
pub fn print_blocks(blocks: &[Vec<I3BarBlock>], config: &SharedConfig) -> Result<()> {
let mut last_bg = Color::None;
let mut rendered_blocks = vec![];
// The right most block should never be alternated
let mut alt = true;
for x in blocks.iter() {
if !x.is_empty() {
alt = !alt;
}
}
for widgets in blocks.iter() {
if widgets.is_empty() {
continue;
}
let mut rendered_widgets = widgets.clone();
// Apply tint for all widgets of every second block
// TODO: Allow for other non-additive tints
if alt {
for data in &mut rendered_widgets {
data.background = data.background + config.theme.alternating_tint_bg;
data.color = data.color + config.theme.alternating_tint_fg;
}
}
alt = !alt;
if let Some(separator) = &config.theme.separator {
// The first widget's BG is used to get the FG color for the current separator
let sep_fg = if config.theme.separator_fg == Color::Auto {
rendered_widgets.first().unwrap().background
} else {
config.theme.separator_fg
};
// The separator's BG is the last block's last widget's BG
let sep_bg = if config.theme.separator_bg == Color::Auto {
last_bg
} else {
config.theme.separator_bg
};
// The last widget's BG is used to get the BG color for the next separator
last_bg = rendered_widgets.last().unwrap().background;
let separator = I3BarBlock {
full_text: separator.clone().into(),
background: sep_bg,
color: sep_fg,
..Default::default()
};
rendered_blocks.push(separator);
rendered_blocks.extend(rendered_widgets);
} else {
// Re-add native separator on last widget for native theme
rendered_widgets.last_mut().unwrap().separator = None;
rendered_widgets.last_mut().unwrap().separator_block_width = None;
rendered_blocks.extend(rendered_widgets);
}
}
println!("{},", serde_json::to_string(&rendered_blocks).unwrap());
Ok(())
}