mirror of https://github.com/lcpz/lain.git
from asynchshell to awful.spawn.easy_async; started making every widget asynchronous
This commit is contained in:
parent
7e4175f7aa
commit
0279482eeb
|
@ -1,79 +0,0 @@
|
||||||
|
|
||||||
--[[
|
|
||||||
|
|
||||||
Licensed under GNU General Public License v2
|
|
||||||
* (c) 2015, worron
|
|
||||||
* (c) 2013, Alexander Yakushev
|
|
||||||
|
|
||||||
--]]
|
|
||||||
|
|
||||||
-- Asynchronous io.popen for Awesome WM.
|
|
||||||
-- How to use:
|
|
||||||
-- asyncshell.request('wscript -Kiev', function(output) wwidget.text = output end)
|
|
||||||
|
|
||||||
-- Grab environment
|
|
||||||
local awful = require('awful')
|
|
||||||
|
|
||||||
-- Avoid discrepancies across multiple shells
|
|
||||||
awful.util.shell = '/bin/sh'
|
|
||||||
|
|
||||||
-- Initialize tables for module
|
|
||||||
asyncshell = { request_table = {}, id_counter = 0 }
|
|
||||||
|
|
||||||
-- Request counter
|
|
||||||
local function next_id()
|
|
||||||
asyncshell.id_counter = (asyncshell.id_counter + 1) % 10000
|
|
||||||
return asyncshell.id_counter
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Remove given request
|
|
||||||
function asyncshell.clear(id)
|
|
||||||
if asyncshell.request_table[id] then
|
|
||||||
if asyncshell.request_table[id].timer then
|
|
||||||
asyncshell.request_table[id].timer:stop()
|
|
||||||
asyncshell.request_table[id].timer = nil
|
|
||||||
end
|
|
||||||
asyncshell.request_table[id] = nil
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Sends an asynchronous request for an output of the shell command
|
|
||||||
-- @param command Command to be executed and taken output from
|
|
||||||
-- @param callback Function to be called when the command finishes
|
|
||||||
-- @param timeout Maximum amount of time to wait for the result (optional)
|
|
||||||
function asyncshell.request(command, callback, timeout)
|
|
||||||
local id = next_id()
|
|
||||||
asyncshell.request_table[id] = { callback = callback }
|
|
||||||
|
|
||||||
local formatted_command = string.gsub(command, '"','\"')
|
|
||||||
|
|
||||||
local req = string.format(
|
|
||||||
"echo \"asyncshell.deliver(%s, [[\\\"$(%s)\\\"]])\" | awesome-client &",
|
|
||||||
id, formatted_command
|
|
||||||
)
|
|
||||||
|
|
||||||
if type(awful.spawn) == 'table' and awful.spawn.with_shell then
|
|
||||||
awful.spawn.with_shell(req)
|
|
||||||
else
|
|
||||||
awful.util.spawn_with_shell(req)
|
|
||||||
end
|
|
||||||
|
|
||||||
if timeout then
|
|
||||||
asyncshell.request_table[id].timer = timer({ timeout = timeout })
|
|
||||||
asyncshell.request_table[id].timer:connect_signal("timeout", function() asyncshell.clear(id) end)
|
|
||||||
asyncshell.request_table[id].timer:start()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Calls the remembered callback function on the output of the shell command
|
|
||||||
-- @param id Request ID
|
|
||||||
-- @param output Shell command output to be delievered
|
|
||||||
function asyncshell.deliver(id, output)
|
|
||||||
local output = string.sub(output, 2, -2)
|
|
||||||
if asyncshell.request_table[id] then
|
|
||||||
asyncshell.request_table[id].callback(output)
|
|
||||||
asyncshell.clear(id)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return asyncshell
|
|
43
helpers.lua
43
helpers.lua
|
@ -6,17 +6,17 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local debug = require("debug")
|
|
||||||
|
|
||||||
local assert = assert
|
local debug = require("debug")
|
||||||
local capi = { timer = require("gears.timer") }
|
local io = { lines = io.lines,
|
||||||
local io = { open = io.open,
|
open = io.open,
|
||||||
lines = io.lines,
|
popen = io.popen }
|
||||||
popen = io.popen }
|
local rawget = rawget
|
||||||
local rawget = rawget
|
local table = { sort = table.sort }
|
||||||
local table = { sort = table.sort }
|
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local easy_async = require("awful.spawn").easy_async
|
||||||
|
local timer = require("gears.timer")
|
||||||
|
local wibox = require("wibox")
|
||||||
|
|
||||||
-- Lain helper functions for internal use
|
-- Lain helper functions for internal use
|
||||||
-- lain.helpers
|
-- lain.helpers
|
||||||
|
@ -95,7 +95,7 @@ helpers.timer_table = {}
|
||||||
function helpers.newtimer(_name, timeout, fun, nostart)
|
function helpers.newtimer(_name, timeout, fun, nostart)
|
||||||
local name = timeout
|
local name = timeout
|
||||||
if not helpers.timer_table[name] then
|
if not helpers.timer_table[name] then
|
||||||
helpers.timer_table[name] = capi.timer({ timeout = timeout })
|
helpers.timer_table[name] = timer({ timeout = timeout })
|
||||||
helpers.timer_table[name]:start()
|
helpers.timer_table[name]:start()
|
||||||
end
|
end
|
||||||
helpers.timer_table[name]:connect_signal("timeout", fun)
|
helpers.timer_table[name]:connect_signal("timeout", fun)
|
||||||
|
@ -108,22 +108,25 @@ end
|
||||||
|
|
||||||
-- {{{ Pipe operations
|
-- {{{ Pipe operations
|
||||||
|
|
||||||
-- read the full output of a command output
|
-- return the full output of an input command (synchronous pipe)
|
||||||
|
-- @param cmd the input command
|
||||||
|
-- @return command output (string)
|
||||||
function helpers.read_pipe(cmd)
|
function helpers.read_pipe(cmd)
|
||||||
local f = assert(io.popen(cmd))
|
local f = io.popen(cmd)
|
||||||
local output = f:read("*all")
|
local output = f:read("*all")
|
||||||
f:close()
|
f:close()
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
-- return line iterator of a command output
|
-- run a command and execute a function on its output (asynchronous pipe)
|
||||||
function helpers.pipelines(...)
|
-- @param cmd the input command
|
||||||
local f = assert(io.popen(...))
|
-- @param callback function to execute on cmd output
|
||||||
return function () -- iterator
|
-- @return cmd PID
|
||||||
local data = f:read()
|
function helpers.async(cmd, callback)
|
||||||
if data == nil then f:close() end
|
return easy_async(cmd,
|
||||||
return data
|
function (stdout, stderr, reason, exit_code)
|
||||||
end
|
callback(stdout)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- }}}
|
-- }}}
|
||||||
|
|
|
@ -6,10 +6,8 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local async = require("lain.asyncshell")
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- Basic template for custom widgets (asynchronous version)
|
-- Basic template for custom widgets (asynchronous version)
|
||||||
|
@ -22,10 +20,10 @@ local function worker(args)
|
||||||
local cmd = args.cmd or ""
|
local cmd = args.cmd or ""
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
abase.widget = wibox.widget.textbox('')
|
abase.widget = wibox.widget.textbox()
|
||||||
|
|
||||||
function abase.update()
|
function abase.update()
|
||||||
async.request(cmd, function(f)
|
helpers.async(cmd, function(f)
|
||||||
output = f
|
output = f
|
||||||
if output ~= abase.prev then
|
if output ~= abase.prev then
|
||||||
widget = abase.widget
|
widget = abase.widget
|
||||||
|
@ -35,7 +33,7 @@ local function worker(args)
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
newtimer(cmd, timeout, abase.update)
|
helpers.newtimer(cmd, timeout, abase.update)
|
||||||
|
|
||||||
return setmetatable(abase, { __index = abase.widget })
|
return setmetatable(abase, { __index = abase.widget })
|
||||||
end
|
end
|
||||||
|
|
|
@ -8,13 +8,9 @@
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
|
||||||
|
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local string = { match = string.match,
|
local string = { match = string.match,
|
||||||
format = string.format }
|
format = string.format }
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- ALSA volume
|
-- ALSA volume
|
||||||
|
@ -26,29 +22,20 @@ local function worker(args)
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 5
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
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.last = {}
|
||||||
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))
|
helpers.async(alsa.cmd, function(mixer)
|
||||||
l, s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
local l,s = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
if alsa.last.level ~= l or alsa.last.status ~= s then
|
||||||
-- HDMIs can have a channel different from Master for toggling mute
|
volume_now = { level = l, status = s }
|
||||||
if alsa.togglechannel then
|
widget = alsa.widget
|
||||||
s = string.match(read_pipe(string.format("%s get %s", alsa.cmd, alsa.togglechannel)), "%[(%a+)%]")
|
settings()
|
||||||
end
|
alsa.last = volume_now
|
||||||
|
end
|
||||||
if alsa.last_level ~= l or alsa.last_status ~= s then
|
end)
|
||||||
volume_now = { level = l, status = s }
|
|
||||||
alsa.last_level = l
|
|
||||||
alsa.last_status = s
|
|
||||||
|
|
||||||
widget = alsa.widget
|
|
||||||
settings()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
timer_id = string.format("alsa-%s-%s", alsa.cmd, alsa.channel)
|
||||||
|
|
|
@ -7,8 +7,7 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local helpers = require("lain.helpers")
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
|
||||||
|
|
||||||
local awful = require("awful")
|
local awful = require("awful")
|
||||||
local beautiful = require("beautiful")
|
local beautiful = require("beautiful")
|
||||||
|
@ -35,9 +34,6 @@ local alsabar = {
|
||||||
unmute = "#A4CE8A"
|
unmute = "#A4CE8A"
|
||||||
},
|
},
|
||||||
|
|
||||||
terminal = terminal or "xterm",
|
|
||||||
mixer = string.format("%s -e alsamixer", terminal),
|
|
||||||
|
|
||||||
notifications = {
|
notifications = {
|
||||||
font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
|
font = beautiful.font:sub(beautiful.font:find(""), beautiful.font:find(" ")),
|
||||||
font_size = "11",
|
font_size = "11",
|
||||||
|
@ -49,46 +45,6 @@ local alsabar = {
|
||||||
_muted = false
|
_muted = false
|
||||||
}
|
}
|
||||||
|
|
||||||
function alsabar.notify()
|
|
||||||
alsabar.update()
|
|
||||||
|
|
||||||
local preset = {
|
|
||||||
title = "",
|
|
||||||
text = "",
|
|
||||||
timeout = 5,
|
|
||||||
screen = alsabar.notifications.screen,
|
|
||||||
font = string.format("%s %s", alsabar.notifications.font,
|
|
||||||
alsabar.notifications.font_size),
|
|
||||||
fg = alsabar.notifications.color
|
|
||||||
}
|
|
||||||
|
|
||||||
if alsabar._muted
|
|
||||||
then
|
|
||||||
preset.title = string.format("%s - Muted", alsabar.channel)
|
|
||||||
else
|
|
||||||
preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
|
|
||||||
end
|
|
||||||
|
|
||||||
int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
|
|
||||||
preset.text = string.format("[%s%s]", string.rep("|", int),
|
|
||||||
string.rep(" ", awful.screen.focused().mywibox.height - int))
|
|
||||||
|
|
||||||
if alsabar.followtag then
|
|
||||||
preset.screen = awful.screen.focused()
|
|
||||||
end
|
|
||||||
|
|
||||||
if alsabar._notify ~= nil then
|
|
||||||
alsabar._notify = naughty.notify ({
|
|
||||||
replaces_id = alsabar._notify.id,
|
|
||||||
preset = preset,
|
|
||||||
})
|
|
||||||
else
|
|
||||||
alsabar._notify = naughty.notify ({
|
|
||||||
preset = preset,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
local function worker(args)
|
local function worker(args)
|
||||||
local args = args or {}
|
local args = args or {}
|
||||||
local timeout = args.timeout or 5
|
local timeout = args.timeout or 5
|
||||||
|
@ -101,7 +57,6 @@ local function worker(args)
|
||||||
|
|
||||||
alsabar.cmd = args.cmd or "amixer"
|
alsabar.cmd = args.cmd or "amixer"
|
||||||
alsabar.channel = args.channel or alsabar.channel
|
alsabar.channel = args.channel or alsabar.channel
|
||||||
alsabar.togglechannel = args.togglechannel
|
|
||||||
alsabar.step = args.step or alsabar.step
|
alsabar.step = args.step or alsabar.step
|
||||||
alsabar.colors = args.colors or alsabar.colors
|
alsabar.colors = args.colors or alsabar.colors
|
||||||
alsabar.notifications = args.notifications or alsabar.notifications
|
alsabar.notifications = args.notifications or alsabar.notifications
|
||||||
|
@ -122,66 +77,72 @@ local function worker(args)
|
||||||
|
|
||||||
alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
|
alsabar.tooltip = awful.tooltip({ objects = { alsabar.bar } })
|
||||||
|
|
||||||
function alsabar.update()
|
function alsabar.update(callback)
|
||||||
-- Get mixer control contents
|
helpers.async(alsabar.cmd, function(mixer)
|
||||||
local mixer = read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.channel))
|
local volu,mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
||||||
|
if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted)
|
||||||
-- Capture mixer control state: [5%] ... ... [on]
|
|
||||||
local volu, mute = string.match(mixer, "([%d]+)%%.*%[([%l]*)")
|
|
||||||
|
|
||||||
-- HDMIs can have a channel different from Master for toggling mute
|
|
||||||
if alsabar.togglechannel then
|
|
||||||
mute = string.match(read_pipe(string.format("%s get %s", alsabar.cmd, alsabar.togglechannel)), "%[(%a+)%]")
|
|
||||||
end
|
|
||||||
|
|
||||||
if (volu and tonumber(volu) ~= alsabar._current_level) or (mute and string.match(mute, "on") ~= alsabar._muted)
|
|
||||||
then
|
|
||||||
alsabar._current_level = tonumber(volu) or alsabar._current_level
|
|
||||||
alsabar.bar:set_value(alsabar._current_level / 100)
|
|
||||||
if (not mute and tonumber(volu) == 0) or mute == "off"
|
|
||||||
then
|
then
|
||||||
alsabar._muted = true
|
alsabar._current_level = tonumber(volu) or alsabar._current_level
|
||||||
alsabar.tooltip:set_text ("[Muted]")
|
alsabar.bar:set_value(alsabar._current_level / 100)
|
||||||
alsabar.bar.color = alsabar.colors.mute
|
if (not mute and tonumber(volu) == 0) or mute == "off"
|
||||||
else
|
then
|
||||||
alsabar._muted = false
|
alsabar._muted = true
|
||||||
alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
|
alsabar.tooltip:set_text ("[Muted]")
|
||||||
alsabar.bar.color = alsabar.colors.unmute
|
alsabar.bar.color = alsabar.colors.mute
|
||||||
|
else
|
||||||
|
alsabar._muted = false
|
||||||
|
alsabar.tooltip:set_text(string.format("%s: %s", alsabar.channel, volu))
|
||||||
|
alsabar.bar.color = alsabar.colors.unmute
|
||||||
|
end
|
||||||
|
|
||||||
|
volume_now = {}
|
||||||
|
volume_now.level = tonumber(volu)
|
||||||
|
volume_now.status = mute
|
||||||
|
|
||||||
|
settings()
|
||||||
|
|
||||||
|
if callback then callback() end
|
||||||
end
|
end
|
||||||
|
end)
|
||||||
volume_now = {}
|
|
||||||
volume_now.level = tonumber(volu)
|
|
||||||
volume_now.status = mute
|
|
||||||
|
|
||||||
settings()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
alsabar.bar:buttons(awful.util.table.join (
|
function alsabar.notify()
|
||||||
awful.button({}, 1, function()
|
alsabar.update(function()
|
||||||
awful.util.spawn(alsabar.mixer)
|
local preset = {
|
||||||
end),
|
title = "",
|
||||||
awful.button({}, 2, function()
|
text = "",
|
||||||
awful.util.spawn(string.format("%s set %s 100%%", alsabar.cmd, alsabar.channel))
|
timeout = 5,
|
||||||
alsabar.update()
|
screen = alsabar.notifications.screen,
|
||||||
end),
|
font = string.format("%s %s", alsabar.notifications.font,
|
||||||
awful.button({}, 3, function()
|
alsabar.notifications.font_size),
|
||||||
awful.util.spawn(string.format("%s set %s toggle", alsabar.cmd, alsabar.togglechannel or alsabar.channel))
|
fg = alsabar.notifications.color
|
||||||
alsabar.update()
|
}
|
||||||
end),
|
|
||||||
awful.button({}, 4, function()
|
if alsabar._muted then
|
||||||
awful.util.spawn(string.format("%s set %s %s+", alsabar.cmd, alsabar.channel, alsabar.step))
|
preset.title = string.format("%s - Muted", alsabar.channel)
|
||||||
alsabar.update()
|
else
|
||||||
end),
|
preset.title = string.format("%s - %s%%", alsabar.channel, alsabar._current_level)
|
||||||
awful.button({}, 5, function()
|
end
|
||||||
awful.util.spawn(string.format("%s set %s %s-", alsabar.cmd, alsabar.channel, alsabar.step))
|
|
||||||
alsabar.update()
|
int = math.modf((alsabar._current_level / 100) * awful.screen.focused().mywibox.height)
|
||||||
end)
|
preset.text = string.format("[%s%s]", string.rep("|", int),
|
||||||
))
|
string.rep(" ", awful.screen.focused().mywibox.height - int))
|
||||||
|
|
||||||
|
if alsabar.followtag then preset.screen = awful.screen.focused() end
|
||||||
|
|
||||||
|
if alsabar._notify then
|
||||||
|
alsabar._notify = naughty.notify ({
|
||||||
|
replaces_id = alsabar._notify.id,
|
||||||
|
preset = preset,
|
||||||
|
})
|
||||||
|
else
|
||||||
|
alsabar._notify = naughty.notify ({ preset = preset })
|
||||||
|
end
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
|
timer_id = string.format("alsabar-%s-%s", alsabar.cmd, alsabar.channel)
|
||||||
|
helpers.newtimer(timer_id, timeout, alsabar.update)
|
||||||
newtimer(timer_id, timeout, alsabar.update)
|
|
||||||
|
|
||||||
return alsabar
|
return alsabar
|
||||||
end
|
end
|
||||||
|
|
|
@ -44,8 +44,7 @@ local function worker(args)
|
||||||
function gpmdp.update()
|
function gpmdp.update()
|
||||||
local filelines = helpers.lines_from(file_location)
|
local filelines = helpers.lines_from(file_location)
|
||||||
|
|
||||||
if not next(filelines)
|
if not next(filelines) then
|
||||||
then
|
|
||||||
local gpm_now = { running = false, playing = false }
|
local gpm_now = { running = false, playing = false }
|
||||||
else
|
else
|
||||||
dict, pos, err = json.decode(table.concat(filelines), 1, nil)
|
dict, pos, err = json.decode(table.concat(filelines), 1, nil)
|
||||||
|
@ -67,16 +66,12 @@ local function worker(args)
|
||||||
widget = gpmdp.widget
|
widget = gpmdp.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
if gpm_now.playing
|
if gpm_now.playing then
|
||||||
then
|
if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current") then
|
||||||
if notify == "on" and gpm_now.title ~= helpers.get_map("gpmdp_current")
|
|
||||||
then
|
|
||||||
helpers.set_map("gpmdp_current", gpm_now.title)
|
helpers.set_map("gpmdp_current", gpm_now.title)
|
||||||
os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
|
os.execute(string.format("curl %d -o /tmp/gpmcover.png", gpm_now.cover_url))
|
||||||
|
|
||||||
if followtag then
|
if followtag then gpmdp_notification_preset.screen = focused() end
|
||||||
gpmdp_notification_preset.screen = focused()
|
|
||||||
end
|
|
||||||
|
|
||||||
gpmdp.id = naughty.notify({
|
gpmdp.id = naughty.notify({
|
||||||
preset = gpmdp_notification_preset,
|
preset = gpmdp_notification_preset,
|
||||||
|
|
|
@ -38,8 +38,10 @@ local function worker(args)
|
||||||
|
|
||||||
local function run_settings(layout, variant)
|
local function run_settings(layout, variant)
|
||||||
widget = kbdlayout.widget
|
widget = kbdlayout.widget
|
||||||
kbdlayout_now = { layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only.
|
kbdlayout_now = {
|
||||||
variant=variant }
|
layout=string.match(layout, "[^,]+"), -- Make sure to match the primary layout only.
|
||||||
|
variant=variant
|
||||||
|
}
|
||||||
settings()
|
settings()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -6,52 +6,40 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
local async = require("lain.asyncshell")
|
|
||||||
|
|
||||||
local focused = require("awful.screen").focused
|
local shell = require("awful.util").shell
|
||||||
local escape_f = require("awful.util").escape
|
local focused = require("awful.screen").focused
|
||||||
local naughty = require("naughty")
|
local escape_f = require("awful.util").escape
|
||||||
local wibox = require("wibox")
|
local naughty = require("naughty")
|
||||||
|
local wibox = require("wibox")
|
||||||
|
|
||||||
local io = { popen = io.popen }
|
local os = { getenv = os.getenv }
|
||||||
local os = { execute = os.execute,
|
local string = { format = string.format,
|
||||||
getenv = os.getenv }
|
gmatch = string.gmatch }
|
||||||
local string = { format = string.format,
|
|
||||||
gmatch = string.gmatch }
|
|
||||||
|
|
||||||
local setmetatable = setmetatable
|
local setmetatable = setmetatable
|
||||||
|
|
||||||
-- MOC audio player
|
-- MOC audio player
|
||||||
-- lain.widgets.contrib.moc
|
-- lain.widgets.contrib.moc
|
||||||
local moc = {}
|
local moc = helpers.make_widget_textbox()
|
||||||
|
|
||||||
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 music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
|
local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
|
||||||
local cover_size = args.cover_size or 100
|
local cover_pattern = args.cover_pattern or "*\\.(jpg|jpeg|png|gif)$"
|
||||||
local default_art = args.default_art or ""
|
local cover_size = args.cover_size or 100
|
||||||
local followtag = args.followtag or false
|
local default_art = args.default_art or ""
|
||||||
local settings = args.settings or function() end
|
local followtag = args.followtag or false
|
||||||
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
local mpdcover = helpers.scripts_dir .. "mpdcover"
|
moc_notification_preset = { title = "Now playing", timeout = 6 }
|
||||||
|
|
||||||
moc.widget = wibox.widget.textbox('')
|
|
||||||
|
|
||||||
moc_notification_preset = {
|
|
||||||
title = "Now playing",
|
|
||||||
timeout = 6
|
|
||||||
}
|
|
||||||
|
|
||||||
helpers.set_map("current moc track", nil)
|
helpers.set_map("current moc track", nil)
|
||||||
|
|
||||||
function moc.update()
|
function moc.update()
|
||||||
-- mocp -i will produce output like:
|
helpers.async("mocp -i", function(f)
|
||||||
-- Artist: Travis
|
|
||||||
-- Album: The Man Who
|
|
||||||
-- etc.
|
|
||||||
async.request("mocp -i", function(f)
|
|
||||||
moc_now = {
|
moc_now = {
|
||||||
state = "N/A",
|
state = "N/A",
|
||||||
file = "N/A",
|
file = "N/A",
|
||||||
|
@ -64,13 +52,13 @@ local function worker(args)
|
||||||
|
|
||||||
for line in string.gmatch(f, "[^\n]+") do
|
for line in string.gmatch(f, "[^\n]+") do
|
||||||
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
for k, v in string.gmatch(line, "([%w]+):[%s](.*)$") do
|
||||||
if k == "State" then moc_now.state = v
|
if k == "State" then moc_now.state = v
|
||||||
elseif k == "File" then moc_now.file = v
|
elseif k == "File" then moc_now.file = v
|
||||||
elseif k == "Artist" then moc_now.artist = escape_f(v)
|
elseif k == "Artist" then moc_now.artist = escape_f(v)
|
||||||
elseif k == "SongTitle" then moc_now.title = 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 == "Album" then moc_now.album = escape_f(v)
|
||||||
elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
|
elseif k == "CurrentTime" then moc_now.elapsed = escape_f(v)
|
||||||
elseif k == "TotalTime" then moc_now.total = escape_f(v)
|
elseif k == "TotalTime" then moc_now.total = escape_f(v)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -83,18 +71,22 @@ local function worker(args)
|
||||||
if moc_now.state == "PLAY" then
|
if moc_now.state == "PLAY" then
|
||||||
if moc_now.title ~= helpers.get_map("current moc track") then
|
if moc_now.title ~= helpers.get_map("current moc track") then
|
||||||
helpers.set_map("current moc track", moc_now.title)
|
helpers.set_map("current moc track", moc_now.title)
|
||||||
os.execute(string.format("%s %q %q %d %q", mpdcover, "",
|
|
||||||
moc_now.file, cover_size, default_art))
|
|
||||||
|
|
||||||
if followtag then
|
if followtag then moc_notification_preset.screen = focused() end
|
||||||
moc_notification_preset.screen = focused()
|
|
||||||
end
|
|
||||||
|
|
||||||
moc.id = naughty.notify({
|
local common = {
|
||||||
preset = moc_notification_preset,
|
preset = moc_notification_preset,
|
||||||
icon = "/tmp/mpdcover.png",
|
icon = default_art,
|
||||||
|
icon_size = cover_size,
|
||||||
replaces_id = moc.id,
|
replaces_id = moc.id,
|
||||||
}).id
|
}
|
||||||
|
|
||||||
|
local path = string.format("%s/%s", music_dir, string.match(moc_now.file, ".*/"))
|
||||||
|
local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern)
|
||||||
|
helpers.async(cover, function(current_icon)
|
||||||
|
common.icon = current_icon:gsub("\n", "")
|
||||||
|
moc.id = naughty.notify(common).id
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
elseif moc_now.state ~= "PAUSE" then
|
elseif moc_now.state ~= "PAUSE" then
|
||||||
helpers.set_map("current moc track", nil)
|
helpers.set_map("current moc track", nil)
|
||||||
|
|
|
@ -12,7 +12,6 @@ local awful = require("awful")
|
||||||
local beautiful = require("beautiful")
|
local beautiful = require("beautiful")
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
|
||||||
local mouse = mouse
|
|
||||||
local io = io
|
local io = io
|
||||||
local string = { len = string.len }
|
local string = { len = string.len }
|
||||||
local tonumber = tonumber
|
local tonumber = tonumber
|
||||||
|
|
|
@ -7,7 +7,6 @@
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
local async = require("lain.asyncshell")
|
|
||||||
|
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
local wibox = require("wibox")
|
local wibox = require("wibox")
|
||||||
|
@ -59,24 +58,19 @@ local function worker(args)
|
||||||
curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
|
curl = string.format("%s --url imaps://%s:%s/INBOX -u %s:%q %s -k",
|
||||||
head_command, server, port, mail, password, request)
|
head_command, server, port, mail, password, request)
|
||||||
|
|
||||||
async.request(curl, function(f)
|
helpers.async(curl, function(f)
|
||||||
_, mailcount = string.gsub(f, "%d+", "")
|
_, mailcount = string.gsub(f, "%d+", "")
|
||||||
_ = nil
|
|
||||||
|
|
||||||
widget = imap.widget
|
widget = imap.widget
|
||||||
settings()
|
settings()
|
||||||
|
|
||||||
if mailcount >= 1 and mailcount > helpers.get_map(mail)
|
if mailcount >= 1 and mailcount > helpers.get_map(mail) then
|
||||||
then
|
|
||||||
if mailcount == 1 then
|
if mailcount == 1 then
|
||||||
nt = mail .. " has one new message"
|
nt = mail .. " has one new message"
|
||||||
else
|
else
|
||||||
nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
|
nt = mail .. " has <b>" .. mailcount .. "</b> new messages"
|
||||||
end
|
end
|
||||||
naughty.notify({
|
naughty.notify({ preset = mail_notification_preset, text = nt })
|
||||||
preset = mail_notification_preset,
|
|
||||||
text = nt
|
|
||||||
})
|
|
||||||
end
|
end
|
||||||
|
|
||||||
helpers.set_map(mail, mailcount)
|
helpers.set_map(mail, mailcount)
|
||||||
|
|
|
@ -7,9 +7,9 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
local async = require("lain.asyncshell")
|
|
||||||
local helpers = require("lain.helpers")
|
local helpers = require("lain.helpers")
|
||||||
|
|
||||||
|
local shell = require("awful.util").shell
|
||||||
local escape_f = require("awful.util").escape
|
local escape_f = require("awful.util").escape
|
||||||
local focused = require("awful.screen").focused
|
local focused = require("awful.screen").focused
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
@ -29,7 +29,7 @@ local mpd = helpers.make_widget_textbox()
|
||||||
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 password = args.password or ""
|
local password = (args.password and #args.password > 0 and string.format("password %s\\n", args.password)) or ""
|
||||||
local host = args.host or "127.0.0.1"
|
local host = args.host or "127.0.0.1"
|
||||||
local port = args.port or "6600"
|
local port = args.port or "6600"
|
||||||
local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
|
local music_dir = args.music_dir or os.getenv("HOME") .. "/Music"
|
||||||
|
@ -38,21 +38,18 @@ local function worker(args)
|
||||||
local default_art = args.default_art or ""
|
local default_art = args.default_art or ""
|
||||||
local notify = args.notify or "on"
|
local notify = args.notify or "on"
|
||||||
local followtag = args.followtag or false
|
local followtag = args.followtag or false
|
||||||
local echo_cmd = args.echo_cmd or "echo"
|
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
local mpdh = string.format("telnet://%s:%s", host, port)
|
local mpdh = string.format("telnet://%s:%s", host, port)
|
||||||
local echo = string.format("%s 'password %s\nstatus\ncurrentsong\nclose'", echo_cmd, password)
|
local echo = string.format("printf \"%sstatus\\ncurrentsong\\nclose\\n\"", password)
|
||||||
|
local cmd = string.format("%s -c '%s | curl --connect-timeout 1 -fsm 3 %s'", shell, echo, mpdh)
|
||||||
|
|
||||||
mpd_notification_preset = {
|
mpd_notification_preset = { title = "Now playing", timeout = 6 }
|
||||||
title = "Now playing",
|
|
||||||
timeout = 6
|
|
||||||
}
|
|
||||||
|
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", nil)
|
||||||
|
|
||||||
function mpd.update()
|
function mpd.update()
|
||||||
async.request(string.format("%s | curl --connect-timeout 1 -fsm 3 %s", echo, mpdh), function (f)
|
helpers.async(cmd, function(f)
|
||||||
mpd_now = {
|
mpd_now = {
|
||||||
random_mode = false,
|
random_mode = false,
|
||||||
single_mode = false,
|
single_mode = false,
|
||||||
|
@ -105,22 +102,26 @@ local function worker(args)
|
||||||
if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") then
|
if notify == "on" and mpd_now.title ~= helpers.get_map("current mpd track") then
|
||||||
helpers.set_map("current mpd track", mpd_now.title)
|
helpers.set_map("current mpd track", mpd_now.title)
|
||||||
|
|
||||||
local current icon = default_art
|
if followtag then mpd_notification_preset.screen = focused() end
|
||||||
|
|
||||||
|
local common = {
|
||||||
|
preset = mpd_notification_preset,
|
||||||
|
icon = default_art,
|
||||||
|
icon_size = cover_size,
|
||||||
|
replaces_id = mpd.id,
|
||||||
|
}
|
||||||
|
|
||||||
if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream
|
if not string.match(mpd_now.file, "http.*://") then -- local file instead of http stream
|
||||||
local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/"))
|
local path = string.format("%s/%s", music_dir, string.match(mpd_now.file, ".*/"))
|
||||||
local cover = string.format("find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'", path, cover_pattern)
|
local cover = string.format("%s -c \"find '%s' -maxdepth 1 -type f | egrep -i -m1 '%s'\"", shell, path, cover_pattern)
|
||||||
current_icon = helpers.read_pipe(cover):gsub("\n", "")
|
helpers.async(cover, function(current_icon)
|
||||||
|
common.icon = current_icon:gsub("\n", "")
|
||||||
|
mpd.id = naughty.notify(common).id
|
||||||
|
end)
|
||||||
|
else
|
||||||
|
mpd.id = naughty.notify(common).id
|
||||||
end
|
end
|
||||||
|
|
||||||
if followtag then mpd_notification_preset.screen = focused() end
|
|
||||||
|
|
||||||
mpd.id = naughty.notify({
|
|
||||||
preset = mpd_notification_preset,
|
|
||||||
icon = current_icon,
|
|
||||||
icon_size = cover_size,
|
|
||||||
replaces_id = mpd.id,
|
|
||||||
}).id
|
|
||||||
end
|
end
|
||||||
elseif mpd_now.state ~= "pause" then
|
elseif mpd_now.state ~= "pause" then
|
||||||
helpers.set_map("current mpd track", nil)
|
helpers.set_map("current mpd track", nil)
|
||||||
|
|
|
@ -6,12 +6,10 @@
|
||||||
|
|
||||||
--]]
|
--]]
|
||||||
|
|
||||||
|
local async = require("lain.helpers").async
|
||||||
local newtimer = require("lain.helpers").newtimer
|
local newtimer = require("lain.helpers").newtimer
|
||||||
local read_pipe = require("lain.helpers").read_pipe
|
|
||||||
|
|
||||||
local async = require("lain.asyncshell")
|
|
||||||
local json = require("lain.util").dkjson
|
|
||||||
local lain_icons = require("lain.helpers").icons_dir
|
local lain_icons = require("lain.helpers").icons_dir
|
||||||
|
local json = require("lain.util").dkjson
|
||||||
|
|
||||||
local focused = require("awful.screen").focused
|
local focused = require("awful.screen").focused
|
||||||
local naughty = require("naughty")
|
local naughty = require("naughty")
|
||||||
|
@ -54,14 +52,14 @@ local function worker(args)
|
||||||
local notification_preset = args.notification_preset or {}
|
local notification_preset = args.notification_preset or {}
|
||||||
local notification_text_fun = args.notification_text_fun or
|
local notification_text_fun = args.notification_text_fun or
|
||||||
function (wn)
|
function (wn)
|
||||||
local day = string.gsub(read_pipe(string.format(date_cmd, wn["dt"])), "\n", "")
|
local day = os.date("%a %d", wn["dt"])
|
||||||
local tmin = math.floor(wn["temp"]["min"])
|
local tmin = math.floor(wn["temp"]["min"])
|
||||||
local tmax = math.floor(wn["temp"]["max"])
|
local tmax = math.floor(wn["temp"]["max"])
|
||||||
local desc = wn["weather"][1]["description"]
|
local desc = wn["weather"][1]["description"]
|
||||||
return string.format("<b>%s</b>: %s, %d - %d ", day, desc, tmin, tmax)
|
return string.format("<b>%s</b>: %s, %d - %d ", day, desc, tmin, tmax)
|
||||||
end
|
end
|
||||||
local weather_na_markup = args.weather_na_markup or " N/A "
|
local weather_na_markup = args.weather_na_markup or " N/A "
|
||||||
local followtag = args.followtag or false
|
local followtag = args.followtag or false
|
||||||
local settings = args.settings or function() end
|
local settings = args.settings or function() end
|
||||||
|
|
||||||
weather.widget = wibox.widget.textbox(weather_na_markup)
|
weather.widget = wibox.widget.textbox(weather_na_markup)
|
||||||
|
@ -105,7 +103,7 @@ local function worker(args)
|
||||||
|
|
||||||
function weather.forecast_update()
|
function weather.forecast_update()
|
||||||
local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
|
local cmd = string.format(forecast_call, city_id, units, lang, cnt, APPID)
|
||||||
async.request(cmd, function(f)
|
async(cmd, function(f)
|
||||||
local pos, err
|
local pos, err
|
||||||
weather_now, pos, err = json.decode(f, 1, nil)
|
weather_now, pos, err = json.decode(f, 1, nil)
|
||||||
|
|
||||||
|
@ -125,7 +123,7 @@ local function worker(args)
|
||||||
|
|
||||||
function weather.update()
|
function weather.update()
|
||||||
local cmd = string.format(current_call, city_id, units, lang, APPID)
|
local cmd = string.format(current_call, city_id, units, lang, APPID)
|
||||||
async.request(cmd, function(f)
|
async(cmd, function(f)
|
||||||
local pos, err, icon
|
local pos, err, icon
|
||||||
weather_now, pos, err = json.decode(f, 1, nil)
|
weather_now, pos, err = json.decode(f, 1, nil)
|
||||||
|
|
||||||
|
@ -135,12 +133,9 @@ local function worker(args)
|
||||||
local sunrise = tonumber(weather_now["sys"]["sunrise"])
|
local sunrise = tonumber(weather_now["sys"]["sunrise"])
|
||||||
local sunset = tonumber(weather_now["sys"]["sunset"])
|
local sunset = tonumber(weather_now["sys"]["sunset"])
|
||||||
local icon = weather_now["weather"][1]["icon"]
|
local icon = weather_now["weather"][1]["icon"]
|
||||||
local utc_m = string.gsub(read_pipe(string.format("date -u -d 'today 00:00:00' +'%%s'")), "\n", "")
|
local loc_m = os.time { year = os.date("%Y"), month = os.date("%m"), day = os.date("%d"), hour = 0 }
|
||||||
local loc_m = string.gsub(read_pipe(string.format("date -d 'today 00:00:00' +'%%s'")), "\n", "")
|
local offset = utc_offset()
|
||||||
|
local utc_m = loc_m + offset
|
||||||
loc_m = tonumber(loc_m)
|
|
||||||
utc_m = tonumber(utc_m)
|
|
||||||
offset = utc_offset()
|
|
||||||
|
|
||||||
-- if we are 1 day after the GMT, return 1 day back, and viceversa
|
-- if we are 1 day after the GMT, return 1 day back, and viceversa
|
||||||
if offset > 0 and loc_m >= utc_m then
|
if offset > 0 and loc_m >= utc_m then
|
||||||
|
|
2
wiki
2
wiki
|
@ -1 +1 @@
|
||||||
Subproject commit cf17caf2b889d58d4f00a47cd168f53ae85b6d9f
|
Subproject commit fd369119050a6674c7bb4ef3b2b1d6c6dbdecb83
|
Loading…
Reference in New Issue