Initial commit
This commit is contained in:
commit
82fc0c1671
6
init.lua
Normal file
6
init.lua
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
-- {{{ Configure widgets
|
||||||
|
require("iniquitous.mpc")
|
||||||
|
require("iniquitous.volume")
|
||||||
|
-- }}}
|
||||||
|
|
||||||
|
module("iniquitous")
|
127
mpc.lua
Executable file
127
mpc.lua
Executable file
@ -0,0 +1,127 @@
|
|||||||
|
local awful = awful
|
||||||
|
local naughty = { notify = naughty.notify }
|
||||||
|
local widget = widget
|
||||||
|
local timer = timer
|
||||||
|
local string = string
|
||||||
|
local os = {
|
||||||
|
getenv = os.getenv,
|
||||||
|
execute = os.execute
|
||||||
|
}
|
||||||
|
local io = {
|
||||||
|
open = io.open,
|
||||||
|
close = io.close
|
||||||
|
}
|
||||||
|
local table = {
|
||||||
|
insert = table.insert
|
||||||
|
}
|
||||||
|
local print = print
|
||||||
|
local tonumber = tonumber
|
||||||
|
|
||||||
|
module("iniquitous.mpc")
|
||||||
|
|
||||||
|
function music_current_short()
|
||||||
|
local music = awful.util.pread('mpc -f "[%artist%]##[%track%]##[%title%]##[%time%]##" | head -2 | sed "s/^\\[\\(playing\\|paused\\)\\] \\+#[0-9]\\+\\/[0-9]\\+ \\+\\([0-9]\\+:[0-9]\\+\\)\\/.*$/\\1#\\2#/" | tr -d "\\n"')
|
||||||
|
--print(music)
|
||||||
|
|
||||||
|
local len_max = 20
|
||||||
|
local t = {}
|
||||||
|
for k in string.gmatch(music, "[^#]*#") do
|
||||||
|
k = string.sub(k, 1, string.len(k)-1)
|
||||||
|
if(string.len(k) > len_max) then
|
||||||
|
k = string.sub(k, 1, len_max).."..."
|
||||||
|
end
|
||||||
|
table.insert(t, k)
|
||||||
|
end
|
||||||
|
|
||||||
|
local res
|
||||||
|
if(#t >= 6) then
|
||||||
|
res = t[1].. " - " ..t[2].. " - " ..t[3].. " # " .. t[6] .. "/" ..t[4].. " ["..t[5].."]"
|
||||||
|
else
|
||||||
|
res = "Mpd Daemon is not runnig"
|
||||||
|
end
|
||||||
|
|
||||||
|
return awful.util.escape(res)
|
||||||
|
end
|
||||||
|
function music_current_full()
|
||||||
|
local music = awful.util.pread("mpc -f \"[%artist%]\\n%album%\\n%track% - %title%\\n## %time%\" | head -4");
|
||||||
|
|
||||||
|
if(string.len(music) == 0) then
|
||||||
|
music = "Mpd Daemon is not runnig"
|
||||||
|
else
|
||||||
|
music = string.sub(music, 1, string.len(music)-1)
|
||||||
|
end
|
||||||
|
|
||||||
|
return awful.util.escape(music)
|
||||||
|
end
|
||||||
|
function music_cover()
|
||||||
|
local cover = os.getenv("HOME") .. "/.album/default.png"
|
||||||
|
local music = awful.util.pread("mpc -f \"%artist%-%album%\"")
|
||||||
|
--local dir = awful.util.pread("qdbus org.gnome.Rhythmbox /org/gnome/Rhythmbox/Player \"org.gnome.Rhythmbox.Player.getPlayingUri\"")
|
||||||
|
--local dir_format = url_decode(dir:sub(8, dir:find("\/[^\/]+$")))
|
||||||
|
--print(dir_format)
|
||||||
|
|
||||||
|
local dir = "/home/gdott9/Music/" .. awful.util.pread("dirname \"`mpc -f '%file%' | head -1`\"")
|
||||||
|
|
||||||
|
if(string.len(music) > 0) then
|
||||||
|
music = string.gsub(string.sub(music, 1, string.len(music)-1), "[/\?%*:|\"<>]", "_")
|
||||||
|
--local file = os.getenv("HOME") .. "/.album/".. music ..".jpg"
|
||||||
|
local file = string.sub(dir, 1, string.len(dir)-1) .. "/cover.jpg"
|
||||||
|
local test = io.open(file)
|
||||||
|
--print(file)
|
||||||
|
|
||||||
|
if(test ~= nil) then
|
||||||
|
--print("good")
|
||||||
|
io.close(test)
|
||||||
|
cover = file
|
||||||
|
else
|
||||||
|
file = os.getenv("HOME") .. "/.album/".. music ..".jpg"
|
||||||
|
test = io.open(file)
|
||||||
|
if(test ~= nil) then
|
||||||
|
io.close(test)
|
||||||
|
cover = file
|
||||||
|
end
|
||||||
|
--print("bad")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return cover
|
||||||
|
--local cover = awful.util.pread("conkyRhythmbox -d CA")
|
||||||
|
|
||||||
|
--return (cover.len > 0) and cover or os.getenv("HOME") .. "/.album/default.png"
|
||||||
|
end
|
||||||
|
function notify()
|
||||||
|
naughty.notify({
|
||||||
|
icon=music_cover(),
|
||||||
|
icon_size=50,
|
||||||
|
text=music_current_full(),
|
||||||
|
position="bottom_right",
|
||||||
|
timeout=2
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function init()
|
||||||
|
tb = widget({ type = "textbox" })
|
||||||
|
tb.text = "Rhythmbox"
|
||||||
|
tb:buttons(awful.util.table.join(
|
||||||
|
awful.button({ }, 1, function () notify() end),
|
||||||
|
awful.button({ }, 3, function ()
|
||||||
|
os.execute("mpc toggle >/dev/null")
|
||||||
|
tb.text = music_current_short()
|
||||||
|
end)
|
||||||
|
))
|
||||||
|
|
||||||
|
local timer = timer { timeout = 2 }
|
||||||
|
timer:add_signal("timeout", function() tb.text = music_current_short() end)
|
||||||
|
timer:start()
|
||||||
|
|
||||||
|
tb.text = music_current_short()
|
||||||
|
return tb
|
||||||
|
end
|
||||||
|
|
||||||
|
function url_decode(str)
|
||||||
|
str = string.gsub (str, "+", " ")
|
||||||
|
str = string.gsub (str, "%%(%x%x)",
|
||||||
|
function(h) return string.char(tonumber(h,16)) end)
|
||||||
|
str = string.gsub (str, "\r\n", "\n")
|
||||||
|
return str
|
||||||
|
end
|
125
volume.lua
Executable file
125
volume.lua
Executable file
@ -0,0 +1,125 @@
|
|||||||
|
local awful = awful
|
||||||
|
local beautiful = beautiful
|
||||||
|
local widget = widget
|
||||||
|
local timer = timer
|
||||||
|
local string = string
|
||||||
|
local tonumber = tonumber
|
||||||
|
local image = image
|
||||||
|
local os = {
|
||||||
|
getenv = os.getenv,
|
||||||
|
execute = os.execute
|
||||||
|
}
|
||||||
|
local io = {
|
||||||
|
open = io.open,
|
||||||
|
close = io.close
|
||||||
|
}
|
||||||
|
local table = {
|
||||||
|
insert = table.insert
|
||||||
|
}
|
||||||
|
module("iniquitous.volume")
|
||||||
|
|
||||||
|
local img = widget({ type = "imagebox" })
|
||||||
|
local tb = widget({ type = "textbox" })
|
||||||
|
tb.text = "N/A%"
|
||||||
|
|
||||||
|
local initialized = false
|
||||||
|
|
||||||
|
local channel = ""
|
||||||
|
local mode = ""
|
||||||
|
|
||||||
|
local mute = ""
|
||||||
|
local unmute = ""
|
||||||
|
local unmute2 = ""
|
||||||
|
|
||||||
|
local up = ""
|
||||||
|
local down = ""
|
||||||
|
local value = nil
|
||||||
|
|
||||||
|
local vol = 0
|
||||||
|
|
||||||
|
function init(a_mode, a_channel)
|
||||||
|
mode = a_mode
|
||||||
|
channel = a_channel
|
||||||
|
|
||||||
|
if mode == "oss" then
|
||||||
|
up = "ossmix " .. channel .. " +2"
|
||||||
|
down = "ossmix " .. channel .. " -- -2"
|
||||||
|
mute = "ossmix " .. channel .. " 0"
|
||||||
|
unmute = "ossmix " .. channel .. " "
|
||||||
|
value = function() return awful.util.pread("ossmix " .. channel):match("(%d+)") end
|
||||||
|
|
||||||
|
initialized = true
|
||||||
|
elseif mode == "alsa" then
|
||||||
|
up = "amixer sset " .. channel .. " 2%+"
|
||||||
|
down = "amixer sset " .. channel .. " 2%-"
|
||||||
|
mute = "amixer sset " .. channel .. " 0"
|
||||||
|
unmute = "amixer sset " .. channel .. " "
|
||||||
|
unmute2 = "%"
|
||||||
|
value = function() return awful.util.pread("amixer get " .. channel):match("(%d+)%%") end
|
||||||
|
|
||||||
|
initialized = true
|
||||||
|
end
|
||||||
|
volume(display)
|
||||||
|
|
||||||
|
local but = awful.util.table.join(
|
||||||
|
awful.button({ }, 3, function () volume("mute") end),
|
||||||
|
awful.button({ }, 4, function () volume("up") end),
|
||||||
|
awful.button({ }, 5, function () volume("down") end)
|
||||||
|
)
|
||||||
|
tb:buttons(but)
|
||||||
|
img:buttons(but)
|
||||||
|
|
||||||
|
local timer = timer { timeout = 7 }
|
||||||
|
timer:add_signal("timeout", function() volume("display") end)
|
||||||
|
timer:start()
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
function volume(mode)
|
||||||
|
if mode == "up" then
|
||||||
|
os.execute(up .. " >/dev/null")
|
||||||
|
elseif mode == "down" then
|
||||||
|
os.execute(down .. " >/dev/null")
|
||||||
|
elseif mode == "mute" then
|
||||||
|
--The mute option is useless without ossvol, ossmix does not navitely support muting
|
||||||
|
--awful.util.spawn("ossvol -t")
|
||||||
|
local volume = value()
|
||||||
|
|
||||||
|
volume = tonumber(volume)
|
||||||
|
if volume == 0 then
|
||||||
|
os.execute(unmute .. vol .. unmute2 .. " >/dev/null")
|
||||||
|
else
|
||||||
|
vol = volume
|
||||||
|
os.execute(mute .. " >/dev/null")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local volume = tonumber(value())
|
||||||
|
display(volume)
|
||||||
|
end
|
||||||
|
|
||||||
|
function display(volume)
|
||||||
|
if volume == nil then
|
||||||
|
vol_lvl = "mute"
|
||||||
|
volume = 0
|
||||||
|
elseif volume == 0 then
|
||||||
|
vol_lvl = "mute"
|
||||||
|
elseif volume < 25 then
|
||||||
|
vol_lvl = "low"
|
||||||
|
elseif volume < 50 then
|
||||||
|
vol_lvl = "med"
|
||||||
|
elseif volume < 75 then
|
||||||
|
vol_lvl = "med2"
|
||||||
|
else
|
||||||
|
vol_lvl = "high"
|
||||||
|
end
|
||||||
|
img.image = image(beautiful["vol_" .. vol_lvl])
|
||||||
|
tb.text = volume .."%"
|
||||||
|
end
|
||||||
|
|
||||||
|
function textbox()
|
||||||
|
return tb
|
||||||
|
end
|
||||||
|
function imagebox()
|
||||||
|
return img
|
||||||
|
end
|
Loading…
x
Reference in New Issue
Block a user