add configuration value to drop default keybindings

resolves #204
This commit is contained in:
Henrik Friedrichsen
2020-06-18 19:33:19 +02:00
parent d36fb4fe40
commit 65126c5c78
4 changed files with 14 additions and 9 deletions

View File

@@ -128,6 +128,8 @@ values are:
<true/false>
* `volnorm`: Enable or disable volume normalization, off by default <true/false>
* `volnorm_pregain`: Normalization pregain to apply (if enabled)
* `default_keybindings`: If disabled, the default keybindings are discarded, off
by default <true/false>
Keybindings can be configured in `[keybindings]` section in `config.toml`, e.g. as such:

View File

@@ -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<Spotify>,
queue: Arc<Queue>,
library: Arc<Library>,
bindings: Option<HashMap<String, String>>,
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<HashMap<String, String>> = 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);

View File

@@ -9,6 +9,7 @@ pub const CLIENT_ID: &str = "d420a117a32841c2b3474932e49fb54b";
#[derive(Clone, Serialize, Deserialize, Debug, Default)]
pub struct Config {
pub default_keybindings: Option<bool>,
pub keybindings: Option<HashMap<String, String>>,
pub theme: Option<ConfigTheme>,
pub use_nerdfont: Option<bool>,

View File

@@ -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);