config: Add config support
This commit is contained in:
+28
-73
@@ -1,5 +1,6 @@
|
||||
mod buffer;
|
||||
mod color;
|
||||
mod config;
|
||||
mod draw;
|
||||
mod event;
|
||||
mod fonts;
|
||||
@@ -8,6 +9,8 @@ mod state;
|
||||
mod utils;
|
||||
mod widgets;
|
||||
|
||||
use std::fs::File;
|
||||
|
||||
use wayland_client::{Connection, QueueHandle, WaylandSource};
|
||||
|
||||
use calloop::{
|
||||
@@ -17,13 +20,11 @@ use calloop::{
|
||||
use chrono::{Duration, Local, Timelike};
|
||||
|
||||
use buffer::BufferView;
|
||||
use config::{Config, Widget as ConfigWidget};
|
||||
use event::{Event, Events};
|
||||
use fonts::{FontMap, MaybeFontMap};
|
||||
use state::{OperationMode, State};
|
||||
use widgets::{
|
||||
Backlight, Battery, Calendar, Clock, Date, Geometry, HorizontalLayout, IndexedLayout,
|
||||
Interface, InvertedHorizontalLayout, Layout, Line, Margin, PulseAudio, VerticalLayout, Widget,
|
||||
};
|
||||
use widgets::{Geometry, Widget};
|
||||
|
||||
use std::{env, rc::Rc, thread};
|
||||
|
||||
@@ -115,77 +116,31 @@ fn main() {
|
||||
|
||||
let mut fm = FontMap::new();
|
||||
|
||||
// TODO: Cache in a file
|
||||
fm.add_font_path(
|
||||
"sans",
|
||||
"/usr/share/fonts/noto/NotoSans-Regular.ttf".to_string(),
|
||||
);
|
||||
fm.add_font_path(
|
||||
"monospace",
|
||||
"/usr/share/fonts/noto/NotoSansMono-Regular.ttf".to_string(),
|
||||
);
|
||||
|
||||
let (widgets, layout): (Vec<Box<dyn Widget>>, Rc<Box<dyn Layout>>) = match version {
|
||||
UIVersion::V1 => {
|
||||
let clock = Box::new(Clock::new(&mut fm, "sans", 256.));
|
||||
let calendar = Box::new(Calendar::new(&mut fm, "monospace", "sans", 36.0, 3, 1));
|
||||
let date = Box::new(Date::new(&mut fm, "sans", 48.));
|
||||
let launcher = Box::new(Interface::new(events.clone(), &mut fm, "monospace", 32.));
|
||||
let battery = Box::new(Battery::new(events.clone(), &mut fm, "sans", 24.));
|
||||
let backlight = Box::new(Backlight::new("intel_backlight", &mut fm, "sans", 24.));
|
||||
let audio = Box::new(PulseAudio::new(events.clone(), &mut fm, "sans", 24.));
|
||||
|
||||
let v: Vec<Box<dyn Widget>> =
|
||||
vec![clock, date, battery, backlight, audio, calendar, launcher];
|
||||
let l = Rc::new(Margin::new(
|
||||
VerticalLayout::new(vec![
|
||||
HorizontalLayout::new(vec![
|
||||
VerticalLayout::new(vec![IndexedLayout::new(1), IndexedLayout::new(0)]),
|
||||
Margin::new(
|
||||
VerticalLayout::new(vec![
|
||||
Margin::new(IndexedLayout::new(2), (0, 0, 0, 8)),
|
||||
Margin::new(IndexedLayout::new(3), (0, 0, 0, 8)),
|
||||
Margin::new(IndexedLayout::new(4), (0, 0, 0, 8)),
|
||||
]),
|
||||
(88, 0, 0, 0),
|
||||
),
|
||||
]),
|
||||
IndexedLayout::new(5),
|
||||
IndexedLayout::new(6),
|
||||
]),
|
||||
(20, 20, 20, 20),
|
||||
));
|
||||
(v, l)
|
||||
}
|
||||
UIVersion::V2 => {
|
||||
let clock = Box::new(Clock::new(&mut fm, "sans", 128.));
|
||||
let calendar = Box::new(Calendar::new(&mut fm, "monospace", "sans", 24.0, 1, -1));
|
||||
let date = Box::new(Date::new(&mut fm, "sans", 48.));
|
||||
let line = Box::new(Line::new(1));
|
||||
let launcher = Box::new(Interface::new(events.clone(), &mut fm, "monospace", 32.));
|
||||
let battery = Box::new(Battery::new(events.clone(), &mut fm, "sans", 24.));
|
||||
let backlight = Box::new(Backlight::new("intel_backlight", &mut fm, "sans", 24.));
|
||||
let audio = Box::new(PulseAudio::new(events.clone(), &mut fm, "sans", 24.));
|
||||
let v: Vec<Box<dyn Widget>> = vec![
|
||||
clock, date, battery, backlight, audio, line, calendar, launcher,
|
||||
];
|
||||
let l = Rc::new(VerticalLayout::new(vec![
|
||||
HorizontalLayout::new(vec![
|
||||
IndexedLayout::new(0),
|
||||
Margin::new(IndexedLayout::new(1), (16, 16, 0, 0)),
|
||||
VerticalLayout::new(vec![
|
||||
Margin::new(IndexedLayout::new(2), (16, 8, 8, 0)),
|
||||
Margin::new(IndexedLayout::new(3), (16, 8, 8, 0)),
|
||||
Margin::new(IndexedLayout::new(4), (16, 8, 8, 0)),
|
||||
]),
|
||||
]),
|
||||
IndexedLayout::new(5),
|
||||
InvertedHorizontalLayout::new(vec![IndexedLayout::new(6), IndexedLayout::new(7)]),
|
||||
]));
|
||||
(v, l)
|
||||
}
|
||||
let home = env::var_os("HOME").unwrap().into_string().unwrap();
|
||||
let config: Config = match File::open(format!("{}/.config/wldash/config.yml", home)) {
|
||||
Ok(f) => serde_yaml::from_reader(f).unwrap(),
|
||||
Err(_) => Default::default(),
|
||||
};
|
||||
|
||||
let widget = match config.widget {
|
||||
Some(w) => w,
|
||||
None => match version {
|
||||
UIVersion::V1 => ConfigWidget::v1(),
|
||||
UIVersion::V2 => ConfigWidget::v2(),
|
||||
},
|
||||
};
|
||||
|
||||
if let Some(font_paths) = config.font_paths {
|
||||
for (key, value) in font_paths.into_iter() {
|
||||
fm.add_font_path(Box::leak(key.into_boxed_str()), value);
|
||||
}
|
||||
}
|
||||
|
||||
let layout = Rc::new(widget.construct_layout(&mut 0));
|
||||
let mut widgets: Vec<Box<dyn Widget>> = Vec::new();
|
||||
widget.construct_widgets(&mut widgets, &mut fm, &events);
|
||||
|
||||
|
||||
let font_thread = thread::Builder::new()
|
||||
.name("fontloader".to_string())
|
||||
.spawn(move || {
|
||||
|
||||
Reference in New Issue
Block a user