diff --git a/README.md b/README.md index 068ce23..643586d 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,7 @@ These screenshots use the [Canta GTK theme](https://github.com/vinceliuice/Canta * Allows manual entry of username and session command * Remembers the last authenticated user * Automatically selects the last used session per user +* Can also skip selecting the user/session and choose the last user and their last used session. * Allows setting environment variables for created sessions * Supports customizing: - Background image @@ -89,7 +90,7 @@ These are: Environment Variable | Default | Use -- | -- | -- GREETD\_CONFIG\_DIR | `/etc/greetd` | The configuration directory used by greetd -CACHE\_DIR | `/var/cache/regreet` | The directory used to store cache +STATE\_DIR | `/var/lib/regreet` | The directory used to store the ReGreet state/cache LOG\_DIR | `/var/log/regreet` | The directory used to store logs SESSION\_DIRS | `/usr/share/xsessions:/usr/share/wayland-sessions` | A colon (:) separated list of directories where the greeter looks for session files REBOOT\_CMD | `reboot` | The default command used to reboot the system @@ -97,7 +98,7 @@ POWEROFF\_CMD | `poweroff` | The default command used to shut down the system The greeter can be installed by copying the file `target/release/regreet` to `/usr/bin` (or similar directories like `/bin`). -Optionally, to set up the log and cache directories using systemd-tmpfiles, do either of the following: +Optionally, to set up the log and state directories using systemd-tmpfiles, do either of the following: * Copy the configuration given in [systemd-tmpfiles.conf](./systemd-tmpfiles.conf) to `/etc/tmpfiles.d/regreet.conf` or `/usr/lib/tmpfiles.d/regreet.conf`. * Run the `systemd-tmpfiles` CLI: ```sh @@ -175,6 +176,7 @@ Currently, the following can be configured: * Font * Reboot command * Shut down command +* Whether to skip selecting the user/session and choose the last user and session. ### Custom CSS ReGreet supports loading CSS files to act as a custom global stylesheet. @@ -206,7 +208,7 @@ Here, each command needs to be separated into a list containing the main command These commands can also be specified during compilation using the `REBOOT_CMD` and `POWEROFF_CMD` environment variables. ### Logging and Caching -The cache is are stored in `/var/cache/regreet/cache.toml` (configurable during installation). +The state is are stored in `/var/lib/regreet/state.toml` (configurable during installation). It contains the last authenticated user and the last used session per user, which are automatically selected on next login. If the greeter is unable to write to this file, then it reverts to the default behaviour. @@ -227,7 +229,7 @@ regreet --verbose ``` The recommended configuration is to run greetd greeters as a separate user (`greeter` in the above examples). -This can lead to insufficient permissions for either creating the cache/log directories, or writing to them. +This can lead to insufficient permissions for either creating the state/log directories, or writing to them. To make use of the caching and logging features, please create the directories manually with the correct permissions, if not done during installation with systemd-tmpfiles. ## Contributing diff --git a/regreet.sample.toml b/regreet.sample.toml index e62614b..2051a94 100644 --- a/regreet.sample.toml +++ b/regreet.sample.toml @@ -2,6 +2,9 @@ # # SPDX-License-Identifier: GPL-3.0-or-later +# Whether to skip asking for username and session, and use the last used ones. +skip_selection = false + [background] # Path to the background image path = "/usr/share/backgrounds/greeter.jpg" diff --git a/src/cache/mod.rs b/src/cache/mod.rs index d85571f..36319d7 100644 --- a/src/cache/mod.rs +++ b/src/cache/mod.rs @@ -70,6 +70,11 @@ impl Cache { self.last_user.as_deref() } + /// Check whether the cache has the last used session by the given user. + pub fn has_last_session(&self, user: &str) -> bool { + self.user_to_last_sess.contains(user) + } + /// Get the last used session by the given user. pub fn get_last_session(&mut self, user: &str) -> Option<&str> { self.user_to_last_sess.get(user).map(String::as_str) diff --git a/src/config.rs b/src/config.rs index d7eb290..8155267 100644 --- a/src/config.rs +++ b/src/config.rs @@ -93,6 +93,8 @@ fn default_greeting_msg() -> String { /// The configuration struct #[derive(Default, Deserialize, Serialize)] pub struct Config { + #[serde(default)] + skip_selection: bool, #[serde(default)] appearance: AppearanceSettings, #[serde(default)] @@ -134,4 +136,8 @@ impl Config { pub fn get_default_message(&self) -> String { self.appearance.greeting_msg.clone() } + + pub fn skip_selection(&self) -> bool { + self.skip_selection + } } diff --git a/src/constants.rs b/src/constants.rs index ef442d6..5154f48 100644 --- a/src/constants.rs +++ b/src/constants.rs @@ -32,9 +32,9 @@ pub const CONFIG_PATH: &str = concatcp!(GREETD_CONFIG_DIR, "/", GREETER_NAME, ". pub const CSS_PATH: &str = concatcp!(GREETD_CONFIG_DIR, "/", GREETER_NAME, ".css"); /// The directory for system cache files -const CACHE_DIR: &str = env_or!("CACHE_DIR", concatcp!("/var/cache/", GREETER_NAME)); +const CACHE_DIR: &str = env_or!("STATE_DIR", concatcp!("/var/lib/", GREETER_NAME)); /// Path to the cache file -pub const CACHE_PATH: &str = concatcp!(CACHE_DIR, "/cache.toml"); +pub const CACHE_PATH: &str = concatcp!(CACHE_DIR, "/state.toml"); /// The directory for system log files const LOG_DIR: &str = env_or!("LOG_DIR", concatcp!("/var/log/", GREETER_NAME)); diff --git a/src/gui/component.rs b/src/gui/component.rs index 288dd0a..b9e9bcf 100644 --- a/src/gui/component.rs +++ b/src/gui/component.rs @@ -398,6 +398,13 @@ impl AsyncComponent for Greeter { // Set the default behaviour of pressing the Return key to act like the login button. root.set_default_widget(Some(&widgets.ui.login_button)); + if let Some(user) = model.cache.get_last_user() { + if model.config.skip_selection() && model.cache.has_last_session(user) { + debug!("Skipping user & session selection and using those from the cache"); + widgets.ui.login_button.emit_clicked(); + } + } + AsyncComponentParts { model, widgets } } diff --git a/systemd-tmpfiles.conf b/systemd-tmpfiles.conf index baf61b8..195ea3f 100644 --- a/systemd-tmpfiles.conf +++ b/systemd-tmpfiles.conf @@ -2,6 +2,6 @@ # # SPDX-License-Identifier: CC0-1.0 -# Create the log and cache directories. +# Create the log and state directories. d /var/log/regreet 0755 greeter greeter - - -d /var/cache/regreet 0755 greeter greeter - - +d /var/lib/regreet 0755 greeter greeter - -