we asynchronous wallpapers now

This commit is contained in:
Izaya 2021-10-25 17:24:33 +11:00
parent 06d632dd8a
commit b64b7c0f95

35
rc.lua
View File

@ -165,25 +165,42 @@ local tasklist_buttons = gears.table.join(
awful.button({ }, 5, function () awful.button({ }, 5, function ()
awful.client.focus.byidx(-1) awful.client.focus.byidx(-1)
end)) end))
local used_wallpapers = {}
local function set_wallpaper(s) local function set_wallpaper(s)
print(s)
local wpath local wpath
if s.geometry.width > s.geometry.height then -- landscape if s.geometry.width > s.geometry.height then -- landscape
wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers" wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers"
else else -- portrait
wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers/Phone" wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers/Phone"
end end
return awful.spawn.easy_async_with_shell(string.format('ls "%s"',wpath), function(out)
local tWP = {} local tWP = {}
for line in io.popen(string.format('ls "%s"',wpath),"r"):read("*a"):gmatch("([^\n]+)") do for line in out:gmatch("[^\n]+") do
tWP[#tWP+1] = line tWP[#tWP+1] = line
end end
local rv local rv, unique
repeat repeat
unique = true
rv = tWP[math.random(1,#tWP)] rv = tWP[math.random(1,#tWP)]
local width, height = io.popen(string.format('identify -format "%%w %%h" "%s/%s"',wpath,rv)):read("*a"):match("(%d+) (%d+)") for k,v in pairs(used_wallpapers) do
if v == rv then
unique = false
end
end
until unique
awful.spawn.easy_async_with_shell(string.format('identify -format "%%w %%h" "%s/%s"',wpath,rv), function(out)
local width, height = out:match("(%d+) (%d+)")
width, height = tonumber(width) or 0, tonumber(height) or 0 width, height = tonumber(width) or 0, tonumber(height) or 0
until width > s.geometry.width and height > s.geometry.height print(width, height)
if width > s.geometry.width and height > s.geometry.height then
gears.wallpaper.maximized(wpath .. "/" .. rv, s, false) gears.wallpaper.maximized(wpath .. "/" .. rv, s, false)
collectgarbage("step",4000) used_wallpapers[s:index()] = rv
else
return set_wallpaper(s)
end
end)
end)
end end
-- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution)
screen.connect_signal("property::geometry", set_wallpaper) screen.connect_signal("property::geometry", set_wallpaper)
@ -614,11 +631,11 @@ awful.rules.rules = {
{ rule = { class = "Steam", name = "Steam" }, { rule = { class = "Steam", name = "Steam" },
properties = {tag = "2", titlebars_enabled = false } }, properties = {tag = "2", titlebars_enabled = false } },
{ rule = { class = "Steam", name = "Friends List.*"}, { rule = { class = "Steam", name = "Friends List.*"},
properties = {tag = "4", titlebars_enabled = false } }, properties = {tag = "5", titlebars_enabled = false } },
{ rule = { class = "Pidgin"}, { rule = { class = "Pidgin"},
properties = {tag = "4"} }, properties = {tag = "5"} },
{ rule = { class = "Gajim", name = ".*File Transfer.*"}, { rule = { class = "Gajim", name = ".*File Transfer.*"},
properties = {tag = "3", floating = true } }, properties = {tag = "4", floating = true } },
} }
-- }}} -- }}}