1
0
Fork 0
forked from wry/wry

tree: add window-management mode

This commit is contained in:
Julian Orth 2024-05-26 02:24:52 +02:00
parent 1a73bbd075
commit 70a8f47288
20 changed files with 644 additions and 9 deletions

View file

@ -111,6 +111,8 @@ impl ActionParser<'_> {
"none" => None,
"forward" => Forward(true),
"consume" => Forward(false),
"enable-window-management" => EnableWindowManagement(true),
"disable-window-management" => EnableWindowManagement(false),
_ => {
return Err(ActionParserError::UnknownSimpleAction(string.to_string()).spanned(span))
}

View file

@ -2,7 +2,7 @@ use {
crate::{
config::{
context::Context,
extractor::{arr, bol, opt, recover, val, Extractor, ExtractorError},
extractor::{arr, bol, opt, recover, str, val, Extractor, ExtractorError},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::{
action::ActionParser,
@ -17,7 +17,10 @@ use {
log_level::LogLevelParser,
output::OutputsParser,
repeat_rate::RepeatRateParser,
shortcuts::{ComplexShortcutsParser, ShortcutsParser, ShortcutsParserError},
shortcuts::{
parse_modified_keysym_str, ComplexShortcutsParser, ShortcutsParser,
ShortcutsParserError,
},
status::StatusParser,
theme::ThemeParser,
},
@ -97,7 +100,13 @@ impl Parser for ConfigParser<'_> {
_,
idle_val,
),
(explicit_sync, repeat_rate_val, complex_shortcuts_val, focus_follows_mouse),
(
explicit_sync,
repeat_rate_val,
complex_shortcuts_val,
focus_follows_mouse,
window_management_key_val,
),
) = ext.extract((
(
opt(val("keymap")),
@ -128,6 +137,7 @@ impl Parser for ConfigParser<'_> {
opt(val("repeat-rate")),
opt(val("complex-shortcuts")),
recover(opt(bol("focus-follows-mouse"))),
recover(opt(str("window-management-key"))),
),
))?;
let mut keymap = None;
@ -286,6 +296,12 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut window_management_key = None;
if let Some(value) = window_management_key_val {
if let Some(key) = parse_modified_keysym_str(self.0, value.span, value.value) {
window_management_key = Some(key);
}
}
Ok(Config {
keymap,
repeat_rate,
@ -309,6 +325,7 @@ impl Parser for ConfigParser<'_> {
inputs,
idle,
focus_follows_mouse: focus_follows_mouse.despan().unwrap_or(true),
window_management_key,
})
}
}

View file

@ -175,10 +175,18 @@ fn parse_action(cx: &Context<'_>, key: &str, value: &Spanned<Value>) -> Option<A
}
fn parse_modified_keysym(cx: &Context<'_>, key: &Spanned<String>) -> Option<ModifiedKeySym> {
match ModifiedKeysymParser.parse_string(key.span, &key.value) {
parse_modified_keysym_str(cx, key.span, &key.value)
}
pub fn parse_modified_keysym_str(
cx: &Context<'_>,
span: Span,
value: &str,
) -> Option<ModifiedKeySym> {
match ModifiedKeysymParser.parse_string(span, value) {
Ok(k) => Some(k),
Err(e) => {
log::warn!("Could not parse keysym {}: {}", key.value, cx.error(e));
log::warn!("Could not parse keysym {}: {}", value, cx.error(e));
None
}
}