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

@ -23,6 +23,7 @@ use {
status::MessageFormat,
theme::Color,
video::{Format, GfxApi, TearingMode, Transform, VrrMode},
xwayland::XScalingMode,
Axis, Direction, Workspace,
},
std::{
@ -302,6 +303,11 @@ pub struct Vrr {
pub cursor_hz: Option<f64>,
}
#[derive(Debug, Clone)]
pub struct Xwayland {
pub scaling_mode: Option<XScalingMode>,
}
#[derive(Debug, Clone)]
pub struct Tearing {
pub mode: Option<TearingMode>,
@ -349,6 +355,7 @@ pub struct Config {
pub tearing: Option<Tearing>,
pub libei: Libei,
pub ui_drag: UiDrag,
pub xwayland: Option<Xwayland>,
}
#[derive(Debug, Error)]

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)
}
}

View file

@ -34,6 +34,7 @@ use {
set_direct_scanout_enabled, set_gfx_api, set_tearing_mode, set_vrr_cursor_hz,
set_vrr_mode, Connector, DrmDevice,
},
xwayland::set_x_scaling_mode,
},
std::{cell::RefCell, io::ErrorKind, path::PathBuf, rc::Rc, time::Duration},
};
@ -1061,6 +1062,11 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
if let Some(threshold) = config.ui_drag.threshold {
set_ui_drag_threshold(threshold);
}
if let Some(xwayland) = config.xwayland {
if let Some(mode) = xwayland.scaling_mode {
set_x_scaling_mode(mode);
}
}
}
fn create_command(exec: &Exec) -> Command {