Refactor a bit and add backlight brightness keys handling

This will only work if the video driver supports the xrandr backlight
property.  It's possible only Intel does this...
This commit is contained in:
2022-05-23 20:27:59 -07:00
parent 6e5dfabcfd
commit 8eb8dfac2e
6 changed files with 459 additions and 263 deletions

View File

@ -10,6 +10,7 @@ const LOCK_TIMEOUT: &str = "lock-timeout";
const BLANK_BEFORE_LOCKING: &str = "blank-before-locking";
const DIALOG_BACKEND: &str = "dialog-backend";
const NEW_LOGIN_COMMAND: &str = "new-login-command";
const HANDLE_BRIGHTNESS_KEYS: &str = "handle-brightness-keys";
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum DialogBackend {
@ -54,6 +55,7 @@ pub struct Configuration {
pub blank_before_locking: Duration,
pub dialog_backend: DialogBackend,
pub new_login_command: NewLoginCommand,
pub handle_brightness_keys: bool,
}
impl Configuration {
@ -84,6 +86,10 @@ impl Configuration {
None => config.new_login_command,
Some(val) => val.try_into().unwrap_or(NewLoginCommand::Auto),
};
config.handle_brightness_keys = match config_toml.get(HANDLE_BRIGHTNESS_KEYS) {
None => config.handle_brightness_keys,
Some(val) => val.as_bool().ok_or(anyhow!("'handle-brightness-keys' must be a boolean"))?,
}
}
if config.blank_before_locking >= config.lock_timeout {
@ -102,6 +108,7 @@ impl Configuration {
config_map.insert(BLANK_BEFORE_LOCKING.to_string(), Value::String(format_duration(self.blank_before_locking).to_string()));
config_map.insert(DIALOG_BACKEND.to_string(), Value::String(self.dialog_backend.to_string()));
config_map.insert(NEW_LOGIN_COMMAND.to_string(), self.new_login_command.clone().try_into()?);
config_map.insert(HANDLE_BRIGHTNESS_KEYS.to_string(), Value::Boolean(self.handle_brightness_keys));
let config_path = xdg::BaseDirectories::new()?.place_config_file(CONFIG_FILE_RELATIVE_PATH)?;
let mut tmp_filename = config_path.file_name().unwrap().to_os_string();
@ -123,6 +130,7 @@ impl Default for Configuration {
blank_before_locking: Duration::ZERO,
dialog_backend: DialogBackend::Gtk3,
new_login_command: NewLoginCommand::Auto,
handle_brightness_keys: false,
}
}
}