awful.spawn.easy_async
This commit is contained in:
parent
707aa98908
commit
5ea554c068
|
@ -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)
|
||||
|
|
|
@ -54,33 +54,43 @@ 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
|
||||
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)
|
||||
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&')
|
||||
os.execute('sleep 0.2')
|
||||
ret.execute_command('noop')
|
||||
else
|
||||
set_text('music-server not running')
|
||||
end
|
||||
elseif start_server_command then
|
||||
-- Start the server and re-exec the command
|
||||
os.execute('music-server&')
|
||||
os.execute('sleep 0.2')
|
||||
ret.execute_command('noop')
|
||||
else
|
||||
set_text('music-server not running')
|
||||
end
|
||||
|
||||
if text[2] ~= nil then
|
||||
icon = text[2]
|
||||
end
|
||||
if text[2] ~= nil then
|
||||
icon = text[2]
|
||||
end
|
||||
|
||||
end)
|
||||
|
||||
update_widget()
|
||||
end
|
||||
|
||||
function update_widget()
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Reference in New Issue