2011-12-01 12:03:54 +00:00
|
|
|
-- aweswt.lua
|
|
|
|
-- Application switcher using dmenu
|
|
|
|
--
|
|
|
|
|
2012-03-15 23:52:06 +00:00
|
|
|
local M = {}
|
2011-12-01 12:03:54 +00:00
|
|
|
|
2012-03-16 09:29:47 +00:00
|
|
|
-- 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
|
|
|
|
|
2012-03-15 23:52:06 +00:00
|
|
|
|
|
|
|
|
|
|
|
-- switch with window titles
|
|
|
|
M.switch = function()
|
|
|
|
_switch(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
-- switch with client instance and class
|
|
|
|
M.switch_class = function()
|
|
|
|
_switch(false)
|
|
|
|
end
|
|
|
|
|
2012-03-16 09:29:47 +00:00
|
|
|
-- {{{ 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
|
2012-03-15 23:52:06 +00:00
|
|
|
get_out = function (a)
|
2011-12-01 12:03:54 +00:00
|
|
|
local f = io.popen(a)
|
|
|
|
t = {}
|
|
|
|
for line in f:lines() do
|
|
|
|
table.insert(t, line)
|
|
|
|
end
|
|
|
|
return t
|
|
|
|
end
|
|
|
|
|
2012-03-15 23:52:06 +00:00
|
|
|
get_input = function (a)
|
2012-03-16 09:29:47 +00:00
|
|
|
s1 = 'echo "' .. a .. '" | ' .. command
|
2011-12-01 12:03:54 +00:00
|
|
|
return get_out(s1)
|
|
|
|
end
|
|
|
|
|
2012-03-16 09:29:47 +00:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
-- {{{ main worker function
|
2012-03-15 23:52:06 +00:00
|
|
|
_switch = function(use_name)
|
2011-12-01 12:03:54 +00:00
|
|
|
local clients = client.get()
|
|
|
|
|
|
|
|
if table.getn(clients) == 0 then
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
local client_list_table = {}
|
|
|
|
local apps = {}
|
|
|
|
|
|
|
|
for key, client in pairs(clients) do
|
|
|
|
local app
|
|
|
|
|
2012-03-15 23:52:06 +00:00
|
|
|
if use_name then
|
2011-12-01 12:03:54 +00:00
|
|
|
app = client['name']
|
|
|
|
else
|
|
|
|
app = key .. ':' .. client['instance'] .. '.' .. client['class']
|
|
|
|
end
|
|
|
|
|
|
|
|
table.insert(client_list_table, app)
|
|
|
|
apps[app] = client
|
|
|
|
end
|
|
|
|
|
|
|
|
table.sort(client_list_table, function(a, b)
|
|
|
|
return string.lower(a) < string.lower(b)
|
|
|
|
end)
|
|
|
|
local client_list = table.concat(client_list_table, "\n")
|
|
|
|
|
|
|
|
local client_selected = apps[get_input(client_list)[1]]
|
|
|
|
if client_selected then
|
|
|
|
local ctags = client_selected:tags()
|
|
|
|
awful.tag.viewonly(ctags[1])
|
|
|
|
client.focus = client_selected
|
|
|
|
client_selected:raise()
|
|
|
|
end
|
|
|
|
end
|
2012-03-16 09:29:47 +00:00
|
|
|
-- }}}
|
|
|
|
|
|
|
|
assemble_command = function()
|
|
|
|
command = string.format(settings.menu_cmd,
|
|
|
|
settings.fg_normal,
|
|
|
|
settings.bg_normal,
|
|
|
|
settings.fg_focus,
|
|
|
|
settings.bg_focus,
|
|
|
|
settings.font)
|
|
|
|
end
|
2010-09-03 23:09:24 +00:00
|
|
|
|
2012-03-16 09:29:47 +00:00
|
|
|
assemble_command()
|
2012-03-15 23:52:06 +00:00
|
|
|
return M
|