summaryrefslogtreecommitdiff
path: root/widgets
diff options
context:
space:
mode:
Diffstat (limited to 'widgets')
-rw-r--r--widgets/cal.lua21
-rw-r--r--widgets/volume.lua124
2 files changed, 70 insertions, 75 deletions
diff --git a/widgets/cal.lua b/widgets/cal.lua
index 10dc982..c1f8551 100644
--- a/widgets/cal.lua
+++ b/widgets/cal.lua
@@ -23,17 +23,15 @@
-- On clicking or by using the mouse wheel the displayed month changes.
-- Pressing Shift + Mouse click change the year.
-local string = {format = string.format}
-local os = {date = os.date, time = os.time}
local awful = require("awful")
-module("widgets.cal")
-
local tooltip
local state = {}
local current_day_format = "<u>%s</u>"
-function displayMonth(month,year,weekStart)
+local cal = {}
+
+local function displayMonth(month,year,weekStart)
local t,wkSt=os.time{year=year, month=month+1, day=0},weekStart or 1
local d=os.date("*t",t)
local mthDays,stDay=d.day,(d.wday-d.day-wkSt+1)%7
@@ -79,8 +77,13 @@ function displayMonth(month,year,weekStart)
return header .. "\n" .. lines
end
+local function switchMonth(delta)
+ state[1] = state[1] + (delta or 1)
+ local text = displayMonth(state[1], state[2], 2)
+ tooltip:set_markup(text)
+end
-function register(mywidget, custom_current_day_format)
+function cal.register(mywidget, custom_current_day_format)
if custom_current_day_format then current_day_format = custom_current_day_format end
if not tooltip then
@@ -121,8 +124,4 @@ function register(mywidget, custom_current_day_format)
end)))
end
-function switchMonth(delta)
- state[1] = state[1] + (delta or 1)
- local text = displayMonth(state[1], state[2], 2)
- tooltip:set_markup(text)
-end
+return cal
diff --git a/widgets/volume.lua b/widgets/volume.lua
index 172931d..e73ad37 100644
--- a/widgets/volume.lua
+++ b/widgets/volume.lua
@@ -1,87 +1,83 @@
--- 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 wibox = require('wibox')
local beautiful = require('beautiful')
-module('widgets.volume')
-
local cardid = nil
local channel = 'Master'
--- command must start with a space!
-local function mixercommand(w, command)
- local cmd = 'amixer'
- if cardid then
- cmd = cmd .. ' -c ' .. cardid
- end
- local fd = io.popen(cmd .. command)
- local status = fd:read('*all')
- fd:close()
- if status == '' then
- w.visible = false
- else
- 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
- p.border_color = beautiful.bg_normal
- end
- end
+local function mixercommand(w, command, arg)
+ local cmd = {'amixer'}
+ if cardid then
+ table.insert(cmd, '-c')
+ table.insert(cmd, cardid)
+ end
+ table.insert(cmd, command)
+ table.insert(cmd, channel)
+ if arg then
+ table.insert(cmd, arg)
+ end
+ awful.spawn.easy_async(cmd, function(out)
+ if out == '' then
+ w.visible = false
+ else
+ local p = w:get_children_by_id('p')[1]
+ local volume = string.match(out, '(%d?%d?%d)%%')
+ local status = string.match(out, '%[(o[^%]]*)%]')
+ p.value = tonumber(volume)
+ if status == 'on' then
+ p.border_color = beautiful.fg_normal
+ else
+ p.border_color = beautiful.bg_normal
+ end
+ end
+
+ end)
end
local function update(w)
- mixercommand(w, ' sget ' .. channel)
+ mixercommand(w, 'sget')
end
local function up(w)
- mixercommand(w, ' sset ' .. channel .. ' 10%+')
+ mixercommand(w, 'sset', '10%+')
end
local function down(w)
- mixercommand(w, ' sset ' .. channel .. ' 10%-')
+ mixercommand(w, 'sset', '10%-')
end
local function toggle(w)
- mixercommand(w, ' sset ' .. channel .. ' toggle')
+ mixercommand(w, 'sset', 'toggle')
end
local function new(args)
- local args = args or {}
- local w = wibox.widget{
- {
- image = beautiful.widget_vol,
- widget = wibox.widget.imagebox,
- },
+ local args = args or {}
+ 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,
+ 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,
},
- 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
+ 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
end
-setmetatable(_M, { __call = function(_, ...) return new(...) end })
+return new