we asynchronous wallpapers now

This commit is contained in:
Izaya 2021-10-25 17:24:33 +11:00
parent 06d632dd8a
commit b64b7c0f95
1 changed files with 33 additions and 16 deletions

49
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
local tWP = {} return awful.spawn.easy_async_with_shell(string.format('ls "%s"',wpath), function(out)
for line in io.popen(string.format('ls "%s"',wpath),"r"):read("*a"):gmatch("([^\n]+)") do local tWP = {}
tWP[#tWP+1] = line for line in out:gmatch("[^\n]+") do
end tWP[#tWP+1] = line
local rv end
repeat local rv, unique
rv = tWP[math.random(1,#tWP)] repeat
local width, height = io.popen(string.format('identify -format "%%w %%h" "%s/%s"',wpath,rv)):read("*a"):match("(%d+) (%d+)") unique = true
width, height = tonumber(width) or 0, tonumber(height) or 0 rv = tWP[math.random(1,#tWP)]
until width > s.geometry.width and height > s.geometry.height for k,v in pairs(used_wallpapers) do
gears.wallpaper.maximized(wpath .. "/" .. rv, s, false) if v == rv then
collectgarbage("step",4000) 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
print(width, height)
if width > s.geometry.width and height > s.geometry.height then
gears.wallpaper.maximized(wpath .. "/" .. rv, s, false)
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 } },
} }
-- }}} -- }}}