From 65126c5c78fd41ad4d49e21fee101402ec3b1307 Mon Sep 17 00:00:00 2001 From: Henrik Friedrichsen Date: Thu, 18 Jun 2020 19:33:19 +0200 Subject: [PATCH] add configuration value to drop default keybindings resolves #204 --- README.md | 2 ++ src/commands.rs | 12 +++++++++--- src/config.rs | 1 + src/main.rs | 8 ++------ 4 files changed, 14 insertions(+), 9 deletions(-) diff --git a/README.md b/README.md index 276d5f9..6d6bbac 100644 --- a/README.md +++ b/README.md @@ -128,6 +128,8 @@ values are: * `volnorm`: Enable or disable volume normalization, off by default * `volnorm_pregain`: Normalization pregain to apply (if enabled) +* `default_keybindings`: If disabled, the default keybindings are discarded, off + by default Keybindings can be configured in `[keybindings]` section in `config.toml`, e.g. as such: diff --git a/src/commands.rs b/src/commands.rs index deb25f0..903cb58 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -5,6 +5,7 @@ use std::time::Duration; use crate::command::{ parse, Command, GotoMode, MoveAmount, MoveMode, SeekDirection, ShiftMode, TargetMode, }; +use crate::config::Config; use crate::library::Library; use crate::queue::{Queue, RepeatSetting}; use crate::spotify::{Spotify, VOLUME_PERCENT}; @@ -36,11 +37,16 @@ impl CommandManager { spotify: Arc, queue: Arc, library: Arc, - bindings: Option>, + config: &Config, ) -> CommandManager { - let mut kb = Self::default_keybindings(); + let mut kb = if config.default_keybindings.unwrap_or(true) { + Self::default_keybindings() + } else { + HashMap::new() + }; + let custom_bindings: Option> = config.keybindings.clone(); - for (key, command) in bindings.unwrap_or_default() { + for (key, command) in custom_bindings.unwrap_or_default() { if let Some(command) = parse(&command) { info!("Custom keybinding: {} -> {:?}", key, command); kb.insert(key, command); diff --git a/src/config.rs b/src/config.rs index e951c46..68d6955 100644 --- a/src/config.rs +++ b/src/config.rs @@ -9,6 +9,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b"; #[derive(Clone, Serialize, Deserialize, Debug, Default)] pub struct Config { + pub default_keybindings: Option, pub keybindings: Option>, pub theme: Option, pub use_nerdfont: Option, diff --git a/src/main.rs b/src/main.rs index c69e259..b157040 100644 --- a/src/main.rs +++ b/src/main.rs @@ -216,12 +216,8 @@ fn main() { cfg.use_nerdfont.unwrap_or(false), )); - let mut cmd_manager = CommandManager::new( - spotify.clone(), - queue.clone(), - library.clone(), - cfg.keybindings.clone(), - ); + let mut cmd_manager = + CommandManager::new(spotify.clone(), queue.clone(), library.clone(), &cfg); cmd_manager.register_all(); let cmd_manager = Arc::new(cmd_manager);