Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to send notifications for volume change #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions widget.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ local color_bg_mute = '#532a15' -- background color when muted
local mixer = 'pavucontrol' -- mixer command
local show_text = false -- show percentages on progressbar
local text_color = '#fff' -- color of text
local notify = false
local notify_arguments = { title = 'Volume', timeout = 2 }

-- End of configuration

Expand All @@ -44,6 +46,13 @@ color_mute = beautiful.apw_mute_fg_color or color_mute
color_bg_mute = beautiful.apw_mute_bg_color or color_bg_mute
show_text = beautiful.apw_show_text or show_text
text_color = beautiful.apw_text_colot or text_color
notify = beautiful.apw_notify or notify
notify_arguments = beautiful.apw_notify_arguments or notify_arguments

local naughty
if notify then
naughty = require("naughty")
end

local p = pulseaudio:Create()

Expand Down Expand Up @@ -89,24 +98,49 @@ local function _update()
end
end

local notification = nil

notify_arguments.destroy = function()
notification = nil
end

local function _notify()
if notify then
if p.Mute then
notify_arguments.text = 'Muted'
else
notify_arguments.text = math.ceil(p.Volume*100)..'%'
end
if notification then
notify_arguments.replaces_id = notification.id
else
notify_arguments.replaces_id = nil
end
notification = naughty.notify(notify_arguments)
end
end

function pulseWidget.SetMixer(command)
mixer = command
end

function pulseWidget.Up()
p:SetVolume(p.Volume + pulseBar.step)
_update()
_notify()
end

function pulseWidget.Down()
p:SetVolume(p.Volume - pulseBar.step)
_update()
_notify()
end


function pulseWidget.ToggleMute()
p:ToggleMute()
_update()
_notify()
end

function pulseWidget.Update()
Expand Down