summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2011-03-28 19:00:50 +0200
committerNicolas Schodet2011-03-28 19:00:50 +0200
commitc047d077189127f8086cb05d1364e4107149bdc9 (patch)
treef5583ca9f2caba234703222f1e212bab1a42234e
parentb385090be29a26dd1a1173430c9cfb5ca2514d28 (diff)
add volume widget
-rw-r--r--rc.lua7
-rw-r--r--widgets/volume.lua63
2 files changed, 70 insertions, 0 deletions
diff --git a/rc.lua b/rc.lua
index 2ab67f7..d9f30bd 100644
--- a/rc.lua
+++ b/rc.lua
@@ -10,6 +10,9 @@ require("naughty")
-- Load Debian menu entries
require("debian.menu")
+-- Load my modules
+require("widgets.volume")
+
-- {{{ Variable definitions
-- Themes define colours, icons, and wallpapers
beautiful.init(os.getenv ("HOME") .. "/.config/awesome/ni/theme.lua")
@@ -80,6 +83,9 @@ mytextclock = awful.widget.textclock({ align = "right" })
-- Create a systray
mysystray = widget({ type = "systray" })
+-- Create my widgets
+myvolume = widgets.volume()
+
-- Create a wibox for each screen and add it
mywibox = {}
mypromptbox = {}
@@ -149,6 +155,7 @@ for s = 1, screen.count() do
layout = awful.widget.layout.horizontal.leftright
},
mylayoutbox[s],
+ myvolume,
mytextclock,
s == 1 and mysystray or nil,
mytasklist[s],
diff --git a/widgets/volume.lua b/widgets/volume.lua
new file mode 100644
index 0000000..80d170f
--- /dev/null
+++ b/widgets/volume.lua
@@ -0,0 +1,63 @@
+-- Inspired by https://awesome.naquadah.org/wiki/Farhavens_volume_widget
+
+local setmetatable = setmetatable
+local io = io
+local string = string
+local tonumber = tonumber
+local capi = { widget = widget }
+local awful = require ("awful")
+local beautiful = require ("beautiful")
+
+module("widgets.volume")
+
+local cardid = 0
+local channel = "Master"
+
+-- command must start with a space!
+local function mixercommand(w, command)
+ local fd = io.popen("amixer -c " .. cardid .. command)
+ local status = fd:read("*all")
+ fd:close()
+ local volume = string.match(status, "(%d?%d?%d)%%")
+ status = string.match(status, "%[(o[^%]]*)%]")
+ w:set_value(tonumber(volume))
+ if string.find(status, "on", 1, true) then
+ w:set_border_color(beautiful.fg_normal)
+ else
+ w:set_border_color(beautiful.bg_normal)
+ end
+end
+
+local function update(w)
+ mixercommand(w, " sget " .. channel)
+end
+local function up()
+ mixercommand(w, " sset " .. channel .. " 10%+")
+end
+local function down()
+ mixercommand(w, " sset " .. channel .. " 10%-")
+end
+local function toggle()
+ mixercommand(w, " sset " .. channel .. " toggle")
+end
+
+function new(args)
+ local args = args or {}
+ args.width = args.width or 8
+ args.height = args.height or beautiful.wibox_height or 16
+ w = awful.widget.progressbar(args)
+ w:set_vertical(true)
+ w:set_background_color(beautiful.bg_normal)
+ w:set_color(beautiful.fg_normal)
+ w:set_max_value(100)
+ w:set_value(50)
+ w.widget:buttons(awful.util.table.join(
+ awful.button({}, 1, nil, function () toggle(w) end),
+ awful.button({}, 4, nil, function () up(w) end),
+ awful.button({}, 5, nil, function () down(w) end)
+ ))
+ update(w)
+ return w.widget
+end
+
+setmetatable(_M, { __call = function(_, ...) return new(...) end })