From b64b7c0f95d1ed2e5a5613362b52954fe0f2f94b Mon Sep 17 00:00:00 2001 From: XeonSquared Date: Mon, 25 Oct 2021 17:24:33 +1100 Subject: [PATCH] we asynchronous wallpapers now --- rc.lua | 49 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 33 insertions(+), 16 deletions(-) diff --git a/rc.lua b/rc.lua index 2ea7f70..0f6f1cd 100644 --- a/rc.lua +++ b/rc.lua @@ -165,25 +165,42 @@ local tasklist_buttons = gears.table.join( awful.button({ }, 5, function () awful.client.focus.byidx(-1) end)) +local used_wallpapers = {} local function set_wallpaper(s) + print(s) local wpath if s.geometry.width > s.geometry.height then -- landscape wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers" - else + else -- portrait wpath = "/home/izaya/Nextcloud/Pictures/Wallpapers/Phone" end - local tWP = {} - for line in io.popen(string.format('ls "%s"',wpath),"r"):read("*a"):gmatch("([^\n]+)") do - tWP[#tWP+1] = line - end - local rv - repeat - 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+)") - width, height = tonumber(width) or 0, tonumber(height) or 0 - until width > s.geometry.width and height > s.geometry.height - gears.wallpaper.maximized(wpath .. "/" .. rv, s, false) - collectgarbage("step",4000) + return awful.spawn.easy_async_with_shell(string.format('ls "%s"',wpath), function(out) + local tWP = {} + for line in out:gmatch("[^\n]+") do + tWP[#tWP+1] = line + end + local rv, unique + repeat + unique = true + rv = tWP[math.random(1,#tWP)] + 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 + 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 -- Re-set wallpaper when a screen's geometry changes (e.g. different resolution) screen.connect_signal("property::geometry", set_wallpaper) @@ -614,11 +631,11 @@ awful.rules.rules = { { rule = { class = "Steam", name = "Steam" }, properties = {tag = "2", titlebars_enabled = false } }, { rule = { class = "Steam", name = "Friends List.*"}, - properties = {tag = "4", titlebars_enabled = false } }, + properties = {tag = "5", titlebars_enabled = false } }, { rule = { class = "Pidgin"}, - properties = {tag = "4"} }, + properties = {tag = "5"} }, { rule = { class = "Gajim", name = ".*File Transfer.*"}, - properties = {tag = "3", floating = true } }, + properties = {tag = "4", floating = true } }, } -- }}}