seat: implement per-device keymaps
This commit is contained in:
parent
225995eb2f
commit
826f40adca
21 changed files with 293 additions and 71 deletions
|
|
@ -241,6 +241,7 @@ pub struct Input {
|
|||
pub natural_scrolling: Option<bool>,
|
||||
pub px_per_wheel_scroll: Option<f64>,
|
||||
pub transform_matrix: Option<[[f64; 2]; 2]>,
|
||||
pub keymap: Option<ConfigKeymap>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,10 @@ use {
|
|||
context::Context,
|
||||
extractor::{bol, fltorint, opt, recover, str, val, Extractor, ExtractorError},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
parsers::input_match::{InputMatchParser, InputMatchParserError},
|
||||
parsers::{
|
||||
input_match::{InputMatchParser, InputMatchParserError},
|
||||
keymap::KeymapParser,
|
||||
},
|
||||
Input,
|
||||
},
|
||||
toml::{
|
||||
|
|
@ -62,7 +65,7 @@ impl<'a> Parser for InputParser<'a> {
|
|||
natural_scrolling,
|
||||
px_per_wheel_scroll,
|
||||
),
|
||||
(transform_matrix,),
|
||||
(transform_matrix, keymap),
|
||||
) = ext.extract((
|
||||
(
|
||||
opt(str("tag")),
|
||||
|
|
@ -76,7 +79,7 @@ impl<'a> Parser for InputParser<'a> {
|
|||
recover(opt(bol("natural-scrolling"))),
|
||||
recover(opt(fltorint("px-per-wheel-scroll"))),
|
||||
),
|
||||
(recover(opt(val("transform-matrix"))),),
|
||||
(recover(opt(val("transform-matrix"))), opt(val("keymap"))),
|
||||
))?;
|
||||
let accel_profile = match accel_profile {
|
||||
None => None,
|
||||
|
|
@ -109,6 +112,19 @@ impl<'a> Parser for InputParser<'a> {
|
|||
);
|
||||
}
|
||||
}
|
||||
let keymap = match keymap {
|
||||
None => None,
|
||||
Some(map) => match map.parse(&mut KeymapParser {
|
||||
cx: self.cx,
|
||||
definition: false,
|
||||
}) {
|
||||
Ok(v) => Some(v),
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse keymap: {}", self.cx.error(e));
|
||||
None
|
||||
}
|
||||
},
|
||||
};
|
||||
Ok(Input {
|
||||
tag: tag.despan_into(),
|
||||
match_: match_val.parse_map(&mut InputMatchParser(self.cx))?,
|
||||
|
|
@ -121,6 +137,7 @@ impl<'a> Parser for InputParser<'a> {
|
|||
natural_scrolling: natural_scrolling.despan(),
|
||||
px_per_wheel_scroll: px_per_wheel_scroll.despan(),
|
||||
transform_matrix,
|
||||
keymap,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -92,7 +92,7 @@ impl Action {
|
|||
Box::new(move || {
|
||||
for c in input_devices() {
|
||||
if input.match_.matches(c, &state) {
|
||||
input.apply(c);
|
||||
input.apply(c, &state);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
@ -361,7 +361,7 @@ impl InputMatch {
|
|||
}
|
||||
|
||||
impl Input {
|
||||
fn apply(&self, c: InputDevice) {
|
||||
fn apply(&self, c: InputDevice, state: &State) {
|
||||
if let Some(v) = self.accel_profile {
|
||||
c.set_accel_profile(v);
|
||||
}
|
||||
|
|
@ -389,6 +389,11 @@ impl Input {
|
|||
if let Some(v) = self.transform_matrix {
|
||||
c.set_transform_matrix(v);
|
||||
}
|
||||
if let Some(v) = &self.keymap {
|
||||
if let Some(km) = state.get_keymap(v) {
|
||||
c.set_keymap(km);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -554,19 +559,25 @@ impl State {
|
|||
}
|
||||
}
|
||||
|
||||
fn set_keymap(&self, map: &ConfigKeymap) {
|
||||
fn get_keymap(&self, map: &ConfigKeymap) -> Option<Keymap> {
|
||||
let map = match map {
|
||||
ConfigKeymap::Named(n) => match self.keymaps.get(n) {
|
||||
None => {
|
||||
log::warn!("Unknown keymap {n}");
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
Some(m) => *m,
|
||||
},
|
||||
ConfigKeymap::Defined { map, .. } => *map,
|
||||
ConfigKeymap::Literal(map) => *map,
|
||||
};
|
||||
self.persistent.seat.set_keymap(map);
|
||||
Some(map)
|
||||
}
|
||||
|
||||
fn set_keymap(&self, map: &ConfigKeymap) {
|
||||
if let Some(map) = self.get_keymap(map) {
|
||||
self.persistent.seat.set_keymap(map);
|
||||
}
|
||||
}
|
||||
|
||||
fn set_status(&self, status: &Option<Status>) {
|
||||
|
|
@ -816,7 +827,7 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
|
|||
move |c| {
|
||||
for input in &config.inputs {
|
||||
if input.match_.matches(c, &state) {
|
||||
input.apply(c);
|
||||
input.apply(c, &state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue