]> gitweb.fluxo.info Git - metadot.git/commitdiff
Adding volume keys and widgets
authorSilvio Rhatto <rhatto@riseup.net>
Fri, 22 Feb 2013 18:09:51 +0000 (15:09 -0300)
committerSilvio Rhatto <rhatto@riseup.net>
Fri, 22 Feb 2013 18:09:51 +0000 (15:09 -0300)
modules/awesome/config.dot/awesome.link/keys.lua
modules/awesome/config.dot/awesome.link/rc.lua
modules/awesome/config.dot/awesome.link/volume.lua [new file with mode: 0644]

index 2b1294eb5d699a60f3a39a55bcf786fef184f9e0..04e154933cb4968ef98551516a38a0b9cbfb7748 100644 (file)
@@ -11,8 +11,13 @@ globalkeys = awful.util.table.join(root.keys(),
     awful.key({ modkey, "Control" }, "h", function () awful.util.spawn("xhibernate") end),
     awful.key({ modkey, "Control" }, "k", function () awful.util.spawn("kedpm") end),
     awful.key({ modkey, "Control" }, "c", function () awful.util.spawn("chromium-browser") end),
-    awful.key({ modkey, "Control" }, "t", function () awful.util.spawn("thunar") end)
+    awful.key({ modkey, "Control" }, "t", function () awful.util.spawn("thunar") end),
     --awful.key({ modkey, "Control" }, "b", function () awful.util.spawn("terminal irssi") end),
+
+    -- Volume keys
+    awful.key({ }, "XF86AudioRaiseVolume", function () awful.util.spawn("amixer set Master 9%+", false) end),
+    awful.key({ }, "XF86AudioLowerVolume", function () awful.util.spawn("amixer set Master 9%-", false) end),
+    awful.key({ }, "XF86AudioMute", function () awful.util.spawn("amixer sset Master toggle", false) end)
 )
 
 -- Set keys
index 0fbe0ed123da29630a19507d448d7ee4a5ff7278..181e05841baef2bf15451c1609d0240e6446094f 100644 (file)
@@ -55,6 +55,7 @@ layouts =
 -- {{{ Widgets
 -- Leds
 dofile(configdir .. "/leds.lua")
+--dofile(configdir .. "/volume.lua")
 -- }}}
 
 -- {{{ Tags
@@ -163,6 +164,7 @@ for s = 1, screen.count() do
         mytextclock,
         s == 1 and mysystray or nil,
         myledbox,
+        volume_widget,
         mytasklist[s],
         layout = awful.widget.layout.horizontal.rightleft
     }
diff --git a/modules/awesome/config.dot/awesome.link/volume.lua b/modules/awesome/config.dot/awesome.link/volume.lua
new file mode 100644 (file)
index 0000000..0a5bb45
--- /dev/null
@@ -0,0 +1,34 @@
+-- See http://awesome.naquadah.org/wiki/Volume_control_and_display
+volume_widget = widget({ type = "textbox", name = "tb_volume",
+                         align = "right" })
+
+function update_volume(widget)
+    local fd = io.popen("amixer sget Master")
+    local status = fd:read("*all")
+    fd:close()
+    
+    local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
+    -- volume = string.format("% 3d", volume)
+
+    status = string.match(status, "%[(o[^%]]*)%]")
+
+    -- starting colour
+    local sr, sg, sb = 0x3F, 0x3F, 0x3F
+    -- ending colour
+    local er, eg, eb = 0xDC, 0xDC, 0xCC
+
+    local ir = volume * (er - sr) + sr
+    local ig = volume * (eg - sg) + sg
+    local ib = volume * (eb - sb) + sb
+    interpol_colour = string.format("%.2x%.2x%.2x", ir, ig, ib)
+    if string.find(status, "on", 1, true) then
+        volume = " <span background='#" .. interpol_colour .. "'>   </span>"
+    else
+        volume = " <span color='red' background='#" .. interpol_colour .. "'> M </span>"
+    end
+    widget.text = volume
+ end
+
+mytimer = timer({ timeout = 1 })
+mytimer:add_signal("timeout", function () update_volume(volume_widget) end)
+mytimer:start()