Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
121 changes: 119 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ tracing = "0.1"
tracing-appender = "0.2"
tracing-subscriber = { version = "0.3", features = ["local-time"] }
tracker = "0.2"
wayland-client = "0.31.11"
wayland-protocols = { version = "0.32.9", features = ["staging", "client"] }
wayland-protocols-wlr = { version = "0.3.9", features = ["client"] }

[features]
gtk4_8 = ["gtk4/v4_8"]
Expand Down
5 changes: 4 additions & 1 deletion regreet.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,15 @@ reboot = ["systemctl", "reboot"]
poweroff = ["systemctl", "poweroff"]

# The command prefix for X11 sessions to start the X server
x11_prefix = [ "startx", "/usr/bin/env" ]
x11_prefix = ["startx", "/usr/bin/env"]

[appearance]
# The message that initially displays on startup
greeting_msg = "Welcome back!"

[idle_timeout]
# Time in seconds before turning off screens
timeout_duration = 30
Comment on lines +52 to +54
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A bit of bikeshedding - I think that the top-level key should just be called [idle]. But it's not that important.

The thing that bothers me more is the unspecific timeout_duration key.

I think it would be nice for the greeter to optionally suspend the system if it is idle. It doesn't need to be done in this PR, but I think such a feature will be added eventually. Thus, the key that turns the screens off should be more specific to avoid confusion in the future. For user's convenience, I don't see any issues with aliasing it in serde it to allow "screen", "monitor", and "display" timeouts.

Additionally, it would be nice to use humantime-serde because ffs if I have to convert from minutes, or hours to seconds once again, I will go insane.

[idle]
# Alias: monitor_timeout, display_timeout
screen_timeout = "20min"


[widget.clock]
# strftime format argument
Expand Down
13 changes: 13 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,12 @@ fn default_greeting_msg() -> String {
GREETING_MSG.to_string()
}

#[derive(Default, Deserialize, Serialize)]
pub struct IdleTimeoutSettings {
#[serde(default)]
timeout_duration: Option<u64>,
}

/// The configuration struct
#[derive(Default, Deserialize)]
pub struct Config {
Expand All @@ -124,6 +130,9 @@ pub struct Config {

#[serde(default)]
pub(crate) widget: WidgetConfig,

#[serde(default)]
idle_timeout: IdleTimeoutSettings,
}

#[derive(Deserialize, Default)]
Expand Down Expand Up @@ -161,4 +170,8 @@ impl Config {
pub fn get_default_message(&self) -> String {
self.appearance.greeting_msg.clone()
}

pub fn get_idle_timeout(&self) -> Option<u64> {
self.idle_timeout.timeout_duration
}
}
13 changes: 13 additions & 0 deletions src/gui/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,19 @@ impl AsyncComponent for Greeter {
let mut model = Self::new(&input.config_path, input.demo).await;
let widgets = view_output!();

// Start idle monitoring in a separate thread if configured
if let Some(timeout_seconds) = model.config.get_idle_timeout() {
if timeout_seconds > 0 {
let timeout_ms = (timeout_seconds * 1000) as u32;
std::thread::spawn(move || {
if let Err(e) = crate::idle::run_idle_loop(timeout_ms) {
tracing::error!("Idle monitoring failed: {}", e);
}
});
Comment on lines +343 to +347
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use tokio::spawn_blocking instead.

tracing::info!("Started idle monitoring with {}s timeout", timeout_seconds);
}
}

// Make the info bar permanently visible, since it was made invisible during init. The
// actual visuals are controlled by `InfoBar::set_revealed`.
widgets.ui.error_info.set_visible(true);
Expand Down
Loading