Added pager widget
This commit is contained in:
parent
328f7aa71b
commit
db4839b716
|
@ -0,0 +1,37 @@
|
|||
local awful = require("awful")
|
||||
local awmtk = require("awmtk")
|
||||
local wibox = require("wibox")
|
||||
|
||||
return function(widget,list,max_elements)
|
||||
if not tostring(widget):match("wibox.layout") then
|
||||
error("Cannot attach pager to widget that isn't a layout")
|
||||
end
|
||||
local new_pager = {
|
||||
page = widget,
|
||||
list = list,
|
||||
index = 0,
|
||||
max = max_elements
|
||||
}
|
||||
function new_pager:update()
|
||||
self.page:reset()
|
||||
for i = 1+(self.max*self.index),self.max+(self.max*self.index) do
|
||||
if self.list[i] then
|
||||
self.page:add(self.list[i])
|
||||
end
|
||||
end
|
||||
end
|
||||
function new_pager:next()
|
||||
if #list > self.index*self.max then
|
||||
self.index = self.index + 1
|
||||
new_pager:update()
|
||||
end
|
||||
end
|
||||
function new_pager:prev()
|
||||
if self.index > 0 then
|
||||
self.index = self.index - 1
|
||||
new_pager:update()
|
||||
end
|
||||
end
|
||||
new_pager:update()
|
||||
return new_pager
|
||||
end
|
|
@ -1,4 +1,5 @@
|
|||
local awful = require("awful")
|
||||
local pager = require("widgets.pager")
|
||||
local beautiful = require("beautiful")
|
||||
local gears = require("gears")
|
||||
local spawn = require("awful.spawn")
|
||||
|
@ -67,20 +68,22 @@ local function worker(args)
|
|||
})
|
||||
return new_widget
|
||||
end
|
||||
local copy_list = {
|
||||
widget = wibox.layout.grid,
|
||||
local copy_list = wibox.widget {
|
||||
layout = wibox.layout.grid,
|
||||
forced_num_cols = args.columns or 4,
|
||||
homogeneous = true,
|
||||
expand = true,
|
||||
orientation = "vertical",
|
||||
spacing = 5
|
||||
}
|
||||
local pager = pager(copy_list,{},20)
|
||||
for k,v in pairs(image_list) do
|
||||
local new_widget = new_wallpaper_button(v,args["screen"])
|
||||
table.insert(copy_list,new_widget)
|
||||
table.insert(pager.list,new_widget)
|
||||
end
|
||||
pager:update()
|
||||
local popup = awful.popup(style.container(
|
||||
copy_list,
|
||||
pager.page,
|
||||
{
|
||||
visible = false,
|
||||
ontop = true
|
||||
|
@ -102,6 +105,16 @@ local function worker(args)
|
|||
end
|
||||
})
|
||||
widget = clip_widget
|
||||
root.keys(gears.table.join(
|
||||
root.keys(),
|
||||
awful.key({global.modkey,"Control"},"b",function()
|
||||
pager:next()
|
||||
end),
|
||||
awful.key({global.modkey,"Control"},"v",function()
|
||||
pager:prev()
|
||||
end)
|
||||
))
|
||||
|
||||
return clip_widget
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,108 @@
|
|||
local awful = require("awful")
|
||||
local beautiful = require("beautiful")
|
||||
local gears = require("gears")
|
||||
local spawn = require("awful.spawn")
|
||||
local wibox = require("wibox")
|
||||
local awmtk = require("awmtk")
|
||||
local thumbnailer = require("thumbnail")
|
||||
local widget = {}
|
||||
local function ls(path)
|
||||
local ls_data = io.popen("ls -1 "..path)
|
||||
local output = {}
|
||||
if ls_data then
|
||||
ls_data:read("*a"):gsub("[^\n]+",function(capt) table.insert(output,capt) end)
|
||||
ls_data:close()
|
||||
else
|
||||
error("ls "..path.." failed.")
|
||||
end
|
||||
return output
|
||||
end
|
||||
|
||||
local function worker(args)
|
||||
local args = args or {}
|
||||
assert(type(args["screen"]) ~= "nil","Screen not specified")
|
||||
assert(type(args["path"]) ~= "nil","Path to wallpapers folder not specified")
|
||||
--add an extra slash to path if there is none
|
||||
if not args["path"]:match("/$") then
|
||||
args["path"] = args["path"].."/"
|
||||
end
|
||||
--create local style
|
||||
local style = awmtk.style(awmtk.defaults,args.style or {},"wallpapers_")
|
||||
--set wallpaper
|
||||
local handler = io.open(global.config_dir.."/.wallpaper","r")
|
||||
if handler then
|
||||
local wallpaper_path = handler:read("*a")
|
||||
gears.wallpaper.maximized(wallpaper_path,args["screen"])
|
||||
end
|
||||
local function update_last_wallpaper(s)
|
||||
local handler = io.open(global.config_dir.."/.wallpaper","w")
|
||||
handler:write(s)
|
||||
handler:close()
|
||||
end
|
||||
--read wallpapers from the wallpaper directory
|
||||
local image_list = ls(args["path"])
|
||||
for k,v in pairs(image_list) do
|
||||
if not (v:match("%.jpg$") or v:match("%.png$")) then
|
||||
image_list[k] = nil
|
||||
end
|
||||
end
|
||||
--generate thumbnails to save up memory
|
||||
thumbnailer.generate(args["path"],args["path"]..".thumbnails",60)
|
||||
--style variables
|
||||
local button_bg = style.wallpapers_button_bg_focus
|
||||
local function new_wallpaper_button(image,s)
|
||||
local new_widget = style.button({
|
||||
image = args["path"]..".thumbnails/"..image,
|
||||
resize = true,
|
||||
widget = wibox.widget.imagebox
|
||||
},{
|
||||
bg = button_bg,
|
||||
forced_height = style.wallpapers_button_height or 60,
|
||||
forced_width = style.wallpapers_button_width or 100
|
||||
},{
|
||||
function()
|
||||
gears.wallpaper.maximized(args["path"]..image,s)
|
||||
update_last_wallpaper(args["path"]..image)
|
||||
end
|
||||
})
|
||||
return new_widget
|
||||
end
|
||||
local copy_list = {
|
||||
widget = wibox.layout.grid,
|
||||
forced_num_cols = args.columns or 4,
|
||||
homogeneous = true,
|
||||
expand = true,
|
||||
orientation = "vertical",
|
||||
spacing = 5
|
||||
}
|
||||
for k,v in pairs(image_list) do
|
||||
local new_widget = new_wallpaper_button(v,args["screen"])
|
||||
table.insert(copy_list,new_widget)
|
||||
end
|
||||
local popup = awful.popup(style.container(
|
||||
copy_list,
|
||||
{
|
||||
visible = false,
|
||||
ontop = true
|
||||
}
|
||||
))
|
||||
local clip_widget = style.icon({
|
||||
image = style["wallpapers_icon"],
|
||||
resize = true,
|
||||
widget = wibox.widget.imagebox
|
||||
},{},{
|
||||
function()
|
||||
if popup.visible then
|
||||
--rows = nil
|
||||
popup.visible = not popup.visible
|
||||
else
|
||||
--init_popup()
|
||||
popup:move_next_to(mouse.current_widget_geometry)
|
||||
end
|
||||
end
|
||||
})
|
||||
widget = clip_widget
|
||||
return clip_widget
|
||||
end
|
||||
|
||||
return setmetatable(widget, { __call = function(_, ...) return worker(...) end })
|
Loading…
Reference in New Issue