Skip to content

Commit

Permalink
audqt: Mute/unmute with middle mouse click on volume button. Closes: #…
Browse files Browse the repository at this point in the history
  • Loading branch information
radioactiveman committed May 26, 2023
1 parent c24e83c commit 945b2ec
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/libaudqt/volumebutton.cc
Expand Up @@ -21,6 +21,7 @@

#include <QIcon>
#include <QMenu>
#include <QMouseEvent>
#include <QSlider>
#include <QToolButton>
#include <QVBoxLayout>
Expand All @@ -39,20 +40,23 @@ class VolumeButton : public QToolButton
public:
VolumeButton(QWidget * parent = nullptr);

protected:
void mousePressEvent(QMouseEvent * e) override;
void wheelEvent(QWheelEvent * e) override;

private:
void updateDelta();
void updateIcon(int val);
void updateVolume();
void setVolume(int val);
void setUpButton(QToolButton * button, int dir);

void wheelEvent(QWheelEvent * e);

QMenu m_menu;
QWidgetAction m_action;
QWidget m_container;
QToolButton m_buttons[2];
QSlider m_slider;
int m_old_volume = 0;
int m_scroll_delta = 0;

HookReceiver<VolumeButton> update_hook{"set volume_delta", this,
Expand Down Expand Up @@ -154,6 +158,24 @@ void VolumeButton::setUpButton(QToolButton * button, int dir)
});
}

void VolumeButton::mousePressEvent(QMouseEvent * e)
{
/* (un)mute with middle mouse button */
if (e->button() == Qt::MiddleButton)
{
int current_volume = aud_drct_get_volume_main();
if (current_volume)
{
m_old_volume = current_volume;
aud_drct_set_volume_main(0);
}
else
aud_drct_set_volume_main(m_old_volume);
}

QToolButton::mousePressEvent(e);
}

void VolumeButton::wheelEvent(QWheelEvent * e)
{
m_scroll_delta += e->angleDelta().y();
Expand Down

0 comments on commit 945b2ec

Please sign in to comment.