mirror of https://github.com/lcpz/lain.git
alsa/bat textbox resize fix
This commit is contained in:
parent
7dce46c34d
commit
fd35485c20
|
@ -15,7 +15,7 @@ Description
|
||||||
|
|
||||||
**Note:** the update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process.
|
**Note:** the update to 4.x is still in progress: if you experience issues, please report them in order to speed up the process.
|
||||||
|
|
||||||
Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, in order to improve Awesome_ usability and configurability.
|
Successor of awesome-vain_, this module provides new layouts, a set of widgets and utility functions, with the aim of improving Awesome_ usability and configurability.
|
||||||
|
|
||||||
Read the wiki_ for all the info.
|
Read the wiki_ for all the info.
|
||||||
|
|
||||||
|
|
|
@ -12,8 +12,7 @@ local wibox = require("wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Basic template for custom widgets
|
-- Basic template for custom widgets (asynchronous version)
|
||||||
-- Asynchronous version
|
|
||||||
-- lain.widgets.abase
|
-- lain.widgets.abase
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
local read_pipe = require("lain.helpers").read_pipe
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
@ -19,7 +19,7 @@ local setmetatable = setmetatable
|
||||||
|
|
||||||
-- ALSA volume
|
-- ALSA volume
|
||||||
-- lain.widgets.alsa
|
-- lain.widgets.alsa
|
||||||
local alsa = { last_level = "0", last_status = "" }
|
local alsa = helpers.make_widget_textbox()
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
|
@ -29,11 +29,12 @@ local function worker(args)
|
||||||
alsa.cmd = args.cmd or "amixer"
|
alsa.cmd = args.cmd or "amixer"
|
||||||
alsa.channel = args.channel or "Master"
|
alsa.channel = args.channel or "Master"
|
||||||
alsa.togglechannel = args.togglechannel
|
alsa.togglechannel = args.togglechannel
|
||||||
alsa.widget = wibox.widget.textbox('')
|
alsa.last_level = "0"
|
||||||
|
alsa.last_status = ""
|
||||||
|
|
||||||
function alsa.update()
|
function alsa.update()
|
||||||
mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
|
mixer = read_pipe(string.format("%s get %s", alsa.cmd, alsa.channel))
|
||||||
l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
|
||||||
-- HDMIs can have a channel different from Master for toggling mute
|
-- HDMIs can have a channel different from Master for toggling mute
|
||||||
if alsa.togglechannel then
|
if alsa.togglechannel then
|
||||||
|
@ -51,9 +52,9 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
||||||
newtimer(timer_id, timeout, alsa.update)
|
helpers.newtimer(timer_id, timeout, alsa.update)
|
||||||
|
|
||||||
return setmetatable(alsa, { __index = alsa.widget })
|
return alsa
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
return setmetatable(alsa, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -8,7 +8,6 @@
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local newtimer = require("lain.helpers").newtimer
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
local read_pipe = require("lain.helpers").read_pipe
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local first_line = require("lain.helpers").first_line
|
local first_line = require("lain.helpers").first_line
|
||||||
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
@ -27,7 +27,7 @@ local setmetatable = setmetatable
|
||||||
-- lain.widgets.bat
|
-- lain.widgets.bat
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local bat = {}
|
local bat = helpers.make_widget_textbox()
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 30
|
local timeout = args.timeout or 30
|
||||||
local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT0"}
|
local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT0"}
|
||||||
|
@ -35,8 +35,6 @@ local function worker(args)
|
||||||
local notify = args.notify or "on"
|
local notify = args.notify or "on"
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
bat.widget = wibox.widget.textbox('')
|
|
||||||
|
|
||||||
bat_notification_low_preset = {
|
bat_notification_low_preset = {
|
||||||
title = "Battery low",
|
title = "Battery low",
|
||||||
text = "Plug the cable!",
|
text = "Plug the cable!",
|
||||||
|
@ -165,9 +163,9 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(battery, timeout, bat.update)
|
helpers.newtimer(battery, timeout, bat.update)
|
||||||
|
|
||||||
return setmetatable(bat, { __index = bat.widget })
|
return bat
|
||||||
end
|
end
|
||||||
|
|
||||||
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
return setmetatable({}, { __call = function(_, ...) return worker(...) end })
|
||||||
|
|
|
@ -25,28 +25,26 @@ local cpu = { core = {} }
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 2
|
local timeout = args.timeout or 2
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
cpu.widget = wibox.widget.textbox('')
|
cpu.widget = wibox.widget.textbox('')
|
||||||
|
|
||||||
function update()
|
function update()
|
||||||
-- Read the amount of time the CPUs have spent performing
|
-- Read the amount of time the CPUs have spent performing
|
||||||
-- different kinds of work. Read the first line of /proc/stat
|
-- different kinds of work. Read the first line of /proc/stat
|
||||||
-- which is the sum of all CPUs.
|
-- which is the sum of all CPUs.
|
||||||
local times = lines_match("cpu","/proc/stat")
|
local times = lines_match("cpu","/proc/stat")
|
||||||
|
|
||||||
for index,time in pairs(times)
|
for index,time in pairs(times) do
|
||||||
do
|
|
||||||
local coreid = index - 1
|
local coreid = index - 1
|
||||||
local core = cpu.core[coreid] or
|
local core = cpu.core[coreid] or
|
||||||
{ last_active = 0 , last_total = 0, usage = 0 }
|
{ last_active = 0 , last_total = 0, usage = 0 }
|
||||||
local at = 1
|
local at = 1
|
||||||
local idle = 0
|
local idle = 0
|
||||||
local total = 0
|
local total = 0
|
||||||
|
|
||||||
for field in string.gmatch(time, "[%s]+([^%s]+)")
|
for field in string.gmatch(time, "[%s]+([^%s]+)") do
|
||||||
do
|
|
||||||
-- 4 = idle, 5 = ioWait. Essentially, the CPUs have done
|
-- 4 = idle, 5 = ioWait. Essentially, the CPUs have done
|
||||||
-- nothing during these times.
|
-- nothing during these times.
|
||||||
if at == 4 or at == 5 then
|
if at == 4 or at == 5 then
|
||||||
|
@ -62,15 +60,14 @@ local function worker(args)
|
||||||
-- Read current data and calculate relative values.
|
-- Read current data and calculate relative values.
|
||||||
local dactive = active - core.last_active
|
local dactive = active - core.last_active
|
||||||
local dtotal = total - core.last_total
|
local dtotal = total - core.last_total
|
||||||
|
local usage = math.ceil((dactive / dtotal) * 100)
|
||||||
local usage = math.ceil((dactive / dtotal) * 100)
|
|
||||||
|
|
||||||
core.last_active = active
|
core.last_active = active
|
||||||
core.last_total = total
|
core.last_total = total
|
||||||
core.usage = usage
|
core.usage = usage
|
||||||
|
|
||||||
-- Save current data for the next run.
|
-- Save current data for the next run.
|
||||||
cpu.core[coreid] = core;
|
cpu.core[coreid] = core
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -82,6 +79,7 @@ local function worker(args)
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer("cpu", timeout, update)
|
newtimer("cpu", timeout, update)
|
||||||
|
|
||||||
return cpu.widget
|
return cpu.widget
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue