Add example config
This commit is contained in:
parent
92504d279a
commit
2ae04ff91a
5
Makefile
5
Makefile
@ -3,7 +3,9 @@
|
|||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
BINDIR ?= $(PREFIX)/bin
|
BINDIR ?= $(PREFIX)/bin
|
||||||
LIBEXECDIR ?= $(PREFIX)/libexec
|
LIBEXECDIR ?= $(PREFIX)/libexec
|
||||||
|
SYSCONFDIR ?= $(PREFIX)/etc
|
||||||
|
|
||||||
|
CONFIG_DIR = $(SYSCONFDIR)/xdg/bscreensaver
|
||||||
HELPER_DIR = $(LIBEXECDIR)/bscreensaver
|
HELPER_DIR = $(LIBEXECDIR)/bscreensaver
|
||||||
HELPERS = \
|
HELPERS = \
|
||||||
bscreensaver-dbus-service \
|
bscreensaver-dbus-service \
|
||||||
@ -24,9 +26,10 @@ build-dev:
|
|||||||
HELPER_DIR=target/debug cargo build
|
HELPER_DIR=target/debug cargo build
|
||||||
|
|
||||||
install: build
|
install: build
|
||||||
$(INSTALL) -m 0755 -d $(BINDIR) $(HELPER_DIR)
|
$(INSTALL) -m 0755 -d $(BINDIR) $(HELPER_DIR) $(CONFIG_DIR)
|
||||||
$(INSTALL) -m 0755 target/release/bscreensaver $(BINDIR)
|
$(INSTALL) -m 0755 target/release/bscreensaver $(BINDIR)
|
||||||
$(INSTALL) -m 0755 $(addprefix target/release/,$(HELPERS)) $(HELPER_DIR)
|
$(INSTALL) -m 0755 $(addprefix target/release/,$(HELPERS)) $(HELPER_DIR)
|
||||||
|
$(INSTALL) -m 0644 bscreensaver.toml.example $(CONFIG_DIR)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
cargo clean
|
cargo clean
|
||||||
|
20
bscreensaver.toml.example
Normal file
20
bscreensaver.toml.example
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
# Config files are searched for in this order:
|
||||||
|
#
|
||||||
|
# $XDG_CONFIG_DIRS/bscreensaver/bscreensaver.toml
|
||||||
|
# $XDG_CONFIG_HOME/bscreensaver/bscreensaver.toml
|
||||||
|
#
|
||||||
|
# Settings specified in files later in the search path override
|
||||||
|
# settings from prior files. $XDG_CONFIG_DIRS (default /etc/xdg/) is a
|
||||||
|
# colon-separated list of directories, while $XDG_CONFIG_HOME (default
|
||||||
|
# $HOME/.config/) is a single directory.
|
||||||
|
|
||||||
|
# Lock the screen after this amount of time of no user activity
|
||||||
|
lock-timeout = "10m"
|
||||||
|
# Blank the screen this amount of time before locking (must be less
|
||||||
|
# than 'lock-timeout')
|
||||||
|
blank-before-locking = "1m"
|
||||||
|
# Backend to use for the unlock dialog. Current options: 'gtk3'
|
||||||
|
dialog-backend = "gtk3"
|
||||||
|
# Adds a 'New Login' button to the unlock dialog that will run the
|
||||||
|
# specified command when clicked
|
||||||
|
new-login-command = "dm-tool switch-to-greeter"
|
@ -14,11 +14,21 @@ const DIALOG_TIMEOUT: Duration = Duration::from_secs(60);
|
|||||||
fn main() -> anyhow::Result<()> {
|
fn main() -> anyhow::Result<()> {
|
||||||
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
|
init_logging("BSCREENSAVER_DIALOG_GTK3_LOG");
|
||||||
|
|
||||||
let mut new_login_command = load_configuration()?.and_then(|config_toml| {
|
let config_tomls = load_configuration()?;
|
||||||
config_toml.get("new-login-command")
|
let mut config_tomls_iter = config_tomls.into_iter().rev();
|
||||||
.and_then(|nlc| nlc.as_str().map(|s| s.to_string()))
|
let mut new_login_command: Option<Vec<String>> = loop {
|
||||||
.map(|nlc| shell_words::split(&nlc))
|
if let Some(config_toml) = config_tomls_iter.next() {
|
||||||
}).transpose()?.filter(|nlc| !nlc.is_empty());
|
if let Some(nlc) = config_toml.get("new-login-command")
|
||||||
|
.and_then(|nlc| nlc.as_str().map(|s| s.to_string()))
|
||||||
|
.map(|nlc| shell_words::split(&nlc))
|
||||||
|
.transpose()?
|
||||||
|
{
|
||||||
|
break Some(nlc);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
break None;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let standalone = std::env::var("BSCREENSAVER_DIALOG_STANDALONE").is_ok();
|
let standalone = std::env::var("BSCREENSAVER_DIALOG_STANDALONE").is_ok();
|
||||||
|
|
||||||
|
@ -279,29 +279,26 @@ fn parse_config() -> anyhow::Result<Configuration> {
|
|||||||
use humantime::parse_duration;
|
use humantime::parse_duration;
|
||||||
|
|
||||||
let mut config = Configuration::default();
|
let mut config = Configuration::default();
|
||||||
match load_configuration()? {
|
for config_toml in load_configuration()? {
|
||||||
None => Ok(config),
|
config.lock_timeout = match config_toml.get("lock-timeout") {
|
||||||
Some(config_toml) => {
|
None => config.lock_timeout,
|
||||||
config.lock_timeout = match config_toml.get("lock-timeout") {
|
Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'lock-timeout' must be a duration string like '10m' or '90s'"))?)?,
|
||||||
None => config.lock_timeout,
|
};
|
||||||
Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'lock-timeout' must be a duration string like '10m' or '90s'"))?)?,
|
config.blank_before_locking = match config_toml.get("blank-before-locking") {
|
||||||
};
|
None => config.blank_before_locking,
|
||||||
config.blank_before_locking = match config_toml.get("blank-before-locking") {
|
Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'blank-before-locking' must be a duration string like '10m' or '90s'"))?)?,
|
||||||
None => config.blank_before_locking,
|
};
|
||||||
Some(val) => parse_duration(val.as_str().ok_or(anyhow!("'blank-before-locking' must be a duration string like '10m' or '90s'"))?)?,
|
config.dialog_backend = match config_toml.get("dialog-backend") {
|
||||||
};
|
None => config.dialog_backend,
|
||||||
config.dialog_backend = match config_toml.get("dialog-backend") {
|
Some(val) => DialogBackend::try_from(val.as_str().ok_or(anyhow!("'dialog-backend' must be a string"))?)?,
|
||||||
None => config.dialog_backend,
|
};
|
||||||
Some(val) => DialogBackend::try_from(val.as_str().ok_or(anyhow!("'dialog-backend' must be a string"))?)?,
|
|
||||||
};
|
|
||||||
|
|
||||||
if config.blank_before_locking >= config.lock_timeout {
|
if config.blank_before_locking >= config.lock_timeout {
|
||||||
Err(anyhow!("'blank-before-locking' cannot be greater than 'lock-timeout'"))
|
Err(anyhow!("'blank-before-locking' cannot be greater than 'lock-timeout'"))?
|
||||||
} else {
|
}
|
||||||
Ok(config)
|
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn init_signals() -> anyhow::Result<SignalFd> {
|
fn init_signals() -> anyhow::Result<SignalFd> {
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
use std::{ffi::CStr, fs::File, io::{self, Read}};
|
use std::{ffi::CStr, fs::File, io::{self, Read}, path::PathBuf};
|
||||||
use toml::Value;
|
use toml::Value;
|
||||||
use xcb::x;
|
use xcb::x;
|
||||||
|
|
||||||
@ -11,19 +11,21 @@ pub fn init_logging(env_name: &str) {
|
|||||||
.init();
|
.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_configuration() -> anyhow::Result<Option<Value>> {
|
fn parse_config_toml(config_path: &PathBuf) -> anyhow::Result<Value> {
|
||||||
match xdg::BaseDirectories::new()?.find_config_file("bscreensaver.toml") {
|
let mut f = File::open(config_path)?;
|
||||||
None => Ok(None),
|
let mut config = String::new();
|
||||||
Some(config_path) => {
|
f.read_to_string(&mut config)?;
|
||||||
let mut f = File::open(config_path)?;
|
drop(f);
|
||||||
let mut config = String::new();
|
|
||||||
f.read_to_string(&mut config)?;
|
|
||||||
drop(f);
|
|
||||||
|
|
||||||
let config_toml = config.parse::<Value>()?;
|
let config_toml = config.parse::<Value>()?;
|
||||||
Ok(Some(config_toml))
|
Ok(config_toml)
|
||||||
},
|
}
|
||||||
}
|
|
||||||
|
pub fn load_configuration() -> anyhow::Result<Vec<Value>> {
|
||||||
|
xdg::BaseDirectories::new()?
|
||||||
|
.find_config_files("bscreensaver/bscreensaver.toml")
|
||||||
|
.map(|config_path| parse_config_toml(&config_path))
|
||||||
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result<x::Atom> {
|
pub fn create_atom(conn: &xcb::Connection, name: &[u8]) -> xcb::Result<x::Atom> {
|
||||||
|
Loading…
Reference in New Issue
Block a user