move config to .config/unffettered-keyboard/unffetered.yaml
This commit is contained in:
parent
a0d8bbd1f4
commit
5f2aa46ea9
1 changed files with 53 additions and 54 deletions
|
|
@ -3,15 +3,15 @@
|
||||||
* Copyright (c) 2024, Richard Acayan. All rights reserved.
|
* Copyright (c) 2024, Richard Acayan. All rights reserved.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::convert::TryInto;
|
|
||||||
use std::fs::File;
|
|
||||||
use rgb::alt::BGR;
|
use rgb::alt::BGR;
|
||||||
use rgb::alt::BGRA;
|
use rgb::alt::BGRA;
|
||||||
use rgb::RGB;
|
use rgb::RGB;
|
||||||
|
use std::convert::TryInto;
|
||||||
|
use std::fs::File;
|
||||||
use yaml_rust2::yaml::Hash;
|
use yaml_rust2::yaml::Hash;
|
||||||
use yaml_rust2::yaml::LoadError;
|
use yaml_rust2::yaml::LoadError;
|
||||||
use yaml_rust2::yaml::YamlDecoder;
|
|
||||||
use yaml_rust2::yaml::Yaml;
|
use yaml_rust2::yaml::Yaml;
|
||||||
|
use yaml_rust2::yaml::YamlDecoder;
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct KeyboardColors {
|
pub struct KeyboardColors {
|
||||||
|
|
@ -25,8 +25,7 @@ pub struct KeyboardColors {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for KeyboardColors {
|
impl Default for KeyboardColors {
|
||||||
fn default() -> Self
|
fn default() -> Self {
|
||||||
{
|
|
||||||
Self {
|
Self {
|
||||||
background: RGB::new(0, 0, 0).into(),
|
background: RGB::new(0, 0, 0).into(),
|
||||||
keycap: RGB::new(0, 0, 0).into(),
|
keycap: RGB::new(0, 0, 0).into(),
|
||||||
|
|
@ -39,8 +38,7 @@ impl Default for KeyboardColors {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_color(yaml: &Yaml) -> Option<RGB<u8>>
|
fn parse_color(yaml: &Yaml) -> Option<RGB<u8>> {
|
||||||
{
|
|
||||||
let mut color_bytes = yaml
|
let mut color_bytes = yaml
|
||||||
.as_vec()?
|
.as_vec()?
|
||||||
.iter()
|
.iter()
|
||||||
|
|
@ -50,7 +48,7 @@ fn parse_color(yaml: &Yaml) -> Option<RGB<u8>>
|
||||||
Some(RGB::new(
|
Some(RGB::new(
|
||||||
color_bytes.next()?,
|
color_bytes.next()?,
|
||||||
color_bytes.next()?,
|
color_bytes.next()?,
|
||||||
color_bytes.next()?
|
color_bytes.next()?,
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -71,17 +69,19 @@ pub struct Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Configuration {
|
impl Configuration {
|
||||||
fn get_configuration_file() -> Result<File, Box<dyn std::error::Error>>
|
fn get_configuration_file() -> Result<File, Box<dyn std::error::Error>> {
|
||||||
{
|
let xdg_dirs = xdg::BaseDirectories::with_prefix("unfettered-keyboard")?;
|
||||||
let xdg_dirs = xdg::BaseDirectories::new()?;
|
let config_file = xdg_dirs
|
||||||
let config_file = xdg_dirs.find_config_file("unfettered-keyboard.yaml")
|
.find_config_file("unfettered-keyboard.yaml")
|
||||||
.ok_or(std::io::Error::new(std::io::ErrorKind::NotFound, "Config file not found"))?;
|
.ok_or(std::io::Error::new(
|
||||||
println!("test{:?}",config_file);
|
std::io::ErrorKind::NotFound,
|
||||||
|
"Config file not found",
|
||||||
|
))?;
|
||||||
|
println!("test{:?}", config_file);
|
||||||
Ok(File::open(config_file)?)
|
Ok(File::open(config_file)?)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_evfb(&mut self, yaml: &Hash)
|
fn load_evfb(&mut self, yaml: &Hash) {
|
||||||
{
|
|
||||||
let height = yaml.get(&Yaml::String(String::from("height")));
|
let height = yaml.get(&Yaml::String(String::from("height")));
|
||||||
if let Some(height) = height {
|
if let Some(height) = height {
|
||||||
let height = match height.as_f64() {
|
let height = match height.as_f64() {
|
||||||
|
|
@ -93,8 +93,7 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_wayland(&mut self, yaml: &Hash)
|
fn load_wayland(&mut self, yaml: &Hash) {
|
||||||
{
|
|
||||||
let height = yaml.get(&Yaml::String(String::from("height")));
|
let height = yaml.get(&Yaml::String(String::from("height")));
|
||||||
if let Some(height) = height {
|
if let Some(height) = height {
|
||||||
let height = match height.as_i64() {
|
let height = match height.as_i64() {
|
||||||
|
|
@ -113,8 +112,7 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_colors(&mut self, yaml: &Hash)
|
fn load_colors(&mut self, yaml: &Hash) {
|
||||||
{
|
|
||||||
if let Some(keycap) = yaml.get(&Yaml::String(String::from("keycap"))) {
|
if let Some(keycap) = yaml.get(&Yaml::String(String::from("keycap"))) {
|
||||||
self.colors.keycap = parse_color(keycap)
|
self.colors.keycap = parse_color(keycap)
|
||||||
.expect("Keycap color needs to be a list of 3 8-bit unsigned integers")
|
.expect("Keycap color needs to be a list of 3 8-bit unsigned integers")
|
||||||
|
|
@ -152,26 +150,27 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load() -> Result<Self, LoadError>
|
pub fn load() -> Result<Self, LoadError> {
|
||||||
{
|
|
||||||
let mut cfg = Configuration {
|
let mut cfg = Configuration {
|
||||||
longpress: 600,
|
longpress: 600,
|
||||||
repeat: 25,
|
repeat: 25,
|
||||||
layout: String::from("latn_qwerty_us.xml"),
|
layout: String::from("latn_qwerty_us.xml"),
|
||||||
extra_keys: vec![ String::from("alt"), String::from("meta") ],
|
extra_keys: vec![String::from("alt"), String::from("meta")],
|
||||||
wayland_height: 185,
|
wayland_height: 185,
|
||||||
wayland_im_enable: true,
|
wayland_im_enable: true,
|
||||||
evfb_height: 0.25,
|
evfb_height: 0.25,
|
||||||
|
|
||||||
key_padding: 2,
|
key_padding: 2,
|
||||||
key_corner_radius: 5,
|
key_corner_radius: 5,
|
||||||
|
|
||||||
colors: KeyboardColors::default(),
|
colors: KeyboardColors::default(),
|
||||||
};
|
};
|
||||||
|
|
||||||
if let Ok(file) = Self::get_configuration_file() {
|
if let Ok(file) = Self::get_configuration_file() {
|
||||||
let yaml = YamlDecoder::read(file).decode()?;
|
let yaml = YamlDecoder::read(file).decode()?;
|
||||||
let yaml = yaml[0].as_hash().expect("Top-level configuration should be a YAML mapping");
|
let yaml = yaml[0]
|
||||||
|
.as_hash()
|
||||||
|
.expect("Top-level configuration should be a YAML mapping");
|
||||||
|
|
||||||
let longpress = yaml.get(&Yaml::String(String::from("longpress_ms")));
|
let longpress = yaml.get(&Yaml::String(String::from("longpress_ms")));
|
||||||
if let Some(longpress) = longpress {
|
if let Some(longpress) = longpress {
|
||||||
|
|
@ -179,7 +178,8 @@ impl Configuration {
|
||||||
Some(l) => l.try_into().ok(),
|
Some(l) => l.try_into().ok(),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
let longpress = longpress.expect("Longpress time should be a 64-bit unsigned integer");
|
let longpress =
|
||||||
|
longpress.expect("Longpress time should be a 64-bit unsigned integer");
|
||||||
cfg.longpress = longpress;
|
cfg.longpress = longpress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -202,19 +202,26 @@ impl Configuration {
|
||||||
let keys = yaml.get(&Yaml::String(String::from("extra_keys")));
|
let keys = yaml.get(&Yaml::String(String::from("extra_keys")));
|
||||||
if let Some(keys) = keys {
|
if let Some(keys) = keys {
|
||||||
let keys = keys.as_vec().expect("Extra keys should be a list");
|
let keys = keys.as_vec().expect("Extra keys should be a list");
|
||||||
cfg.extra_keys = keys.iter().map(|y| String::from(y.as_str().unwrap())).collect();
|
cfg.extra_keys = keys
|
||||||
|
.iter()
|
||||||
|
.map(|y| String::from(y.as_str().unwrap()))
|
||||||
|
.collect();
|
||||||
cfg.extra_keys.sort_unstable();
|
cfg.extra_keys.sort_unstable();
|
||||||
}
|
}
|
||||||
|
|
||||||
let wl = yaml.get(&Yaml::String(String::from("wayland")));
|
let wl = yaml.get(&Yaml::String(String::from("wayland")));
|
||||||
if let Some(wl) = wl {
|
if let Some(wl) = wl {
|
||||||
let wl = wl.as_hash().expect("Wayland configuration should be a YAML mapping");
|
let wl = wl
|
||||||
|
.as_hash()
|
||||||
|
.expect("Wayland configuration should be a YAML mapping");
|
||||||
cfg.load_wayland(wl);
|
cfg.load_wayland(wl);
|
||||||
}
|
}
|
||||||
|
|
||||||
let evfb = yaml.get(&Yaml::String(String::from("evfb")));
|
let evfb = yaml.get(&Yaml::String(String::from("evfb")));
|
||||||
if let Some(evfb) = evfb {
|
if let Some(evfb) = evfb {
|
||||||
let evfb = evfb.as_hash().expect("Linux evdev-fbdev configuration should be a YAML mapping");
|
let evfb = evfb
|
||||||
|
.as_hash()
|
||||||
|
.expect("Linux evdev-fbdev configuration should be a YAML mapping");
|
||||||
cfg.load_evfb(evfb);
|
cfg.load_evfb(evfb);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -224,7 +231,8 @@ impl Configuration {
|
||||||
Some(l) => l.try_into().ok(),
|
Some(l) => l.try_into().ok(),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
let key_padding = key_padding.expect("Key padding should be a 64-bit unsigned integer");
|
let key_padding =
|
||||||
|
key_padding.expect("Key padding should be a 64-bit unsigned integer");
|
||||||
cfg.key_padding = key_padding;
|
cfg.key_padding = key_padding;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -234,14 +242,16 @@ impl Configuration {
|
||||||
Some(l) => l.try_into().ok(),
|
Some(l) => l.try_into().ok(),
|
||||||
None => None,
|
None => None,
|
||||||
};
|
};
|
||||||
let key_corner_radius = key_corner_radius.expect("Key corner radius should be a 64-bit unsigned integer");
|
let key_corner_radius = key_corner_radius
|
||||||
|
.expect("Key corner radius should be a 64-bit unsigned integer");
|
||||||
cfg.key_corner_radius = key_corner_radius;
|
cfg.key_corner_radius = key_corner_radius;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
let colors = yaml.get(&Yaml::String(String::from("colors")));
|
let colors = yaml.get(&Yaml::String(String::from("colors")));
|
||||||
if let Some(colors) = colors {
|
if let Some(colors) = colors {
|
||||||
let colors = colors.as_hash().expect("Color configuration should be a YAML mapping");
|
let colors = colors
|
||||||
|
.as_hash()
|
||||||
|
.expect("Color configuration should be a YAML mapping");
|
||||||
cfg.load_colors(colors);
|
cfg.load_colors(colors);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -250,63 +260,52 @@ impl Configuration {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn longpress_ms(&self) -> u64
|
pub fn longpress_ms(&self) -> u64 {
|
||||||
{
|
|
||||||
self.longpress
|
self.longpress
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn repeat_ms(&self) -> u64
|
pub fn repeat_ms(&self) -> u64 {
|
||||||
{
|
|
||||||
self.repeat
|
self.repeat
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn layout(&self) -> &str
|
pub fn layout(&self) -> &str {
|
||||||
{
|
|
||||||
&self.layout
|
&self.layout
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn extra_keys(&self) -> &Vec<String>
|
pub fn extra_keys(&self) -> &Vec<String> {
|
||||||
{
|
|
||||||
&self.extra_keys
|
&self.extra_keys
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn wayland_height(&self) -> i32
|
pub fn wayland_height(&self) -> i32 {
|
||||||
{
|
|
||||||
self.wayland_height
|
self.wayland_height
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn wayland_im_enable(&self) -> bool
|
pub fn wayland_im_enable(&self) -> bool {
|
||||||
{
|
|
||||||
self.wayland_im_enable
|
self.wayland_im_enable
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn evfb_height(&self) -> f64
|
pub fn evfb_height(&self) -> f64 {
|
||||||
{
|
|
||||||
self.evfb_height
|
self.evfb_height
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn colors(&self) -> &KeyboardColors
|
pub fn colors(&self) -> &KeyboardColors {
|
||||||
{
|
|
||||||
&self.colors
|
&self.colors
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn key_padding(&self) -> u64
|
pub fn key_padding(&self) -> u64 {
|
||||||
{
|
|
||||||
self.key_padding
|
self.key_padding
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn key_corner_radius(&self) -> u64
|
pub fn key_corner_radius(&self) -> u64 {
|
||||||
{
|
|
||||||
self.key_corner_radius
|
self.key_corner_radius
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue