SpeakerWidget

Heh, next time avoids to write shit like this ...
message by Awaxx

Using an awesome.widget.launcher, I've created a simple speaker widget, which will change its icon to muted, or high or low volume. Eventually I want to be able to click on the speaker icon and open alsamixer, but I cannot figure out how to do that, but I'm open to suggestions. You're going to want to down load and and untar the Faenza icon theme from https://code.google.com/p/faenza-icon-theme/downloads/list and put it in ~/.config/awesome/icons/Faenza/

Here is a youtube video to show you how the speaker widget works now:

https://www.youtube.com/watch?v=be7OwUsm6Y4&list=UU8sTvGJGIMFPP48K7CNmx-Q

Here is the code that'll make the magic happen:

Create a file called ~/.config/awesome/speaker.lua and put in it:

local awful = require ('awful') --let's get the percent that the speakers are on -- this code only works because amixer outputs whole numbers for percents

--define a global variable. volume = "off" --let's find out if the speakers are on if os.execute("amixer get Master | grep '\\[on\\]'") then volume = "on" else volume = "off" end

-- let's find out what percent the speakers are on percent = os.capture ("amixer get Master | grep % | gawk '{ print $4 }' ", raw) if string.len(percent) == 4 then percent = 0 elseif string.len(percent) == 5 then percent = tonumber (string.sub (percent, 2, 3)) else percent = 100 end

if (percent <= 30) then alsamixer_launcher  = awful.widget.launcher({ image = configd .. "icons/Faenza/status/48/audio-volume-off.png",						  command = awful.util.spawn_with_shell(terminal .. " alsamixer") }) elseif (percent >= 31) and (percent < 61) then alsamixer_launcher  = awful.widget.launcher({ image = configd .. "icons/Faenza/status/48/audio-volume-low.png",						  command = awful.util.spawn_with_shell(terminal .. " alsamixer") }) elseif (percent >= 62) and (percent < 92) then alsamixer_launcher  = awful.widget.launcher({ image = configd .. "icons/Faenza/status/48/audio-volume-medium.png",						  command = awful.util.spawn_with_shell(terminal .. " alsamixer") }) else -- p >= 88 alsamixer_launcher  = awful.widget.launcher({ image = configd .. "icons/Faenza/status/48/audio-volume-high.png",						  command = awful.util.spawn_with_shell(terminal .. " alsamixer") }) end

In your rc.lua add this:

beautiful.init("/home/joshua/.config/awesome/themes/zenburn/theme.lua") --change this line next line to YOUR CONFIG PATH. My configd looks like: configd = "/home/joshua/.config/awesome/" editor_cmd = terminal .. " -e " .. editor

dofile (configd .. "speaker.lua")

local right_layout = wibox.layout.fixed.horizontal if s == 1 then right_layout:add(wibox.widget.systray) end right_layout:add(alsamixer_launcher) right_layout:add(mytextclock) right_layout:add(mylayoutbox[s])

And that's all you need!

plugins for a shiny systray sound volume icon in your systray! works on awesome 3.4


Just put the volume.lua inside you $HOME/.config/awesome be sure you have Faenza icons & amixer installed on your system

the plugin work with your mouse (scroll increase/decrease volume and middle button to mute/unmute) but you may easily add a keybinding to:

increase sound : amixer set Master 3%+

decrease sound : amixer set Master 3%-

unmute : amixer set Master unmute

mute : amixer set Master mute

Look around Key binding inside you rc.lua awful.key({ modkey, "Control" }, "e",     function  awful.util.spawn("PROGRAM_NAME") end),

-- by [Awaxx] for awesome community local setmetatable = setmetatable local io = io local string = string local tonumber = tonumber local image = image local awful = require("awful") local widget = widget local timer = timer

local icons_path = "/usr/share/icons/Faenza-Dark" local sound = { high   = icons_path .. "/status/16/audio-volume-high-panel.png", -- 66-100 medium = icons_path .. "/status/16/audio-volume-medium-panel.png", -- 33-66 low    = icons_path .. "/status/16/audio-volume-low-panel.png", -- 0-33 zero   = icons_path .. "/status/16/audio-volume-low-zero-panel.png", -- 0 mute   = icons_path .. "/status/16/audio-volume-muted-blocked-panel.png" -- mute }

module("volume")

local devnull = ">/dev/null"

local function update_icon -- body f = io.popen("amixer get Master | tail -1 | awk '{print $4 $6}'") volume_data = f:read(11) f:close

volume_percent = tonumber(string.match(volume_data, "(%d?%d?%d)%%")) volume_state = string.match(volume_data, "%[on]")

if not volume_state then return sound.mute elseif not volume_percent then return sound.mute end

if volume_percent == 0 then return sound.zero elseif volume_percent <= 40 then return sound.low elseif volume_percent <= 80 then return sound.medium else return sound.high end end

local function mute local f = io.popen("amixer get Master | tail -1 | awk '{print $4 $6}'") local data = f:read(11) f:close local volstate = string.match(data, "%[on]") if not volstate then awful.util.spawn_with_shell("amixer set Master unmute " .. devnull, false) else awful.util.spawn_with_shell("amixer set Master mute " .. devnull, false) end end

function new local w = widget({ type = "imagebox" }) w.image = image(update_icon) w:buttons(awful.util.table.join( awful.button({ }, 4, function awful.util.spawn_with_shell("amixer set Master 3%+ " .. devnull, false) end), -- up -- awful.button({ }, 5, function awful.util.spawn_with_shell("amixer set Master 3%- " .. devnull, false) end), -- down -- awful.button({ }, 2, function mute end) -- mute -- amixer set Master unmute ))   local recall = timer { timeout = 0.5 } recall:add_signal("timeout", function w.image = image(update_icon) end) recall:start return w end

setmetatable(_M, { __call = function(_, ...) return new(...) end }) -- end of volume.lua --

and put : -- add it at the head of rc.lua after awful,beautiful requires... ... require('volume') myvolume = volume ...

-- then at the middle of your rc.lua -- add "myvolume," to your wibox which handle your menus, taglists, taskbars... -- i provide an example (you just need add myvolume,): ...   -- Add widgets to the wibox - order matters --- mywibox[s].widgets = { {           mylauncher, mytaglist[s], mypromptbox[s], layout = awful.widget.layout.horizontal.leftright },       mylayoutbox[s], mytextclock, myvolume,                                     <<=============================== THERE s == 1 and mysystray or nil, mytasklist[s], layout = awful.widget.layout.horizontal.rightleft } ...

By [Awaxx] you can contact me with irc:oftc/#awesome