From c56bbec1dbbe51f9672e27ea5f96ab481acf713f Mon Sep 17 00:00:00 2001 From: crater2150 Date: Fri, 16 Mar 2012 10:29:47 +0100 Subject: [PATCH] aweswt with theme support --- aweswt.lua | 72 +++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 3 deletions(-) diff --git a/aweswt.lua b/aweswt.lua index f743c45..f7eb326 100644 --- a/aweswt.lua +++ b/aweswt.lua @@ -4,9 +4,26 @@ local M = {} -local dmenu = "dmenu -nf '#888888' -nb '#222222' -sf '#ffffff' -sb '#285577' -p 'switch to application:' -fn 'Terminus 8' -i" +-- local functions +local get_out, get_input, _switch, assemble_command + +local defaults = {} +local settings = {} + +defaults.bg_focus = theme.bg_focus +defaults.fg_focus = theme.fg_focus +defaults.bg_normal = theme.bg_normal +defaults.fg_normal = theme.fg_normal +defaults.font = string.gsub(theme.font, " ","-") +defaults.menu_cmd = "dmenu -nf %q -nb %q -sf %q -sb %q -p 'Switch to' -fn %q -i" + +local command + +for key, value in pairs(defaults) do + settings[key] = value +end + -local get_out, get_input, _switch -- switch with window titles M.switch = function() @@ -18,6 +35,41 @@ M.switch_class = function() _switch(false) end +-- {{{ option setters + +M.set_bg_focus = function (color) + settings.bg_focus = color or defaults.bg_focus + assemble_command() +end + +M.set_fg_focus = function (color) + settings.fg_focus = color or defaults.fg_focus + assemble_command() +end + +M.set_bg_normal = function (color) + settings.bg_normal = color or defaults.bg_normal + assemble_command() +end + +M.set_fg_normal = function (color) + settings.fg_normal = color or defaults.fg_normal + assemble_command() +end + +M.set_font = function (font) + settings.font = font or defaults.font + assemble_command() +end + +M.set_menu_command = function (command) + settings.menu_cmd = command or defaults.menu_cmd + assemble_command() +end + +-- }}} + +-- {{{ io functions get_out = function (a) local f = io.popen(a) t = {} @@ -28,10 +80,13 @@ get_out = function (a) end get_input = function (a) - s1 = 'echo "' .. a .. '" | ' .. dmenu + s1 = 'echo "' .. a .. '" | ' .. command return get_out(s1) end +-- }}} + +-- {{{ main worker function _switch = function(use_name) local clients = client.get() @@ -68,5 +123,16 @@ _switch = function(use_name) client_selected:raise() end end +-- }}} +assemble_command = function() + command = string.format(settings.menu_cmd, + settings.fg_normal, + settings.bg_normal, + settings.fg_focus, + settings.bg_focus, + settings.font) +end + +assemble_command() return M