Add themes and wallpapers menus.
--- a/awesome/my.lua Sat Jun 20 16:21:25 2015 -0400
+++ b/awesome/my.lua Sat Jun 20 20:32:45 2015 -0400
@@ -1,6 +1,7 @@
local os = require("os")
local io = require("io")
local debug = require("debug")
+local table = require("table")
local awesome = require("awesome")
local naughty = require("naughty")
local awful = require("awful")
@@ -61,8 +62,8 @@
notify_error = mk_notify_error_dialog(3)
-local function get_gradient_colors(c1, c2, c3)
- return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c1 }, { 0.5, c2 }, { 1, c3 } }}
+local function get_gradient_colors(c1, c2)
+ return { type = "linear", from = { 0, 0 }, to = { 0, 20 }, stops = { { 0, c2 }, { 1, c1 } }}
end
function mkspawn(p)
@@ -102,8 +103,8 @@
local w = awful.widget.graph()
-- Graph properties
w:set_width(30)
- w:set_background_color("#729fcf")
- w:set_color(get_gradient_colors("#729fcf", "LightBlue", "white"))
+ w:set_background_color(beautiful.bg_normal)
+ w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent))
-- Register widget
vicious.register(w, vicious.widgets.cpu, "$1", 1)
return w
@@ -130,8 +131,8 @@
-- Progressbar properties
w:set_width(10)
w:set_vertical(true)
- w:set_background_color("#729fcf")
- w:set_color(get_gradient_colors("#729fcf", "LightBlue", "white"))
+ w:set_background_color(beautiful.bg_normal)
+ w:set_color(get_gradient_colors(beautiful.bg_focus, beautiful.bg_urgent))
-- Register widget
vicious.register(w, vicious.widgets.mem, "$1", 5)
return w
@@ -223,8 +224,7 @@
if event == "release" then
return true
end
- local theme = beautiful.get()
- widgets.mode_widget_bg:set_bg(theme.bg_focus)
+ widgets.mode_widget_bg:set_bg(beautiful.bg_focus)
if key == "Escape" then
return false
end
@@ -239,7 +239,7 @@
end
end
-- notify_error("Nothing for " .. skey)
- widgets.mode_widget_bg:set_bg(theme.bg_urgent)
+ widgets.mode_widget_bg:set_bg(beautiful.bg_urgent)
return true
end
@@ -260,7 +260,7 @@
function run_kt(c, keytable, title)
widgets.mode_widget:set_text("Mode: " .. title)
-- widgets.mode_widget:show()
- widgets.mode_widget_bg:set_bg("LightBlue")
+ widgets.mode_widget_bg:set_bg(beautiful.bg_focus)
widgets.mode_widget:buttons(
awful.util.table.join(
awful.button({}, 1, function () show_kt(keytable, "Binding") end),
@@ -353,3 +353,48 @@
end
end)
end
+
+-- theme menu
+function theme_load(theme)
+ local cfg_path = awful.util.getdir("config")
+ awful.util.spawn("ln -sfn " .. cfg_path .. "/themes/" .. theme .. " " .. cfg_path .. "/current_theme")
+ awesome.restart()
+end
+
+function theme_menu()
+ -- List your theme files and feed the menu table
+ local cmd = "ls -1 " .. awful.util.getdir("config") .. "/themes/"
+ local f = io.popen(cmd)
+
+ local themes = {}
+ for l in f:lines() do
+ local item = { l, function () theme_load(l) end }
+ table.insert(themes, item)
+ end
+
+ f:close()
+ return themes
+end
+
+function set_wallpaper(wallpaper)
+ local cfg_path = awful.util.getdir("config")
+ local source_path = cfg_path .. "/wallpapers/" .. wallpaper
+ local default_path = cfg_path .. "/default"
+ awful.util.spawn("ln -sfn " .. source_path .. " " .. default_path )
+ awful.util.spawn("fbsetbg -a " .. default_path)
+end
+
+function wallpaper_menu()
+ local cmd = "ls " .. awful.util.getdir("config") .. "/wallpapers/"
+ local f = io.popen(cmd)
+ local wallpapers = {}
+ for l in f:lines() do
+ local name, ext = capi.string.match(l, "(.-)(%.[^%.]+)$")
+ local item = { name, function () set_wallpaper(l) end }
+ table.insert(wallpapers, item)
+ end
+
+ f:close()
+ return wallpapers
+end
+
--- a/awesome/rc.lua Sat Jun 20 16:21:25 2015 -0400
+++ b/awesome/rc.lua Sat Jun 20 20:32:45 2015 -0400
@@ -51,7 +51,7 @@
-- The default is a dark theme
-- theme_path = "/usr/share/awesome/themes/default/theme.lua"
-- Uncommment this for a lighter theme
-theme_path = "/usr/share/awesome/themes/sky/theme.lua"
+theme_path = awful.util.getdir("config") .. "/current_theme/theme.lua"
-- This is used later as the default terminal and editor to run.
terminal = "x-terminal-emulator"
@@ -76,12 +76,12 @@
-- another modifier like Mod1, but it may interact with others.
modkey = "Mod4"
-wallpaper_dir = "/home/fabien/themes/backgrounds/"
-wallpaper = wallpaper_dir .. "universalis_1024_jsh.jpg"
+wallpaper = awful.util.getdir("config") .. "/default"
+wallpaper_cmd = "fbsetbg -a " .. wallpaper
-- Actually load theme
beautiful.init(theme_path)
-beautiful.get().wallpaper_cmd = { "awsetbg -a " .. wallpaper }
+beautiful.wallpaper_cmd = { wallpaper_cmd }
awful.util.spawn_with_shell("pgrep unagi || unagi &")
@@ -275,6 +275,8 @@
{"manual", terminal .. " -e man awesome"},
{"edit config",
editor_cmd .. " " .. awful.util.getdir("config") .. "/rc.lua"},
+ {"themes", my.theme_menu()},
+ {"wallpapers", my.wallpaper_menu()},
{"restart", awesome.restart},
{"quit", my.quit}
}
@@ -337,7 +339,7 @@
local myktwidget = my.widgets.mode()
for s = 1, screen.count() do
- awful.util.spawn("awsetbg -a " .. wallpaper, false, s)
+ awful.util.spawn(wallpaper_cmd, false, s)
-- status box