added config file and deserialization
This commit is contained in:
parent
d3b4fcbf18
commit
3a56102ec2
|
@ -16,3 +16,5 @@ indexmap = "1.6.2"
|
||||||
thiserror = "1.0.30"
|
thiserror = "1.0.30"
|
||||||
bitflags = "1.3.2"
|
bitflags = "1.3.2"
|
||||||
derivative = "2.2.0"
|
derivative = "2.2.0"
|
||||||
|
serde = { version = "1.0", features = ["derive"] }
|
||||||
|
toml = "0.5"
|
4
nowm.toml
Normal file
4
nowm.toml
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
num_virtualscreens = 10
|
||||||
|
mod_key = "Super"
|
||||||
|
gap = 5
|
||||||
|
kill_clients_on_exit = false
|
|
@ -24,7 +24,9 @@ pub enum KeyState {
|
||||||
Released,
|
Released,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy)]
|
#[derive(
|
||||||
|
Debug, PartialEq, Eq, PartialOrd, Ord, Hash, Clone, Copy, serde::Deserialize,
|
||||||
|
)]
|
||||||
#[repr(u8)]
|
#[repr(u8)]
|
||||||
pub enum ModifierKey {
|
pub enum ModifierKey {
|
||||||
Shift,
|
Shift,
|
||||||
|
|
21
src/main.rs
21
src/main.rs
|
@ -1,5 +1,7 @@
|
||||||
#![allow(dead_code, unused_variables)]
|
#![allow(dead_code, unused_variables)]
|
||||||
|
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
use log::{debug, error, info, trace, warn};
|
use log::{debug, error, info, trace, warn};
|
||||||
use log4rs::{
|
use log4rs::{
|
||||||
append::{console::ConsoleAppender, file::FileAppender},
|
append::{console::ConsoleAppender, file::FileAppender},
|
||||||
|
@ -67,8 +69,23 @@ fn main() {
|
||||||
|
|
||||||
log_prologue();
|
log_prologue();
|
||||||
|
|
||||||
state::WindowManager::<backends::xlib::XLib>::new(WMConfig::default())
|
let mut config_path = std::path::PathBuf::from(env!("HOME"));
|
||||||
.run();
|
config_path.push(".config/nowm.toml");
|
||||||
|
|
||||||
|
let config = std::fs::File::open(config_path)
|
||||||
|
.and_then(|mut file| {
|
||||||
|
let mut content = String::new();
|
||||||
|
file.read_to_string(&mut content)?;
|
||||||
|
Ok(content)
|
||||||
|
})
|
||||||
|
.and_then(|content| Ok(toml::from_str::<WMConfig>(&content)?))
|
||||||
|
.unwrap_or_else(|e| {
|
||||||
|
warn!("error parsing config file: {}", e);
|
||||||
|
info!("falling back to default config.");
|
||||||
|
WMConfig::default()
|
||||||
|
});
|
||||||
|
|
||||||
|
state::WindowManager::<backends::xlib::XLib>::new(config).run();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn log_prologue() {
|
fn log_prologue() {
|
||||||
|
|
|
@ -22,10 +22,13 @@ use crate::{
|
||||||
clients::{Client, ClientEntry, ClientKey, ClientState},
|
clients::{Client, ClientEntry, ClientKey, ClientState},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
use serde::Deserialize;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Contains static config data for the window manager, the sort of stuff you might want to
|
Contains static config data for the window manager, the sort of stuff you might want to
|
||||||
be able to configure in a config file.
|
be able to configure in a config file.
|
||||||
*/
|
*/
|
||||||
|
#[derive(Debug, Deserialize)]
|
||||||
pub struct WMConfig {
|
pub struct WMConfig {
|
||||||
num_virtualscreens: usize,
|
num_virtualscreens: usize,
|
||||||
mod_key: ModifierKey,
|
mod_key: ModifierKey,
|
||||||
|
|
Loading…
Reference in a new issue