From 63f517dbfb70369f15738dfe7b6e5447cac9db9e Mon Sep 17 00:00:00 2001 From: Thomas Forgione Date: Fri, 31 Aug 2018 16:31:37 +0200 Subject: [PATCH] Random wallpaper --- awesome/rc.lua | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/awesome/rc.lua b/awesome/rc.lua index 0eab51e..8c10dfb 100644 --- a/awesome/rc.lua +++ b/awesome/rc.lua @@ -1,3 +1,6 @@ +local os = require('os') +local math = require('math') + -- Standard awesome library local gears = require("gears") local awful = require("awful") @@ -18,6 +21,26 @@ home = os.getenv('HOME') os.execute('xset m 16/1 0') os.setlocale("fr_FR.UTF-8") +local wallpaper_root = home .. "/Pictures/current-wallpapers/" +local max_wallpaper_index = 192 +math.randomseed(os.time()) + +current_wallpaper_index = math.floor(1 + math.random() * (max_wallpaper_index)) + +function update_wallpaper() + for s = 1, screen.count() do + current_wallpaper_index = current_wallpaper_index + 1 + if current_wallpaper_index > max_wallpaper_index then + current_wallpaper_index = 1 + end + local wallpaper = wallpaper_root .. string.format("%04d", current_wallpaper_index) .. '.jpg' + gears.wallpaper.maximized(wallpaper, s, true) + end +end + +local wallpaper_timer = timer({timeout=600}) +wallpaper_timer:connect_signal("timeout", update_wallpaper) + -- Run xsession if exists function file_exists(name) local f=io.open(name,"r") @@ -699,4 +722,8 @@ end) client.connect_signal("focus", function(c) c.border_color = beautiful.border_focus end) client.connect_signal("unfocus", function(c) c.border_color = beautiful.border_normal end) + +wallpaper_timer:start() +update_wallpaper() + -- }}}