summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas Schodet2017-09-17 23:15:40 +0200
committerNicolas Schodet2017-09-17 23:15:40 +0200
commit20fae489af0ff9d111dd6a161465305da7395c93 (patch)
tree19e00ee528bc89a9af0b109a0f4d859f741b90f0
parent2a958b324624ef16f5edb424b9ca75a8eec20c52 (diff)
widget/volume: port to 4.0
-rw-r--r--rc.lua10
-rw-r--r--widgets/volume.lua80
2 files changed, 51 insertions, 39 deletions
diff --git a/rc.lua b/rc.lua
index a92ace9..8043cb0 100644
--- a/rc.lua
+++ b/rc.lua
@@ -41,7 +41,7 @@ end
-- Load my modules
--require("vicious")
---require("widgets.volume")
+local vol = require("widgets.volume")
local cal = require("widgets.cal")
-- {{{ Variable definitions
@@ -132,12 +132,7 @@ mytextclock = wibox.widget.textclock()
cal.register(mytextclock)
-- Create my widgets
---[[
-myvolume = widgets.volume()
-myvolumeicon = widget({ type = "imagebox" })
-myvolumeicon.image = image(beautiful.widget_vol)
-myvolumeicon:buttons (myvolume:buttons ())
-]]--
+myvolume = vol()
--[[
mybat = widget({ type = "textbox" })
@@ -270,6 +265,7 @@ awful.screen.connect_for_each_screen(function(s)
layout = wibox.layout.fixed.horizontal,
mykeyboardlayout,
wibox.widget.systray(),
+ myvolume,
mytextclock,
s.mylayoutbox,
},
diff --git a/widgets/volume.lua b/widgets/volume.lua
index 122714a..172931d 100644
--- a/widgets/volume.lua
+++ b/widgets/volume.lua
@@ -5,67 +5,83 @@ local io = io
local string = string
local tonumber = tonumber
local capi = { widget = widget }
-local awful = require ("awful")
-local beautiful = require ("beautiful")
+local awful = require('awful')
+local wibox = require('wibox')
+local beautiful = require('beautiful')
-module("widgets.volume")
+module('widgets.volume')
local cardid = nil
-local channel = "Master"
+local channel = 'Master'
-- command must start with a space!
local function mixercommand(w, command)
- cmd = "amixer"
+ local cmd = 'amixer'
if cardid then
- cmd = cmd .. " -c " .. cardid
+ cmd = cmd .. ' -c ' .. cardid
end
local fd = io.popen(cmd .. command)
- local status = fd:read("*all")
+ local status = fd:read('*all')
fd:close()
if status == '' then
- w.widget.visible = false
+ w.visible = false
else
- 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)
+ local p = w:get_children_by_id('p')[1]
+ local volume = string.match(status, '(%d?%d?%d)%%')
+ status = string.match(status, '%[(o[^%]]*)%]')
+ p.value = tonumber(volume)
+ if string.find(status, 'on', 1, true) then
+ p.border_color = beautiful.fg_normal
else
- w:set_border_color(beautiful.bg_normal)
+ p.border_color = beautiful.bg_normal
end
end
end
local function update(w)
- mixercommand(w, " sget " .. channel)
+ mixercommand(w, ' sget ' .. channel)
end
-local function up()
- mixercommand(w, " sset " .. channel .. " 10%+")
+local function up(w)
+ mixercommand(w, ' sset ' .. channel .. ' 10%+')
end
-local function down()
- mixercommand(w, " sset " .. channel .. " 10%-")
+local function down(w)
+ mixercommand(w, ' sset ' .. channel .. ' 10%-')
end
-local function toggle()
- mixercommand(w, " sset " .. channel .. " toggle")
+local function toggle(w)
+ mixercommand(w, ' sset ' .. channel .. ' toggle')
end
-function new(args)
+local 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(
+ local w = wibox.widget{
+ {
+ image = beautiful.widget_vol,
+ widget = wibox.widget.imagebox,
+ },
+ {
+ {
+ id = 'p',
+ forced_height = args.width or 8,
+ forced_width = args.height or beautiful.wibox_height or 16,
+ border_width = 1,
+ color = beautiful.fg_normal,
+ background_color = beautiful.bg_normal,
+ value = 10,
+ max_value = 100,
+ widget = wibox.widget.progressbar,
+ },
+ direction = 'east',
+ layout = wibox.container.rotate,
+ },
+ layout = wibox.layout.fixed.horizontal,
+ }
+ w: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
+ return w
end
setmetatable(_M, { __call = function(_, ...) return new(...) end })