awful.spawn.easy_async

This commit is contained in:
Thomas Forgione 2017-10-19 18:04:37 +02:00
parent 707aa98908
commit 5ea554c068
No known key found for this signature in database
GPG Key ID: C75CD416BD1FFCE1
3 changed files with 40 additions and 40 deletions

View File

@ -1,19 +1,8 @@
local awful = require("awful")
function get_calendar()
local f = io.popen('gcal -i- -s1 .+')
local l = nil
if f ~= nil then
f:read()
l = f:read("*all")
else
l = '?'
end
f:close()
return l
end
textclock_widget = awful.widget.textclock(" %a %d %b %H:%M ")
calendar_widget = awful.tooltip({objects={textclock_widget}})
calendar_widget:set_text(get_calendar())
awful.spawn.easy_async('gcal -i- -s1 .+', function(stdout)
calendar_widget:set_text(stdout)
end)

View File

@ -54,19 +54,28 @@ local function set_text(text)
end
ret.execute_command = function(command)
local fd = io.popen('music-client ' .. command)
local text = string_split(fd:read('*all'), '\n')
local rc = {fd:close()}
local active_command = string_starts_with(command, 'file') or string_starts_with(command, 'next') or string_starts_with(command, 'previous')
local start_server_command = active_command or string_starts_with(command, 'play') or string_starts_with(command, 'pause')
if rc[3] == 0 then
awful.spawn.easy_async('music-client ' .. command, function(stdout, stderr, reason, code)
local text = string_split(stdout, '\n')
local active_command =
string_starts_with(command, 'file') or
string_starts_with(command, 'next') or
string_starts_with(command, 'previous')
local start_server_command = active_command or
string_starts_with(command, 'play') or
string_starts_with(command, 'pause')
if code == 0 then
if active_command then
set_text(text[1])
elseif string_starts_with(command, 'noop') then
total_text = text[1]
position = math.floor((width - string.len(total_text)) / 2)
end
elseif start_server_command then
-- Start the server and re-exec the command
os.execute('music-server&')
@ -80,7 +89,8 @@ ret.execute_command = function(command)
icon = text[2]
end
update_widget()
end)
end
function update_widget()

View File

@ -5,10 +5,10 @@ volume_widget = wibox.widget.textbox()
volume_widget:set_align("right")
function update_volume()
fd = io.popen("amixer sget Master")
local status = fd:read("*all")
awful.spawn.easy_async('amixer sget Master', function(stdout, stderr)
local status = stdout
local widget = volume_widget
fd:close()
-- local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
local volume = string.match(status, "(%d?%d?%d)%%")
@ -23,6 +23,7 @@ function update_volume()
volume = volume .. "M"
end
widget:set_markup("V :" .. volume)
end)
end
update_volume()