From c4e225c02c4a854a443b6a13bc4dea3cf77461d8 Mon Sep 17 00:00:00 2001 From: Don Armstrong Date: Tue, 29 Jul 2014 15:41:20 -0700 Subject: [PATCH] update rc.lua to add backgrounds --- .config/awesome/rc.lua | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/.config/awesome/rc.lua b/.config/awesome/rc.lua index 59136b8..a3b3b94 100644 --- a/.config/awesome/rc.lua +++ b/.config/awesome/rc.lua @@ -13,6 +13,23 @@ require("obvious.battery") -- Load Debian menu entries require("debian.menu") +-- from https://github.com/tony/awesome-config/blob/master/helpers.lua +function clean(string) + s = string.gsub(string, '^%s+', '') + s = string.gsub(s, '%s+$', '') + s = string.gsub(s, '[\n\r]+', ' ') + return s +end + +function file_exists(file) + local cmd = "/bin/dash -c 'if [ -e " .. file .. " ]; then echo true; fi;'" + local fh = io.popen(cmd) + + s = clean(fh:read('*a')) + + if s == 'true' then return true else return nil end +end + -- {{{ Variable definitions -- Themes define colours, icons, and wallpapers beautiful.init("/usr/share/awesome/themes/default/theme.lua") @@ -21,9 +38,38 @@ beautiful.init("/usr/share/awesome/themes/default/theme.lua") terminal = "x-terminal-emulator" editor = os.getenv("EDITOR") or "editor" editor_cmd = terminal .. " -e " .. editor +home = os.getenv("HOME") hostname = awful.util.pread("hostname -f"):gsub("\n", "") +wallpaper_dir = home .. "/media/photos/gallery.donarmstrong.com/" +if (not file_exists(wallpaper_dir)) then + wallpaper_dir = "/usr/share/awesome/themes/default/background.png" +end + +wallpaper_cmd = "find " .. wallpaper_dir .. + " -xtype f \\( -iname '*.jpg' -o -iname '*.png' \\) " .. + " -not -name '.*' -print0 | shuf -n" .. screen.count() .. " -z | xargs -0 feh --bg-max" + +-- set up the wallpaper timer +wallpaper_timer = timer { timeout = 0 } +wallpaper_timer:add_signal("timeout", + function() + -- tell awsetbg to randomly choose a wallpaper from your wallpaper directory + if file_exists(wallpaper_dir) and whereis_app('feh') then + os.execute(wallpaper_cmd) + end + -- stop the timer (we don't need multiple instances running at the same time) + mytimer:stop() + + -- define the interval in which the next wallpaper change should occur in seconds + -- (in this case anytime between 10 and 20 minutes) + --restart the timer + mytimer.timeout = math.random(600,1200) + mytimer:start() + end +) + -- Default modkey. -- Usually, Mod4 is the key with a logo between Control and Alt. -- If you do not like this or do not have such a key, -- 2.39.2