awful.spawn.easy_async
This commit is contained in:
parent
707aa98908
commit
5ea554c068
|
@ -1,19 +1,8 @@
|
||||||
local awful = require("awful")
|
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 ")
|
textclock_widget = awful.widget.textclock(" %a %d %b %H:%M ")
|
||||||
|
|
||||||
calendar_widget = awful.tooltip({objects={textclock_widget}})
|
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,19 +54,28 @@ local function set_text(text)
|
||||||
end
|
end
|
||||||
|
|
||||||
ret.execute_command = function(command)
|
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
|
if active_command then
|
||||||
set_text(text[1])
|
set_text(text[1])
|
||||||
elseif string_starts_with(command, 'noop') then
|
elseif string_starts_with(command, 'noop') then
|
||||||
total_text = text[1]
|
total_text = text[1]
|
||||||
position = math.floor((width - string.len(total_text)) / 2)
|
position = math.floor((width - string.len(total_text)) / 2)
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif start_server_command then
|
elseif start_server_command then
|
||||||
-- Start the server and re-exec the command
|
-- Start the server and re-exec the command
|
||||||
os.execute('music-server&')
|
os.execute('music-server&')
|
||||||
|
@ -80,7 +89,8 @@ ret.execute_command = function(command)
|
||||||
icon = text[2]
|
icon = text[2]
|
||||||
end
|
end
|
||||||
|
|
||||||
update_widget()
|
end)
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function update_widget()
|
function update_widget()
|
||||||
|
|
|
@ -5,10 +5,10 @@ volume_widget = wibox.widget.textbox()
|
||||||
volume_widget:set_align("right")
|
volume_widget:set_align("right")
|
||||||
|
|
||||||
function update_volume()
|
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
|
local widget = volume_widget
|
||||||
fd:close()
|
|
||||||
|
|
||||||
-- local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
|
-- local volume = tonumber(string.match(status, "(%d?%d?%d)%%")) / 100
|
||||||
local volume = string.match(status, "(%d?%d?%d)%%")
|
local volume = string.match(status, "(%d?%d?%d)%%")
|
||||||
|
@ -23,6 +23,7 @@ function update_volume()
|
||||||
volume = volume .. "M"
|
volume = volume .. "M"
|
||||||
end
|
end
|
||||||
widget:set_markup("V :" .. volume)
|
widget:set_markup("V :" .. volume)
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
update_volume()
|
update_volume()
|
||||||
|
|
Loading…
Reference in New Issue