Klaus Dieter volume widget FreeBSD

From awesome
Jump to: navigation, search

This is my volume changer widget - it does not do muting yet but its easy to implement. Also it updates the progress bar as soon as the user scrolls on the bar. To make the popup work you need naughty.


 volumewidget = widget({ type = "progressbar", name = "volumewidget",  align = "right" })
 volumewidget.width = 40
 volumewidget.height = 0.40
 volumewidget.ticks_count = 100 
 
 volumewidget.gap = 1
 volumewidget.border_padding = 1
 volumewidget.border_width = 0
 volumewidget.ticks_gap = 0
 volumewidget.vertical = false
 volumewidget:bar_properties_set('vol', {
   bg = 'black',
   fg = 'blue4',
   fg_off = 'red',
   reverse = false,
   min_value = 0,
   max_value = 100
 })
 
 local mixer = nil
 
 function remove_mixer()
   if mixer ~= nil then
     naughty.destroy(mixer)
     mixer = nil
   end
 end
 
 function add_mixer()
   local mix = awful.util.pread("mixer |sed -e 's/Mixer//' -e 's/currently //'");
 
   remove_mixer()
 
   mixer = naughty.notify({
     text = string.format('%s',"monospace", mix),
     timeout = 0, hover_timeout = 0.5,
     width = 220
   })
 end

 volumewidget.mouse_enter = function()
   add_mixer(0)
 end
 volumewidget.mouse_leave = remove_mixer
 
 
 volumewidget:buttons({
 
   button({ }, 5, function()
     os.execute("mixer vol -5:-5 pcm -5:-5")
     volval = volval - 5
     volumewidget:bar_data_add("vol", volval)
 end),
   button({ }, 4, function()
     os.execute("mixer vol +5:+5 pcm +5:+5")
     volval = volval + 5
     volumewidget:bar_data_add("vol", volval)
 end),
 
 })
 
 --{{{ batt hook
 local function get_vol()
 local vol =   awful.util.pread("/usr/sbin/mixer vol|/usr/bin/awk '{print $7}'|/usr/bin/cut -d: -f1")
 local pcm = awful.util.pread("/usr/sbin/mixer pcm|awk '{print $7}'|cut -d: -f1") 
 local val = math.floor( (vol + pcm ) / 2 )
 volumewidget:bar_data_add("vol", val )
 volval = val
 --   dtextbox.text =  tostring(pcm)
 end
 
 awful.hooks.timer.register(30, function() get_vol() end)
Personal tools