-
-
Save andreymal/500b96c3c9e63944007d4b9bd5c34e2e to your computer and use it in GitHub Desktop.
Random wallpaper in Awesome WM
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Sources: | |
-- * https://wiki.archlinux.org/index.php?oldid=265165#Random_Background_Image | |
-- * https://wiki.archlinux.org/title/Special:Diff/265909 | |
-- * https://www.reddit.com/r/awesomewm/comments/3r01p1/ | |
-- {{{ Function definitions | |
-- scan directory, and optionally filter outputs | |
function scandir(directory, filter) | |
local i, t, popen = 0, {}, io.popen | |
if not filter then | |
filter = function(s) return true end | |
end | |
print(filter) | |
for filename in popen('ls -a "'..directory..'"'):lines() do | |
if filter(filename) then | |
i = i + 1 | |
t[i] = filename | |
end | |
end | |
return t | |
end | |
-- }}} | |
-- configuration - edit to your liking | |
wp_timeout = 10 | |
wp_path = "/path/to/wallpapers/" | |
wp_filter = function(s) return string.match(s,"%.png$") or string.match(s,"%.jpg$") end | |
wp_files = scandir(wp_path, wp_filter) | |
-- initialize the random generator | |
math.randomseed(os.time()) | |
-- setup the timer | |
wp_timer = timer { timeout = wp_timeout } | |
wp_timer:connect_signal("timeout", function() | |
-- get random index | |
local wp_index = math.random( 1, #wp_files) | |
-- set wallpaper to current index for all screens | |
for s = 1, screen.count() do | |
gears.wallpaper.maximized(wp_path .. wp_files[wp_index], s, true) | |
end | |
-- stop the timer (we don't need multiple instances running at the same time) | |
wp_timer:stop() | |
--restart the timer | |
wp_timer.timeout = wp_timeout | |
wp_timer:start() | |
end) | |
-- initial start when rc.lua is first run | |
wp_timer:start() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks