Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add config option to skip selecting user/session #81

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
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
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -89,15 +90,15 @@ 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
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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.

Expand All @@ -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
Expand Down
3 changes: 3 additions & 0 deletions regreet.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
5 changes: 5 additions & 0 deletions src/cache/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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
}
}
4 changes: 2 additions & 2 deletions src/constants.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions src/gui/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}

Expand Down
4 changes: 2 additions & 2 deletions systemd-tmpfiles.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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 - -
Loading