config: allow configuring the simple IM
This commit is contained in:
parent
58b9830aaa
commit
2f22a61710
15 changed files with 367 additions and 7 deletions
|
|
@ -85,6 +85,9 @@ pub enum SimpleCommand {
|
|||
CreateMark,
|
||||
JumpToMark,
|
||||
PopMode(bool),
|
||||
EnableSimpleIm(bool),
|
||||
ToggleSimpleImEnabled,
|
||||
ReloadSimpleIm,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
@ -446,6 +449,11 @@ pub struct Vrr {
|
|||
pub cursor_hz: Option<f64>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct SimpleIm {
|
||||
pub enabled: Option<bool>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct Xwayland {
|
||||
pub scaling_mode: Option<XScalingMode>,
|
||||
|
|
@ -520,6 +528,7 @@ pub struct Config {
|
|||
pub middle_click_paste: Option<bool>,
|
||||
pub input_modes: AHashMap<String, InputMode>,
|
||||
pub workspace_display_order: Option<WorkspaceDisplayOrder>,
|
||||
pub simple_im: Option<SimpleIm>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@ mod output;
|
|||
mod output_match;
|
||||
mod repeat_rate;
|
||||
pub mod shortcuts;
|
||||
mod simple_im;
|
||||
mod status;
|
||||
mod tearing;
|
||||
mod theme;
|
||||
|
|
|
|||
|
|
@ -155,6 +155,10 @@ impl ActionParser<'_> {
|
|||
"jump-to-mark" => JumpToMark,
|
||||
"clear-modes" => PopMode(false),
|
||||
"pop-mode" => PopMode(true),
|
||||
"enable-simple-im" => EnableSimpleIm(true),
|
||||
"disable-simple-im" => EnableSimpleIm(false),
|
||||
"toggle-simple-im-enabled" => ToggleSimpleImEnabled,
|
||||
"reload-simple-im" => ReloadSimpleIm,
|
||||
_ => {
|
||||
return Err(
|
||||
ActionParserError::UnknownSimpleAction(string.to_string()).spanned(span)
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ use {
|
|||
ComplexShortcutsParser, ShortcutsParser, ShortcutsParserError,
|
||||
parse_modified_keysym_str,
|
||||
},
|
||||
simple_im::SimpleImParser,
|
||||
status::StatusParser,
|
||||
tearing::TearingParser,
|
||||
theme::ThemeParser,
|
||||
|
|
@ -139,7 +140,13 @@ impl Parser for ConfigParser<'_> {
|
|||
show_bar,
|
||||
focus_history_val,
|
||||
),
|
||||
(middle_click_paste, input_modes_val, workspace_display_order_val, auto_reload),
|
||||
(
|
||||
middle_click_paste,
|
||||
input_modes_val,
|
||||
workspace_display_order_val,
|
||||
auto_reload,
|
||||
simple_im_val,
|
||||
),
|
||||
) = ext.extract((
|
||||
(
|
||||
opt(val("keymap")),
|
||||
|
|
@ -194,6 +201,7 @@ impl Parser for ConfigParser<'_> {
|
|||
opt(val("modes")),
|
||||
opt(val("workspace-display-order")),
|
||||
recover(opt(bol("auto-reload"))),
|
||||
opt(val("simple-im")),
|
||||
),
|
||||
))?;
|
||||
let mut keymap = None;
|
||||
|
|
@ -505,6 +513,15 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
}
|
||||
let mut simple_im = None;
|
||||
if let Some(value) = simple_im_val {
|
||||
match value.parse(&mut SimpleImParser(self.0)) {
|
||||
Ok(v) => simple_im = Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse simple IM setting: {}", self.0.error(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
Ok(Config {
|
||||
keymap,
|
||||
repeat_rate,
|
||||
|
|
@ -549,6 +566,7 @@ impl Parser for ConfigParser<'_> {
|
|||
middle_click_paste: middle_click_paste.despan(),
|
||||
input_modes,
|
||||
workspace_display_order,
|
||||
simple_im,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
44
toml-config/src/config/parsers/simple_im.rs
Normal file
44
toml-config/src/config/parsers/simple_im.rs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
use {
|
||||
crate::{
|
||||
config::{
|
||||
SimpleIm,
|
||||
context::Context,
|
||||
extractor::{Extractor, ExtractorError, bol, opt, recover},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
},
|
||||
toml::{
|
||||
toml_span::{DespanExt, Span, Spanned},
|
||||
toml_value::Value,
|
||||
},
|
||||
},
|
||||
indexmap::IndexMap,
|
||||
thiserror::Error,
|
||||
};
|
||||
|
||||
#[derive(Debug, Error)]
|
||||
pub enum SimpleImParserError {
|
||||
#[error(transparent)]
|
||||
Expected(#[from] UnexpectedDataType),
|
||||
#[error(transparent)]
|
||||
Extract(#[from] ExtractorError),
|
||||
}
|
||||
|
||||
pub struct SimpleImParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for SimpleImParser<'_> {
|
||||
type Value = SimpleIm;
|
||||
type Error = SimpleImParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Table];
|
||||
|
||||
fn parse_table(
|
||||
&mut self,
|
||||
span: Span,
|
||||
table: &IndexMap<Spanned<String>, Spanned<Value>>,
|
||||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let (enabled,) = ext.extract((recover(opt(bol("enabled"))),))?;
|
||||
Ok(SimpleIm {
|
||||
enabled: enabled.despan(),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
@ -224,6 +224,18 @@ impl Action {
|
|||
let state = state.clone();
|
||||
b.new(move || state.pop_mode(pop))
|
||||
}
|
||||
SimpleCommand::EnableSimpleIm(v) => {
|
||||
let persistent = state.persistent.clone();
|
||||
b.new(move || persistent.seat.set_simple_im_enabled(v))
|
||||
}
|
||||
SimpleCommand::ToggleSimpleImEnabled => {
|
||||
let persistent = state.persistent.clone();
|
||||
b.new(move || persistent.seat.toggle_simple_im_enabled())
|
||||
}
|
||||
SimpleCommand::ReloadSimpleIm => {
|
||||
let persistent = state.persistent.clone();
|
||||
b.new(move || persistent.seat.reload_simple_im())
|
||||
}
|
||||
},
|
||||
Action::Multi { actions } => {
|
||||
let actions: Vec<_> = actions.into_iter().map(|a| a.into_fn(state)).collect();
|
||||
|
|
@ -1559,6 +1571,11 @@ fn load_config(initial_load: bool, auto_reload: bool, persistent: &Rc<Persistent
|
|||
if let Some(v) = config.workspace_display_order {
|
||||
set_workspace_display_order(v);
|
||||
}
|
||||
if let Some(simple_im) = config.simple_im {
|
||||
if let Some(enabled) = simple_im.enabled {
|
||||
persistent.seat.set_simple_im_enabled(enabled);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn create_command(exec: &Exec) -> Command {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue