More stuff
This commit is contained in:
+40
-80
@@ -170,20 +170,27 @@ impl BufferManager {
|
||||
}
|
||||
|
||||
pub struct BufferView<'a> {
|
||||
buf: &'a mut MmapMut,
|
||||
view: &'a mut [u32],
|
||||
dimensions: (u32, u32),
|
||||
subdimensions: Option<(u32, u32, u32, u32)>,
|
||||
}
|
||||
|
||||
impl<'a> BufferView<'a> {
|
||||
pub fn new(buf: &'a mut MmapMut, dimensions: (u32, u32)) -> BufferView {
|
||||
let view = unsafe {
|
||||
std::slice::from_raw_parts_mut(
|
||||
buf.as_mut_ptr() as *mut u32,
|
||||
(dimensions.0 * dimensions.1) as usize,
|
||||
)
|
||||
};
|
||||
BufferView {
|
||||
buf,
|
||||
view,
|
||||
dimensions,
|
||||
subdimensions: None,
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get_bounds(&self) -> (u32, u32, u32, u32) {
|
||||
if let Some(subdim) = self.subdimensions {
|
||||
subdim
|
||||
@@ -195,22 +202,16 @@ impl<'a> BufferView<'a> {
|
||||
pub fn subdimensions(
|
||||
&mut self,
|
||||
subdimensions: (u32, u32, u32, u32),
|
||||
) -> Result<BufferView, ::std::io::Error> {
|
||||
) -> BufferView {
|
||||
let bounds = self.get_bounds();
|
||||
if subdimensions.0 + subdimensions.2 > bounds.2
|
||||
|| subdimensions.1 + subdimensions.3 > bounds.3
|
||||
if cfg!(debug_assertions) && (subdimensions.0 + subdimensions.2 > bounds.2
|
||||
|| subdimensions.1 + subdimensions.3 > bounds.3)
|
||||
{
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::Other,
|
||||
format!(
|
||||
"cannot create subdimensions larger than buffer: {:?} > {:?}",
|
||||
subdimensions, bounds
|
||||
),
|
||||
));
|
||||
panic!("cannot create subdimensions larger than buffer: {:?} > {:?}", subdimensions, bounds);
|
||||
}
|
||||
|
||||
Ok(BufferView {
|
||||
buf: self.buf,
|
||||
BufferView {
|
||||
view: self.view,
|
||||
dimensions: self.dimensions,
|
||||
subdimensions: Some((
|
||||
subdimensions.0 + bounds.0,
|
||||
@@ -218,27 +219,21 @@ impl<'a> BufferView<'a> {
|
||||
subdimensions.2,
|
||||
subdimensions.3,
|
||||
)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn subgeometry(&mut self, geo: Geometry) -> Result<BufferView, ::std::io::Error> {
|
||||
pub fn subgeometry(&mut self, geo: Geometry) -> BufferView {
|
||||
self.subdimensions((geo.x, geo.y, geo.width, geo.height))
|
||||
}
|
||||
|
||||
pub fn offset(&mut self, offset: (u32, u32)) -> Result<BufferView, ::std::io::Error> {
|
||||
pub fn offset(&mut self, offset: (u32, u32)) -> BufferView {
|
||||
let bounds = self.get_bounds();
|
||||
if offset.0 > bounds.2 || offset.1 > bounds.3 {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::Other,
|
||||
format!(
|
||||
"cannot create offset outside buffer: {:?} > {:?}",
|
||||
offset, bounds
|
||||
),
|
||||
));
|
||||
if cfg!(debug_assertions) && (offset.0 > bounds.2 || offset.1 > bounds.3) {
|
||||
panic!("cannot create offset outside buffer: {:?} > {:?}", offset, bounds);
|
||||
}
|
||||
|
||||
Ok(BufferView {
|
||||
buf: self.buf,
|
||||
BufferView {
|
||||
view: self.view,
|
||||
dimensions: self.dimensions,
|
||||
subdimensions: Some((
|
||||
offset.0 + bounds.0,
|
||||
@@ -246,82 +241,47 @@ impl<'a> BufferView<'a> {
|
||||
bounds.2 - offset.0,
|
||||
bounds.3 - offset.1,
|
||||
)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn limit(&mut self, dimensions: (u32, u32)) -> Result<BufferView, ::std::io::Error> {
|
||||
pub fn limit(&mut self, dimensions: (u32, u32)) -> BufferView {
|
||||
let bounds = self.get_bounds();
|
||||
if dimensions.0 > bounds.2 || dimensions.1 > bounds.3 {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::Other,
|
||||
format!(
|
||||
"cannot create offset outside buffer: {:?} > {:?}",
|
||||
dimensions, bounds
|
||||
),
|
||||
));
|
||||
if cfg!(debug_assertions) && (dimensions.0 > bounds.2 || dimensions.1 > bounds.3) {
|
||||
panic!("cannot create offset outside buffer: {:?} > {:?}", dimensions, bounds);
|
||||
}
|
||||
|
||||
Ok(BufferView {
|
||||
buf: self.buf,
|
||||
BufferView {
|
||||
view: self.view,
|
||||
dimensions: self.dimensions,
|
||||
subdimensions: Some((bounds.0, bounds.1, dimensions.0, dimensions.1)),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn memset(&mut self, c: &Color) {
|
||||
let v = c.as_argb8888();
|
||||
pub fn memset(&mut self, c: Color) {
|
||||
if let Some(subdim) = self.subdimensions {
|
||||
unsafe {
|
||||
let ptr = self.buf.as_mut_ptr();
|
||||
for y in subdim.1..(subdim.1 + subdim.3) {
|
||||
for x in subdim.0..(subdim.0 + subdim.2) {
|
||||
*((ptr as *mut u32).offset((x + y * self.dimensions.0) as isize)) = v;
|
||||
}
|
||||
for y in subdim.1..(subdim.1 + subdim.3) {
|
||||
for x in subdim.0..(subdim.0 + subdim.2) {
|
||||
self.view[(x + y * self.dimensions.0) as usize] = c.0;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
unsafe {
|
||||
let ptr = self.buf.as_mut_ptr();
|
||||
for p in 0..(self.dimensions.0 * self.dimensions.1) {
|
||||
*((ptr as *mut u32).offset(p as isize)) = v;
|
||||
}
|
||||
}
|
||||
self.view.fill(c.0);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn put(&mut self, pos: (u32, u32), c: &Color) -> Result<(), ::std::io::Error> {
|
||||
pub fn put(&mut self, pos: (u32, u32), c: Color) {
|
||||
let true_pos = if let Some(subdim) = self.subdimensions {
|
||||
if pos.0 >= subdim.2 || pos.1 >= subdim.3 {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::Other,
|
||||
format!(
|
||||
"put({:?}) is not within subdimensions of buffer ({:?})",
|
||||
pos, subdim
|
||||
),
|
||||
));
|
||||
if cfg!(debug_assertions) && (pos.0 >= subdim.2 || pos.1 >= subdim.3) {
|
||||
panic!("put({:?}) is not within subdimensions of buffer ({:?})", pos, subdim);
|
||||
}
|
||||
(pos.0 + subdim.0, pos.1 + subdim.1)
|
||||
} else {
|
||||
if pos.0 >= self.dimensions.0 || pos.1 >= self.dimensions.1 {
|
||||
return Err(::std::io::Error::new(
|
||||
::std::io::ErrorKind::Other,
|
||||
format!(
|
||||
"put({:?}) is not within dimensions of buffer ({:?})",
|
||||
pos, self.dimensions
|
||||
),
|
||||
));
|
||||
if cfg!(debug_assertions) && (pos.0 >= self.dimensions.0 || pos.1 >= self.dimensions.1) {
|
||||
panic!("put({:?}) is not within dimensions of buffer ({:?})", pos, self.dimensions);
|
||||
}
|
||||
pos
|
||||
};
|
||||
|
||||
unsafe {
|
||||
let ptr = self
|
||||
.buf
|
||||
.as_mut_ptr()
|
||||
.offset(4 * (true_pos.0 + (true_pos.1 * self.dimensions.0)) as isize);
|
||||
*(ptr as *mut u32) = c.as_argb8888();
|
||||
};
|
||||
|
||||
Ok(())
|
||||
self.view[(true_pos.0 + (true_pos.1 * self.dimensions.0)) as usize] = c.0;
|
||||
}
|
||||
}
|
||||
|
||||
+50
-1
@@ -1,5 +1,5 @@
|
||||
//use serde::{Deserialize, Serialize};
|
||||
|
||||
/*
|
||||
//#[derive(Serialize, Deserialize, Debug, Clone, Copy, Default)]
|
||||
pub struct Color {
|
||||
red: f32,
|
||||
@@ -37,6 +37,11 @@ impl Color {
|
||||
| ((255.0 * self.green) as u32 & 0xFF) << 8
|
||||
| ((255.0 * self.blue) as u32 & 0xFF)
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn as_integer(&self) -> IntegerColor {
|
||||
IntegerColor(self.as_argb8888())
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
@@ -69,3 +74,47 @@ fn clamp_f32(v: f32, a: f32, b: f32) -> f32 {
|
||||
fn blend_f32(a: f32, b: f32, r: f32) -> f32 {
|
||||
a + ((b - a) * r)
|
||||
}
|
||||
*/
|
||||
#[inline]
|
||||
fn blend_u8(a: u8, b: u8, r: f32) -> u32 {
|
||||
let af = a as f32;
|
||||
let bf = b as f32;
|
||||
(af + ((bf - af) * r)) as u32
|
||||
}
|
||||
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct Color(pub u32);
|
||||
|
||||
impl Color {
|
||||
pub const BLACK: Color = Color(0xFF000000);
|
||||
pub const WHITE: Color = Color(0xFFFFFFFF);
|
||||
pub const GREY50: Color = Color(0xFF7F7F7F);
|
||||
pub const GREY75: Color = Color(0xFFBFBFBF);
|
||||
pub const GREY80: Color = Color(0xFFCCCCCC);
|
||||
pub const RED: Color = Color(0xFFFF0000);
|
||||
pub const YELLOW: Color = Color(0xFFFFFF00);
|
||||
pub const LIGHTGREEN: Color = Color(0xFF7FFF7F);
|
||||
pub const LIGHTRED: Color = Color(0xFFFF7F7F);
|
||||
pub const LIGHTORANGE: Color = Color(0xFFFFBF00);
|
||||
pub const DARKORANGE: Color = Color(0xFFFF7F00);
|
||||
pub const BUFF: Color = Color(0xFFFFBF7F);
|
||||
|
||||
#[allow(unused)]
|
||||
pub fn new(red: u8, green: u8, blue: u8, opacity: u8) -> Color {
|
||||
Color((opacity as u32) << 24 | (red as u32) << 16 | (green as u32) << 8 | (blue as u32))
|
||||
}
|
||||
|
||||
fn opacity(self) -> u8 {((self.0 >> 24) & 0xFF) as u8 }
|
||||
fn red(self) -> u8 {((self.0 >> 16) & 0xFF) as u8 }
|
||||
fn green(self) -> u8 {((self.0 >> 8) & 0xFF) as u8 }
|
||||
fn blue(self) -> u8 {(self.0 & 0xFF) as u8 }
|
||||
|
||||
pub fn blend(self, other: Color, ratio: f32) -> Color {
|
||||
Color(
|
||||
blend_u8(self.opacity(), other.opacity(), ratio) << 24 |
|
||||
blend_u8(self.red(), other.red(), ratio) << 16 |
|
||||
blend_u8(self.green(), other.green(), ratio) << 8 |
|
||||
blend_u8(self.blue(), other.blue(), ratio)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
+29
-23
@@ -47,7 +47,7 @@ impl CachedGlyph {
|
||||
}
|
||||
}
|
||||
|
||||
fn draw(&self, buf: &mut BufferView, pos: (i32, i32), bg: &Color, c: &Color) {
|
||||
fn draw(&self, buf: &mut BufferView, pos: (i32, i32), bg: Color, c: Color) {
|
||||
let mut x = 0;
|
||||
let mut y = 0;
|
||||
for v in &self.render {
|
||||
@@ -56,7 +56,7 @@ impl CachedGlyph {
|
||||
(x + pos.0 + self.origin.0) as u32,
|
||||
(y + pos.1 + self.origin.1) as u32,
|
||||
),
|
||||
&bg.blend(&c, *v),
|
||||
bg.blend(c, *v),
|
||||
);
|
||||
|
||||
if x == self.dimensions.0 as i32 - 1 {
|
||||
@@ -84,6 +84,12 @@ impl<'a> Font<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn height(&self) -> f32 {
|
||||
let scale = Scale::uniform(self.size);
|
||||
let m = self.font.v_metrics(scale);
|
||||
m.ascent - m.descent
|
||||
}
|
||||
|
||||
pub fn add_str_to_cache(&mut self, s: &str) {
|
||||
for ch in s.chars() {
|
||||
if self.glyphs.get(&ch).is_none() {
|
||||
@@ -96,8 +102,8 @@ impl<'a> Font<'a> {
|
||||
pub fn draw_text(
|
||||
&self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
c: &Color,
|
||||
bg: Color,
|
||||
c: Color,
|
||||
s: &str,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
let mut x_off = 0;
|
||||
@@ -129,8 +135,8 @@ impl<'a> Font<'a> {
|
||||
pub fn draw_text_with_cursor(
|
||||
&self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
c: &Color,
|
||||
bg: Color,
|
||||
c: Color,
|
||||
s: &str,
|
||||
cursor: usize,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
@@ -171,13 +177,13 @@ impl<'a> Font<'a> {
|
||||
pub fn draw_cursor(
|
||||
&self,
|
||||
buf: &mut BufferView,
|
||||
c: &Color,
|
||||
c: Color,
|
||||
offset: u32,
|
||||
height: u32,
|
||||
) -> Result<(), ::std::io::Error> {
|
||||
// draw cursor
|
||||
for i in 1..height {
|
||||
buf.put((offset, i), c)?
|
||||
buf.put((offset, i), c);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
@@ -206,8 +212,8 @@ impl<'a> Font<'a> {
|
||||
pub fn auto_draw_text(
|
||||
&mut self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
c: &Color,
|
||||
bg: Color,
|
||||
c: Color,
|
||||
s: &str,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
self.add_str_to_cache(s);
|
||||
@@ -217,8 +223,8 @@ impl<'a> Font<'a> {
|
||||
pub fn auto_draw_text_with_cursor(
|
||||
&mut self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
c: &Color,
|
||||
bg: Color,
|
||||
c: Color,
|
||||
s: &str,
|
||||
cursor: usize,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
@@ -229,8 +235,8 @@ impl<'a> Font<'a> {
|
||||
pub fn draw_text_fixed_width(
|
||||
&self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
c: &Color,
|
||||
bg: Color,
|
||||
c: Color,
|
||||
distances: &[u32],
|
||||
s: &str,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
@@ -263,7 +269,7 @@ impl<'a> Font<'a> {
|
||||
pub fn draw_text_individual_colors(
|
||||
&self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
bg: Color,
|
||||
color: &[Color],
|
||||
s: &str,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
@@ -286,7 +292,7 @@ impl<'a> Font<'a> {
|
||||
}
|
||||
}
|
||||
for (idx, glyph) in glyphs.into_iter().enumerate() {
|
||||
glyph.draw(buf, (x_off, -off), bg, &color[idx]);
|
||||
glyph.draw(buf, (x_off, -off), bg, color[idx]);
|
||||
x_off += glyph.advance;
|
||||
}
|
||||
|
||||
@@ -296,7 +302,7 @@ impl<'a> Font<'a> {
|
||||
pub fn auto_draw_text_individual_colors(
|
||||
&mut self,
|
||||
buf: &mut BufferView,
|
||||
bg: &Color,
|
||||
bg: Color,
|
||||
color: &[Color],
|
||||
s: &str,
|
||||
) -> Result<(u32, u32), ::std::io::Error> {
|
||||
@@ -305,14 +311,14 @@ impl<'a> Font<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn draw_box(buf: &mut BufferView, c: &Color, dim: (u32, u32)) -> Result<(), ::std::io::Error> {
|
||||
pub fn draw_box(buf: &mut BufferView, c: Color, dim: (u32, u32)) -> Result<(), ::std::io::Error> {
|
||||
for x in 0..dim.0 {
|
||||
let _ = buf.put((x, 0), c);
|
||||
let _ = buf.put((x, dim.1 - 1), c);
|
||||
buf.put((x, 0), c);
|
||||
buf.put((x, dim.1 - 1), c);
|
||||
}
|
||||
for y in 0..dim.1 {
|
||||
buf.put((0, y), c)?;
|
||||
buf.put((dim.0 - 1, y), c)?;
|
||||
buf.put((0, y), c);
|
||||
buf.put((dim.0 - 1, y), c);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
@@ -320,7 +326,7 @@ pub fn draw_box(buf: &mut BufferView, c: &Color, dim: (u32, u32)) -> Result<(),
|
||||
|
||||
pub fn draw_bar(
|
||||
buf: &mut BufferView,
|
||||
color: &Color,
|
||||
color: Color,
|
||||
length: u32,
|
||||
height: u32,
|
||||
fill: f32,
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
use std::sync::{Arc, Mutex};
|
||||
|
||||
use calloop::ping::Ping;
|
||||
|
||||
use crate::keyboard::KeyEvent;
|
||||
|
||||
#[derive(Copy, Clone, Debug)]
|
||||
pub enum PointerButton {
|
||||
Left,
|
||||
Right,
|
||||
Middle,
|
||||
ScrollVertical(f64),
|
||||
ScrollHorizontal(f64),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct PointerEvent {
|
||||
pub button: PointerButton,
|
||||
pub pos: (u32, u32),
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Event {
|
||||
NewMinute,
|
||||
PowerUpdate,
|
||||
LauncherUpdate,
|
||||
AudioUpdate,
|
||||
KeyEvent(KeyEvent),
|
||||
PointerEvent(PointerEvent),
|
||||
TokenUpdate(String),
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
dirty: bool,
|
||||
events: Vec<Event>,
|
||||
ping: Ping,
|
||||
}
|
||||
|
||||
impl Events {
|
||||
pub fn new(ping: Ping) -> Arc<Mutex<Events>> {
|
||||
Arc::new(Mutex::new(Events {
|
||||
dirty: false,
|
||||
events: Vec::new(),
|
||||
ping,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn add_event(&mut self, ev: Event) {
|
||||
self.events.push(ev);
|
||||
if !self.dirty {
|
||||
self.dirty = true;
|
||||
self.ping.ping();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) -> Vec<Event> {
|
||||
self.dirty = false;
|
||||
self.events.drain(..).collect()
|
||||
}
|
||||
}
|
||||
|
||||
+37
-31
@@ -1,7 +1,6 @@
|
||||
//! Utility module for fonts
|
||||
|
||||
use crate::draw;
|
||||
//use fontconfig::Fontconfig as FontConfig;
|
||||
use rusttype::Font;
|
||||
use std::{
|
||||
cell::RefCell,
|
||||
@@ -10,7 +9,7 @@ use std::{
|
||||
hash,
|
||||
io::Read,
|
||||
mem,
|
||||
path::{Path, PathBuf},
|
||||
path::Path,
|
||||
rc::Rc,
|
||||
thread,
|
||||
};
|
||||
@@ -18,19 +17,24 @@ use std::{
|
||||
/// FontRef is used to store Fonts on widgets.
|
||||
pub type FontRef<'a> = &'a rusttype::Font<'a>;
|
||||
|
||||
/*
|
||||
/// FontSeeker is a marker struct that is used to look up fonts
|
||||
pub(crate) struct FontSeeker;
|
||||
|
||||
impl FontSeeker {
|
||||
#[cfg(feature = "fontloading")]
|
||||
mod fc {
|
||||
use fontconfig::Fontconfig as FontConfig;
|
||||
/// Acts like fc-match.
|
||||
/// Given a string, it matches it to a font file and returns its path.
|
||||
pub(crate) fn from_string(name: &str) -> PathBuf {
|
||||
pub(crate) fn from_string(name: &str) -> String {
|
||||
let fc = FontConfig::new().unwrap();
|
||||
fc.find(name, None).unwrap().path
|
||||
fc.find(name, None).unwrap().path.to_str().unwrap().to_string()
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
#[cfg(not(feature = "fontloading"))]
|
||||
mod fc {
|
||||
pub(crate) fn from_string(_name: &str) -> String {
|
||||
panic!("fontloading feature not enabled");
|
||||
}
|
||||
}
|
||||
|
||||
/// FontLoader is a marker struct that is used to load files
|
||||
pub(crate) struct FontLoader;
|
||||
|
||||
@@ -77,51 +81,53 @@ impl Eq for ComparableF32 {}
|
||||
|
||||
pub struct FontMap {
|
||||
fonts: HashMap<(&'static str, ComparableF32), draw::Font<'static>>,
|
||||
required_fonts: HashMap<&'static str, (&'static str, Vec<f32>)>,
|
||||
font_paths: HashMap<&'static str, String>,
|
||||
required_fonts: HashMap<&'static str, (&'static str, Vec<(f32, &'static str)>)>,
|
||||
}
|
||||
|
||||
impl FontMap {
|
||||
pub fn new() -> FontMap {
|
||||
FontMap {
|
||||
fonts: HashMap::new(),
|
||||
font_paths: HashMap::new(),
|
||||
required_fonts: HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_font_name(&mut self, font_name: &'static str, size: f32) {
|
||||
pub fn queue_font(&mut self, font_name: &'static str, size: f32, preload: &'static str) {
|
||||
match self.required_fonts.get_mut(font_name) {
|
||||
Some(v) => v.1.push(size),
|
||||
Some(v) => v.1.push((size, preload)),
|
||||
None => {
|
||||
self.required_fonts
|
||||
.insert(font_name, (font_name, vec![size]));
|
||||
self.required_fonts.insert(font_name, (font_name, vec![(size, preload)]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn queue_font_path(&mut self, font_name: &'static str, font_path: &'static str, size: f32) {
|
||||
match self.required_fonts.get_mut(font_name) {
|
||||
Some(v) => v.1.push(size),
|
||||
None => {
|
||||
self.required_fonts
|
||||
.insert(font_name, (font_path, vec![size]));
|
||||
}
|
||||
}
|
||||
pub fn add_font_path(&mut self, font_name: &'static str, font_path: String) {
|
||||
self.font_paths.insert(font_name, font_path);
|
||||
}
|
||||
|
||||
pub fn load_fonts(&mut self) {
|
||||
for (font_name, v) in self.required_fonts.iter() {
|
||||
let path = if v.0.starts_with("/") {
|
||||
std::path::PathBuf::from(v.0)
|
||||
} else {
|
||||
//FontSeeker::from_string(v.0)
|
||||
panic!("required FontSeeker");
|
||||
let path = match self.font_paths.get(font_name) {
|
||||
Some(res) => res,
|
||||
_ => {
|
||||
let s = fc::from_string(font_name);
|
||||
self.font_paths.insert(font_name, s);
|
||||
self.font_paths.get(font_name).unwrap()
|
||||
}
|
||||
};
|
||||
let fontref = Box::leak(Box::new(
|
||||
FontLoader::from_path(path).expect("unable to load font"),
|
||||
));
|
||||
for size in &v.1 {
|
||||
let font = draw::Font::new(fontref, *size);
|
||||
self.fonts.insert((font_name, ComparableF32(*size)), font);
|
||||
for (size, preload) in &v.1 {
|
||||
if let Some(font) = self.fonts.get_mut(&(font_name, ComparableF32(*size))) {
|
||||
font.add_str_to_cache(preload);
|
||||
} else {
|
||||
let mut font = draw::Font::new(fontref, *size);
|
||||
font.add_str_to_cache(preload);
|
||||
self.fonts.insert((font_name, ComparableF32(*size)), font);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-2
@@ -12,8 +12,10 @@
|
||||
//! calloop event loop. Not doing so will prevent key repetition to work
|
||||
//! (but the rest of the functionnality will not be affected).
|
||||
|
||||
use std::default::Default;
|
||||
use std::os::unix::io::{AsRawFd, OwnedFd};
|
||||
use std::{
|
||||
default::Default,
|
||||
os::unix::io::{AsRawFd, OwnedFd},
|
||||
};
|
||||
|
||||
use wayland_client::{protocol::wl_keyboard, WEnum};
|
||||
use xkbcommon::xkb;
|
||||
@@ -24,6 +26,7 @@ mod state;
|
||||
use self::state::KbState;
|
||||
pub use self::state::ModifiersState;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub struct KeyEvent {
|
||||
pub serial: u32,
|
||||
pub time: u32,
|
||||
|
||||
@@ -50,6 +50,9 @@ impl ModifiersState {
|
||||
}
|
||||
}
|
||||
|
||||
// Safety: No.
|
||||
unsafe impl Send for KbState {}
|
||||
|
||||
impl KbState {
|
||||
pub(crate) fn update_modifiers(
|
||||
&mut self,
|
||||
|
||||
+86
-63
@@ -6,6 +6,7 @@ mod keyboard;
|
||||
mod state;
|
||||
mod utils;
|
||||
mod widgets;
|
||||
mod event;
|
||||
|
||||
use wayland_client::{Connection, QueueHandle, WaylandSource};
|
||||
|
||||
@@ -18,44 +19,17 @@ use chrono::{Duration, Local, Timelike};
|
||||
use buffer::BufferView;
|
||||
use color::Color;
|
||||
use fonts::{FontMap, MaybeFontMap};
|
||||
use state::{Event, Events, State};
|
||||
use state::State;
|
||||
use event::{Event, Events};
|
||||
use widgets::{
|
||||
Backlight, Battery, Calendar, Clock, Date, Geometry, HorizontalLayout, IndexedLayout,
|
||||
Audio, Backlight, Battery, Calendar, Clock, Date, Geometry, HorizontalLayout, IndexedLayout,
|
||||
Interface, InvertedHorizontalLayout, Line, Margin, VerticalLayout, Widget,
|
||||
};
|
||||
|
||||
use std::{rc::Rc, thread};
|
||||
|
||||
fn main() {
|
||||
let font_thread = thread::spawn(move || {
|
||||
let mut fm = FontMap::new();
|
||||
// Hard-coding font paths make things a lot faster
|
||||
fm.queue_font_path("sans", "/usr/share/fonts/noto/NotoSans-Regular.ttf", 128.);
|
||||
fm.queue_font_path("sans", "/usr/share/fonts/noto/NotoSans-Regular.ttf", 48.);
|
||||
fm.queue_font_path("sans", "/usr/share/fonts/noto/NotoSans-Regular.ttf", 24.);
|
||||
fm.queue_font_path(
|
||||
"monospace",
|
||||
"/usr/share/fonts/noto/NotoSansMono-Regular.ttf",
|
||||
32.,
|
||||
);
|
||||
fm.queue_font_path(
|
||||
"monospace",
|
||||
"/usr/share/fonts/noto/NotoSansMono-Regular.ttf",
|
||||
12.,
|
||||
);
|
||||
fm.queue_font_path(
|
||||
"monospace",
|
||||
"/usr/share/fonts/noto/NotoSansMono-Regular.ttf",
|
||||
12. * 1.5,
|
||||
);
|
||||
fm.queue_font_path(
|
||||
"monospace",
|
||||
"/usr/share/fonts/noto/NotoSansMono-Regular.ttf",
|
||||
12. * 2.0,
|
||||
);
|
||||
fm.load_fonts();
|
||||
fm
|
||||
});
|
||||
// let now = Local::now();
|
||||
let conn = Connection::connect_to_env().unwrap();
|
||||
|
||||
let event_queue = conn.new_event_queue();
|
||||
@@ -66,32 +40,6 @@ fn main() {
|
||||
|
||||
let (ping_sender, ping_source) = calloop::ping::make_ping().unwrap();
|
||||
|
||||
let events = Events::new(ping_sender);
|
||||
|
||||
let clock = Box::new(Clock::new("sans", 128.));
|
||||
// let calendar = Box::new(Calendar::new("monospace", 12.0, 1, -1));
|
||||
let date = Box::new(Date::new("sans", 48.));
|
||||
let line = Box::new(Line::new());
|
||||
let launcher = Box::new(Interface::new("monospace", 32.));
|
||||
let battery = Box::new(Battery::new(events.clone(), "sans", 24.));
|
||||
let backlight = Box::new(Backlight::new("intel_backlight", "sans", 24.));
|
||||
|
||||
let widgets: Vec<Box<dyn Widget>> =
|
||||
vec![clock, date, battery, backlight, line, launcher];
|
||||
let layout = Rc::new(VerticalLayout::new(vec![
|
||||
HorizontalLayout::new(vec![
|
||||
IndexedLayout::new(0),
|
||||
Margin::new(IndexedLayout::new(1), (16, 8, 0, 0)),
|
||||
VerticalLayout::new(vec![
|
||||
Margin::new(IndexedLayout::new(2), (16, 8, 8, 0)),
|
||||
Margin::new(IndexedLayout::new(3), (16, 8, 8, 0)),
|
||||
]),
|
||||
]),
|
||||
IndexedLayout::new(4),
|
||||
IndexedLayout::new(5),
|
||||
// InvertedHorizontalLayout::new(vec![IndexedLayout::new(5), IndexedLayout::new(6)]),
|
||||
]));
|
||||
|
||||
let mut event_loop: EventLoop<State> =
|
||||
EventLoop::try_new().expect("Failed to initialize the event loop!");
|
||||
|
||||
@@ -136,6 +84,79 @@ fn main() {
|
||||
})
|
||||
.expect("Failed to insert event source!");
|
||||
|
||||
let events = Events::new(ping_sender);
|
||||
|
||||
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 clock = Box::new(Clock::new(&mut fm, "sans", 128.));
|
||||
let calendar = Box::new(Calendar::new(&mut fm, "monospace", 12.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(Audio::new(events.clone(), &mut fm, "sans", 24.));
|
||||
|
||||
let widgets: Vec<Box<dyn Widget>> =
|
||||
vec![clock, date, battery, backlight, audio, line, calendar, launcher];
|
||||
|
||||
let layout = 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)]),
|
||||
]));
|
||||
|
||||
/* 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()
|
||||
.name("fontloader".to_string())
|
||||
.spawn(move || {
|
||||
fm.load_fonts();
|
||||
fm
|
||||
}).unwrap();
|
||||
|
||||
let mut state = State::new(widgets, layout, MaybeFontMap::Waiting(font_thread), events);
|
||||
|
||||
let mut damage = Vec::new();
|
||||
@@ -174,16 +195,16 @@ fn main() {
|
||||
(state.dimensions.0 as u32, state.dimensions.1 as u32),
|
||||
);
|
||||
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
// eprintln!("time: {}", (Local::now() - now).num_milliseconds());
|
||||
|
||||
let surface = state.base_surface.as_ref().unwrap().clone();
|
||||
if force {
|
||||
// Other compositors probably need this.
|
||||
//bufview.memset(Color::BLACK);
|
||||
for (idx, widget) in state.widgets.iter_mut().enumerate() {
|
||||
if force || widget.get_dirty() {
|
||||
let geo = widget.geometry();
|
||||
bufview.subgeometry(geo).unwrap().memset(&bg);
|
||||
|
||||
let mut subview = bufview.subgeometry(geo).unwrap();
|
||||
let mut subview = bufview.subgeometry(geo);
|
||||
damage[idx] = widget.draw(&mut state.fonts.unwrap().borrow_mut(), &mut subview);
|
||||
//draw_box(&mut subview, &Color::new(1.0, 0.5, 0.0, 1.0), (geo.width, geo.height));
|
||||
}
|
||||
@@ -196,10 +217,10 @@ fn main() {
|
||||
drew = true;
|
||||
|
||||
let old_damage = damage[idx];
|
||||
bufview.subgeometry(old_damage).unwrap().memset(&bg);
|
||||
bufview.subgeometry(old_damage).memset(Color::BLACK);
|
||||
|
||||
let geo = widget.geometry();
|
||||
let mut subview = bufview.subgeometry(geo).unwrap();
|
||||
let mut subview = bufview.subgeometry(geo);
|
||||
|
||||
let new_damage =
|
||||
widget.draw(&mut state.fonts.unwrap().borrow_mut(), &mut subview);
|
||||
@@ -223,5 +244,7 @@ fn main() {
|
||||
|
||||
surface.attach(Some(&buf.buffer), 0, 0);
|
||||
surface.commit();
|
||||
// eprintln!("draw time: {}", (Local::now() - now).num_milliseconds());
|
||||
// std::process::exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
+86
-40
@@ -5,12 +5,10 @@ use std::{
|
||||
sync::{Arc, Mutex},
|
||||
};
|
||||
|
||||
use calloop::ping::Ping;
|
||||
|
||||
use wayland_client::{
|
||||
protocol::{
|
||||
wl_buffer, wl_compositor, wl_keyboard, wl_registry, wl_seat, wl_shm, wl_shm_pool,
|
||||
wl_surface,
|
||||
wl_surface, wl_pointer,
|
||||
},
|
||||
Connection, Dispatch, QueueHandle, WEnum,
|
||||
};
|
||||
@@ -23,46 +21,11 @@ use wayland_protocols::xdg::{
|
||||
use crate::{
|
||||
buffer::BufferManager,
|
||||
fonts::{FontMap, MaybeFontMap},
|
||||
keyboard::{KeyEvent, Keyboard},
|
||||
keyboard::Keyboard,
|
||||
widgets::{Geometry, Layout, Widget, WidgetUpdater},
|
||||
event::{Event, Events, PointerEvent, PointerButton},
|
||||
};
|
||||
|
||||
pub enum Event {
|
||||
NewMinute,
|
||||
PowerUpdate,
|
||||
KeyEvent(KeyEvent),
|
||||
TokenUpdate(String),
|
||||
}
|
||||
|
||||
pub struct Events {
|
||||
dirty: bool,
|
||||
events: Vec<Event>,
|
||||
ping: Ping,
|
||||
}
|
||||
|
||||
impl Events {
|
||||
pub fn new(ping: Ping) -> Arc<Mutex<Events>> {
|
||||
Arc::new(Mutex::new(Events {
|
||||
dirty: false,
|
||||
events: Vec::new(),
|
||||
ping,
|
||||
}))
|
||||
}
|
||||
|
||||
pub fn add_event(&mut self, ev: Event) {
|
||||
self.events.push(ev);
|
||||
if !self.dirty {
|
||||
self.dirty = true;
|
||||
self.ping.ping();
|
||||
}
|
||||
}
|
||||
|
||||
pub fn flush(&mut self) -> Vec<Event> {
|
||||
self.dirty = false;
|
||||
self.events.drain(..).collect()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
pub running: bool,
|
||||
pub dirty: bool,
|
||||
@@ -77,6 +40,7 @@ pub struct State {
|
||||
pub bufmgr: BufferManager,
|
||||
pub widgets: Vec<Box<dyn Widget>>,
|
||||
keyboard: Keyboard,
|
||||
pointer: Option<(f64, f64)>,
|
||||
pub fonts: MaybeFontMap,
|
||||
pub events: Arc<Mutex<Events>>,
|
||||
layout: Rc<Box<dyn Layout>>,
|
||||
@@ -102,6 +66,7 @@ impl State {
|
||||
dimensions: (320, 240),
|
||||
bufmgr: BufferManager::new(),
|
||||
keyboard: Keyboard::new(),
|
||||
pointer: None,
|
||||
widgets,
|
||||
fonts,
|
||||
events,
|
||||
@@ -380,6 +345,9 @@ impl Dispatch<wl_seat::WlSeat, ()> for State {
|
||||
if capabilities.contains(wl_seat::Capability::Keyboard) {
|
||||
seat.get_keyboard(qh, ());
|
||||
}
|
||||
if capabilities.contains(wl_seat::Capability::Pointer) {
|
||||
seat.get_pointer(qh, ());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -431,6 +399,84 @@ impl Dispatch<wl_keyboard::WlKeyboard, ()> for State {
|
||||
}
|
||||
}
|
||||
|
||||
const BTN_LEFT: u32 = 0x110;
|
||||
const BTN_RIGHT: u32 = 0x111;
|
||||
const BTN_MIDDLE: u32 = 0x112;
|
||||
|
||||
impl Dispatch<wl_pointer::WlPointer, ()> for State {
|
||||
fn event(
|
||||
state: &mut Self,
|
||||
_: &wl_pointer::WlPointer,
|
||||
event: wl_pointer::Event,
|
||||
_: &(),
|
||||
_: &Connection,
|
||||
_: &QueueHandle<Self>,
|
||||
) {
|
||||
match event {
|
||||
wl_pointer::Event::Enter { surface_x, surface_y, .. } => {
|
||||
state.pointer = Some((surface_x, surface_y));
|
||||
},
|
||||
wl_pointer::Event::Motion { surface_x, surface_y, .. } => {
|
||||
state.pointer = Some((surface_x, surface_y));
|
||||
},
|
||||
wl_pointer::Event::Leave { .. } => {
|
||||
state.pointer = None
|
||||
},
|
||||
wl_pointer::Event::Axis { axis, value, .. } => match state.pointer {
|
||||
Some((x, y)) => {
|
||||
let axis = match axis {
|
||||
WEnum::Value(wl_pointer::Axis::VerticalScroll) => PointerButton::ScrollVertical(value),
|
||||
WEnum::Value(wl_pointer::Axis::HorizontalScroll) => PointerButton::ScrollHorizontal(value),
|
||||
_ => return,
|
||||
};
|
||||
let pos = (x as u32, y as u32);
|
||||
for widget in state.widgets.iter_mut() {
|
||||
let geo = widget.geometry();
|
||||
if geo.contains(pos) {
|
||||
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
||||
let ev = Event::PointerEvent(PointerEvent{
|
||||
button: axis,
|
||||
pos: pos,
|
||||
});
|
||||
widget.event(&ev);
|
||||
state.dirty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
wl_pointer::Event::Button { button, state: button_state, .. } => match (button, button_state, state.pointer) {
|
||||
(button, WEnum::Value(wl_pointer::ButtonState::Pressed), Some((x, y))) => {
|
||||
let button = match button {
|
||||
BTN_LEFT => PointerButton::Left,
|
||||
BTN_RIGHT => PointerButton::Right,
|
||||
BTN_MIDDLE => PointerButton::Middle,
|
||||
_ => return,
|
||||
};
|
||||
let pos = (x as u32, y as u32);
|
||||
for widget in state.widgets.iter_mut() {
|
||||
let geo = widget.geometry();
|
||||
if geo.contains(pos) {
|
||||
|
||||
let pos = (pos.0 - geo.x, pos.1 - geo.y);
|
||||
let ev = Event::PointerEvent(PointerEvent{
|
||||
button: button,
|
||||
pos: pos,
|
||||
});
|
||||
widget.event(&ev);
|
||||
state.dirty = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Dispatch<xdg_activation_v1::XdgActivationV1, ()> for State {
|
||||
fn event(
|
||||
_: &mut Self,
|
||||
|
||||
+48
-48
@@ -1,12 +1,16 @@
|
||||
use ini::{Ini, ParseOption};
|
||||
use itertools::Itertools;
|
||||
use std::cmp::Ordering;
|
||||
use std::env;
|
||||
use std::error::Error;
|
||||
use std::io::Error as io_error;
|
||||
use std::io::ErrorKind;
|
||||
use std::{
|
||||
cmp::Ordering,
|
||||
collections::HashSet,
|
||||
env,
|
||||
error::Error,
|
||||
fs::read_to_string,
|
||||
io::{Error as io_error, ErrorKind},
|
||||
};
|
||||
|
||||
use walkdir::WalkDir;
|
||||
|
||||
use crate::utils::inish;
|
||||
|
||||
#[derive(Clone, Debug, Eq, Hash)]
|
||||
pub struct Desktop {
|
||||
pub entry_type: String,
|
||||
@@ -21,23 +25,18 @@ pub struct Desktop {
|
||||
|
||||
impl Desktop {
|
||||
fn parse(f: &str) -> Result<Desktop, Box<dyn Error>> {
|
||||
let file = Ini::load_from_file_opt(
|
||||
f,
|
||||
ParseOption {
|
||||
enabled_quote: false,
|
||||
enabled_escape: false,
|
||||
},
|
||||
)?;
|
||||
match file.section(Some("Desktop Entry")) {
|
||||
Some(desktop) => Ok(Desktop {
|
||||
entry_type: desktop.get("Type").unwrap_or(&"".to_string()).to_string(),
|
||||
name: desktop.get("Name").unwrap_or(&"".to_string()).to_string(),
|
||||
term: desktop.get("Terminal").unwrap_or(&"".to_string()) == "true",
|
||||
no_display: desktop.get("NoDisplay").unwrap_or(&"".to_string()) == "true",
|
||||
hidden: desktop.get("Hidden").unwrap_or(&"".to_string()) == "true",
|
||||
exec: desktop.get("Exec").map(|x| x.to_string()),
|
||||
url: desktop.get("URL").map(|x| x.to_string()),
|
||||
keywords: desktop
|
||||
let s = read_to_string(f)?;
|
||||
let config = inish::parse(&s)?;
|
||||
match config.get("Desktop Entry") {
|
||||
Some(section) => Ok(Desktop {
|
||||
entry_type: section.get("Type").unwrap_or(&"").to_string(),
|
||||
name: section.get("Name").unwrap_or(&"").to_string(),
|
||||
term: section.get("Terminal").unwrap_or(&"") == &"true",
|
||||
no_display: section.get("NoDisplay").unwrap_or(&"") == &"true",
|
||||
hidden: section.get("Hidden").unwrap_or(&"") == &"true",
|
||||
exec: section.get("Exec").map(|x| x.to_string()),
|
||||
url: section.get("URL").map(|x| x.to_string()),
|
||||
keywords: section
|
||||
.get("Keywords")
|
||||
.map(|x| {
|
||||
x.split(';')
|
||||
@@ -53,20 +52,6 @@ impl Desktop {
|
||||
))),
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_dir(d: &str) -> Result<Vec<Desktop>, Box<dyn Error>> {
|
||||
let mut files: Vec<Desktop> = Vec::with_capacity(16);
|
||||
for entry in WalkDir::new(d) {
|
||||
let entry = entry?;
|
||||
let path = entry.path();
|
||||
|
||||
if let Ok(d) = Desktop::parse(path.to_str().unwrap()) {
|
||||
files.push(d)
|
||||
}
|
||||
}
|
||||
|
||||
Ok(files)
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for Desktop {
|
||||
@@ -99,14 +84,29 @@ pub fn load_desktop_files() -> Vec<Desktop> {
|
||||
None => "/usr/local/share:/usr/share".to_string(),
|
||||
};
|
||||
|
||||
std::iter::once(xdg_data_home.as_str())
|
||||
.chain(xdg_data_dirs.split(':'))
|
||||
.map(|p| Desktop::parse_dir(&format!("{}/applications", p)))
|
||||
.filter_map(Result::ok)
|
||||
.flatten()
|
||||
.filter(|d| {
|
||||
!d.hidden && !d.no_display && (d.entry_type == "Application" || d.entry_type == "Link")
|
||||
})
|
||||
.unique_by(|x| x.name.clone())
|
||||
.collect()
|
||||
let dirs = std::iter::once(xdg_data_home.as_str()).chain(xdg_data_dirs.split(':'));
|
||||
|
||||
let mut desktop: Vec<Desktop> = Vec::new();
|
||||
let mut seen: HashSet<String> = HashSet::new();
|
||||
|
||||
for dir in dirs {
|
||||
for entry in WalkDir::new(format!("{}/applications", dir)) {
|
||||
if let Ok(entry) = entry {
|
||||
if let Ok(d) = Desktop::parse(entry.path().to_str().unwrap()) {
|
||||
if d.hidden
|
||||
|| d.no_display
|
||||
|| (d.entry_type != "Application" && d.entry_type != "Link")
|
||||
{
|
||||
continue;
|
||||
}
|
||||
if !seen.contains(&d.name) {
|
||||
seen.insert(d.name.to_string());
|
||||
desktop.push(d);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
desktop
|
||||
}
|
||||
|
||||
@@ -0,0 +1,134 @@
|
||||
use std::{collections::HashMap, error::Error};
|
||||
|
||||
fn parse_field<'a>(line: &'a str) -> Result<(&'a str, &'a str), Box<dyn Error>> {
|
||||
let split = match line.find('=') {
|
||||
Some(v) => v,
|
||||
None => return Err("expected equals sign on line, but found none".into()),
|
||||
};
|
||||
|
||||
let (key, value) = line.split_at(split);
|
||||
let (key, value) = (key.trim(), value.trim_matches('=').trim());
|
||||
|
||||
Ok((key, value))
|
||||
}
|
||||
|
||||
type InishSection<'a> = HashMap<&'a str, &'a str>;
|
||||
type Inish<'a> = HashMap<&'a str, InishSection<'a>>;
|
||||
|
||||
pub fn parse<'a>(s: &'a str) -> Result<Inish<'a>, Box<dyn Error>> {
|
||||
let mut sections: Inish<'a> = HashMap::new();
|
||||
let mut current_section = HashMap::new();
|
||||
let mut current_section_name = "";
|
||||
|
||||
for line in s.lines() {
|
||||
let line = line.trim();
|
||||
let mut chars = line.chars();
|
||||
let start = chars.next();
|
||||
let end = chars.last();
|
||||
match (start, end) {
|
||||
(Some('#'), _) => continue,
|
||||
(Some('['), Some(']')) => {
|
||||
sections.insert(current_section_name, current_section);
|
||||
current_section = HashMap::new();
|
||||
let len = line.bytes().count();
|
||||
current_section_name = &line[1..len - 1].trim();
|
||||
}
|
||||
(Some('['), v) => {
|
||||
return Err(format!(
|
||||
"expected Some(']') to terminate section name, but got {:?}",
|
||||
v
|
||||
)
|
||||
.into());
|
||||
}
|
||||
_ if line.is_empty() => continue,
|
||||
_ => {
|
||||
let (key, value) = parse_field(line)?;
|
||||
current_section.insert(key, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
sections.insert(current_section_name, current_section);
|
||||
Ok(sections)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn sections() {
|
||||
let config = parse(
|
||||
"
|
||||
[section_a]
|
||||
[section_b]
|
||||
",
|
||||
)
|
||||
.expect("config didn't parse");
|
||||
|
||||
if !config.contains_key("section_a") {
|
||||
panic!("named section did not exist");
|
||||
}
|
||||
|
||||
if !config.contains_key("section_b") {
|
||||
panic!("named section did not exist");
|
||||
}
|
||||
|
||||
if !config.contains_key("") {
|
||||
panic!("unnamed section did not exist");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn fields() {
|
||||
let config = parse(
|
||||
"
|
||||
field_outside = 'hello'
|
||||
[section_a]
|
||||
field_a = 1234
|
||||
",
|
||||
)
|
||||
.expect("config didn't parse");
|
||||
|
||||
let section_a = match config.get("section_a") {
|
||||
Some(v) => v,
|
||||
None => panic!("named section did not exist"),
|
||||
};
|
||||
|
||||
assert_eq!(section_a.get("field_a"), Some(&"1234"));
|
||||
|
||||
let section_unnamed = match config.get("") {
|
||||
Some(v) => v,
|
||||
None => panic!("unnamed section did not exist"),
|
||||
};
|
||||
|
||||
assert_eq!(section_unnamed.get("field_outside"), Some(&"'hello'"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn whitespaces() {
|
||||
let config = parse(
|
||||
"
|
||||
|
||||
field outside = 'hello'
|
||||
|
||||
[ section a ]
|
||||
field a = 1234 ",
|
||||
)
|
||||
.expect("config didn't parse");
|
||||
|
||||
let section_a = match config.get("section a") {
|
||||
Some(v) => v,
|
||||
None => panic!("named section did not exist"),
|
||||
};
|
||||
|
||||
assert_eq!(section_a.get("field a"), Some(&"1234"));
|
||||
|
||||
let section_unnamed = match config.get("") {
|
||||
Some(v) => v,
|
||||
None => panic!("unnamed section did not exist"),
|
||||
};
|
||||
|
||||
assert_eq!(section_unnamed.get("field outside"), Some(&"'hello'"));
|
||||
}
|
||||
}
|
||||
@@ -1 +1,2 @@
|
||||
pub mod desktop;
|
||||
mod inish;
|
||||
|
||||
@@ -0,0 +1,238 @@
|
||||
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
error::Error,
|
||||
rc::Rc,
|
||||
cell::RefCell,
|
||||
os::fd::RawFd,
|
||||
};
|
||||
|
||||
use nix::unistd::{
|
||||
pipe, write, read,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
color::Color,
|
||||
event::{Event, Events, PointerButton},
|
||||
fonts::FontMap,
|
||||
widgets::bar_widget::{BarWidget, BarWidgetImpl},
|
||||
};
|
||||
|
||||
use libpulse_binding::volume::ChannelVolumes;
|
||||
|
||||
fn monitor(events: Arc<Mutex<Events>>, inner: Arc<Mutex<InnerAudio>>, pipe: RawFd) -> Result<(), Box<dyn Error>> {
|
||||
use libpulse_binding::{
|
||||
mainloop::{
|
||||
self,
|
||||
standard::{
|
||||
IterateResult,
|
||||
},
|
||||
api::Mainloop,
|
||||
events::io::FlagSet as IoFlagSet,
|
||||
},
|
||||
callbacks::ListResult,
|
||||
context::{
|
||||
Context,
|
||||
FlagSet,
|
||||
subscribe::{InterestMaskSet, Facility},
|
||||
State,
|
||||
},
|
||||
proplist::{properties, Proplist},
|
||||
volume::Volume,
|
||||
};
|
||||
|
||||
let mut proplist = Proplist::new().unwrap();
|
||||
proplist
|
||||
.set_str(properties::APPLICATION_NAME, "wldash")
|
||||
.unwrap();
|
||||
|
||||
let mut mainloop = mainloop::standard::Mainloop::new().unwrap();
|
||||
let context = Rc::new(RefCell::new(Context::new_with_proplist(&mainloop, "wldash_context", &proplist).unwrap()));
|
||||
context.borrow_mut().connect(None, FlagSet::NOFLAGS, None)?;
|
||||
|
||||
loop {
|
||||
mainloop.iterate(false);
|
||||
match context.borrow().get_state() {
|
||||
State::Ready => break,
|
||||
State::Failed | State::Terminated => panic!("damn"),
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
let local_context = context.clone();
|
||||
let local_inner = inner.clone();
|
||||
let local_events = events.clone();
|
||||
context
|
||||
.borrow_mut()
|
||||
.set_subscribe_callback(Some(Box::new(move |facility, _operation, index| {
|
||||
match facility {
|
||||
Some(Facility::Sink) => {
|
||||
let introspector = local_context.borrow_mut().introspect();
|
||||
let inner = local_inner.clone();
|
||||
let events = local_events.clone();
|
||||
introspector.get_sink_info_by_index(index, move |res| {
|
||||
match res {
|
||||
ListResult::End | ListResult::Error => (),
|
||||
ListResult::Item(sink_info) => if let Some(_) = &sink_info.name {
|
||||
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
||||
let mut inner = inner.lock().unwrap();
|
||||
inner.volume = avg;
|
||||
inner.mute = sink_info.mute;
|
||||
inner.dirty = true;
|
||||
drop(inner);
|
||||
let mut events = events.lock().unwrap();
|
||||
events.add_event(Event::AudioUpdate);
|
||||
},
|
||||
}
|
||||
});
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
})));
|
||||
|
||||
context
|
||||
.borrow_mut()
|
||||
.subscribe(InterestMaskSet::SINK, |_| {});
|
||||
|
||||
let introspector = context.borrow_mut().introspect();
|
||||
let local_inner = inner.clone();
|
||||
introspector.get_sink_info_by_name("@DEFAULT_SINK@", move |res| {
|
||||
match res {
|
||||
ListResult::End | ListResult::Error => (),
|
||||
ListResult::Item(sink_info) => if let Some(_) = &sink_info.name {
|
||||
let avg = sink_info.volume.avg().0 as f32 / Volume::NORMAL.0 as f32;
|
||||
let mut inner = local_inner.lock().unwrap();
|
||||
inner.volume = avg;
|
||||
inner.channel_volume = Some(sink_info.volume);
|
||||
inner.mute = sink_info.mute;
|
||||
inner.dirty = true;
|
||||
drop(inner);
|
||||
let mut events = events.lock().unwrap();
|
||||
events.add_event(Event::AudioUpdate);
|
||||
},
|
||||
}
|
||||
});
|
||||
drop(introspector);
|
||||
|
||||
let local_context = context.clone();
|
||||
let local_inner = inner.clone();
|
||||
let event_source = mainloop.new_io_event(pipe as i32, IoFlagSet::INPUT, Box::new(move |_, _, _| {
|
||||
let mut buf = [0; 8];
|
||||
_ = read(pipe, &mut buf);
|
||||
|
||||
let mut inner = local_inner.lock().unwrap();
|
||||
let mut introspector = local_context.borrow_mut().introspect();
|
||||
match inner.last_click.take() {
|
||||
Some(Change::Volume(volume)) => {
|
||||
// do something
|
||||
let mut vol = inner.channel_volume.unwrap();
|
||||
vol.scale(Volume((volume * Volume::NORMAL.0 as f32).round() as u32));
|
||||
introspector.set_sink_volume_by_name("@DEFAULT_SINK@", &vol, None);
|
||||
},
|
||||
Some(Change::VolumeInc(value)) => {
|
||||
let mut vol = inner.channel_volume.unwrap();
|
||||
// apply step to volumes
|
||||
let step = (value * Volume::NORMAL.0 as f32).round() as i32;
|
||||
if step > 0 {
|
||||
vol.inc_clamp(Volume(step as u32), Volume::NORMAL);
|
||||
} else {
|
||||
vol.decrease(Volume(-step as u32));
|
||||
}
|
||||
// HACK: It would be better to only update the volume from feedback, but axis
|
||||
// events fire fast and require the last set volume immediately for reference.
|
||||
inner.channel_volume = Some(vol);
|
||||
introspector.set_sink_volume_by_name("@DEFAULT_SINK@", &vol, None);
|
||||
},
|
||||
Some(Change::ToggleMute) => {
|
||||
introspector.set_sink_mute_by_name("@DEFAULT_SINK@", !inner.mute, None);
|
||||
},
|
||||
None => (),
|
||||
}
|
||||
}));
|
||||
|
||||
loop {
|
||||
match mainloop.iterate(true) {
|
||||
IterateResult::Quit(_) | IterateResult::Err(_) => break,
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
// Need to keep the event source alive
|
||||
_ = event_source;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn start_monitor(events: Arc<Mutex<Events>>, inner: Arc<Mutex<InnerAudio>>, pipe: RawFd) {
|
||||
thread::Builder::new()
|
||||
.name("audiomon".to_string())
|
||||
.spawn(move || { monitor(events, inner, pipe).unwrap() })
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
enum Change {
|
||||
Volume(f32),
|
||||
VolumeInc(f32),
|
||||
ToggleMute,
|
||||
}
|
||||
|
||||
pub struct InnerAudio {
|
||||
volume: f32,
|
||||
channel_volume: Option<ChannelVolumes>,
|
||||
mute: bool,
|
||||
dirty: bool,
|
||||
last_click: Option<Change>,
|
||||
pipe: RawFd,
|
||||
}
|
||||
|
||||
pub struct Audio {
|
||||
inner: Arc<Mutex<InnerAudio>>,
|
||||
}
|
||||
|
||||
impl Audio {
|
||||
pub fn new(events: Arc<Mutex<Events>>, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
||||
let (a, b) = pipe().unwrap();
|
||||
let audio = Audio {
|
||||
inner: Arc::new(Mutex::new(InnerAudio{
|
||||
volume: 0.0,
|
||||
channel_volume: None,
|
||||
mute: false,
|
||||
dirty: false,
|
||||
last_click: None,
|
||||
pipe: b,
|
||||
})),
|
||||
};
|
||||
start_monitor(events, audio.inner.clone(), a);
|
||||
BarWidget::new(Box::new(audio), fm, font, size)
|
||||
}
|
||||
}
|
||||
|
||||
impl BarWidgetImpl for Audio {
|
||||
fn get_dirty(&self) -> bool {
|
||||
self.inner.lock().unwrap().dirty
|
||||
}
|
||||
fn name(&self) -> &'static str {
|
||||
"volume"
|
||||
}
|
||||
fn value(&self) -> f32 {
|
||||
self.inner.lock().unwrap().volume
|
||||
}
|
||||
fn color(&self) -> Color {
|
||||
match self.inner.lock().unwrap().mute {
|
||||
true => Color::YELLOW,
|
||||
false => Color::WHITE,
|
||||
}
|
||||
}
|
||||
fn click(&mut self, pos: f32, btn: PointerButton) {
|
||||
let mut inner = self.inner.lock().unwrap();
|
||||
inner.last_click = match btn {
|
||||
PointerButton::Left => Some(Change::Volume(pos)),
|
||||
PointerButton::Right => Some(Change::ToggleMute),
|
||||
PointerButton::ScrollVertical(val) => Some(Change::VolumeInc((val / 512.) as f32)),
|
||||
PointerButton::ScrollHorizontal(val) => Some(Change::VolumeInc((val / 100.) as f32)),
|
||||
_ => None,
|
||||
};
|
||||
_ = write(inner.pipe, &[0]);
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ use std::{
|
||||
|
||||
use crate::{
|
||||
color::Color,
|
||||
fonts::FontMap,
|
||||
widgets::bar_widget::{BarWidget, BarWidgetImpl},
|
||||
};
|
||||
|
||||
@@ -28,7 +29,7 @@ impl Backlight {
|
||||
self.max = read_file_as_u64(self.device_path.join("max_brightness").as_path()).unwrap();
|
||||
}
|
||||
|
||||
pub fn new(path: &str, font: &'static str, size: f32) -> BarWidget {
|
||||
pub fn new(path: &str, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
||||
let mut dev = Backlight {
|
||||
device_path: Path::new("/sys/class/backlight").to_path_buf().join(path),
|
||||
cur: 0,
|
||||
@@ -36,7 +37,7 @@ impl Backlight {
|
||||
};
|
||||
|
||||
dev.update();
|
||||
BarWidget::new(Box::new(dev), font, size)
|
||||
BarWidget::new(Box::new(dev), fm, font, size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,6 +54,6 @@ impl BarWidgetImpl for Backlight {
|
||||
self.cur as f32 / self.max as f32
|
||||
}
|
||||
fn color(&self) -> Color {
|
||||
Color::new(1.0, 1.0, 1.0, 1.0)
|
||||
Color::WHITE
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use crate::{
|
||||
draw::{draw_bar, draw_box},
|
||||
fonts::FontMap,
|
||||
widgets::{Geometry, Widget},
|
||||
event::{Event, PointerButton},
|
||||
};
|
||||
|
||||
pub trait BarWidgetImpl {
|
||||
@@ -15,6 +16,7 @@ pub trait BarWidgetImpl {
|
||||
fn name(&self) -> &'static str;
|
||||
fn value(&self) -> f32;
|
||||
fn color(&self) -> Color;
|
||||
fn click(&mut self, _pos: f32, _btn: PointerButton) {}
|
||||
}
|
||||
|
||||
pub struct BarWidget {
|
||||
@@ -25,7 +27,8 @@ pub struct BarWidget {
|
||||
}
|
||||
|
||||
impl BarWidget {
|
||||
pub fn new(inner_widget: Box<dyn BarWidgetImpl>, font: &'static str, size: f32) -> BarWidget {
|
||||
pub fn new(inner_widget: Box<dyn BarWidgetImpl>, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
||||
fm.queue_font(font, size, inner_widget.name());
|
||||
BarWidget {
|
||||
geometry: Default::default(),
|
||||
inner_widget,
|
||||
@@ -46,10 +49,10 @@ impl Widget for BarWidget {
|
||||
|
||||
fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
|
||||
let font = fonts.get_font(self.font, self.size);
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
|
||||
font.auto_draw_text(view, &bg, &fg, self.inner_widget.name())
|
||||
font.draw_text(view, bg, fg, self.inner_widget.name())
|
||||
.unwrap();
|
||||
let size = self.size.ceil() as u32;
|
||||
let bar_offset = 4 * size;
|
||||
@@ -57,8 +60,8 @@ impl Widget for BarWidget {
|
||||
|
||||
let c = self.inner_widget.color();
|
||||
draw_bar(
|
||||
&mut view.offset((bar_offset, 0)).unwrap(),
|
||||
&c,
|
||||
&mut view.offset((bar_offset, 0)),
|
||||
c,
|
||||
self.geometry.width - bar_offset,
|
||||
size,
|
||||
val,
|
||||
@@ -66,8 +69,8 @@ impl Widget for BarWidget {
|
||||
.unwrap();
|
||||
|
||||
draw_box(
|
||||
&mut view.offset((bar_offset, 0)).unwrap(),
|
||||
&c,
|
||||
&mut view.offset((bar_offset, 0)),
|
||||
c,
|
||||
(self.geometry.width - bar_offset, size),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -88,4 +91,18 @@ impl Widget for BarWidget {
|
||||
};
|
||||
self.geometry
|
||||
}
|
||||
|
||||
fn event(&mut self, event: &Event) {
|
||||
match event {
|
||||
Event::PointerEvent(ev) => {
|
||||
let offset = 4 * self.size.ceil() as u32;
|
||||
if ev.pos.0 >= offset {
|
||||
let val = (ev.pos.0 - offset) as f32 / (self.geometry.width - offset) as f32;
|
||||
self.inner_widget.click(val, ev.button);
|
||||
}
|
||||
},
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+68
-103
@@ -1,110 +1,81 @@
|
||||
use std::{
|
||||
sync::{Arc, Mutex},
|
||||
thread,
|
||||
time::Duration,
|
||||
};
|
||||
|
||||
use dbus::blocking::{
|
||||
stdintf::org_freedesktop_dbus::{Properties, PropertiesPropertiesChanged},
|
||||
LocalConnection,
|
||||
error::Error,
|
||||
};
|
||||
|
||||
use crate::{
|
||||
color::Color,
|
||||
state::{Event, Events},
|
||||
event::{Event, Events},
|
||||
fonts::FontMap,
|
||||
widgets::bar_widget::{BarWidget, BarWidgetImpl},
|
||||
};
|
||||
|
||||
enum UpowerBatteryState {
|
||||
Charging,
|
||||
Discharging,
|
||||
Empty,
|
||||
Full,
|
||||
NotCharging,
|
||||
Unknown,
|
||||
}
|
||||
use upower_dbus::BatteryState;
|
||||
|
||||
struct InnerBattery {
|
||||
value: f32,
|
||||
state: UpowerBatteryState,
|
||||
state: BatteryState,
|
||||
dirty: bool,
|
||||
}
|
||||
|
||||
async fn monitor(inner: Arc<Mutex<InnerBattery>>, events: Arc<Mutex<Events>>) -> Result<(), Box<dyn Error>> {
|
||||
use zbus::Connection;
|
||||
use upower_dbus::UPowerProxy;
|
||||
use tokio_stream::StreamExt;
|
||||
|
||||
let conn = Connection::system().await?;
|
||||
let proxy = UPowerProxy::new(&conn).await?;
|
||||
|
||||
let device = proxy.get_display_device().await?;
|
||||
|
||||
let local_inner = inner.clone();
|
||||
let local_events = events.clone();
|
||||
let mut percent_stream = device.receive_percentage_changed().await;
|
||||
let a = tokio::spawn(async move {
|
||||
while let Some(percent) = percent_stream.next().await {
|
||||
let percent = percent.get().await.unwrap() as f32 / 100.;
|
||||
let mut inner = local_inner.lock().unwrap();
|
||||
inner.value = percent;
|
||||
inner.dirty = true;
|
||||
drop(inner);
|
||||
|
||||
let mut events = local_events.lock().unwrap();
|
||||
events.add_event(Event::PowerUpdate);
|
||||
}
|
||||
});
|
||||
|
||||
let local_inner = inner.clone();
|
||||
let local_events = events.clone();
|
||||
let mut state_stream = device.receive_state_changed().await;
|
||||
let b = tokio::spawn(async move {
|
||||
while let Some(state) = state_stream.next().await {
|
||||
let state = state.get().await.unwrap();
|
||||
let mut inner = local_inner.lock().unwrap();
|
||||
inner.state = state;
|
||||
inner.dirty = true;
|
||||
drop(inner);
|
||||
|
||||
let mut events = local_events.lock().unwrap();
|
||||
events.add_event(Event::PowerUpdate);
|
||||
}
|
||||
});
|
||||
a.await?;
|
||||
b.await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn start_monitor(inner: Arc<Mutex<InnerBattery>>, events: Arc<Mutex<Events>>) {
|
||||
use tokio::runtime;
|
||||
thread::Builder::new()
|
||||
.name("battmon".to_string())
|
||||
.spawn(move || {
|
||||
let conn = LocalConnection::new_system().unwrap();
|
||||
let device_path = "/org/freedesktop/UPower/devices/DisplayDevice";
|
||||
let proxy = conn.with_proxy(
|
||||
"org.freedesktop.UPower",
|
||||
device_path,
|
||||
Duration::from_millis(500),
|
||||
);
|
||||
|
||||
let capacity: f64 = proxy
|
||||
.get("org.freedesktop.UPower.Device", "Percentage")
|
||||
.expect("unable to get property");
|
||||
let state: u32 = proxy
|
||||
.get("org.freedesktop.UPower.Device", "State")
|
||||
.expect("unable to get state");
|
||||
|
||||
{
|
||||
let mut inner = inner.lock().unwrap();
|
||||
inner.value = capacity as f32 / 100.;
|
||||
inner.state = match state {
|
||||
1 => UpowerBatteryState::Charging,
|
||||
2 => UpowerBatteryState::Discharging,
|
||||
3 => UpowerBatteryState::Empty,
|
||||
4 => UpowerBatteryState::Full,
|
||||
5 => UpowerBatteryState::NotCharging,
|
||||
6 => UpowerBatteryState::Discharging,
|
||||
_ => UpowerBatteryState::Unknown,
|
||||
}
|
||||
}
|
||||
|
||||
proxy
|
||||
.match_signal(
|
||||
move |c: PropertiesPropertiesChanged,
|
||||
_: &LocalConnection,
|
||||
_: &dbus::Message| {
|
||||
if c.interface_name != "org.freedesktop.UPower.Device" {
|
||||
return true;
|
||||
}
|
||||
let mut inner = inner.lock().unwrap();
|
||||
for (key, value) in c.changed_properties {
|
||||
match key.as_str() {
|
||||
"State" => {
|
||||
inner.state = match value.0.as_u64().unwrap() {
|
||||
1 => UpowerBatteryState::Charging,
|
||||
2 => UpowerBatteryState::Discharging,
|
||||
3 => UpowerBatteryState::Empty,
|
||||
4 => UpowerBatteryState::Full,
|
||||
5 => UpowerBatteryState::NotCharging,
|
||||
6 => UpowerBatteryState::Discharging,
|
||||
_ => UpowerBatteryState::Unknown,
|
||||
};
|
||||
inner.dirty = true;
|
||||
let mut events = events.lock().unwrap();
|
||||
events.add_event(Event::PowerUpdate);
|
||||
}
|
||||
"Percentage" => {
|
||||
inner.value = value.0.as_f64().unwrap() as f32 / 100.;
|
||||
inner.dirty = true;
|
||||
let mut events = events.lock().unwrap();
|
||||
events.add_event(Event::PowerUpdate);
|
||||
}
|
||||
_ => (),
|
||||
}
|
||||
}
|
||||
true
|
||||
},
|
||||
)
|
||||
let rt = runtime::Builder::new_current_thread()
|
||||
.enable_io()
|
||||
.build()
|
||||
.unwrap();
|
||||
|
||||
loop {
|
||||
conn.process(Duration::from_millis(60000)).unwrap();
|
||||
}
|
||||
rt.block_on(async move { monitor(inner, events).await }).unwrap();
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
@@ -114,16 +85,16 @@ pub struct Battery {
|
||||
}
|
||||
|
||||
impl Battery {
|
||||
pub fn new(events: Arc<Mutex<Events>>, font: &'static str, size: f32) -> BarWidget {
|
||||
pub fn new(events: Arc<Mutex<Events>>, fm: &mut FontMap, font: &'static str, size: f32) -> BarWidget {
|
||||
let battery = Battery {
|
||||
inner: Arc::new(Mutex::new(InnerBattery {
|
||||
value: 0.,
|
||||
state: UpowerBatteryState::Unknown,
|
||||
state: BatteryState::Unknown,
|
||||
dirty: false,
|
||||
})),
|
||||
};
|
||||
start_monitor(battery.inner.clone(), events);
|
||||
BarWidget::new(Box::new(battery), font, size)
|
||||
BarWidget::new(Box::new(battery), fm, font, size)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -142,20 +113,14 @@ impl BarWidgetImpl for Battery {
|
||||
fn color(&self) -> Color {
|
||||
let inner = self.inner.lock().unwrap();
|
||||
match inner.state {
|
||||
UpowerBatteryState::Discharging | UpowerBatteryState::Unknown => {
|
||||
if inner.value > 0.25 {
|
||||
Color::new(1.0, 1.0, 1.0, 1.0)
|
||||
} else if inner.value > 0.1 {
|
||||
Color::new(1.0, 0.5, 0.0, 1.0)
|
||||
} else {
|
||||
Color::new(1.0, 0.0, 0.0, 1.0)
|
||||
}
|
||||
}
|
||||
UpowerBatteryState::Charging | UpowerBatteryState::Full => {
|
||||
Color::new(0.5, 1.0, 0.5, 1.0)
|
||||
}
|
||||
UpowerBatteryState::NotCharging | UpowerBatteryState::Empty => {
|
||||
Color::new(1.0, 0.5, 0.5, 1.0)
|
||||
BatteryState::Charging | BatteryState::FullyCharged => Color::LIGHTGREEN,
|
||||
BatteryState::PendingCharge => Color::LIGHTRED,
|
||||
_ => if inner.value > 0.25 {
|
||||
Color::WHITE
|
||||
} else if inner.value > 0.1 {
|
||||
Color::DARKORANGE
|
||||
} else {
|
||||
Color::RED
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+116
-98
@@ -4,7 +4,7 @@ use crate::{
|
||||
buffer::BufferView,
|
||||
color::Color,
|
||||
fonts::FontMap,
|
||||
state::Event,
|
||||
event::Event,
|
||||
widgets::{Geometry, Widget},
|
||||
};
|
||||
|
||||
@@ -14,18 +14,32 @@ pub struct Calendar {
|
||||
font: &'static str,
|
||||
sections_x: i32,
|
||||
sections_y: i32,
|
||||
shown_sections_x: u32,
|
||||
shown_sections_y: u32,
|
||||
size: f32,
|
||||
dirty: bool,
|
||||
geometry: Geometry,
|
||||
}
|
||||
|
||||
const DAY_FACTOR: f32 = 1.;
|
||||
const YEAR_FACTOR: f32 = 1.5;
|
||||
const MONTH_FACTOR: f32 = 2.;
|
||||
const DATE_FACTOR: f32 = 2.;
|
||||
const LINE_HEIGHT: f32 = 1.8;
|
||||
|
||||
impl Calendar {
|
||||
pub fn new(font: &'static str, size: f32, sections_x: i32, sections_y: i32) -> Calendar {
|
||||
pub fn new(fm: &mut FontMap, font: &'static str, size: f32, sections_x: i32, sections_y: i32) -> Calendar {
|
||||
fm.queue_font(font, size, "ADEFHIMNORSTUW");
|
||||
fm.queue_font(font, size * 1.5, "0123456789");
|
||||
fm.queue_font(font, size * 2.0, "0123456789 ADFJMOSabcehgilmnoprstuvy");
|
||||
|
||||
Calendar {
|
||||
font,
|
||||
size,
|
||||
sections_x,
|
||||
sections_y,
|
||||
shown_sections_x: 0,
|
||||
shown_sections_y: 0,
|
||||
dirty: true,
|
||||
geometry: Default::default(),
|
||||
}
|
||||
@@ -38,10 +52,62 @@ impl Calendar {
|
||||
orig: NaiveDate,
|
||||
mut time: NaiveDate,
|
||||
) {
|
||||
let black = Color::new(0., 0., 0., 1.);
|
||||
let white = Color::new(1., 1., 1., 1.);
|
||||
let dim = Color::new(0.8, 0.8, 0.8, 1.);
|
||||
let dimmer = Color::new(0.75, 0.75, 0.75, 1.);
|
||||
let black = Color::BLACK;
|
||||
let white = Color::WHITE;
|
||||
let dim = Color::GREY80;
|
||||
let dimmer = Color::GREY75;
|
||||
|
||||
let mut y_off = 1;
|
||||
// TODO: Fix offsets:
|
||||
// - Headline font is not correctly accounted for
|
||||
|
||||
//
|
||||
// Draw the week day
|
||||
//
|
||||
for idx in 1..8 {
|
||||
let day_font = fonts.get_font(self.font, self.size * DAY_FACTOR);
|
||||
let wk_chr = match idx {
|
||||
1 => "MON",
|
||||
2 => "TUE",
|
||||
3 => "WED",
|
||||
4 => "THU",
|
||||
5 => "FRI",
|
||||
6 => "SAT",
|
||||
7 => "SUN",
|
||||
_ => panic!("impossible value"),
|
||||
};
|
||||
|
||||
day_font
|
||||
.draw_text(
|
||||
&mut view
|
||||
.offset((
|
||||
idx * (self.size * 2.5).ceil() as u32 + (self.size / 5.).ceil() as u32,
|
||||
y_off * (self.size * LINE_HEIGHT).ceil() as u32
|
||||
+ (self.size * 1.).ceil() as u32,
|
||||
)),
|
||||
black,
|
||||
white,
|
||||
&wk_chr,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the month
|
||||
//
|
||||
if time.year() != orig.year() {
|
||||
let year_font = fonts.get_font(self.font, self.size * YEAR_FACTOR);
|
||||
year_font
|
||||
.draw_text(
|
||||
&mut view.offset(((self.size * 17.).ceil() as u32, 0)),
|
||||
black,
|
||||
dim,
|
||||
&format!("{:}", time.year()),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let cal_font = fonts.get_font(self.font, self.size * DATE_FACTOR);
|
||||
let month_str = match time.month() {
|
||||
1 => "January",
|
||||
2 => "February",
|
||||
@@ -57,62 +123,8 @@ impl Calendar {
|
||||
12 => "December",
|
||||
_ => panic!("impossible value"),
|
||||
};
|
||||
|
||||
|
||||
let mut y_off = 1;
|
||||
// TODO: Fix offsets:
|
||||
// - Headline font is not correctly accounted for
|
||||
|
||||
//
|
||||
// Draw the week day
|
||||
//
|
||||
for idx in 1..8 {
|
||||
let day_font = fonts.get_font(self.font, self.size);
|
||||
let wk_chr = match idx {
|
||||
1 => "MON",
|
||||
2 => "TUE",
|
||||
3 => "WED",
|
||||
4 => "THU",
|
||||
5 => "FRI",
|
||||
6 => "SAT",
|
||||
7 => "SUN",
|
||||
_ => panic!("impossible value"),
|
||||
};
|
||||
|
||||
day_font
|
||||
.auto_draw_text(
|
||||
&mut view
|
||||
.offset((
|
||||
idx * (self.size * 2.5).ceil() as u32 + (self.size / 5.).ceil() as u32,
|
||||
y_off * (self.size * 1.8).ceil() as u32
|
||||
+ (self.size * 1.).ceil() as u32,
|
||||
))
|
||||
.unwrap(),
|
||||
&black,
|
||||
&white,
|
||||
&wk_chr,
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
//
|
||||
// Draw the month
|
||||
//
|
||||
if time.year() != orig.year() {
|
||||
let year_font = fonts.get_font(self.font, self.size * 1.5);
|
||||
year_font
|
||||
.auto_draw_text(
|
||||
&mut view.offset(((self.size * 17.).ceil() as u32, 0)).unwrap(),
|
||||
&black,
|
||||
&dim,
|
||||
&format!("{:}", time.year()),
|
||||
)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
let cal_font = fonts.get_font(self.font, self.size * 2.);
|
||||
cal_font
|
||||
.auto_draw_text(&mut view, &black, &white, month_str)
|
||||
.draw_text(&mut view, black, white, month_str)
|
||||
.unwrap();
|
||||
|
||||
let mut done = false;
|
||||
@@ -133,16 +145,15 @@ impl Calendar {
|
||||
//
|
||||
let wk = time.iso_week();
|
||||
cal_font
|
||||
.auto_draw_text(
|
||||
.draw_text(
|
||||
&mut view
|
||||
.offset((
|
||||
0,
|
||||
y_off * (self.size * 1.8).ceil() as u32
|
||||
+ (self.size * 2.).ceil() as u32,
|
||||
))
|
||||
.unwrap(),
|
||||
&black,
|
||||
&dimmer,
|
||||
y_off * (self.size * LINE_HEIGHT).ceil() as u32
|
||||
+ (self.size * MONTH_FACTOR).ceil() as u32,
|
||||
)),
|
||||
black,
|
||||
dimmer,
|
||||
&format!("{:02}", wk.week()),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -153,21 +164,21 @@ impl Calendar {
|
||||
//
|
||||
while x_pos < 8 {
|
||||
let c = if time.day() == orig.day() && time.month() == orig.month() {
|
||||
Color::new(1.0, 1.0, 1.0, 1.0)
|
||||
Color::WHITE
|
||||
} else {
|
||||
Color::new(0.5, 0.5, 0.5, 1.0)
|
||||
Color::GREY50
|
||||
};
|
||||
|
||||
cal_font
|
||||
.auto_draw_text(
|
||||
.draw_text(
|
||||
&mut view
|
||||
.offset((
|
||||
x_pos * (self.size * 2.5).ceil() as u32,
|
||||
y_off * (self.size * 1.8).ceil() as u32 + (self.size * 2.) as u32,
|
||||
))
|
||||
.unwrap(),
|
||||
&black,
|
||||
&c,
|
||||
y_off * (self.size * LINE_HEIGHT).ceil() as u32
|
||||
+ (self.size * MONTH_FACTOR).ceil() as u32,
|
||||
)),
|
||||
black,
|
||||
c,
|
||||
&format!("{:02}", time.day()),
|
||||
)
|
||||
.unwrap();
|
||||
@@ -205,35 +216,33 @@ impl<'a> Widget for Calendar {
|
||||
}
|
||||
|
||||
fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
|
||||
if self.shown_sections_y == 0 || self.shown_sections_x == 0 {
|
||||
return Geometry {
|
||||
x: self.geometry.x,
|
||||
y: self.geometry.y,
|
||||
width: 0,
|
||||
height: 0,
|
||||
};
|
||||
}
|
||||
|
||||
let time = Local::now().naive_local().date();
|
||||
|
||||
let cal_height = (self.size * 16.25).ceil() as u32;
|
||||
let cal_width = (7. * self.size * 3. + self.size * 2.).ceil() as u32;
|
||||
let cal_width = (7. * self.size * 2.5 + self.size * 2.).ceil() as u32;
|
||||
let cal_pad = (3. * self.size).ceil() as u32;
|
||||
let sections_y = if self.sections_y > 0 {
|
||||
self.sections_y as u32
|
||||
} else {
|
||||
self.geometry.height / cal_height
|
||||
};
|
||||
let sections_x = if self.sections_x > 0 {
|
||||
self.sections_x as u32
|
||||
} else {
|
||||
self.geometry.width / (cal_height + cal_pad)
|
||||
};
|
||||
|
||||
let mut t = time.with_day(1).unwrap();
|
||||
let cals = sections_y * sections_x - 1;
|
||||
if cals >=3 {
|
||||
let cals = self.shown_sections_y * self.shown_sections_x;
|
||||
if cals >= 3 {
|
||||
t = t.pred_opt().unwrap().with_day(1).unwrap();
|
||||
}
|
||||
|
||||
for ydx in 0..sections_y {
|
||||
for idx in 0..sections_x {
|
||||
for ydx in 0..self.shown_sections_y {
|
||||
for idx in 0..self.shown_sections_x {
|
||||
self.draw_month(
|
||||
fonts,
|
||||
&mut view
|
||||
.offset(((cal_width + cal_pad) * idx, (cal_height) * ydx))
|
||||
.unwrap(),
|
||||
.offset(((cal_width + cal_pad) * idx, (cal_height) * ydx)),
|
||||
time,
|
||||
t,
|
||||
);
|
||||
@@ -249,17 +258,26 @@ impl<'a> Widget for Calendar {
|
||||
}
|
||||
|
||||
fn geometry_update(&mut self, _fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
||||
let cal_width = (7. * self.size * 3. + self.size * 2.).ceil() as u32;
|
||||
let cal_height = (self.size * 16.25).ceil() as u32; // TODO: Calculate from font sizes
|
||||
let cal_width = 7 * (self.size * 2.5).ceil() as u32 + (self.size * 2.).ceil() as u32;
|
||||
let cal_height = (self.size * MONTH_FACTOR).ceil() as u32
|
||||
+ (self.size * LINE_HEIGHT * 8.).ceil() as u32;
|
||||
let cal_pad = (self.size * 3.).ceil() as u32;
|
||||
let width = if self.sections_x > 0 {
|
||||
|
||||
let possible_sections_x = geometry.width / (cal_width + cal_pad);
|
||||
let possible_sections_y = geometry.height / cal_height;
|
||||
|
||||
let width = if self.sections_x > 0 && self.sections_x < possible_sections_x as i32 {
|
||||
self.shown_sections_x = self.sections_x as u32;
|
||||
cal_width * self.sections_x as u32 + cal_pad * (self.sections_x as u32 - 1)
|
||||
} else {
|
||||
(geometry.width / (cal_width + cal_pad)) * (cal_width + cal_pad)
|
||||
self.shown_sections_x = possible_sections_x;
|
||||
(geometry.width / (cal_width + cal_pad)) * (cal_width + cal_pad)
|
||||
};
|
||||
let height = if self.sections_y > 0 {
|
||||
let height = if self.sections_y > 0 && self.sections_y < possible_sections_y as i32 {
|
||||
self.shown_sections_y = self.sections_y as u32;
|
||||
cal_height * self.sections_y as u32
|
||||
} else {
|
||||
self.shown_sections_y = possible_sections_y;
|
||||
(geometry.height / cal_height) * cal_height
|
||||
};
|
||||
self.geometry = Geometry {
|
||||
|
||||
@@ -4,7 +4,7 @@ use crate::{
|
||||
buffer::BufferView,
|
||||
color::Color,
|
||||
fonts::FontMap,
|
||||
state::Event,
|
||||
event::Event,
|
||||
widgets::{Geometry, Widget},
|
||||
};
|
||||
|
||||
@@ -20,7 +20,8 @@ pub struct Clock {
|
||||
}
|
||||
|
||||
impl<'a> Clock {
|
||||
pub fn new(font: &'static str, size: f32) -> Clock {
|
||||
pub fn new(fm: &mut FontMap, font: &'static str, size: f32) -> Clock {
|
||||
fm.queue_font(font, size, "0123456789: ");
|
||||
Clock {
|
||||
font,
|
||||
size,
|
||||
@@ -52,16 +53,16 @@ impl<'a> Widget for Clock {
|
||||
|
||||
fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
|
||||
let time = Local::now().naive_local();
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
|
||||
let digit = self.digit_width;
|
||||
let colon = self.colon_width;
|
||||
let font = fonts.get_font(self.font, self.size);
|
||||
font.draw_text_fixed_width(
|
||||
view,
|
||||
&bg,
|
||||
&fg,
|
||||
bg,
|
||||
fg,
|
||||
&[digit, digit, colon, digit, digit],
|
||||
&format!("{:02}:{:02}", time.hour(), time.minute()),
|
||||
)
|
||||
|
||||
+12
-11
@@ -4,7 +4,7 @@ use crate::{
|
||||
buffer::BufferView,
|
||||
color::Color,
|
||||
fonts::FontMap,
|
||||
state::Event,
|
||||
event::Event,
|
||||
widgets::{Geometry, Widget},
|
||||
};
|
||||
|
||||
@@ -18,7 +18,8 @@ pub struct Date {
|
||||
}
|
||||
|
||||
impl Date {
|
||||
pub fn new(font: &'static str, size: f32) -> Date {
|
||||
pub fn new(fm: &mut FontMap, font: &'static str, size: f32) -> Date {
|
||||
fm.queue_font(font, size, "0123456789/, adehinortuFMSTW");
|
||||
Date {
|
||||
font,
|
||||
size,
|
||||
@@ -48,14 +49,13 @@ impl<'a> Widget for Date {
|
||||
|
||||
fn draw(&mut self, fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
|
||||
let time = Local::now().naive_local();
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let mut date_line = view.offset((0, 8)).unwrap();
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
let font = fonts.get_font(self.font, self.size);
|
||||
font.auto_draw_text(
|
||||
&mut date_line,
|
||||
&bg,
|
||||
&fg,
|
||||
font.draw_text(
|
||||
view,
|
||||
bg,
|
||||
fg,
|
||||
&format!(
|
||||
"{}, {:02}/{:02}/{:4}",
|
||||
time.weekday(),
|
||||
@@ -69,13 +69,14 @@ impl<'a> Widget for Date {
|
||||
self.geometry
|
||||
}
|
||||
|
||||
fn geometry_update(&mut self, _fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
||||
fn geometry_update(&mut self, fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
||||
let width = (3. + 2. + 2. + 2. + 4.) * self.size / 2.;
|
||||
let font = fonts.get_font(self.font, self.size);
|
||||
self.geometry = Geometry {
|
||||
x: geometry.x,
|
||||
y: geometry.y,
|
||||
width: width.ceil() as u32,
|
||||
height: self.size.ceil() as u32,
|
||||
height: font.height().ceil() as u32,
|
||||
};
|
||||
self.geometry
|
||||
}
|
||||
|
||||
+71
-38
@@ -12,7 +12,7 @@ use crate::{
|
||||
color::Color,
|
||||
fonts::FontMap,
|
||||
keyboard::{keysyms, KeyEvent},
|
||||
state::Event,
|
||||
event::{Event, Events, PointerEvent, PointerButton},
|
||||
utils::desktop::{load_desktop_files, Desktop},
|
||||
widgets::{Geometry, Widget},
|
||||
};
|
||||
@@ -205,14 +205,20 @@ struct Launcher {
|
||||
}
|
||||
|
||||
impl Launcher {
|
||||
fn new() -> Launcher {
|
||||
fn new(events: Arc<Mutex<Events>>) -> Launcher {
|
||||
let options = Arc::new(Mutex::new(Vec::new()));
|
||||
{
|
||||
let options = Arc::clone(&options);
|
||||
thread::spawn(move || {
|
||||
let mut options = options.lock().unwrap();
|
||||
*options = load_desktop_files();
|
||||
});
|
||||
thread::Builder::new()
|
||||
.name("desktopini".to_string())
|
||||
.spawn(move || {
|
||||
let mut options = options.lock().unwrap();
|
||||
*options = load_desktop_files();
|
||||
drop(options);
|
||||
let mut events = events.lock().unwrap();
|
||||
events.add_event(Event::LauncherUpdate);
|
||||
})
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
Launcher {
|
||||
@@ -280,31 +286,31 @@ impl InterfaceWidget for Launcher {
|
||||
fonts: &mut FontMap,
|
||||
view: &mut BufferView,
|
||||
) -> Geometry {
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
|
||||
let line_height = intf.size.ceil() as u32;
|
||||
|
||||
// Draw line
|
||||
let mut prompt_offset = intf.geometry.height - line_height;
|
||||
let mut prompt_line = view.offset((0, prompt_offset)).unwrap();
|
||||
let mut prompt_line = view.offset((0, prompt_offset));
|
||||
|
||||
let font = fonts.get_font(intf.font, intf.size);
|
||||
let mut x_max = font
|
||||
.auto_draw_text_with_cursor(
|
||||
&mut prompt_line,
|
||||
&bg,
|
||||
&fg,
|
||||
bg,
|
||||
fg,
|
||||
&format!(" {}", &intf.prompt.input),
|
||||
intf.prompt.cursor + 3,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
font.auto_draw_text(&mut prompt_line, &bg, &fg, ">")
|
||||
font.auto_draw_text(&mut prompt_line, bg, fg, ">")
|
||||
.unwrap();
|
||||
|
||||
// Draw entries
|
||||
let dimfg = Color::new(0.5, 0.5, 0.5, 1.0);
|
||||
let dimfg = Color::GREY50;
|
||||
prompt_offset -= 16;
|
||||
|
||||
for (idx, m) in self.matches.iter().enumerate() {
|
||||
@@ -312,7 +318,7 @@ impl InterfaceWidget for Launcher {
|
||||
break;
|
||||
}
|
||||
prompt_offset -= line_height;
|
||||
let mut line = view.offset((0, prompt_offset)).unwrap();
|
||||
let mut line = view.offset((0, prompt_offset));
|
||||
|
||||
if idx == intf.selection {
|
||||
let fuzzy_matcher = SkimMatcherV2::default();
|
||||
@@ -323,20 +329,20 @@ impl InterfaceWidget for Launcher {
|
||||
let mut colors = Vec::with_capacity(m.name.len());
|
||||
for pos in 0..m.name.len() {
|
||||
if indices.contains(&pos) {
|
||||
colors.push(Color::new(1.0, 0.65, 0., 1.0));
|
||||
colors.push(Color::LIGHTORANGE);
|
||||
} else {
|
||||
colors.push(Color::new(0.75, 0.75, 0.75, 1.0));
|
||||
colors.push(Color::GREY75);
|
||||
}
|
||||
}
|
||||
x_max = max(
|
||||
x_max,
|
||||
font.auto_draw_text_individual_colors(&mut line, &bg, &colors, &m.name)
|
||||
font.auto_draw_text_individual_colors(&mut line, bg, &colors, &m.name)
|
||||
.unwrap(),
|
||||
);
|
||||
} else {
|
||||
x_max = max(
|
||||
x_max,
|
||||
font.auto_draw_text(&mut line, &bg, &dimfg, &m.name)
|
||||
font.auto_draw_text(&mut line, bg, dimfg, &m.name)
|
||||
.unwrap(),
|
||||
);
|
||||
}
|
||||
@@ -379,27 +385,27 @@ impl InterfaceWidget for Shell {
|
||||
fonts: &mut FontMap,
|
||||
view: &mut BufferView,
|
||||
) -> Geometry {
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
|
||||
let line_height = intf.size.ceil() as u32;
|
||||
|
||||
// Draw line
|
||||
let prompt_offset = intf.geometry.height - line_height;
|
||||
let mut prompt_line = view.offset((0, prompt_offset)).unwrap();
|
||||
let mut prompt_line = view.offset((0, prompt_offset));
|
||||
|
||||
// Draw prompt
|
||||
let font = fonts.get_font(intf.font, intf.size);
|
||||
let x_max = font
|
||||
.auto_draw_text_with_cursor(
|
||||
&mut prompt_line,
|
||||
&bg,
|
||||
&fg,
|
||||
bg,
|
||||
fg,
|
||||
&format!(" {}", &intf.prompt.input),
|
||||
intf.prompt.cursor + 3,
|
||||
)
|
||||
.unwrap();
|
||||
font.auto_draw_text(&mut prompt_line, &bg, &Color::new(1., 0.75, 0.5, 1.), "!")
|
||||
font.auto_draw_text(&mut prompt_line, bg, Color::BUFF, "!")
|
||||
.unwrap();
|
||||
|
||||
Geometry {
|
||||
@@ -440,45 +446,45 @@ impl InterfaceWidget for Calc {
|
||||
fonts: &mut FontMap,
|
||||
view: &mut BufferView,
|
||||
) -> Geometry {
|
||||
let fg = Color::new(1., 1., 1., 1.);
|
||||
let bg = Color::new(0., 0., 0., 1.);
|
||||
let fg = Color::WHITE;
|
||||
let bg = Color::BLACK;
|
||||
|
||||
let line_height = intf.size.ceil() as u32;
|
||||
|
||||
// Draw line
|
||||
let mut prompt_offset = intf.geometry.height - (line_height);
|
||||
let mut prompt_line = view.offset((0, prompt_offset)).unwrap();
|
||||
let mut prompt_line = view.offset((0, prompt_offset));
|
||||
|
||||
// Draw prompt
|
||||
let font = fonts.get_font(intf.font, intf.size);
|
||||
let res_off = font
|
||||
.auto_draw_text_with_cursor(
|
||||
&mut prompt_line,
|
||||
&bg,
|
||||
&fg,
|
||||
bg,
|
||||
fg,
|
||||
&format!(" {} ", &intf.prompt.input),
|
||||
intf.prompt.cursor + 3,
|
||||
)
|
||||
.unwrap();
|
||||
|
||||
font.auto_draw_text(&mut prompt_line, &bg, &Color::new(1., 0.75, 0.5, 1.), "=")
|
||||
font.auto_draw_text(&mut prompt_line, bg, Color::BUFF, "=")
|
||||
.unwrap();
|
||||
|
||||
if let Some(res) = &self.result {
|
||||
let resfg = Color::new(1.0, 0.65, 0., 1.0);
|
||||
let mut result_line = view.offset((res_off.0, prompt_offset)).unwrap();
|
||||
font.auto_draw_text(&mut result_line, &bg, &resfg, &format!(" = {}", &res))
|
||||
let resfg = Color::LIGHTORANGE;
|
||||
let mut result_line = view.offset((res_off.0, prompt_offset));
|
||||
font.auto_draw_text(&mut result_line, bg, resfg, &format!(" = {}", &res))
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
for m in self.old.iter().rev() {
|
||||
let dimfg = Color::new(0.5, 0.5, 0.5, 1.0);
|
||||
let dimfg = Color::GREY50;
|
||||
if prompt_offset < line_height {
|
||||
break;
|
||||
}
|
||||
prompt_offset -= line_height;
|
||||
let mut result_line = view.offset((0, prompt_offset)).unwrap();
|
||||
font.auto_draw_text(&mut result_line, &bg, &dimfg, &m)
|
||||
let mut result_line = view.offset((0, prompt_offset));
|
||||
font.auto_draw_text(&mut result_line, bg, dimfg, &m)
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
@@ -512,9 +518,14 @@ pub struct Interface {
|
||||
}
|
||||
|
||||
impl Interface {
|
||||
pub fn new(font: &'static str, size: f32) -> Interface {
|
||||
pub fn new(events: Arc<Mutex<Events>>, fm: &mut FontMap, font: &'static str, size: f32) -> Interface {
|
||||
fm.queue_font(
|
||||
font, size,
|
||||
"abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789 >=!,.-/()",
|
||||
);
|
||||
|
||||
Interface {
|
||||
launcher: Launcher::new(),
|
||||
launcher: Launcher::new(events),
|
||||
shell: Shell {},
|
||||
calc: Calc {
|
||||
old: Vec::new(),
|
||||
@@ -531,6 +542,23 @@ impl Interface {
|
||||
}
|
||||
}
|
||||
|
||||
fn pointer_input(&mut self, event: &PointerEvent) {
|
||||
if let PointerButton::Left = event.button {
|
||||
let line_height = self.inner.size.ceil() as u32;
|
||||
let height = self.inner.geometry.height - line_height - 16;
|
||||
let lines = height / line_height;
|
||||
|
||||
let offset = height % line_height;
|
||||
let pos = if event.pos.1 >= offset {
|
||||
event.pos.1 - offset
|
||||
} else {
|
||||
return;
|
||||
};
|
||||
self.inner.selection = (lines - pos / line_height - 1) as usize;
|
||||
self.inner.dirty = true;
|
||||
}
|
||||
}
|
||||
|
||||
fn keyboard_input(&mut self, event: &KeyEvent) {
|
||||
if event.state != WEnum::Value(wl_keyboard::KeyState::Pressed) {
|
||||
return;
|
||||
@@ -616,6 +644,11 @@ impl Widget for Interface {
|
||||
fn event(&mut self, event: &Event) {
|
||||
match event {
|
||||
Event::KeyEvent(e) => self.keyboard_input(e),
|
||||
Event::PointerEvent(e) => self.pointer_input(e),
|
||||
Event::LauncherUpdate => {
|
||||
self.inner.dirty = true;
|
||||
self.launcher.update(&self.inner);
|
||||
},
|
||||
Event::TokenUpdate(t) => self.launcher.next_token = Some(t.to_string()),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -0,0 +1,174 @@
|
||||
use std::cmp::max;
|
||||
|
||||
use crate::{
|
||||
fonts::FontMap,
|
||||
state::State,
|
||||
widgets::{Geometry},
|
||||
};
|
||||
|
||||
pub trait Layout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry;
|
||||
}
|
||||
|
||||
pub struct HorizontalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl HorizontalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(HorizontalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for HorizontalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_width = 0;
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let result = w.geometry_update(fonts, &geo, state);
|
||||
geo.x = result.x + result.width;
|
||||
geo.width -= result.width;
|
||||
max_width += result.width;
|
||||
max_height = max(result.height, max_height);
|
||||
}
|
||||
geo.width = max_width;
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VerticalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl VerticalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(VerticalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for VerticalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_width = 0;
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let result = w.geometry_update(fonts, &geo, state);
|
||||
geo.y = result.y + result.height;
|
||||
geo.height -= result.height;
|
||||
max_width = max(result.width, max_width);
|
||||
max_height += result.height;
|
||||
}
|
||||
geo.width = max_width;
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetUpdater {
|
||||
fn geometry_update(&mut self, idx: usize, fonts: &mut FontMap, geometry: &Geometry)
|
||||
-> Geometry;
|
||||
}
|
||||
|
||||
pub struct IndexedLayout {
|
||||
pub widget_idx: usize,
|
||||
}
|
||||
|
||||
impl IndexedLayout {
|
||||
pub fn new(widget_idx: usize) -> Box<dyn Layout> {
|
||||
Box::new(IndexedLayout { widget_idx })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for IndexedLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
state.geometry_update(self.widget_idx, fonts, geometry)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Margin {
|
||||
pub widget: Box<dyn Layout>,
|
||||
pub margin: (u32, u32, u32, u32),
|
||||
}
|
||||
|
||||
impl Margin {
|
||||
pub fn new(widget: Box<dyn Layout>, margin: (u32, u32, u32, u32)) -> Box<dyn Layout> {
|
||||
Box::new(Margin { widget, margin })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for Margin {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let geo = Geometry {
|
||||
x: geometry.x + self.margin.0,
|
||||
y: geometry.y + self.margin.1,
|
||||
width: geometry.width - self.margin.0 - self.margin.2,
|
||||
height: geometry.height - self.margin.1 - self.margin.3,
|
||||
};
|
||||
let out = self.widget.geometry_update(fonts, &geo, state);
|
||||
Geometry {
|
||||
x: out.x - self.margin.0,
|
||||
y: out.y - self.margin.1,
|
||||
width: out.width + self.margin.0 + self.margin.2,
|
||||
height: out.height + self.margin.1 + self.margin.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InvertedHorizontalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl InvertedHorizontalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(InvertedHorizontalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for InvertedHorizontalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let mut temp_geo = geo.clone();
|
||||
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
||||
temp_geo.x = geo.x + (geo.width - temp_result.width);
|
||||
let result = w.geometry_update(fonts, &temp_geo, state);
|
||||
geo.width -= result.width;
|
||||
max_height = max(result.height, max_height);
|
||||
}
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
+8
-6
@@ -7,14 +7,17 @@ use crate::{
|
||||
widgets::{Geometry, Widget},
|
||||
};
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct Line {
|
||||
geometry: Geometry,
|
||||
thickness: u32,
|
||||
}
|
||||
|
||||
impl Line {
|
||||
pub fn new() -> Line {
|
||||
Default::default()
|
||||
pub fn new(thickness: u32) -> Line {
|
||||
Line{
|
||||
geometry: Default::default(),
|
||||
thickness,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +26,15 @@ impl Widget for Line {
|
||||
self.geometry
|
||||
}
|
||||
fn draw(&mut self, _fonts: &mut FontMap, view: &mut BufferView) -> Geometry {
|
||||
view.memset(&Color::new(1., 1., 1., 1.));
|
||||
view.memset(Color::WHITE);
|
||||
self.geometry
|
||||
}
|
||||
|
||||
fn geometry_update(&mut self, _fonts: &mut FontMap, geometry: &Geometry) -> Geometry {
|
||||
self.geometry = Geometry {
|
||||
x: geometry.x,
|
||||
y: geometry.y,
|
||||
width: geometry.width,
|
||||
height: 1,
|
||||
height: self.thickness,
|
||||
};
|
||||
self.geometry
|
||||
}
|
||||
|
||||
+5
-4
@@ -1,3 +1,4 @@
|
||||
mod audio;
|
||||
mod backlight;
|
||||
mod bar_widget;
|
||||
mod battery;
|
||||
@@ -7,7 +8,9 @@ mod date;
|
||||
mod launcher;
|
||||
mod line;
|
||||
mod widget;
|
||||
mod layout;
|
||||
|
||||
pub use audio::Audio;
|
||||
pub use backlight::Backlight;
|
||||
pub use battery::Battery;
|
||||
pub use calendar::Calendar;
|
||||
@@ -15,7 +18,5 @@ pub use clock::Clock;
|
||||
pub use date::Date;
|
||||
pub use launcher::Interface;
|
||||
pub use line::Line;
|
||||
pub use widget::{
|
||||
Geometry, HorizontalLayout, IndexedLayout, InvertedHorizontalLayout, Layout, Margin,
|
||||
VerticalLayout, Widget, WidgetUpdater,
|
||||
};
|
||||
pub use layout::{VerticalLayout, HorizontalLayout, IndexedLayout, InvertedHorizontalLayout, Layout, Margin, WidgetUpdater};
|
||||
pub use widget::{Geometry, Widget};
|
||||
|
||||
+6
-167
@@ -6,7 +6,7 @@ use std::{
|
||||
use crate::{
|
||||
buffer::BufferView,
|
||||
fonts::FontMap,
|
||||
state::{Event, State},
|
||||
event::Event,
|
||||
};
|
||||
|
||||
#[derive(Debug, Default, Clone, Copy)]
|
||||
@@ -47,6 +47,11 @@ impl Geometry {
|
||||
height: max(self.height + self.y, other.height + other.height) - y,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn contains(&self, position: (u32, u32)) -> bool {
|
||||
position.0 >= self.x && position.0 < self.x + self.width &&
|
||||
position.1 >= self.y && position.1 < self.y + self.height
|
||||
}
|
||||
}
|
||||
|
||||
pub trait Widget {
|
||||
@@ -59,169 +64,3 @@ pub trait Widget {
|
||||
fn event(&mut self, _event: &Event) {}
|
||||
}
|
||||
|
||||
pub trait Layout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry;
|
||||
}
|
||||
pub struct HorizontalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl HorizontalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(HorizontalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for HorizontalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_width = 0;
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let result = w.geometry_update(fonts, &geo, state);
|
||||
geo.x = result.x + result.width;
|
||||
geo.width -= result.width;
|
||||
max_width += result.width;
|
||||
max_height = max(result.height, max_height);
|
||||
}
|
||||
geo.width = max_width;
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
|
||||
pub struct VerticalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl VerticalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(VerticalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for VerticalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_width = 0;
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let result = w.geometry_update(fonts, &geo, state);
|
||||
geo.y = result.y + result.height;
|
||||
geo.height -= result.height;
|
||||
max_width = max(result.width, max_width);
|
||||
max_height += result.height;
|
||||
}
|
||||
geo.width = max_width;
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
|
||||
pub trait WidgetUpdater {
|
||||
fn geometry_update(&mut self, idx: usize, fonts: &mut FontMap, geometry: &Geometry)
|
||||
-> Geometry;
|
||||
}
|
||||
|
||||
pub struct IndexedLayout {
|
||||
pub widget_idx: usize,
|
||||
}
|
||||
|
||||
impl IndexedLayout {
|
||||
pub fn new(widget_idx: usize) -> Box<dyn Layout> {
|
||||
Box::new(IndexedLayout { widget_idx })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for IndexedLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
state.geometry_update(self.widget_idx, fonts, geometry)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Margin {
|
||||
pub widget: Box<dyn Layout>,
|
||||
pub margin: (u32, u32, u32, u32),
|
||||
}
|
||||
|
||||
impl Margin {
|
||||
pub fn new(widget: Box<dyn Layout>, margin: (u32, u32, u32, u32)) -> Box<dyn Layout> {
|
||||
Box::new(Margin { widget, margin })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for Margin {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let geo = Geometry {
|
||||
x: geometry.x + self.margin.0,
|
||||
y: geometry.y + self.margin.1,
|
||||
width: geometry.width - self.margin.0 - self.margin.2,
|
||||
height: geometry.height - self.margin.1 - self.margin.3,
|
||||
};
|
||||
|
||||
let out = self.widget.geometry_update(fonts, &geo, state);
|
||||
Geometry {
|
||||
x: out.x - self.margin.0,
|
||||
y: out.y - self.margin.1,
|
||||
width: out.width + self.margin.0 + self.margin.2,
|
||||
height: out.height + self.margin.1 + self.margin.3,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct InvertedHorizontalLayout {
|
||||
pub widgets: Vec<Box<dyn Layout>>,
|
||||
}
|
||||
|
||||
impl InvertedHorizontalLayout {
|
||||
pub fn new(widgets: Vec<Box<dyn Layout>>) -> Box<dyn Layout> {
|
||||
Box::new(InvertedHorizontalLayout { widgets })
|
||||
}
|
||||
}
|
||||
|
||||
impl Layout for InvertedHorizontalLayout {
|
||||
fn geometry_update(
|
||||
&self,
|
||||
fonts: &mut FontMap,
|
||||
geometry: &Geometry,
|
||||
state: &mut State,
|
||||
) -> Geometry {
|
||||
let mut geo = geometry.clone();
|
||||
let mut max_height = 0;
|
||||
for w in self.widgets.iter() {
|
||||
let mut temp_geo = geo.clone();
|
||||
let temp_result = w.geometry_update(fonts, &temp_geo, state);
|
||||
temp_geo.x = geo.x + (geo.width - temp_result.width);
|
||||
let result = w.geometry_update(fonts, &temp_geo, state);
|
||||
geo.width -= result.width;
|
||||
max_height = max(result.height, max_height);
|
||||
}
|
||||
geo.height = max_height;
|
||||
geo
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user