config: add fallback output mode
This commit is contained in:
parent
a975e3b25a
commit
dd3f8bad40
16 changed files with 215 additions and 19 deletions
|
|
@ -21,6 +21,7 @@ mod drm_device;
|
|||
mod drm_device_match;
|
||||
mod env;
|
||||
pub mod exec;
|
||||
mod fallback_output_mode;
|
||||
pub mod float;
|
||||
pub mod focus_history;
|
||||
mod format;
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ use {
|
|||
drm_device::DrmDevicesParser,
|
||||
drm_device_match::DrmDeviceMatchParser,
|
||||
env::EnvParser,
|
||||
fallback_output_mode::FallbackOutputModeParser,
|
||||
float::FloatParser,
|
||||
focus_history::FocusHistoryParser,
|
||||
gfx_api::GfxApiParser,
|
||||
|
|
@ -147,6 +148,7 @@ impl Parser for ConfigParser<'_> {
|
|||
auto_reload,
|
||||
simple_im_val,
|
||||
show_titles,
|
||||
fallback_output_mode_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
|
|
@ -204,6 +206,7 @@ impl Parser for ConfigParser<'_> {
|
|||
recover(opt(bol("auto-reload"))),
|
||||
opt(val("simple-im")),
|
||||
recover(opt(bol("show-titles"))),
|
||||
opt(val("fallback-output-mode")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -524,6 +527,18 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut fallback_output_mode = None;
|
||||
if let Some(value) = fallback_output_mode_val {
|
||||
match value.parse(&mut FallbackOutputModeParser) {
|
||||
Ok(v) => fallback_output_mode = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!(
|
||||
"Could not parse the fallback output mode: {}",
|
||||
self.0.error(e)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
|
|
@ -570,6 +585,7 @@ impl Parser for ConfigParser<'_> {
|
|||
input_modes,
|
||||
workspace_display_order,
|
||||
simple_im,
|
||||
fallback_output_mode,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
38
toml-config/src/config/parsers/fallback_output_mode.rs
Normal file
38
toml-config/src/config/parsers/fallback_output_mode.rs
Normal file
|
|
@ -0,0 +1,38 @@
|
|||
use {
|
||||
crate::{
|
||||
config::parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
toml::toml_span::{Span, SpannedExt},
|
||||
},
|
||||
jay_config::input::FallbackOutputMode,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
pub struct FallbackOutputModeParser;
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum FallbackOutputModeParserError {
|
||||
#[error(transparent)]
|
||||
DataType(#[from] UnexpectedDataType),
|
||||
#[error("Unknown mode {0}")]
|
||||
Unknown(String),
|
||||
}
|
||||
|
||||
impl Parser for FallbackOutputModeParser {
|
||||
type Value = FallbackOutputMode;
|
||||
type Error = FallbackOutputModeParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::String];
|
||||
|
||||
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
|
||||
use FallbackOutputMode::*;
|
||||
let api = match string.to_ascii_lowercase().as_str() {
|
||||
"cursor" => Cursor,
|
||||
"focus" => Focus,
|
||||
_ => {
|
||||
return Err(
|
||||
FallbackOutputModeParserError::Unknown(string.to_string()).spanned(span)
|
||||
);
|
||||
}
|
||||
};
|
||||
Ok(api)
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue