This commit is contained in:
Derek Taylor
2025-12-03 11:18:49 -06:00
parent 1764608c79
commit 777960ac7b
758 changed files with 6 additions and 37421 deletions

View File

@@ -1,18 +0,0 @@
--[[
Lain
Layouts, widgets and utilities for Awesome WM
Users contributed widgets section
Licensed under GNU General Public License v2
* (c) 2013, Luke Bonham
--]]
local wrequire = require("lain.helpers").wrequire
local setmetatable = setmetatable
local widget = { _NAME = "lain.widget.contrib" }
return setmetatable(widget, { __index = wrequire })

View File

@@ -1,77 +0,0 @@
--[[
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

View File

@@ -1,97 +0,0 @@
--[[
Licensed under GNU General Public License v2
* (c) 2014, anticlockwise <http://github.com/anticlockwise>
--]]
local helpers = require("lain.helpers")
local shell = require("awful.util").shell
local focused = require("awful.screen").focused
local escape_f = require("awful.util").escape
local naughty = require("naughty")
local wibox = require("wibox")
local os = { getenv = os.getenv }
local string = { format = string.format,
gmatch = string.gmatch }
-- MOC audio player
-- lain.widget.contrib.moc
local function factory(args)
local moc = { widget = wibox.widget.textbox() }
local args = args or {}
local timeout = args.timeout or 2
local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$"
local cover_size = args.cover_size or 100
local default_art = args.default_art or ""
local followtag = args.followtag or false
local settings = args.settings or function() end
moc_notification_preset = { title = "Now playing", timeout = 6 }
helpers.set_map("current moc track", nil)
function moc.update()
helpers.async("mocp -i", function(f)
moc_now = {
state = "N/A",
file = "N/A",
artist = "N/A",
title = "N/A",
album = "N/A",
elapsed = "N/A",
total = "N/A"
}
for line in string.gmatch(f, "[^\n]+") do
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
if k == "State" then moc_now.state = v
elseif k == "File" then moc_now.file = v
elseif k == "Artist" then moc_now.artist = escape_f(v)
elseif k == "SongTitle" then moc_now.title = escape_f(v)
elseif k == "Album" then moc_now.album = escape_f(v)
elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
elseif k == "TotalTime" then moc_now.total = escape_f(v)
end
end
end
moc_notification_preset.text = string.format("%s (%s) - %s\n%s", moc_now.artist,
moc_now.album, moc_now.total, moc_now.title)
widget = moc.widget
settings()
if moc_now.state == "PLAY" then
if moc_now.title ~= helpers.get_map("current moc track") then
helpers.set_map("current moc track", moc_now.title)
if followtag then moc_notification_preset.screen = focused() end
local common = {
preset = moc_notification_preset,
icon = default_art,
icon_size = cover_size,
replaces_id = moc.id,
}
local path = string.format("%s/%s", music_dir, string.match(moc_now.file, ".*/"))
local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern)
helpers.async({ shell, "-c", cover }, function(current_icon)
common.icon = current_icon:gsub("\n", "")
moc.id = naughty.notify(common).id
end)
end
elseif moc_now.state ~= "PAUSE" then
helpers.set_map("current moc track", nil)
end
end)
end
moc.timer = helpers.newtimer("moc", timeout, moc.update, true, true)
return moc
end
return factory

View File

@@ -1,53 +0,0 @@
--[[
Licensed under GNU General Public License v2
* (c) 2014, blueluke <http://github.com/blueluke>
--]]
local async = require("lain.helpers").async
local awful = require("awful")
local execute = os.execute
local type = type
-- Redshift
-- lain.widget.contrib.redshift
local redshift = { active = false, pid = nil }
function redshift:start()
execute("pkill redshift")
awful.spawn.with_shell("redshift -x") -- clear adjustments
redshift.pid = awful.spawn.with_shell("redshift")
redshift.active = true
if type(redshift.update_fun) == "function" then
redshift.update_fun(redshift.active)
end
end
function redshift:toggle()
async({ awful.util.shell, "-c", string.format("ps -p %d -o pid=", redshift.pid) }, function(f)
if f and #f > 0 then -- redshift is running
-- Sending -USR1 toggles redshift (See project website)
execute("pkill -USR1 redshift")
redshift.active = not redshift.active
else -- not started or killed, (re)start it
redshift:start()
end
redshift.update_fun(redshift.active)
end)
end
-- Attach to a widget
-- Provides a button which toggles redshift on/off on click
-- @param widget: Widget to attach to.
-- @param fun: Function to be run each time redshift is toggled (optional).
-- Use it to update widget text or icons on status change.
function redshift:attach(widget, fun)
redshift.update_fun = fun or function() end
if not redshift.pid then redshift:start() end
if widget then
widget:buttons(awful.util.table.join(awful.button({}, 1, function () redshift:toggle() end)))
end
end
return redshift

View File

@@ -1,97 +0,0 @@
--[[
Licensed under GNU General Public License v2
* (c) 2013, Jan Xie
--]]
local helpers = require("lain.helpers")
local markup = require("lain.util").markup
local awful = require("awful")
local naughty = require("naughty")
local mouse = mouse
local string = { format = string.format, gsub = string.gsub }
-- Taskwarrior notification
-- lain.widget.contrib.task
local task = {}
function task.hide()
if not task.notification then return end
naughty.destroy(task.notification)
task.notification = nil
end
function task.show(scr)
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
if mouse.current_widgets then
widget_focused = false
for _,v in ipairs(mouse.current_widgets) do
if task.widget == v then
widget_focused = true
break
end
end
end
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*$", "")))
})
end
end)
end
function task.prompt()
awful.prompt.run {
prompt = task.prompt_text,
textbox = awful.screen.focused().mypromptbox.widget,
exe_callback = function(t)
helpers.async(t, function(f)
naughty.notify {
preset = task.notification_preset,
title = t,
text = markup.font(task.notification_preset.font,
awful.util.escape(f:gsub("\n*$", "")))
}
end)
end,
history_path = awful.util.getdir("cache") .. "/history_task"
}
end
function task.attach(widget, args)
local args = args or {}
task.show_cmd = args.show_cmd or "task next"
task.prompt_text = args.prompt_text or "Enter task command: "
task.followtag = args.followtag or false
task.notification_preset = args.notification_preset
task.widget = widget
if not task.notification_preset then
task.notification_preset = {
font = "Monospace 10",
icon = helpers.icons_dir .. "/taskwarrior.png"
}
end
if widget then
widget:connect_signal("mouse::enter", function () task.show() end)
widget:connect_signal("mouse::leave", function () task.hide() end)
end
end
return task

View File

@@ -1,161 +0,0 @@
--[[
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

@@ -1,98 +0,0 @@
--[[
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