Configurable font support

Use fontconfig to load fonts. Fonts can be added to the `fonts` map in
the config, and referenced from individual widgets' configurations for
customizability.

Fonts default to values "mono" and "sans" if nothing is set.
This commit is contained in:
Hilmar Gústafsson
2020-06-14 17:01:42 +02:00
committed by Kenny Levinsen
parent 1a62696662
commit 48985c470a
26 changed files with 396 additions and 14128 deletions
+12 -4
View File
@@ -1,6 +1,9 @@
use crate::color::Color;
use crate::widget::WaitContext;
use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl};
use crate::{
fonts::FontRef,
widgets::bar_widget::{BarWidget, BarWidgetImpl},
};
use alsa::mixer::{Mixer, Selem, SelemChannelId, SelemId};
@@ -34,15 +37,20 @@ pub struct Alsa {
}
impl Alsa {
pub fn new(font_size: f32, length: u32) -> ::std::io::Result<Box<BarWidget>> {
pub fn new(font: FontRef, font_size: f32, length: u32) -> ::std::io::Result<Box<BarWidget>> {
let mixer = Mixer::new(CARD_NAME, true)
.map_err(|err| alsa_error_to_io_error("Failed to create ALSA mixer", &err))?;
let mixer = Self { mixer };
mixer.get_master_volume()?; // probing
Ok(BarWidget::new_simple(font_size, length, Box::new(mixer)))
Ok(BarWidget::new_simple(
font,
font_size,
length,
Box::new(mixer),
))
}
#[inline]
pub fn get_master<'a>(&'a self) -> ::std::io::Result<Selem<'a>> {
pub fn get_master(&self) -> ::std::io::Result<Selem> {
let master_id = SelemId::new(SELEM_NAME, SELEM_ID);
match self.mixer.find_selem(&master_id) {
Some(master) => Ok(master),
+6 -2
View File
@@ -1,7 +1,10 @@
use crate::cmd::Cmd;
use crate::color::Color;
use crate::widget::WaitContext;
use crate::widgets::bar_widget::{BarWidget, BarWidgetImpl};
use crate::{
fonts::FontRef,
widgets::bar_widget::{BarWidget, BarWidgetImpl},
};
use std::cell::RefCell;
use std::collections::HashMap;
@@ -484,11 +487,12 @@ pub struct PulseAudio {
impl PulseAudio {
pub fn new(
font: FontRef,
font_size: f32,
length: u32,
sender: Sender<Cmd>,
) -> Result<Box<BarWidget>, ::std::io::Error> {
BarWidget::new(font_size, length, move |dirty| {
BarWidget::new(font, font_size, length, move |dirty| {
let device = PulseAudioSoundDevice::new(move || {
*dirty.lock().unwrap() = true;
sender.send(Cmd::Draw).unwrap();