Awesome DM widget
pixelsyntax edited this page Jan 31, 2016
·
3 revisions
Place this script inside ~/.config/awesome/vicious/widgets directory.
cmus.lua
---------------------------------------------------
-- Licensed under the GNU General Public License v2
-- Based on mpd vidget for vicions by Adrian C. <anrxc@sysphere.org>
---------------------------------------------------
-- {{{ Grab environment
local tonumber = tonumber
local io = { popen = io.popen }
local setmetatable = setmetatable
local string = { gmatch = string.gmatch }
local helpers = require("vicious.helpers")
-- }}}
-- Provides information from cmus, a small, fast and powerful console music player for Unix-like operating systems
module("vicious.widgets.cmus")
-- {{{ cmus widget type
local function worker(format, warg)
local cmus_state = {
["{status}"] = "N/A",
["{artist}"] = "N/A",
["{title}"] = "N/A",
["{album}"] = "N/A",
["{genre}"] = "N/A",
}
-- Get data from cmus
local f = io.popen("cmus-remote -Q")
for line in f:lines() do
for k, v in string.gmatch(line, "([%w]+)[%s]([%w]+)$") do
if k == "status" then cmus_state["{"..k.."}"] = helpers.capitalize(v)
end
end
for k, v in string.gmatch(line, "tag[%s]([%w]+)[%s](.*)$") do
if k == "artist" then cmus_state["{"..k.."}"] = helpers.escape(v)
elseif k == "status" then cmus_state["{"..k.."}"] = helpers.escape(v)
elseif k == "title" then cmus_state["{"..k.."}"] = helpers.escape(v)
elseif k == "album" then cmus_state["{"..k.."}"] = helpers.escape(v)
elseif k == "genre" then cmus_state["{"..k.."}"] = helpers.escape(v)
end
end
end
f:close()
return cmus_state
end
-- }}}
setmetatable(_M, { __call = function(_, ...) return worker(...) end })
Then you need to include cmus_widget call to main awesome cofig file (rc.lua) like this:
rc.lua (awesome 3.4)
-- {{{ Cmus info
musicicon = widget({ type = "imagebox" })
musicicon.image = image(beautiful.widget_music)
-- Initialize widget
cmus_widget = widget({ type = "textbox" })
-- Register widget
vicious.register(cmus_widget, vicious.widgets.cmus,
function (widget, args)
if args["{status}"] == "Stopped" then
return " - "
else
return args["{status}"]..': '.. args["{artist}"]..' - '.. args["{title}"]..' ### '.. args["{genre}"]
end
end, 7)
--}}}
rc.lua (awesome 3.5)
-- {{{ Cmus info
musicicon = wibox.widget.imagebox()
musicicon:set_image(beautiful.widget_music)
-- Initialize widget
cmus_widget = wibox.widget.textbox()
-- Register widget
vicious.register(cmus_widget, vicious.widgets.cmus,
function (widget, args)
if args["{status}"] == "Stopped" then
return " - "
else
return args["{status}"]..': '.. args["{artist}"]..' - '.. args["{title}"]..' ### '.. args["{genre}"]
end
end, 7)
--}}}
Then look for mywibox defined somewhere in rc.lua and add cmus_widget
-- Add widgets to the wibox - order matters
mywibox[s].widgets = {
{
mylauncher,
mytaglist[s],
mypromptbox[s],
layout = awful.widget.layout.horizontal.leftright
},
mylayoutbox[s],
mytextclock,
-- Add the cmus_widget to the wibox
cmus_widget,
-- --------------------------------
s == 1 and mysystray or nil,
mytasklist[s],
layout = awful.widget.layout.horizontal.rightleft
}
Or for awesome 3.5:
-- Widgets that are aligned to the right
local right_layout = wibox.layout.fixed.horizontal()
if s == 1 then right_layout:add(wibox.widget.systray()) end
right_layout:add(cmus_widget)
right_layout:add(mytextclock)
right_layout:add(mylayoutbox[s])