1
0
Fork 0
forked from wry/wry

config: make ui dragging configurable

This commit is contained in:
Julian Orth 2024-10-01 11:18:25 +02:00
parent 1dd20fb87b
commit d8ee1ac19c
19 changed files with 255 additions and 12 deletions

View file

@ -154,6 +154,12 @@ pub struct Status {
pub separator: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct UiDrag {
pub enabled: Option<bool>,
pub threshold: Option<i32>,
}
#[derive(Debug, Clone)]
pub enum OutputMatch {
Any(Vec<OutputMatch>),
@ -342,6 +348,7 @@ pub struct Config {
pub vrr: Option<Vrr>,
pub tearing: Option<Tearing>,
pub libei: Libei,
pub ui_drag: UiDrag,
}
#[derive(Debug, Error)]

View file

@ -32,6 +32,7 @@ pub mod shortcuts;
mod status;
mod tearing;
mod theme;
mod ui_drag;
mod vrr;
#[derive(Debug, Error)]

View file

@ -25,10 +25,11 @@ use {
status::StatusParser,
tearing::TearingParser,
theme::ThemeParser,
ui_drag::UiDragParser,
vrr::VrrParser,
},
spanned::SpannedErrorExt,
Action, Config, Libei, Theme,
Action, Config, Libei, Theme, UiDrag,
},
toml::{
toml_span::{DespanExt, Span, Spanned},
@ -112,6 +113,7 @@ impl Parser for ConfigParser<'_> {
vrr_val,
tearing_val,
libei_val,
ui_drag_val,
),
) = ext.extract((
(
@ -147,6 +149,7 @@ impl Parser for ConfigParser<'_> {
opt(val("vrr")),
opt(val("tearing")),
opt(val("libei")),
opt(val("ui-drag")),
),
))?;
let mut keymap = None;
@ -338,6 +341,15 @@ impl Parser for ConfigParser<'_> {
}
}
}
let mut ui_drag = UiDrag::default();
if let Some(value) = ui_drag_val {
match value.parse(&mut UiDragParser(self.0)) {
Ok(v) => ui_drag = v,
Err(e) => {
log::warn!("Could not parse ui-drag setting: {}", self.0.error(e));
}
}
}
Ok(Config {
keymap,
repeat_rate,
@ -365,6 +377,7 @@ impl Parser for ConfigParser<'_> {
vrr,
tearing,
libei,
ui_drag,
})
}
}

View file

@ -0,0 +1,49 @@
use {
crate::{
config::{
context::Context,
extractor::{bol, int, opt, recover, Extractor, ExtractorError},
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
parsers::exec::ExecParserError,
UiDrag,
},
toml::{
toml_span::{DespanExt, Span, Spanned},
toml_value::Value,
},
},
indexmap::IndexMap,
thiserror::Error,
};
#[derive(Debug, Error)]
pub enum UiDragParserError {
#[error(transparent)]
Expected(#[from] UnexpectedDataType),
#[error(transparent)]
Exec(#[from] ExecParserError),
#[error(transparent)]
Extract(#[from] ExtractorError),
}
pub struct UiDragParser<'a>(pub &'a Context<'a>);
impl Parser for UiDragParser<'_> {
type Value = UiDrag;
type Error = UiDragParserError;
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 (enabled, threshold) =
ext.extract((recover(opt(bol("enabled"))), recover(opt(int("threshold")))))?;
Ok(UiDrag {
enabled: enabled.despan(),
threshold: threshold.despan().map(|v| v as i32),
})
}
}

View file

@ -24,7 +24,7 @@ use {
keyboard::{Keymap, ModifiedKeySym},
logging::set_log_level,
on_devices_enumerated, on_idle, quit, reload, set_default_workspace_capture,
set_explicit_sync_enabled, set_idle,
set_explicit_sync_enabled, set_idle, set_ui_drag_enabled, set_ui_drag_threshold,
status::{set_i3bar_separator, set_status, set_status_command, unset_status_command},
switch_to_vt,
theme::{reset_colors, reset_font, reset_sizes, set_font},
@ -1055,6 +1055,12 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
}
}
set_libei_socket_enabled(config.libei.enable_socket.unwrap_or(false));
if let Some(enabled) = config.ui_drag.enabled {
set_ui_drag_enabled(enabled);
}
if let Some(threshold) = config.ui_drag.threshold {
set_ui_drag_threshold(threshold);
}
}
fn create_command(exec: &Exec) -> Command {