Support toggle between V1 and V2 UIs
This commit is contained in:
+77
-40
@@ -23,13 +23,47 @@ use state::{State, OperationMode};
|
|||||||
use event::{Event, Events};
|
use event::{Event, Events};
|
||||||
use widgets::{
|
use widgets::{
|
||||||
Audio, Backlight, Battery, Calendar, Clock, Date, Geometry, HorizontalLayout, IndexedLayout,
|
Audio, Backlight, Battery, Calendar, Clock, Date, Geometry, HorizontalLayout, IndexedLayout,
|
||||||
Interface, InvertedHorizontalLayout, Line, Margin, VerticalLayout, Widget,
|
Interface, InvertedHorizontalLayout, Line, Margin, VerticalLayout, Widget, Layout,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{rc::Rc, thread};
|
use std::{
|
||||||
|
env,
|
||||||
|
rc::Rc,
|
||||||
|
thread
|
||||||
|
};
|
||||||
|
|
||||||
|
enum UIVersion {
|
||||||
|
V1,
|
||||||
|
V2,
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
// let now = Local::now();
|
// let now = Local::now();
|
||||||
|
|
||||||
|
let mut args = env::args();
|
||||||
|
// Skip program name
|
||||||
|
_ = args.next();
|
||||||
|
|
||||||
|
let mut version = UIVersion::V2;
|
||||||
|
let mut mode = OperationMode::XdgToplevel;
|
||||||
|
loop {
|
||||||
|
match args.next() {
|
||||||
|
Some(ref s) if s == "layer_shell" => {
|
||||||
|
let width = args.next().map(|x| x.parse::<u32>().ok()).flatten();
|
||||||
|
let height = args.next().map(|x| x.parse::<u32>().ok()).flatten();
|
||||||
|
match (width, height) {
|
||||||
|
(Some(w), Some(h)) => mode = OperationMode::LayerSurface((w, h)),
|
||||||
|
_ => panic!("invalid arguments"),
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Some(ref s) if s == "xdg_shell" => mode = OperationMode::XdgToplevel,
|
||||||
|
Some(ref s) if s == "v1" => version = UIVersion::V1,
|
||||||
|
Some(ref s) if s == "v2" => version = UIVersion::V2,
|
||||||
|
Some(_) => panic!("unknown argument"),
|
||||||
|
None => break,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
let conn = Connection::connect_to_env().unwrap();
|
let conn = Connection::connect_to_env().unwrap();
|
||||||
|
|
||||||
let event_queue = conn.new_event_queue();
|
let event_queue = conn.new_event_queue();
|
||||||
@@ -92,6 +126,41 @@ fn main() {
|
|||||||
fm.add_font_path("sans", "/usr/share/fonts/noto/NotoSans-Regular.ttf".to_string());
|
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());
|
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", 18.0, -1, 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(Audio::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 clock = Box::new(Clock::new(&mut fm, "sans", 128.));
|
||||||
let calendar = Box::new(Calendar::new(&mut fm, "monospace", 12.0, 1, -1));
|
let calendar = Box::new(Calendar::new(&mut fm, "monospace", 12.0, 1, -1));
|
||||||
let date = Box::new(Date::new(&mut fm, "sans", 48.));
|
let date = Box::new(Date::new(&mut fm, "sans", 48.));
|
||||||
@@ -100,11 +169,8 @@ fn main() {
|
|||||||
let battery = Box::new(Battery::new(events.clone(), &mut fm, "sans", 24.));
|
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 backlight = Box::new(Backlight::new("intel_backlight", &mut fm, "sans", 24.));
|
||||||
let audio = Box::new(Audio::new(events.clone(), &mut fm, "sans", 24.));
|
let audio = Box::new(Audio::new(events.clone(), &mut fm, "sans", 24.));
|
||||||
|
let v: Vec<Box<dyn Widget>> = vec![clock, date, battery, backlight, audio, line, calendar, launcher];
|
||||||
let widgets: Vec<Box<dyn Widget>> =
|
let l = Rc::new(VerticalLayout::new(vec![
|
||||||
vec![clock, date, battery, backlight, audio, line, calendar, launcher];
|
|
||||||
|
|
||||||
let layout = Rc::new(VerticalLayout::new(vec![
|
|
||||||
HorizontalLayout::new(vec![
|
HorizontalLayout::new(vec![
|
||||||
IndexedLayout::new(0),
|
IndexedLayout::new(0),
|
||||||
Margin::new(IndexedLayout::new(1), (16, 16, 0, 0)),
|
Margin::new(IndexedLayout::new(1), (16, 16, 0, 0)),
|
||||||
@@ -117,38 +183,9 @@ fn main() {
|
|||||||
IndexedLayout::new(5),
|
IndexedLayout::new(5),
|
||||||
InvertedHorizontalLayout::new(vec![IndexedLayout::new(6), IndexedLayout::new(7)]),
|
InvertedHorizontalLayout::new(vec![IndexedLayout::new(6), IndexedLayout::new(7)]),
|
||||||
]));
|
]));
|
||||||
|
(v, l)
|
||||||
/* alt look
|
}
|
||||||
let clock = Box::new(Clock::new(&mut fm, "sans", 256.));
|
};
|
||||||
let date = Box::new(Date::new(&mut fm, "sans", 64.));
|
|
||||||
let calendar = Box::new(Calendar::new(&mut fm, "monospace", 16.0, 3, 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 widgets: Vec<Box<dyn Widget>> =
|
|
||||||
vec![clock, date, battery, backlight, calendar];
|
|
||||||
|
|
||||||
let layout = 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)),
|
|
||||||
]),
|
|
||||||
(88, 0, 0, 0),
|
|
||||||
),
|
|
||||||
]),
|
|
||||||
IndexedLayout::new(4),
|
|
||||||
//IndexedLayout::new(5),
|
|
||||||
]), (20, 20, 20, 20))
|
|
||||||
);
|
|
||||||
*/
|
|
||||||
|
|
||||||
let font_thread = thread::Builder::new()
|
let font_thread = thread::Builder::new()
|
||||||
.name("fontloader".to_string())
|
.name("fontloader".to_string())
|
||||||
@@ -157,7 +194,7 @@ fn main() {
|
|||||||
fm
|
fm
|
||||||
}).unwrap();
|
}).unwrap();
|
||||||
|
|
||||||
let mut state = State::new(OperationMode::XdgToplevel, widgets, layout, MaybeFontMap::Waiting(font_thread), events);
|
let mut state = State::new(mode, widgets, layout, MaybeFontMap::Waiting(font_thread), events);
|
||||||
|
|
||||||
let mut damage = Vec::new();
|
let mut damage = Vec::new();
|
||||||
for _ in 0..state.widgets.len() {
|
for _ in 0..state.widgets.len() {
|
||||||
|
|||||||
Reference in New Issue
Block a user