Awesome configs for Ben.

This commit is contained in:
Derek Taylor
2023-04-05 14:32:50 -05:00
parent 1966d656c1
commit 6252ad30c1
608 changed files with 9300 additions and 3600 deletions

5
.config/awesome/lain/widget/alsa.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010, Adrian C. <anrxc@sysphere.org>
--]]
@@ -9,7 +9,8 @@
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local wibox = require("wibox")
local string = string
local string = { match = string.match,
format = string.format }
-- ALSA volume
-- lain.widget.alsa

47
.config/awesome/lain/widget/alsabar.lua Executable file → Normal file
View File

@@ -1,19 +1,20 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2013, Rman
--]]
local helpers = require("lain.helpers")
local awful = require("awful")
local naughty = require("naughty")
local wibox = require("wibox")
local math = math
local string = string
local type = type
local tonumber = tonumber
local helpers = require("lain.helpers")
local awful = require("awful")
local naughty = require("naughty")
local wibox = require("wibox")
local math = { modf = math.modf }
local string = { format = string.format,
match = string.match,
rep = string.rep }
local type, tonumber = type, tonumber
-- ALSA volume bar
-- lain.widget.alsabar
@@ -35,8 +36,6 @@ local function factory(args)
local settings = args.settings or function() end
local width = args.width or 63
local height = args.height or 1
local margins = args.margins or 1
local paddings = args.paddings or 1
local ticks = args.ticks or false
local ticks_size = args.ticks_size or 7
@@ -60,12 +59,12 @@ local function factory(args)
end
alsabar.bar = wibox.widget {
color = alsabar.colors.unmute,
background_color = alsabar.colors.background,
forced_height = height,
forced_width = width,
margins = margins,
paddings = margins,
color = alsabar.colors.unmute,
background_color = alsabar.colors.background,
margins = 1,
paddings = 1,
ticks = ticks,
ticks_size = ticks_size,
widget = wibox.widget.progressbar
@@ -114,23 +113,9 @@ local function factory(args)
preset.title = preset.title .. " Muted"
end
-- tot is the maximum number of ticks to display in the notification
-- fallback: default horizontal wibox height
local wib, tot = awful.screen.focused().mywibox, 20
-- if we can grab mywibox, tot is defined as its height if
-- horizontal, or width otherwise
if wib then
if wib.position == "left" or wib.position == "right" then
tot = wib.width
else
tot = wib.height
end
end
int = math.modf((alsabar._current_level / 100) * tot)
int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
preset.text = string.format("[%s%s]", string.rep("|", int),
string.rep(" ", tot - int))
string.rep(" ", awful.screen.focused().mywibox.height - int))
if alsabar.followtag then preset.screen = awful.screen.focused() end

108
.config/awesome/lain/widget/bat.lua Executable file → Normal file
View File

@@ -1,53 +1,36 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]
local helpers = require("lain.helpers")
local fs = require("gears.filesystem")
local naughty = require("naughty")
local wibox = require("wibox")
local math = math
local string = string
local ipairs = ipairs
local tonumber = tonumber
local first_line = require("lain.helpers").first_line
local newtimer = require("lain.helpers").newtimer
local naughty = require("naughty")
local wibox = require("wibox")
local math = { abs = math.abs,
floor = math.floor,
log10 = math.log10,
min = math.min }
local string = { format = string.format }
local ipairs = ipairs
local tonumber = tonumber
-- Battery infos
-- lain.widget.bat
local function factory(args)
local pspath = args.pspath or "/sys/class/power_supply/"
if not fs.is_dir(pspath) then
naughty.notify { text = "lain.widget.bat: invalid power supply path", timeout = 0 }
return
end
local bat = { widget = wibox.widget.textbox() }
local args = args or {}
local timeout = args.timeout or 30
local batteries = args.batteries or (args.battery and {args.battery}) or {"BAT1"}
local ac = args.ac or "AC0"
local notify = args.notify or "on"
local n_perc = args.n_perc or { 5, 15 }
local batteries = args.batteries or (args.battery and {args.battery}) or {}
local ac = args.ac or "AC0"
local settings = args.settings or function() end
function bat.get_batteries()
helpers.line_callback("ls -1 " .. pspath, function(line)
local bstr = string.match(line, "BAT%w+")
if bstr then
batteries[#batteries + 1] = bstr
else
ac = string.match(line, "A%w+") or "AC0"
end
end)
end
if #batteries == 0 then bat.get_batteries() end
bat_notification_critical_preset = {
title = "Battery exhausted",
text = "Shutdown imminent",
@@ -64,14 +47,6 @@ local function factory(args)
bg = "#CDCDCD"
}
bat_notification_charged_preset = {
title = "Battery full",
text = "You can unplug the cable",
timeout = 15,
fg = "#202020",
bg = "#CDCDCD"
}
bat_now = {
status = "N/A",
ac_status = "N/A",
@@ -87,9 +62,6 @@ local function factory(args)
bat_now.n_perc[i] = 0
end
-- used to notify full charge only once before discharging
local fullnotification = false
function bat.update()
local sum_rate_current = 0
local sum_rate_voltage = 0
@@ -97,29 +69,30 @@ local function factory(args)
local sum_rate_energy = 0
local sum_energy_now = 0
local sum_energy_full = 0
local pspath = "/sys/class/power_supply/"
for i, battery in ipairs(batteries) do
local bstr = pspath .. battery
local present = helpers.first_line(bstr .. "/present")
local present = first_line(bstr .. "/present")
if tonumber(present) == 1 then
-- current_now(I)[uA], voltage_now(U)[uV], power_now(P)[uW]
local rate_current = tonumber(helpers.first_line(bstr .. "/current_now"))
local rate_voltage = tonumber(helpers.first_line(bstr .. "/voltage_now"))
local rate_power = tonumber(helpers.first_line(bstr .. "/power_now"))
local rate_current = tonumber(first_line(bstr .. "/current_now"))
local rate_voltage = tonumber(first_line(bstr .. "/voltage_now"))
local rate_power = tonumber(first_line(bstr .. "/power_now"))
-- energy_now(P)[uWh], charge_now(I)[uAh]
local energy_now = tonumber(helpers.first_line(bstr .. "/energy_now") or
helpers.first_line(bstr .. "/charge_now"))
local energy_now = tonumber(first_line(bstr .. "/energy_now") or
first_line(bstr .. "/charge_now"))
-- energy_full(P)[uWh], charge_full(I)[uAh]
local energy_full = tonumber(helpers.first_line(bstr .. "/energy_full") or
helpers.first_line(bstr .. "/charge_full"))
local energy_full = tonumber(first_line(bstr .. "/energy_full") or
first_line(bstr .. "/charge_full"))
local energy_percentage = tonumber(helpers.first_line(bstr .. "/capacity")) or
local energy_percentage = tonumber(first_line(bstr .. "/capacity")) or
math.floor((energy_now / energy_full) * 100)
bat_now.n_status[i] = helpers.first_line(bstr .. "/status") or "N/A"
bat_now.n_status[i] = first_line(bstr .. "/status") or "N/A"
bat_now.n_perc[i] = energy_percentage or bat_now.n_perc[i]
sum_rate_current = sum_rate_current + (rate_current or 0)
@@ -141,7 +114,7 @@ local function factory(args)
bat_now.status = status
end
end
bat_now.ac_status = tonumber(helpers.first_line(string.format("%s%s/online", pspath, ac))) or "N/A"
bat_now.ac_status = tonumber(first_line(string.format("%s%s/online", pspath, ac))) or "N/A"
if bat_now.status ~= "N/A" then
if bat_now.status ~= "Full" and sum_rate_power == 0 and bat_now.ac_status == 1 then
@@ -183,32 +156,23 @@ local function factory(args)
widget = bat.widget
settings()
-- notifications for critical, low, and full levels
if notify == "on" then
if bat_now.status == "Discharging" then
if tonumber(bat_now.perc) <= n_perc[1] then
bat.id = naughty.notify({
preset = bat_notification_critical_preset,
replaces_id = bat.id
}).id
elseif tonumber(bat_now.perc) <= n_perc[2] then
bat.id = naughty.notify({
preset = bat_notification_low_preset,
replaces_id = bat.id
}).id
end
fullnotification = false
elseif bat_now.status == "Full" and not fullnotification then
-- notifications for critical and low levels
if notify == "on" and bat_now.status == "Discharging" then
if tonumber(bat_now.perc) <= n_perc[1] then
bat.id = naughty.notify({
preset = bat_notification_charged_preset,
preset = bat_notification_critical_preset,
replaces_id = bat.id
}).id
elseif tonumber(bat_now.perc) <= n_perc[2] then
bat.id = naughty.notify({
preset = bat_notification_low_preset,
replaces_id = bat.id
}).id
fullnotification = true
end
end
end
helpers.newtimer("batteries", timeout, bat.update)
newtimer("batteries", timeout, bat.update)
return bat
end

View File

@@ -1,130 +0,0 @@
--[[
Licensed under GNU General Public License v2
* (c) 2018, Luca CPZ
--]]
local helpers = require("lain.helpers")
local markup = require("lain.util.markup")
local awful = require("awful")
local naughty = require("naughty")
local floor = math.floor
local os = os
local pairs = pairs
local string = string
local tconcat = table.concat
local tonumber = tonumber
local tostring = tostring
-- Calendar notification
-- lain.widget.cal
local function factory(args)
args = args or {}
local cal = {
attach_to = args.attach_to or {},
week_start = args.week_start or 2,
three = args.three or false,
followtag = args.followtag or false,
icons = args.icons or helpers.icons_dir .. "cal/white/",
notification_preset = args.notification_preset or {
font = "Monospace 10", fg = "#FFFFFF", bg = "#000000"
}
}
function cal.build(month, year)
local current_month, current_year = tonumber(os.date("%m")), tonumber(os.date("%Y"))
local is_current_month = (not month or not year) or (month == current_month and year == current_year)
local today = is_current_month and tonumber(os.date("%d")) -- otherwise nil and not highlighted
local t = os.time { year = year or current_year, month = month and month+1 or current_month+1, day = 0 }
local d = os.date("*t", t)
local mth_days, st_day, this_month = d.day, (d.wday-d.day-cal.week_start+1)%7, os.date("%B %Y", t)
local notifytable = { [1] = string.format("%s%s\n", string.rep(" ", floor((28 - this_month:len())/2)), markup.bold(this_month)) }
for x = 0,6 do notifytable[#notifytable+1] = os.date("%a ", os.time { year=2006, month=1, day=x+cal.week_start }) end
notifytable[#notifytable] = string.format("%s\n%s", notifytable[#notifytable]:sub(1, -2), string.rep(" ", st_day*4))
for x = 1,mth_days do
local strx = x ~= today and x or markup.bold(markup.color(cal.notification_preset.bg, cal.notification_preset.fg, x) .. " ")
strx = string.format("%s%s", string.rep(" ", 3 - tostring(x):len()), strx)
notifytable[#notifytable+1] = string.format("%-4s%s", strx, (x+st_day)%7==0 and x ~= mth_days and "\n" or "")
end
if string.len(cal.icons or "") > 0 and today then cal.icon = cal.icons .. today .. ".png" end
cal.month, cal.year = d.month, d.year
return notifytable
end
function cal.getdate(month, year, offset)
if not month or not year then
month = tonumber(os.date("%m"))
year = tonumber(os.date("%Y"))
end
month = month + offset
while month > 12 do
month = month - 12
year = year + 1
end
while month < 1 do
month = month + 12
year = year - 1
end
return month, year
end
function cal.hide()
if not cal.notification then return end
naughty.destroy(cal.notification)
cal.notification = nil
end
function cal.show(timeout, month, year, scr)
cal.notification_preset.text = tconcat(cal.build(month, year))
if cal.three then
local current_month, current_year = cal.month, cal.year
local prev_month, prev_year = cal.getdate(cal.month, cal.year, -1)
local next_month, next_year = cal.getdate(cal.month, cal.year, 1)
cal.notification_preset.text = string.format("%s\n\n%s\n\n%s",
tconcat(cal.build(prev_month, prev_year)), cal.notification_preset.text,
tconcat(cal.build(next_month, next_year)))
cal.month, cal.year = current_month, current_year
end
cal.hide()
cal.notification = naughty.notify {
preset = cal.notification_preset,
screen = cal.followtag and awful.screen.focused() or scr or 1,
icon = cal.icon,
timeout = timeout or cal.notification_preset.timeout or 5
}
end
function cal.hover_on() cal.show(0) end
function cal.move(offset)
local offset = offset or 0
cal.month, cal.year = cal.getdate(cal.month, cal.year, offset)
cal.show(0, cal.month, cal.year)
end
function cal.prev() cal.move(-1) end
function cal.next() cal.move( 1) end
function cal.attach(widget)
widget:connect_signal("mouse::enter", cal.hover_on)
widget:connect_signal("mouse::leave", cal.hide)
widget:buttons(awful.util.table.join(
awful.button({}, 1, cal.prev),
awful.button({}, 3, cal.next),
awful.button({}, 2, cal.hover_on),
awful.button({}, 5, cal.prev),
awful.button({}, 4, cal.next)))
end
for _, widget in pairs(cal.attach_to) do cal.attach(widget) end
return cal
end
return factory

View File

@@ -0,0 +1,127 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luke Bonham
--]]
local helpers = require("lain.helpers")
local markup = require("lain.util.markup")
local awful = require("awful")
local naughty = require("naughty")
local mouse = mouse
local os = { date = os.date }
local string = { format = string.format,
gsub = string.gsub }
local ipairs = ipairs
local tonumber = tonumber
local setmetatable = setmetatable
-- Calendar notification
-- lain.widget.calendar
local calendar = { offset = 0 }
function calendar.hide()
if not calendar.notification then return end
naughty.destroy(calendar.notification)
calendar.notification = nil
end
function calendar.show(t_out, inc_offset, scr)
local f, offs = nil, inc_offset or 0
calendar.notification_preset.screen = scr or (calendar.followtag and awful.screen.focused()) or 1
calendar.offset = calendar.offset + offs
local current_month = (offs == 0 or calendar.offset == 0)
if current_month then -- today highlighted
calendar.offset = 0
calendar.icon = calendar.icons:len() > 0 and string.format("%s%s.png", calendar.icons, tonumber(os.date("%d")))
f = calendar.cal
else -- no current month showing, no day to highlight
local month = tonumber(os.date("%m"))
local year = tonumber(os.date("%Y"))
month = month + calendar.offset
while month > 12 do
month = month - 12
year = year + 1
end
while month < 1 do
month = month + 12
year = year - 1
end
calendar.icon = nil
f = string.format("%s %s %s", calendar.cal, month, year)
end
helpers.async(f, function(ws)
local fg, bg = calendar.notification_preset.fg, calendar.notification_preset.bg
calendar.notification_preset.text = ws:gsub("%c%[%d+[m]?%s?%d+%c%[%d+[m]?",
markup.bold(markup.color(bg, fg, os.date("%e")))):gsub("\n*$", "")
local widget_focused = true
if t_out == 0 and mouse.current_widgets then
widget_focused = false
for i, widget in ipairs(calendar.attach_to) do
for _,v in ipairs(mouse.current_widgets) do
if widget == v then
widget_focused = true
break
end
end
end
end
if widget_focused then
calendar.hide()
calendar.notification = naughty.notify({
preset = calendar.notification_preset,
icon = calendar.icon,
timeout = t_out or calendar.notification_preset.timeout or 5
})
end
end)
end
function calendar.hover_on() calendar.show(0) end
function calendar.hover_off() calendar.hide() end
function calendar.prev() calendar.show(0, -1) end
function calendar.next() calendar.show(0, 1) end
function calendar.attach(widget)
widget:connect_signal("mouse::enter", calendar.hover_on)
widget:connect_signal("mouse::leave", calendar.hover_off)
widget:buttons(awful.util.table.join(
awful.button({}, 1, calendar.prev),
awful.button({}, 3, calendar.next),
awful.button({}, 2, calendar.hover_on),
awful.button({}, 4, calendar.prev),
awful.button({}, 5, calendar.next)))
end
local function factory(args)
local args = args or {}
calendar.cal = args.cal or "/usr/bin/cal"
calendar.attach_to = args.attach_to or {}
calendar.followtag = args.followtag or false
calendar.icons = args.icons or helpers.icons_dir .. "cal/white/"
calendar.notification_preset = args.notification_preset
if not calendar.notification_preset then
calendar.notification_preset = {
font = "Monospace 10",
fg = "#FFFFFF",
bg = "#000000"
}
end
for i, widget in ipairs(calendar.attach_to) do calendar.attach(widget) end
end
return setmetatable(calendar, { __call = function(_, ...) return factory(...) end })

2
.config/awesome/lain/widget/contrib/init.lua Executable file → Normal file
View File

@@ -6,7 +6,7 @@
Users contributed widgets section
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
--]]

View File

@@ -0,0 +1,77 @@
--[[
Licensed under GNU General Public License v2
* (c) 2015, Dario Gjorgjevski
--]]
local helpers = require("lain.helpers")
local awful = require("awful")
local wibox = require("wibox")
local string = { format = string.format,
match = string.match }
local execute = os.execute
local setmetatable = setmetatable
-- Keyboard layout switcher
-- lain.widget.contrib.kblayout
local function factory(args)
local kbdlayout = { widget = wibox.widget.textbox() }
local args = args or {}
local layouts = args.layouts or {}
local settings = args.settings or function () end
local add_us_secondary = true
local timeout = args.timeout or 5
local idx = 1
if args.add_us_secondary == false then add_us_secondary = false end
local function kbd_run_settings(layout, variant)
kbdlayout_now = {
layout = string.match(layout, "[^,]+"), -- Make sure to match the primary layout only.
variant = variant
}
widget = kbdlayout.widget
settings()
end
function kbdlayout.update()
helpers.async("setxkbmap -query", function(status)
kbd_run_settings(string.match(status, "layout:%s*([^\n]*)"),
string.match(status, "variant:%s*([^\n]*)"))
end)
end
function kbdlayout.set(i)
if #layouts == 0 then return end
idx = ((i - 1) % #layouts) + 1 -- Make sure to wrap around as needed.
local to_execute = "setxkbmap " .. layouts[idx].layout
if add_us_secondary and not string.match(layouts[idx].layout, ",?us,?") then
to_execute = to_execute .. ",us"
end
if layouts[idx].variant then
to_execute = to_execute .. " " .. layouts[idx].variant
end
if execute(to_execute) then
kbd_run_settings(layouts[idx].layout, layouts[idx].variant)
end
end
function kbdlayout.next() kbdlayout.set(idx + 1) end
function kbdlayout.prev() kbdlayout.set(idx - 1) end
-- Mouse bindings
kbdlayout.widget:buttons(awful.util.table.join(
awful.button({ }, 1, function () kbdlayout.next() end),
awful.button({ }, 3, function () kbdlayout.prev() end)))
helpers.newtimer("kbdlayout", timeout, kbdlayout.update)
return kbdlayout
end
return factory

5
.config/awesome/lain/widget/contrib/moc.lua Executable file → Normal file
View File

@@ -11,8 +11,9 @@ local focused = require("awful.screen").focused
local escape_f = require("awful.util").escape
local naughty = require("naughty")
local wibox = require("wibox")
local os = os
local string = string
local os = { getenv = os.getenv }
local string = { format = string.format,
gmatch = string.gmatch }
-- MOC audio player
-- lain.widget.contrib.moc

1
.config/awesome/lain/widget/contrib/redshift.lua Executable file → Normal file
View File

@@ -1,7 +1,6 @@
--[[
Licensed under GNU General Public License v2
* (c) 2017, Luca CPZ
* (c) 2014, blueluke <http://github.com/blueluke>
--]]

21
.config/awesome/lain/widget/contrib/task.lua Executable file → Normal file
View File

@@ -10,7 +10,7 @@ local markup = require("lain.util").markup
local awful = require("awful")
local naughty = require("naughty")
local mouse = mouse
local string = string
local string = { format = string.format, gsub = string.gsub }
-- Taskwarrior notification
-- lain.widget.contrib.task
@@ -23,7 +23,12 @@ function task.hide()
end
function task.show(scr)
task.notification_preset.screen = task.followtag and awful.screen.focused() or scr or 1
if task.followtag then
task.notification_preset.screen = awful.screen.focused()
elseif scr then
task.notification_preset.screen = scr
end
helpers.async({ awful.util.shell, "-c", task.show_cmd }, function(f)
local widget_focused = true
@@ -40,12 +45,12 @@ function task.show(scr)
if widget_focused then
task.hide()
task.notification = naughty.notify {
preset = task.notification_preset,
title = "task next",
text = markup.font(task.notification_preset.font,
awful.util.escape(f:gsub("\n*$", "")))
}
task.notification = naughty.notify({
preset = task.notification_preset,
title = "task next",
text = markup.font(task.notification_preset.font,
awful.util.escape(f:gsub("\n*$", "")))
})
end
end)
end

View File

@@ -1,146 +0,0 @@
--[[
Licensed under GNU General Public License v2
* (c) 2018, Luca CPZ
* (c) 2013, Conor Heine
--]]
local helpers = require("lain.helpers")
local focused = require("awful.screen").focused
local gears = require("gears")
local naughty = require("naughty")
local wibox = require("wibox")
local string = string
-- ThinkPad battery infos and widget creator
-- http://www.thinkwiki.org/wiki/Tp_smapi
-- lain.widget.contrib.tp_smapi
local function factory(apipath)
local tp_smapi = {
path = apipath or "/sys/devices/platform/smapi"
}
function tp_smapi.get(batid, feature)
return helpers.first_line(string.format("%s/%s/%s", tp_smapi.path, batid or "BAT0", feature or ""))
end
function tp_smapi.installed(batid)
return tp_smapi.get(batid, "installed") == "1"
end
function tp_smapi.status(batid)
return tp_smapi.get(batid, "state")
end
function tp_smapi.percentage(batid)
return tp_smapi.get(batid, "remaining_percent")
end
-- either running or charging time
function tp_smapi.time(batid)
local status = tp_smapi.status(batid)
local mins_left = tp_smapi.get(batid, string.match(string.lower(status), "discharging") and "remaining_running_time" or "remaining_charging_time")
if not string.find(mins_left, "^%d+") then return "N/A" end
return string.format("%02d:%02d", math.floor(mins_left / 60), mins_left % 60) -- HH:mm
end
function tp_smapi.hide()
if not tp_smapi.notification then return end
naughty.destroy(tp_smapi.notification)
tp_smapi.notification = nil
end
function tp_smapi.show(batid, seconds, scr)
if not tp_smapi.installed(batid) then return end
local mfgr = tp_smapi.get(batid, "manufacturer") or "no_mfgr"
local model = tp_smapi.get(batid, "model") or "no_model"
local chem = tp_smapi.get(batid, "chemistry") or "no_chem"
local status = tp_smapi.get(batid, "state")
local time = tp_smapi.time(batid)
local msg = ""
if status and status ~= "idle" then
msg = string.format("[%s] %s %s", status, time ~= "N/A" and time or "unknown remaining time",
string.lower(status):gsub(" ", ""):gsub("\n", "") == "charging" and " until charged" or " remaining")
else
msg = "On AC power"
end
tp_smapi.hide()
tp_smapi.notification = naughty.notify {
title = string.format("%s: %s %s (%s)", batid, mfgr, model, chem),
text = msg,
timeout = seconds or 0,
screen = scr or focused()
}
end
function tp_smapi.create_widget(args)
local args = args or {}
local pspath = args.pspath or "/sys/class/power_supply/"
local batteries = args.batteries or (args.battery and {args.battery}) or {}
local timeout = args.timeout or 30
local settings = args.settings or function() end
if #batteries == 0 then
helpers.line_callback("ls -1 " .. pspath, function(line)
local bstr = string.match(line, "BAT%w+")
if bstr then batteries[#batteries + 1] = bstr end
end)
end
local all_batteries_installed = true
for i, battery in ipairs(batteries) do
if not tp_smapi.installed(battery) then
naughty.notify {
preset = naughty.config.critical,
title = "tp_smapi: error while creating widget",
text = string.format("battery %s is not installed", battery)
}
all_batteries_installed = false
break
end
end
if not all_batteries_installed then return end
tpbat = {
batteries = batteries,
widget = args.widget or wibox.widget.textbox()
}
function tpbat.update()
tpbat_now = {
n_status = {},
n_perc = {},
n_time = {},
status = "N/A"
}
for i = 1, #batteries do
tpbat_now.n_status[i] = tp_smapi.status(batteries[i]) or "N/A"
tpbat_now.n_perc[i] = tp_smapi.percentage(batteries[i])
tpbat_now.n_time[i] = tp_smapi.time(batteries[i]) or "N/A"
if not tpbat_now.n_status[i]:lower():match("full") then
tpbat_now.status = tpbat_now.n_status[i]
end
end
widget = tpbat.widget -- backwards compatibility
settings()
end
helpers.newtimer("thinkpad-batteries", timeout, tpbat.update)
return tpbat
end
return tp_smapi
end
return factory

View File

@@ -0,0 +1,161 @@
--[[
tpbat.lua
Battery status widget for ThinkPad laptops that use SMAPI
lain.widget.contrib.tpbat
More on tp_smapi: http://www.thinkwiki.org/wiki/Tp_smapi
Licensed under GNU General Public License v2
* (c) 2013, Conor Heine
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]
local debug = { getinfo = debug.getinfo }
local newtimer = require("lain.helpers").newtimer
local first_line = require("lain.helpers").first_line
local naughty = require("naughty")
local wibox = require("wibox")
local string = { format = string.format }
local math = { floor = math.floor }
local tostring = tostring
local setmetatable = setmetatable
package.path = debug.getinfo(1,"S").source:match[[^@?(.*[\/])[^\/]-$]] .. "?.lua;" .. package.path
local smapi = require("smapi")
-- ThinkPad SMAPI-enabled battery info widget
-- lain.widget.contrib.tpbat
local tpbat = {}
function tpbat.hide()
if not tpbat.notification then return end
naughty.destroy(tpbat.notification)
tpbat.notification = nil
end
function tpbat.show(t_out)
tpbat.hide()
local bat = tpbat.bat
if bat == nil or not bat:installed() then return end
local t_out = t_out or 0
local mfgr = bat:get('manufacturer') or "no_mfgr"
local model = bat:get('model') or "no_model"
local chem = bat:get('chemistry') or "no_chem"
local status = bat:get('state') or "nil"
local time = bat:remaining_time()
local msg = "\t"
if status ~= "idle" and status ~= "nil" then
if time == "N/A" then
msg = "...Calculating time remaining..."
else
msg = time .. (status == "charging" and " until charged" or " remaining")
end
else
msg = "On AC Power"
end
local str = string.format("%s : %s %s (%s)\n", bat.name, mfgr, model, chem)
.. string.format("\n%s \t\t\t %s", status:upper(), msg)
tpbat.notification = naughty.notify({
text = str,
timeout = t_out,
screen = client.focus and client.focus.screen or 1
})
end
function tpbat.register(args)
local args = args or {}
local timeout = args.timeout or 30
local battery = args.battery or "BAT0"
local settings = args.settings or function() end
tpbat.bat = smapi:battery(battery) -- Create a new battery
local bat = tpbat.bat
tpbat.widget = wibox.widget.textbox()
bat_notification_low_preset = {
title = "Battery low",
text = "Plug the cable!",
timeout = 15,
fg = "#202020",
bg = "#CDCDCD"
}
bat_notification_critical_preset = {
title = "Battery exhausted",
text = "Shutdown imminent",
timeout = 15,
fg = "#000000",
bg = "#FFFFFF"
}
if bat:get('state') == nil
then
local n = naughty.notify({
preset = bat_notification_low_preset,
title = "SMAPI Battery Warning: Unable to read battery state!",
text = "This widget is intended for ThinkPads. Is tp_smapi installed? Check your configs & paths.",
screen = client.focus and client.focus.screen or 1
})
end
function tpbat.update()
bat_now = {
status = "Not present",
perc = "N/A",
time = "N/A",
watt = "N/A"
}
if bat:installed()
then
bat_now.status = bat:status() or "N/A"
bat_now.perc = bat:percent()
bat_now.time = bat:remaining_time()
-- bat_now.watt = string.format("%.2fW", (VOLTS * AMPS) / 1e12)
-- notifications for low and critical states (when discharging)
if bat_now.status == "discharging"
then
if bat_now.perc <= 5
then
tpbat.id = naughty.notify({
preset = bat_notification_critical_preset,
replaces_id = tpbat.id,
screen = client.focus and client.focus.screen or 1
}).id
elseif bat_now.perc <= 15
then
tpbat.id = naughty.notify({
preset = bat_notification_low_preset,
replaces_id = tpbat.id,
screen = client.focus and client.focus.screen or 1
}).id
end
end
bat_now.perc = tostring(bat_now.perc)
end
widget = tpbat.widget
settings()
end
newtimer("tpbat-" .. bat.name, timeout, tpbat.update)
widget:connect_signal('mouse::enter', function () tpbat.show() end)
widget:connect_signal('mouse::leave', function () tpbat.hide() end)
return tpbat
end
return setmetatable(tpbat, { __call = function(_, ...) return tpbat.register(...) end })

View File

@@ -0,0 +1,98 @@
--[[
smapi.lua
Interface with thinkpad battery information
Licensed under GNU General Public License v2
* (c) 2013, Conor Heine
--]]
local first_line = require("lain.helpers").first_line
local string = { format = string.format }
local tonumber = tonumber
local setmetatable = setmetatable
local smapi = {}
local apipath = "/sys/devices/platform/smapi"
-- Most are readable values, but some can be written to (not implemented, yet?)
local readable = {
barcoding = true,
charging_max_current = true,
charging_max_voltage = true,
chemistry = true,
current_avg = true,
current_now = true,
cycle_count = true,
design_capacity = true,
design_voltage = true,
dump = true,
first_use_date = true,
force_discharge = false,
group0_voltage = true,
group1_voltage = true,
group2_voltage = true,
group3_voltage = true,
inhibit_charge_minutes = false,
installed = true,
last_full_capacity = true,
manufacture_date = true,
manufacturer = true,
model = true,
power_avg = true,
power_now = true,
remaining_capacity = true,
remaining_charging_time = true,
remaining_percent = true,
remaining_percent_error = true,
remaining_running_time = true,
remaining_running_time_now = true,
serial = true,
start_charge_thresh = false,
state = true,
stop_charge_thresh = false,
temperature = true,
voltage = true
}
function smapi:battery(name)
local bat = {}
bat.name = name
bat.path = apipath .. "/" .. name
function bat:get(item)
return self.path ~= nil and readable[item] and first_line(self.path .. "/" .. item) or nil
end
function bat:installed()
return self:get("installed") == "1"
end
function bat:status()
return self:get('state')
end
-- Remaining time can either be time until battery dies or time until charging completes
function bat:remaining_time()
local time_val = bat_now.status == 'discharging' and 'remaining_running_time' or 'remaining_charging_time'
local mins_left = self:get(time_val)
if not mins_left:find("^%d+") then return "N/A" end
local hrs = math.floor(mins_left / 60)
local min = mins_left % 60
return string.format("%02d:%02d", hrs, min)
end
function bat:percent()
return tonumber(self:get("remaining_percent"))
end
return setmetatable(bat, {__metatable = false, __newindex = false})
end
return smapi

7
.config/awesome/lain/widget/cpu.lua Executable file → Normal file
View File

@@ -1,15 +1,16 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]
local helpers = require("lain.helpers")
local wibox = require("wibox")
local math = math
local string = string
local math = { ceil = math.ceil }
local string = { format = string.format,
gmatch = string.gmatch }
local tostring = tostring
-- CPU usage

150
.config/awesome/lain/widget/fs.lua Executable file → Normal file
View File

@@ -1,38 +1,23 @@
--[[
Licensed under GNU General Public License v2
* (c) 2018, Uli Schlacter
* (c) 2018, Otto Modinos
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
--]]
local helpers = require("lain.helpers")
local Gio = require("lgi").Gio
local focused = require("awful.screen").focused
local wibox = require("wibox")
local naughty = require("naughty")
local math = math
local string = string
local tconcat = table.concat
local tonumber = tonumber
local query_size = Gio.FILE_ATTRIBUTE_FILESYSTEM_SIZE
local query_free = Gio.FILE_ATTRIBUTE_FILESYSTEM_FREE
local query_used = Gio.FILE_ATTRIBUTE_FILESYSTEM_USED
local query = query_size .. "," .. query_free .. "," .. query_used
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local focused = require("awful.screen").focused
local wibox = require("wibox")
local naughty = require("naughty")
local string = string
local tonumber = tonumber
-- File systems info
-- File system disk space usage
-- lain.widget.fs
local function factory(args)
local fs = {
widget = wibox.widget.textbox(),
units = {
[1] = "Kb", [2] = "Mb", [3] = "Gb",
[4] = "Tb", [5] = "Pb", [6] = "Eb",
[7] = "Zb", [8] = "Yb"
}
}
local fs = { unit = { ["mb"] = 1024, ["gb"] = 1024^2 }, widget = wibox.widget.textbox() }
function fs.hide()
if not fs.notification then return end
@@ -41,21 +26,29 @@ local function factory(args)
end
function fs.show(seconds, scr)
fs.hide(); fs.update()
fs.notification_preset.screen = fs.followtag and focused() or scr or 1
fs.notification = naughty.notify {
fs.update()
fs.hide()
if fs.followtag then
fs.notification_preset.screen = focused()
else
fs.notification_preset.screen = scr or 1
end
fs.notification = naughty.notify({
preset = fs.notification_preset,
timeout = seconds or 5
}
})
end
local args = args or {}
local timeout = args.timeout or 600
local partition = args.partition
local threshold = args.threshold or 99
local showpopup = args.showpopup or "on"
local settings = args.settings or function() end
local args = args or {}
local timeout = args.timeout or 600
local partition = args.partition or "/"
local showpopup = args.showpopup or "on"
local notify = args.notify or "on"
local settings = args.settings or function() end
fs.options = args.options
fs.followtag = args.followtag or false
fs.notification_preset = args.notification_preset
@@ -67,67 +60,54 @@ local function factory(args)
}
end
helpers.set_map(partition, false)
function fs.update()
local notifytable = { [1] = string.format("%-10s %-5s %s\t%s\t\n", "path", "used", "free", "size") }
local pathlen = 10
fs_now = {}
fs_info, fs_now = {}, {}
helpers.async({ shell, "-c", "/usr/bin/env LC_ALL=C df -k --output=target,size,used,avail,pcent" }, function(f)
for line in string.gmatch(f, "\n[^\n]+") do
local m,s,u,a,p = string.match(line, "(/.-%s).-(%d+).-(%d+).-(%d+).-([%d]+)%%")
m = m:gsub(" ", "") -- clean target from any whitespace
for _, mount in ipairs(Gio.unix_mounts_get()) do
local path = Gio.unix_mount_get_mount_path(mount)
local root = Gio.File.new_for_path(path)
local info = root:query_filesystem_info(query)
if info then
local size = info:get_attribute_uint64(query_size)
local used = info:get_attribute_uint64(query_used)
local free = info:get_attribute_uint64(query_free)
if size > 0 then
local units = math.floor(math.log(size)/math.log(1024))
fs_now[path] = {
units = fs.units[units],
percentage = math.floor(100 * used / size), -- used percentage
size = size / math.pow(1024, math.floor(units)),
used = used / math.pow(1024, math.floor(units)),
free = free / math.pow(1024, math.floor(units))
}
if fs_now[path].percentage > 0 then -- don't notify unused file systems
notifytable[#notifytable+1] = string.format("\n%-10s %-5s %.2f\t%.2f\t%s", path,
fs_now[path].percentage .. "%", fs_now[path].free, fs_now[path].size,
fs_now[path].units)
pathlen = math.max(pathlen, #path)
end
end
fs_info[m .. " size_mb"] = string.format("%.1f", tonumber(s) / fs.unit["mb"])
fs_info[m .. " size_gb"] = string.format("%.1f", tonumber(s) / fs.unit["gb"])
fs_info[m .. " used_mb"] = string.format("%.1f", tonumber(u) / fs.unit["mb"])
fs_info[m .. " used_gb"] = string.format("%.1f", tonumber(u) / fs.unit["gb"])
fs_info[m .. " used_p"] = p
fs_info[m .. " avail_mb"] = string.format("%.1f", tonumber(a) / fs.unit["mb"])
fs_info[m .. " avail_gb"] = string.format("%.1f", tonumber(a) / fs.unit["gb"])
fs_info[m .. " avail_p"] = string.format("%d", 100 - tonumber(p))
end
end
widget = fs.widget
settings()
fs_now.size_mb = fs_info[partition .. " size_mb"] or "N/A"
fs_now.size_gb = fs_info[partition .. " size_gb"] or "N/A"
fs_now.used = fs_info[partition .. " used_p"] or "N/A"
fs_now.used_mb = fs_info[partition .. " used_mb"] or "N/A"
fs_now.used_gb = fs_info[partition .. " used_gb"] or "N/A"
fs_now.available = fs_info[partition .. " avail_p"] or "N/A"
fs_now.available_mb = fs_info[partition .. " avail_mb"] or "N/A"
fs_now.available_gb = fs_info[partition .. " avail_gb"] or "N/A"
if partition and fs_now[partition] and fs_now[partition].percentage >= threshold then
if not helpers.get_map(partition) then
naughty.notify {
notification_preset = fs.notification_preset
widget = fs.widget
settings()
if notify == "on" and tonumber(fs_now.used) and tonumber(fs_now.used) >= 99 and not helpers.get_map(partition) then
naughty.notify({
preset = naughty.config.presets.critical,
title = "Warning",
text = string.format("%s is above %d%% (%d%%)", partition, threshold, fs_now[partition].percentage)
}
text = partition .. " is full",
})
helpers.set_map(partition, true)
else
helpers.set_map(partition, false)
end
end
end)
if pathlen > 10 then -- formatting aesthetics
for i = 1, #notifytable do
local pathspaces = notifytable[i]:match("/%w*[/%w*]*%s*") or notifytable[i]:match("path%s*")
notifytable[i] = notifytable[i]:gsub(pathspaces, pathspaces .. string.rep(" ", pathlen - 10) .. "\t")
end
end
fs.notification_preset.text = tconcat(notifytable)
local notifycmd = (fs.options and string.format("dfs %s", fs.options)) or "dfs"
helpers.async(helpers.scripts_dir .. notifycmd, function(ws)
fs.notification_preset.text = ws:gsub("\n*$", "")
end)
end
if showpopup == "on" then
@@ -135,7 +115,7 @@ local function factory(args)
fs.widget:connect_signal('mouse::leave', function () fs.hide() end)
end
helpers.newtimer(partition or "fs", timeout, fs.update)
helpers.newtimer(partition, timeout, fs.update)
return fs
end

83
.config/awesome/lain/widget/imap.lua Executable file → Normal file
View File

@@ -1,15 +1,15 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
--]]
local helpers = require("lain.helpers")
local naughty = require("naughty")
local wibox = require("wibox")
local awful = require("awful")
local string = string
local string = { format = string.format,
gsub = string.gsub }
local type = type
local tonumber = tonumber
@@ -17,75 +17,66 @@ local tonumber = tonumber
-- lain.widget.imap
local function factory(args)
local imap = { widget = wibox.widget.textbox() }
local args = args or {}
local server = args.server
local mail = args.mail
local password = args.password
local port = args.port or 993
local timeout = args.timeout or 60
local pwdtimeout = args.pwdtimeout or 10
local is_plain = args.is_plain or false
local followtag = args.followtag or false
local notify = args.notify or "on"
local settings = args.settings or function() end
local imap = { widget = wibox.widget.textbox() }
local args = args or {}
local server = args.server
local mail = args.mail
local password = args.password
local port = args.port or 993
local timeout = args.timeout or 60
local is_plain = args.is_plain or false
local followtag = args.followtag or false
local notify = args.notify or "on"
local settings = args.settings or function() end
local head_command = "curl --connect-timeout 3 -fsm 3"
local request = "-X 'STATUS INBOX (MESSAGES RECENT UNSEEN)'"
local request = "-X 'SEARCH (UNSEEN)'"
if not server or not mail or not password then return end
mail_notification_preset = {
icon = helpers.icons_dir .. "mail.png",
position = "top_left"
}
helpers.set_map(mail, 0)
if not is_plain then
if type(password) == "string" or type(password) == "table" then
helpers.async(password, function(f) password = f:gsub("\n", "") end)
elseif type(password) == "function" then
imap.pwdtimer = helpers.newtimer(mail .. "-password", pwdtimeout, function()
local retrieved_password, try_again = password()
if not try_again then
imap.pwdtimer:stop() -- stop trying to retrieve
password = retrieved_password or "" -- failsafe
end
end, true, true)
local p = password()
end
end
function imap.update()
-- do not update if the password has not been retrieved yet
if type(password) ~= "string" then return end
function update()
mail_notification_preset = {
icon = helpers.icons_dir .. "mail.png",
position = "top_left"
}
local curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:'%s' %s -k",
head_command, server, port, mail, password, request)
if followtag then
mail_notification_preset.screen = awful.screen.focused()
end
curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
head_command, server, port, mail, password, request)
helpers.async(curl, function(f)
imap_now = { ["MESSAGES"] = 0, ["RECENT"] = 0, ["UNSEEN"] = 0 }
for s,d in f:gmatch("(%w+)%s+(%d+)") do imap_now[s] = tonumber(d) end
mailcount = imap_now["UNSEEN"] -- backwards compatibility
_, mailcount = string.gsub(f, "%d+", "")
widget = imap.widget
settings()
if notify == "on" and mailcount and mailcount >= 1 and mailcount > helpers.get_map(mail) then
if followtag then mail_notification_preset.screen = awful.screen.focused() end
naughty.notify {
preset = mail_notification_preset,
text = string.format("%s has <b>%d</b> new message%s", mail, mailcount, mailcount == 1 and "" or "s")
}
if notify == "on" and mailcount >= 1 and mailcount > helpers.get_map(mail) then
if mailcount == 1 then
nt = mail .. " has one new message"
else
nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
end
naughty.notify { preset = mail_notification_preset, text = nt }
end
helpers.set_map(mail, imap_now["UNSEEN"])
helpers.set_map(mail, mailcount)
end)
end
imap.timer = helpers.newtimer(mail, timeout, imap.update, true, true)
imap.timer = helpers.newtimer(mail, timeout, update, true, true)
return imap
end

2
.config/awesome/lain/widget/init.lua Executable file → Normal file
View File

@@ -6,7 +6,7 @@
Widgets section
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]

2
.config/awesome/lain/widget/mem.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]

20
.config/awesome/lain/widget/mpd.lua Executable file → Normal file
View File

@@ -1,19 +1,21 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010, Adrian C. <anrxc@sysphere.org>
--]]
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local escape_f = require("awful.util").escape
local focused = require("awful.screen").focused
local naughty = require("naughty")
local wibox = require("wibox")
local os = os
local string = string
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local escape_f = require("awful.util").escape
local focused = require("awful.screen").focused
local naughty = require("naughty")
local wibox = require("wibox")
local os = { getenv = os.getenv }
local string = { format = string.format,
gmatch = string.gmatch,
match = string.match }
-- MPD infos
-- lain.widget.mpd

40
.config/awesome/lain/widget/net.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]
@@ -9,29 +9,28 @@
local helpers = require("lain.helpers")
local naughty = require("naughty")
local wibox = require("wibox")
local string = string
local string = { format = string.format, match = string.match }
-- Network infos
-- lain.widget.net
local function factory(args)
local net = { widget = wibox.widget.textbox(), devices = {} }
local args = args or {}
local timeout = args.timeout or 2
local units = args.units or 1024 -- KB
local notify = args.notify or "on"
local wifi_state = args.wifi_state or "off"
local eth_state = args.eth_state or "off"
local screen = args.screen or 1
local settings = args.settings or function() end
local net = { widget = wibox.widget.textbox(), devices = {} }
local args = args or {}
local timeout = args.timeout or 2
local units = args.units or 1024 -- KB
local notify = args.notify or "on"
local screen = args.screen or 1
local settings = args.settings or function() end
-- Compatibility with old API where iface was a string corresponding to 1 interface
net.iface = (args.iface and (type(args.iface) == "string" and {args.iface}) or
(type(args.iface) == "table" and args.iface)) or {}
function net.get_device()
helpers.line_callback("ip link", function(line)
net.iface[#net.iface + 1] = not string.match(line, "LOOPBACK") and string.match(line, "(%w+): <") or nil
helpers.async(string.format("ip link show", device_cmd), function(ws)
ws = ws:match("(%w+): <BROADCAST,MULTICAST,.-UP,LOWER_UP>")
net.iface = ws and { ws } or {}
end)
end
@@ -46,7 +45,7 @@ local function factory(args)
received = 0
}
for _, dev in ipairs(net.iface) do
for i, dev in ipairs(net.iface) do
local dev_now = {}
local dev_before = net.devices[dev] or { last_t = 0, last_r = 0 }
local now_t = tonumber(helpers.first_line(string.format("/sys/class/net/%s/statistics/tx_bytes", dev)) or 0)
@@ -67,18 +66,9 @@ local function factory(args)
dev_now.last_t = now_t
dev_now.last_r = now_r
if wifi_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) == "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
dev_now.wifi = true
dev_now.signal = tonumber(string.match(helpers.lines_from("/proc/net/wireless")[3], "(%-%d+%.)")) or nil
end
if eth_state == "on" and helpers.first_line(string.format("/sys/class/net/%s/uevent", dev)) ~= "DEVTYPE=wlan" and string.match(dev_now.carrier, "1") then
dev_now.ethernet = true
end
net.devices[dev] = dev_now
-- Notify only once when connection is lost
-- Notify only once when connection is loss
if string.match(dev_now.carrier, "0") and notify == "on" and helpers.get_map(dev) then
naughty.notify {
title = dev,
@@ -94,7 +84,7 @@ local function factory(args)
net_now.carrier = dev_now.carrier
net_now.state = dev_now.state
net_now.devices[dev] = dev_now
-- net_now.sent and net_now.received will be
-- new_now.sent and net_now.received will be
-- the totals across all specified devices
end

8
.config/awesome/lain/widget/pulse.lua Executable file → Normal file
View File

@@ -1,15 +1,17 @@
--[[
Licensed under GNU General Public License v2
* (c) 2016, Luca CPZ
* (c) 2016, Luke Bonham
--]]
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local wibox = require("wibox")
local string = string
local type = type
local string = { gmatch = string.gmatch,
match = string.match,
format = string.format }
local type = type
-- PulseAudio volume
-- lain.widget.pulse

50
.config/awesome/lain/widget/pulsebar.lua Executable file → Normal file
View File

@@ -1,19 +1,21 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2013, Rman
--]]
local helpers = require("lain.helpers")
local awful = require("awful")
local naughty = require("naughty")
local wibox = require("wibox")
local math = math
local string = string
local type = type
local tonumber = tonumber
local helpers = require("lain.helpers")
local awful = require("awful")
local naughty = require("naughty")
local wibox = require("wibox")
local math = { modf = math.modf }
local string = { format = string.format,
match = string.match,
gmatch = string.gmatch,
rep = string.rep }
local type, tonumber = type, tonumber
-- PulseAudio volume bar
-- lain.widget.pulsebar
@@ -35,9 +37,7 @@ local function factory(args)
local timeout = args.timeout or 5
local settings = args.settings or function() end
local width = args.width or 63
local height = args.height or 1
local margins = args.margins or 1
local paddings = args.paddings or 1
local height = args.heigth or 1
local ticks = args.ticks or false
local ticks_size = args.ticks_size or 7
@@ -54,12 +54,12 @@ local function factory(args)
end
pulsebar.bar = wibox.widget {
color = pulsebar.colors.unmute,
background_color = pulsebar.colors.background,
forced_height = height,
forced_width = width,
margins = margins,
paddings = paddings,
color = pulsebar.colors.unmute,
background_color = pulsebar.colors.background,
margins = 1,
paddings = 1,
ticks = ticks,
ticks_size = ticks_size,
widget = wibox.widget.progressbar,
@@ -123,23 +123,9 @@ local function factory(args)
preset.title = preset.title .. " muted"
end
-- tot is the maximum number of ticks to display in the notification
-- fallback: default horizontal wibox height
local wib, tot = awful.screen.focused().mywibox, 20
-- if we can grab mywibox, tot is defined as its height if
-- horizontal, or width otherwise
if wib then
if wib.position == "left" or wib.position == "right" then
tot = wib.width
else
tot = wib.height
end
end
int = math.modf((pulsebar._current_level / 100) * tot)
int = math.modf((pulsebar._current_level / 100) * awful.screen.focused().mywibox.height)
preset.text = string.format("[%s%s]", string.rep("|", int),
string.rep(" ", tot - int))
string.rep(" ", awful.screen.focused().mywibox.height - int))
if pulsebar.followtag then preset.screen = awful.screen.focused() end

2
.config/awesome/lain/widget/sysload.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
* (c) 2010-2012, Peter Hofmann
--]]

2
.config/awesome/lain/widget/temp.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Luca CPZ
* (c) 2013, Luke Bonham
--]]

39
.config/awesome/lain/widget/weather.lua Executable file → Normal file
View File

@@ -1,7 +1,7 @@
--[[
Licensed under GNU General Public License v2
* (c) 2015, Luca CPZ
* (c) 2015, Luke Bonham
--]]
@@ -10,10 +10,8 @@ local json = require("lain.util").dkjson
local focused = require("awful.screen").focused
local naughty = require("naughty")
local wibox = require("wibox")
local math = math
local os = os
local string = string
local tonumber = tonumber
local math, os, string, tonumber = math, os, string, tonumber
-- OpenWeatherMap
-- current weather and X-days forecast
@@ -22,13 +20,14 @@ local tonumber = tonumber
local function factory(args)
local weather = { widget = wibox.widget.textbox() }
local args = args or {}
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain's default
local APPID = args.APPID or "3e321f9414eaedbfab34983bda77a66e" -- lain default
local timeout = args.timeout or 60 * 15 -- 15 min
local timeout_forecast = args.timeout or 60 * 60 * 24 -- 24 hrs
local current_call = args.current_call or "curl -s 'http://api.openweathermap.org/data/2.5/weather?id=%s&units=%s&lang=%s&APPID=%s'"
local forecast_call = args.forecast_call or "curl -s 'http://api.openweathermap.org/data/2.5/forecast/daily?id=%s&units=%s&lang=%s&cnt=%s&APPID=%s'"
local city_id = args.city_id or 0 -- placeholder
local units = args.units or "metric"
-- local units = args.units or "metric"
local units = args.units or "imperial"
local lang = args.lang or "en"
local cnt = args.cnt or 5
local date_cmd = args.date_cmd or "date -u -d @%d +'%%a %%d'"
@@ -116,18 +115,22 @@ local function factory(args)
local sunrise = tonumber(weather_now["sys"]["sunrise"])
local sunset = tonumber(weather_now["sys"]["sunset"])
local icon = weather_now["weather"][1]["icon"]
local loc_now = os.time() -- local time
local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 } -- local time from midnight
local loc_d = os.date("*t", loc_now) -- table YMDHMS for current local time (for TZ calculation)
local utc_d = os.date("!*t", loc_now) -- table YMDHMS for current UTC time
local utc_now = os.time(utc_d) -- UTC time now
local offdt = (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60 -- DST offset
local offset = os.difftime(loc_now, utc_now) + (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60 -- TZ offset (including DST)
local offday = (offset < 0 and -86400) or 86400 -- 24 hour correction value (+86400 or -86400)
local loc_now = os.time()
local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 }
local loc_t = os.difftime(loc_now, loc_m)
local loc_d = os.date("*t", loc_now)
local utc_d = os.date("!*t", loc_now)
local utc_now = os.time(utc_d)
local offdt = (loc_d.isdst and 1 or 0) * 3600 + 100 * (loc_d.min - utc_d.min) / 60
local offset = os.difftime(loc_now, utc_now) + offdt
local offday = (offset < 0 and -86400) or 86400
-- if current UTC time is earlier then local midnight -> positive offset (negative otherwise)
if offset * (loc_m - utc_now + offdt) > 0 then
sunrise = sunrise + offday -- Shift sunset and sunrise times by 24 hours
if math.abs(loc_now - utc_now - offdt + loc_t) >= 86400 then
utc_now = utc_now + offday
end
if offday * (loc_now - utc_now - offdt) > 0 then
sunrise = sunrise + offday
sunset = sunset + offday
end