1
0
Fork 0
forked from wry/wry

config: add initial-tile-state window rule

This commit is contained in:
Julian Orth 2025-05-07 15:59:42 +02:00
parent b1ca98b488
commit 5e3465d861
16 changed files with 258 additions and 26 deletions

View file

@ -28,7 +28,7 @@ use {
status::MessageFormat,
theme::Color,
video::{ColorSpace, Format, GfxApi, TearingMode, TransferFunction, Transform, VrrMode},
window::WindowType,
window::{TileState, WindowType},
xwayland::XScalingMode,
},
std::{
@ -249,6 +249,7 @@ pub struct WindowRule {
pub action: Option<Action>,
pub latch: Option<Action>,
pub auto_focus: Option<bool>,
pub initial_tile_state: Option<TileState>,
}
#[derive(Default, Debug, Clone)]

View file

@ -37,6 +37,7 @@ pub mod shortcuts;
mod status;
mod tearing;
mod theme;
mod tile_state;
mod ui_drag;
mod vrr;
mod window_match;

View file

@ -0,0 +1,35 @@
use {
crate::{
config::parser::{DataType, ParseResult, Parser, UnexpectedDataType},
toml::toml_span::{Span, SpannedExt},
},
jay_config::window::TileState,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum TileStateParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error("Unknown tile state `{}`", .0)]
UnknownTileState(String),
}
pub struct TileStateParser;
impl Parser for TileStateParser {
type Value = TileState;
type Error = TileStateParserError;
const EXPECTED: &'static [DataType] = &[DataType::String];
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
let ty = match string {
"tiled" => TileState::Tiled,
"floating" => TileState::Floating,
_ => {
return Err(TileStateParserError::UnknownTileState(string.to_owned()).spanned(span));
}
};
Ok(ty)
}
}

View file

@ -7,6 +7,7 @@ use {
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::{
action::{ActionParser, ActionParserError},
tile_state::TileStateParser,
window_match::{WindowMatchParser, WindowMatchParserError},
},
spanned::SpannedErrorExt,
@ -47,13 +48,15 @@ impl Parser for WindowRuleParser<'_> {
table: &IndexMap<Spanned<String>, Spanned<Value>>,
) -> ParseResult<Self> {
let mut ext = Extractor::new(self.0, span, table);
let (name, match_val, action_val, latch_val, auto_focus) = ext.extract((
opt(str("name")),
opt(val("match")),
opt(val("action")),
opt(val("latch")),
recover(opt(bol("auto-focus"))),
))?;
let (name, match_val, action_val, latch_val, auto_focus, initial_tile_state_val) = ext
.extract((
opt(str("name")),
opt(val("match")),
opt(val("action")),
opt(val("latch")),
recover(opt(bol("auto-focus"))),
opt(val("initial-tile-state")),
))?;
let mut action = None;
if let Some(value) = action_val {
action = Some(
@ -70,6 +73,18 @@ impl Parser for WindowRuleParser<'_> {
.map_spanned_err(WindowRuleParserError::Latch)?,
);
}
let mut initial_tile_state = None;
if let Some(value) = initial_tile_state_val {
match value.parse(&mut TileStateParser) {
Ok(v) => initial_tile_state = Some(v),
Err(e) => {
log::warn!(
"Could not parse the initial tile state: {}",
self.0.error(e)
);
}
}
}
let match_ = match match_val {
None => WindowMatch::default(),
Some(m) => m.parse_map(&mut WindowMatchParser(self.0))?,
@ -80,6 +95,7 @@ impl Parser for WindowRuleParser<'_> {
action,
latch,
auto_focus: auto_focus.despan(),
initial_tile_state,
})
}
}

View file

@ -336,6 +336,9 @@ impl Rule for WindowRule {
if let Some(auto_focus) = self.auto_focus {
matcher.set_auto_focus(auto_focus);
}
if let Some(tile_state) = self.initial_tile_state {
matcher.set_initial_tile_state(tile_state);
}
}
fn gen_matcher(m: Self::Matcher) -> Self::Criterion<'static> {