add toggle mute keymap
This commit is contained in:
parent
3e3ae64c72
commit
a6fa8add79
|
|
@ -15,6 +15,7 @@ rmptui is a minimal tui mpd client made with rust.
|
||||||
| `p` | Toggle pause |
|
| `p` | Toggle pause |
|
||||||
| `+`/`=` | Increase volume |
|
| `+`/`=` | Increase volume |
|
||||||
| `-` | Decrease volume |
|
| `-` | Decrease volume |
|
||||||
|
| `m` | Toggle Mute |
|
||||||
| `D` | Get dmenu prompt |
|
| `D` | Get dmenu prompt |
|
||||||
| `j`/`Down` | Scroll down |
|
| `j`/`Down` | Scroll down |
|
||||||
| `k`/`Up` | Scroll up |
|
| `k`/`Up` | Scroll up |
|
||||||
|
|
|
||||||
|
|
@ -429,7 +429,7 @@ impl App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn handle_mouse_left_click(&mut self, x: u16, y: u16) -> AppResult<()> {
|
pub fn handle_mouse_left_click(&mut self, _x: u16, _y: u16) -> AppResult<()> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,12 @@ use mpd::{Client, State};
|
||||||
use simple_dmenu::dmenu;
|
use simple_dmenu::dmenu;
|
||||||
use std::time::Duration;
|
use std::time::Duration;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum VolumeStatus {
|
||||||
|
Muted(i8),
|
||||||
|
Unmuted,
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
/// struct storing the mpd Client related stuff
|
/// struct storing the mpd Client related stuff
|
||||||
pub struct Connection {
|
pub struct Connection {
|
||||||
|
|
@ -16,6 +22,7 @@ pub struct Connection {
|
||||||
pub current_song: Song,
|
pub current_song: Song,
|
||||||
pub stats: mpd::Stats,
|
pub stats: mpd::Stats,
|
||||||
pub status: mpd::Status,
|
pub status: mpd::Status,
|
||||||
|
pub volume_status: VolumeStatus,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Connection {
|
impl Connection {
|
||||||
|
|
@ -41,6 +48,13 @@ impl Connection {
|
||||||
.currentsong()
|
.currentsong()
|
||||||
.unwrap_or_else(|_| Some(empty_song.clone()))
|
.unwrap_or_else(|_| Some(empty_song.clone()))
|
||||||
.unwrap_or(empty_song);
|
.unwrap_or(empty_song);
|
||||||
|
|
||||||
|
let volume_status = if status.volume == 0 {
|
||||||
|
VolumeStatus::Muted(status.volume)
|
||||||
|
} else {
|
||||||
|
VolumeStatus::Unmuted
|
||||||
|
};
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
conn,
|
conn,
|
||||||
songs_filenames,
|
songs_filenames,
|
||||||
|
|
@ -50,6 +64,7 @@ impl Connection {
|
||||||
current_song,
|
current_song,
|
||||||
stats,
|
stats,
|
||||||
status,
|
status,
|
||||||
|
volume_status,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -207,6 +222,7 @@ impl Connection {
|
||||||
pub fn inc_volume(&mut self, v: i8) {
|
pub fn inc_volume(&mut self, v: i8) {
|
||||||
let cur = self.status.volume;
|
let cur = self.status.volume;
|
||||||
if cur + v <= 100 {
|
if cur + v <= 100 {
|
||||||
|
self.volume_status = VolumeStatus::Unmuted;
|
||||||
self.conn.volume(cur + v).unwrap();
|
self.conn.volume(cur + v).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -215,6 +231,7 @@ impl Connection {
|
||||||
pub fn dec_volume(&mut self, v: i8) {
|
pub fn dec_volume(&mut self, v: i8) {
|
||||||
let cur = self.status.volume;
|
let cur = self.status.volume;
|
||||||
if cur - v >= 0 {
|
if cur - v >= 0 {
|
||||||
|
self.volume_status = VolumeStatus::Unmuted;
|
||||||
self.conn.volume(cur - v).unwrap();
|
self.conn.volume(cur - v).unwrap();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
use crate::{
|
use crate::{
|
||||||
app::{App, AppResult, SelectedTab},
|
app::{App, AppResult, SelectedTab},
|
||||||
|
connection::VolumeStatus,
|
||||||
ui::InputMode,
|
ui::InputMode,
|
||||||
};
|
};
|
||||||
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
use crossterm::event::{KeyCode, KeyEvent, KeyModifiers, MouseEvent, MouseEventKind};
|
||||||
|
|
@ -138,6 +139,22 @@ pub fn handle_key_events(key_event: KeyEvent, app: &mut App) -> AppResult<()> {
|
||||||
app.conn.update_status();
|
app.conn.update_status();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Toggle Mute
|
||||||
|
KeyCode::Char('m') => {
|
||||||
|
match app.conn.volume_status {
|
||||||
|
VolumeStatus::Muted(v) => {
|
||||||
|
app.conn.conn.volume(v)?;
|
||||||
|
app.conn.volume_status = VolumeStatus::Unmuted;
|
||||||
|
}
|
||||||
|
VolumeStatus::Unmuted => {
|
||||||
|
let current_volume = app.conn.status.volume;
|
||||||
|
app.conn.conn.volume(0)?;
|
||||||
|
app.conn.volume_status = VolumeStatus::Muted(current_volume);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
app.conn.update_status();
|
||||||
|
}
|
||||||
|
|
||||||
// Update MPD database
|
// Update MPD database
|
||||||
KeyCode::Char('U') => {
|
KeyCode::Char('U') => {
|
||||||
app.conn.conn.rescan()?;
|
app.conn.conn.rescan()?;
|
||||||
|
|
|
||||||
Reference in New Issue