Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

113 lines
4.0 KiB

local awful = require("awful")
local pager = require("pager")
local beautiful = require("beautiful")
local gears = require("gears")
local wibox = require("wibox")
local awmtk2 = require("awmtk2")
local thumbnailer = require("thumbnail")
local function ls(path)
local ls_data = io.popen("find "..path.." -maxdepth 1 -type f \\( -name \\*.jpg -o -name \\*.png \\) -exec realpath {} \\;")
local output = {}
if ls_data then
ls_data:read("*a"):gsub("[^\n]+",function(capt)
table.insert(output,capt)
end)
ls_data:close()
return output
end
error("Failed to process directory "..path)
end
return function(args)
local style = awmtk2.create_style("wallpapers",awmtk2.default,args.style)
local templates = awmtk2.create_template_lib("wallpapers",awmtk2.templates,args.templates)
local t = awmtk2.build_templates(templates,style)
-- set wallpaper
local fhandler = io.open(root_path.."/wallpaper.txt","r")
if fhandler then
local wallpaper_path = fhandler:read("*a")
gears.wallpaper.maximized(wallpaper_path,args.screen)
else
-- try to set wallpaper from theme settings
if beautiful.wallpaper then
gears.wallpaper.maximized(beautiful.wallpaper,args.screen)
end
end
-- update wallpaper preference and set wallpaper
local function set_wallpaper(s)
local handler = io.open(root_path.."/wallpaper.txt","w")
handler:write(s)
handler:close()
gears.wallpaper.maximized(s,args.screen)
end
if not args.path then
args.path = os.getenv("HOME").."/Pictures"
end
-- read wallpapers from wallpaper directory
local image_list = ls(args.path)
-- generate thumbnails to save memory
thumbnailer.generate(args.path,args.path.."/.thumbnails",60)
-- create a layout for wallpaper buttons
local layout = wibox.widget({
layout = wibox.layout.grid,
forced_num_cols = args.columns or 4,
homogenous = true,
expand = true,
orientation = "vertical",
spacing = style.base.spacing
})
-- set up a pager for having multiple pages of wallpapers
local pager = pager(layout,{},((args.rows and args.columns) and args.rows*args.columns) or 20)
-- add wallpaper buttons
for k,v in pairs(image_list) do
local new_button = wibox.widget(t.button(t.center({
image = v,
resize = true,
widget = wibox.widget.imagebox
},{
height = args.height or 60,
width = args.width or 100
})))
new_button:connect_signal("button::press",style.button.onpress)
new_button:connect_signal("button::release",style.button.onrelease)
new_button:connect_signal("button::press",function(self,x,y,button)
if button == 1 then
set_wallpaper(v)
elseif button == 4 then
pager:prev()
elseif button == 5 then
pager:next()
end
end)
table.insert(pager.list,new_button)
end
-- update pager
pager:update()
-- create layout popup
local popup = awful.popup(t.popup(t.container(layout),{
visible = false
}))
popup:connect_signal("button::press",function(self,x,y,button)
if button == 3 then
popup.visible = false
end
end)
-- create popup button
local clip_widget = wibox.widget(t.button({
image = beautiful.wallpapers_icon,
resize = true,
widget = wibox.widget.imagebox
}))
clip_widget:connect_signal("button::press",style.button.onpress)
clip_widget:connect_signal("button::release",style.button.onrelease)
clip_widget:connect_signal("button::press",function(self,x,y,button)
if button == 1 then
popup.visible = (not popup.visible)
if popup.visible then
popup:move_next_to(mouse.current_widget_geometry)
end
end
end)
return clip_widget
end