diff options
| author | krolxon <krolyxon@tutanota.com> | 2024-06-11 21:49:35 +0530 |
|---|---|---|
| committer | krolxon <krolyxon@tutanota.com> | 2024-06-11 21:49:35 +0530 |
| commit | a6fa8add79f4d67ef1d4cb904eb0c0166c96b107 (patch) | |
| tree | 6438a77933a69f968641b5c01f434b7623589ba2 /src/connection.rs | |
| parent | 3e3ae64c72c8906513eda4e208c85bbf0e487482 (diff) | |
add toggle mute keymap
Diffstat (limited to 'src/connection.rs')
| -rwxr-xr-x | src/connection.rs | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/connection.rs b/src/connection.rs index c31c346..d3ff3a5 100755 --- a/src/connection.rs +++ b/src/connection.rs @@ -6,6 +6,12 @@ use simple_dmenu::dmenu; use std::time::Duration; #[derive(Debug)] +pub enum VolumeStatus { + Muted(i8), + Unmuted, +} + +#[derive(Debug)] /// struct storing the mpd Client related stuff pub struct Connection { pub conn: Client, @@ -16,6 +22,7 @@ pub struct Connection { pub current_song: Song, pub stats: mpd::Stats, pub status: mpd::Status, + pub volume_status: VolumeStatus, } impl Connection { @@ -41,6 +48,13 @@ impl Connection { .currentsong() .unwrap_or_else(|_| Some(empty_song.clone())) .unwrap_or(empty_song); + + let volume_status = if status.volume == 0 { + VolumeStatus::Muted(status.volume) + } else { + VolumeStatus::Unmuted + }; + Ok(Self { conn, songs_filenames, @@ -50,6 +64,7 @@ impl Connection { current_song, stats, status, + volume_status, }) } @@ -207,6 +222,7 @@ impl Connection { pub fn inc_volume(&mut self, v: i8) { let cur = self.status.volume; if cur + v <= 100 { + self.volume_status = VolumeStatus::Unmuted; self.conn.volume(cur + v).unwrap(); } } @@ -215,6 +231,7 @@ impl Connection { pub fn dec_volume(&mut self, v: i8) { let cur = self.status.volume; if cur - v >= 0 { + self.volume_status = VolumeStatus::Unmuted; self.conn.volume(cur - v).unwrap(); } } |
