-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallpaper.lua
40 lines (31 loc) · 1.08 KB
/
wallpaper.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
-- {{{ Random Wallpapers-- Get the list of files from a directory. Must be all images or folders and non-empty.
local gears = require("gears")
local io = io
local math = math
local os = os
local wallpaper = {}
function wallpaper.scanDir(directory)
local i, fileList, popen = 0, {}, io.popen
for filename in popen([[find "]] ..directory.. [[" -type f -iregex '.*\.\w*' ]]):lines() do
i = i + 1
fileList[i] = filename
end
return fileList
end
wallpaperList = wallpaper.scanDir("/home/grey/Images/FromPhone-Pictures/backgrounds/")
math.randomseed(os.time())
function wallpaper.setPaper(s)
gears.wallpaper.maximized(wallpaperList[math.random(1, #wallpaperList)], s, false)
end
-- Apply a random wallpaper every changeTime seconds.
changeTime = 600
wallpaper.timer = gears.timer { timeout = changeTime }
wallpaper.timer:connect_signal("timeout", function()
wallpaper.setPaper(s)
-- stop the timer (we don't need multiple instances running at the same time)
wallpaper.timer:stop()
--restart the timer
wallpaper.timer.timeout = changeTime
wallpaper.timer:start()
end)
return wallpaper