From 574e084383e5befd2e01d8a77aca1b07d491bfc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Dzi=C4=99giel?= Date: Mon, 6 Sep 2021 12:34:11 +0200 Subject: [PATCH] Toggle mute with Ctrl+M Closes #117 --- src/actions.js | 4 ++++ src/buttons.js | 23 ++++++++++++++++++++++- src/controls.js | 3 +++ ui/help-overlay.ui | 26 ++++++++++++++++---------- 4 files changed, 45 insertions(+), 11 deletions(-) diff --git a/src/actions.js b/src/actions.js index bdbc4680..ae3c49c3 100644 --- a/src/actions.js +++ b/src/actions.js @@ -18,6 +18,7 @@ var actions = { prev_track: ['Left'], volume_up: ['Up'], volume_down: ['Down'], + mute: ['m'], toggle_play: ['space'], change_repeat: ['r'], reveal_controls: ['Return'], @@ -74,6 +75,9 @@ function handleAction(action, window) case 'volume_down': player.adjust_volume(bool); break; + case 'mute': + player.mute ^= true; + break; case 'next_track': player.playlistWidget.nextTrack(); break; diff --git a/src/buttons.js b/src/buttons.js index 1044ca89..0312df85 100644 --- a/src/buttons.js +++ b/src/buttons.js @@ -206,9 +206,30 @@ var VolumeButton = GObject.registerClass({ GTypeName: 'ClapperVolumeButton', Template: Misc.getResourceUri('ui/volume-button.ui'), Children: ['volumeScale'], + Properties: { + 'muted': GObject.ParamSpec.boolean( + 'muted', + 'Set muted', + 'Mark scale as muted', + GObject.ParamFlags.WRITABLE, + false + ), + } }, class ClapperVolumeButton extends PopoverButtonBase { + _init(opts) + { + super._init(opts); + this._isMuted = false; + } + + set muted(isMuted) + { + this._isMuted = isMuted; + this._onVolumeScaleValueChanged(this.volumeScale); + } + _onVolumeScaleValueChanged(scale) { const volume = scale.get_value(); @@ -224,7 +245,7 @@ class ClapperVolumeButton extends PopoverButtonBase scale.remove_css_class(cssClass); } - const icon = (volume <= 0) + const icon = (volume <= 0 || this._isMuted) ? 'muted' : (volume <= 0.3) ? 'low' diff --git a/src/controls.js b/src/controls.js index 8c718a18..ca8d5880 100644 --- a/src/controls.js +++ b/src/controls.js @@ -376,6 +376,9 @@ class ClapperControls extends Gtk.Box : settings.get_double('volume-last'); clapperWidget.player.volume = initialVolume; + clapperWidget.player.bind_property('mute', this.volumeButton, 'muted', + GObject.BindingFlags.DEFAULT + ); } _onPlayerResize(width, height) diff --git a/ui/help-overlay.ui b/ui/help-overlay.ui index 154bbc3a..47f1f55d 100644 --- a/ui/help-overlay.ui +++ b/ui/help-overlay.ui @@ -100,6 +100,20 @@ space + + + Seek forward + Swipe right | Scroll right + Right + + + + + Seek backward + Swipe left | Scroll left + Left + + Volume up @@ -116,16 +130,8 @@ - Seek forward - Swipe right | Scroll right - Right - - - - - Seek backward - Swipe left | Scroll left - Left + Mute volume + <Ctrl>M