idle: add a grace period
This commit is contained in:
parent
1ad3d11616
commit
e8be15a26c
29 changed files with 405 additions and 79 deletions
|
|
@ -67,7 +67,8 @@ pub enum Action {
|
|||
dev: ConfigDrmDevice,
|
||||
},
|
||||
ConfigureIdle {
|
||||
idle: Duration,
|
||||
idle: Option<Duration>,
|
||||
grace_period: Option<Duration>,
|
||||
},
|
||||
ConfigureInput {
|
||||
input: Box<Input>,
|
||||
|
|
@ -348,6 +349,7 @@ pub struct Config {
|
|||
pub render_device: Option<DrmDeviceMatch>,
|
||||
pub inputs: Vec<Input>,
|
||||
pub idle: Option<Duration>,
|
||||
pub grace_period: Option<Duration>,
|
||||
pub explicit_sync_enabled: Option<bool>,
|
||||
pub focus_follows_mouse: bool,
|
||||
pub window_management_key: Option<ModifiedKeySym>,
|
||||
|
|
|
|||
|
|
@ -177,7 +177,10 @@ impl ActionParser<'_> {
|
|||
.extract(val("idle"))?
|
||||
.parse_map(&mut IdleParser(self.0))
|
||||
.map_spanned_err(ActionParserError::ConfigureIdle)?;
|
||||
Ok(Action::ConfigureIdle { idle })
|
||||
Ok(Action::ConfigureIdle {
|
||||
idle: idle.timeout,
|
||||
grace_period: idle.grace_period,
|
||||
})
|
||||
}
|
||||
|
||||
fn parse_configure_output(&mut self, ext: &mut Extractor<'_>) -> ParseResult<Self> {
|
||||
|
|
|
|||
|
|
@ -294,9 +294,13 @@ impl Parser for ConfigParser<'_> {
|
|||
}
|
||||
}
|
||||
let mut idle = None;
|
||||
let mut grace_period = None;
|
||||
if let Some(value) = idle_val {
|
||||
match value.parse(&mut IdleParser(self.0)) {
|
||||
Ok(v) => idle = Some(v),
|
||||
Ok(v) => {
|
||||
idle = v.timeout;
|
||||
grace_period = v.grace_period;
|
||||
}
|
||||
Err(e) => {
|
||||
log::warn!("Could not parse the idle timeout: {}", self.0.error(e));
|
||||
}
|
||||
|
|
@ -384,6 +388,7 @@ impl Parser for ConfigParser<'_> {
|
|||
render_device,
|
||||
inputs,
|
||||
idle,
|
||||
grace_period,
|
||||
focus_follows_mouse: focus_follows_mouse.despan().unwrap_or(true),
|
||||
window_management_key,
|
||||
vrr,
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use {
|
|||
crate::{
|
||||
config::{
|
||||
context::Context,
|
||||
extractor::{n64, opt, Extractor, ExtractorError},
|
||||
extractor::{n64, opt, val, Extractor, ExtractorError},
|
||||
parser::{DataType, ParseResult, Parser, UnexpectedDataType},
|
||||
},
|
||||
toml::{
|
||||
|
|
@ -25,7 +25,45 @@ pub enum IdleParserError {
|
|||
|
||||
pub struct IdleParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
pub struct Idle {
|
||||
pub timeout: Option<Duration>,
|
||||
pub grace_period: Option<Duration>,
|
||||
}
|
||||
|
||||
impl Parser for IdleParser<'_> {
|
||||
type Value = Idle;
|
||||
type Error = IdleParserError;
|
||||
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 (minutes, seconds, grace_period_val) = ext.extract((
|
||||
opt(n64("minutes")),
|
||||
opt(n64("seconds")),
|
||||
opt(val("grace-period")),
|
||||
))?;
|
||||
let mut timeout = None;
|
||||
if minutes.is_some() || seconds.is_some() {
|
||||
timeout = Some(parse_duration(&minutes, &seconds));
|
||||
}
|
||||
let mut grace_period = None;
|
||||
if let Some(gp) = grace_period_val {
|
||||
grace_period = Some(gp.parse(&mut GracePeriodParser(self.0))?);
|
||||
}
|
||||
Ok(Idle {
|
||||
timeout,
|
||||
grace_period,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
struct GracePeriodParser<'a>(pub &'a Context<'a>);
|
||||
|
||||
impl Parser for GracePeriodParser<'_> {
|
||||
type Value = Duration;
|
||||
type Error = IdleParserError;
|
||||
const EXPECTED: &'static [DataType] = &[DataType::Table];
|
||||
|
|
@ -37,9 +75,13 @@ impl Parser for IdleParser<'_> {
|
|||
) -> ParseResult<Self> {
|
||||
let mut ext = Extractor::new(self.0, span, table);
|
||||
let (minutes, seconds) = ext.extract((opt(n64("minutes")), opt(n64("seconds"))))?;
|
||||
let idle = Duration::from_secs(
|
||||
minutes.despan().unwrap_or_default() * 60 + seconds.despan().unwrap_or_default(),
|
||||
);
|
||||
Ok(idle)
|
||||
let grace_period = parse_duration(&minutes, &seconds);
|
||||
Ok(grace_period)
|
||||
}
|
||||
}
|
||||
|
||||
fn parse_duration(minutes: &Option<Spanned<u64>>, seconds: &Option<Spanned<u64>>) -> Duration {
|
||||
Duration::from_secs(
|
||||
minutes.despan().unwrap_or_default() * 60 + seconds.despan().unwrap_or_default(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -24,7 +24,8 @@ 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_ui_drag_enabled, set_ui_drag_threshold,
|
||||
set_explicit_sync_enabled, set_idle, set_idle_grace_period, 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},
|
||||
|
|
@ -188,7 +189,14 @@ impl Action {
|
|||
}
|
||||
})
|
||||
}
|
||||
Action::ConfigureIdle { idle } => B::new(move || set_idle(Some(idle))),
|
||||
Action::ConfigureIdle { idle, grace_period } => B::new(move || {
|
||||
if let Some(idle) = idle {
|
||||
set_idle(Some(idle))
|
||||
}
|
||||
if let Some(period) = grace_period {
|
||||
set_idle_grace_period(period)
|
||||
}
|
||||
}),
|
||||
Action::MoveToOutput { output, workspace } => {
|
||||
let state = state.clone();
|
||||
B::new(move || {
|
||||
|
|
@ -967,6 +975,9 @@ fn load_config(initial_load: bool, persistent: &Rc<PersistentState>) {
|
|||
if let Some(idle) = config.idle {
|
||||
set_idle(Some(idle));
|
||||
}
|
||||
if let Some(period) = config.grace_period {
|
||||
set_idle_grace_period(period);
|
||||
}
|
||||
}
|
||||
on_devices_enumerated({
|
||||
let state = state.clone();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue