1use capybar::{
2 root::Root,
3 util::Color,
4 widgets::{
5 battery::{Battery, BatterySettings},
6 clock::{Clock, ClockSettings},
7 containers::bar::{Bar, BarSettings},
8 cpu::{CPUSettings, CPU},
9 text::TextSettings,
10 Margin, Style, WidgetData, WidgetNew,
11 },
12};
13use wayland_client::{globals::registry_queue_init, Connection};
14
15struct Palete {
16 background: Color,
17 border: Color,
18 font: Color,
19}
20
21fn main() -> Result<(), Box<dyn std::error::Error>> {
22 let catpuccin_mocha = Palete {
23 background: Color::from_hex(0x1e1e2eff),
24 border: Color::from_hex(0x74c7ecff),
25 font: Color::from_hex(0xf5e0dcff),
26 };
27
28 let conn = Connection::connect_to_env()?;
29 let (globals, mut event_queue) = registry_queue_init(&conn)?;
30
31 let mut bar = Bar::new(
32 None,
33 BarSettings {
34 default_data: WidgetData {
35 width: 1920,
36 ..WidgetData::default()
37 },
38 padding: (10, 10, 10),
39
40 style: Style {
41 background: Some(catpuccin_mocha.background),
42 border: Some((1, catpuccin_mocha.border)),
43
44 ..Style::default()
45 },
46
47 ..BarSettings::default()
48 },
49 )?;
50
51 bar.create_widget_left(
53 CPU::new,
54 CPUSettings {
55 update_rate: 1000,
56 text_settings: TextSettings {
57 font_color: catpuccin_mocha.font,
58 size: 25.0,
59
60 ..TextSettings::default()
61 },
62 default_data: WidgetData {
63 ..WidgetData::default()
64 },
65 style: Style {
66 margin: Margin {
67 left: 10,
68 right: 0,
69 up: 0,
70 down: 0,
71 },
72 ..Default::default()
73 },
74 ..CPUSettings::default()
75 },
76 )?;
77
78 bar.create_widget_center(
80 Clock::new,
81 ClockSettings {
82 font_color: catpuccin_mocha.font,
83 size: 25.0,
84
85 ..ClockSettings::default()
86 },
87 )?;
88
89 bar.create_widget_right(
91 Battery::new,
92 BatterySettings {
93 text_settings: TextSettings {
94 font_color: catpuccin_mocha.font,
95 size: 25.0,
96
97 ..TextSettings::default()
98 },
99 default_data: WidgetData {
100 ..WidgetData::default()
101 },
102 style: Style {
103 margin: Margin {
104 left: 0,
105 right: 10,
106 up: 0,
107 down: 0,
108 },
109 ..Default::default()
110 },
111 ..BatterySettings::default()
112 },
113 )?;
114
115 let mut capybar = Root::new(&globals, &mut event_queue, Some(bar))?;
116
117 capybar.add_font_by_name("jetbrainsmononerdfont")?;
121 capybar.add_font_by_name("jetbrainsmononerdfont")?;
122
123 capybar.run(&mut event_queue)?;
124
125 Ok(())
126}