1
0
Fork 0
forked from wry/wry

xwayland: allow windows to scale themselves

This commit is contained in:
Julian Orth 2024-10-08 11:14:13 +02:00
parent cc8db84289
commit 19b07fa7dc
40 changed files with 800 additions and 80 deletions

View file

@ -34,6 +34,7 @@ mod tearing;
mod theme;
mod ui_drag;
mod vrr;
mod xwayland;
#[derive(Debug, Error)]
pub enum StringParserError {

View file

@ -27,6 +27,7 @@ use {
theme::ThemeParser,
ui_drag::UiDragParser,
vrr::VrrParser,
xwayland::XwaylandParser,
},
spanned::SpannedErrorExt,
Action, Config, Libei, Theme, UiDrag,
@ -114,6 +115,7 @@ impl Parser for ConfigParser<'_> {
tearing_val,
libei_val,
ui_drag_val,
xwayland_val,
),
) = ext.extract((
(
@ -150,6 +152,7 @@ impl Parser for ConfigParser<'_> {
opt(val("tearing")),
opt(val("libei")),
opt(val("ui-drag")),
opt(val("xwayland")),
),
))?;
let mut keymap = None;
@ -350,6 +353,15 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut xwayland = None;
if let Some(value) = xwayland_val {
match value.parse(&mut XwaylandParser(self.0)) {
Ok(v) => xwayland = Some(v),
Err(e) => {
log::warn!("Could not parse Xwayland setting: {}", self.0.error(e));
}
}
}
Ok(Config {
keymap,
repeat_rate,
@ -378,6 +390,7 @@ impl Parser for ConfigParser<'_> {
tearing,
libei,
ui_drag,
xwayland,
})
}
}

View file

@ -0,0 +1,75 @@
use {
crate::{
config::{
context::Context,
extractor::{opt, val, Extractor, ExtractorError},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
Xwayland,
},
toml::{
toml_span::{Span, Spanned, SpannedExt},
toml_value::Value,
},
},
indexmap::IndexMap,
jay_config::xwayland::XScalingMode,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum XwaylandParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct XwaylandParser<'a>(pub &'a Context<'a>);
impl Parser for XwaylandParser<'_> {
type Value = Xwayland;
type Error = XwaylandParserError;
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 scaling_mode = ext.extract(opt(val("scaling-mode")))?;
let scaling_mode = scaling_mode.and_then(|m| match m.parse(&mut XScalingModeParser) {
Ok(m) => Some(m),
Err(e) => {
log::error!("Could not parse scaling mode: {}", self.0.error(e));
None
}
});
Ok(Xwayland { scaling_mode })
}
}
#[derive(Debug, Error)]
pub enum XScalingModeParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error("Unknown mode {0}")]
UnknownMode(String),
}
struct XScalingModeParser;
impl Parser for XScalingModeParser {
type Value = XScalingMode;
type Error = XScalingModeParserError;
const EXPECTED: &'static [DataType] = &[DataType::String];
fn parse_string(&mut self, span: Span, string: &str) -> ParseResult<Self> {
let mode = match string {
"default" => XScalingMode::DEFAULT,
"downscaled" => XScalingMode::DOWNSCALED,
_ => return Err(XScalingModeParserError::UnknownMode(string.to_string()).spanned(span)),
};
Ok(mode)
}
}