Skip to content

Instantly share code, notes, and snippets.

Created November 9, 2012 02:44
Show Gist options
  • Save anonymous/4043393 to your computer and use it in GitHub Desktop.
Save anonymous/4043393 to your computer and use it in GitHub Desktop.
require('awful')
require('awful.autofocus')
require('awful.rules')
require('beautiful')
require('naughty')
require('obvious.battery')
require('debian.menu')
beautiful.init('.config/awesome/themes/custom/theme.lua')
mod = 'Mod4'
shift = 'Shift'
ctrl = 'Control'
keys = {
global_prev_tag = { { mod }, 'h' },
global_next_tag = { { mod }, 'l' },
global_prev_win = { { mod }, 'k' },
global_next_win = { { mod }, 'j' },
global_main_menu = { { mod }, 'space' },
global_run = { { mod, ctrl }, 'space' },
global_fancy_run = { { mod, shift }, 'space' },
global_swap_prev = { { mod, shift }, 'k' },
global_swap_next = { { mod, shift }, 'j' },
global_goto_last = { { mod }, '\'' },
global_goto_master = { { mod }, ';' },
global_run_terminal = { { mod }, 'Return' },
global_run_browser = { { mod, ctrl }, 'Return' },
global_quit = { { mod, ctrl }, 'BackSpace' },
global_restart = { { mod, shift }, 'BackSpace' },
global_grow_master = { { mod, ctrl }, 'l' },
global_shrink_master = { { mod, ctrl }, 'h' },
global_inc_masters = { { mod }, ']' },
global_dec_masters = { { mod }, '[' },
global_inc_cols = { { mod, ctrl }, ']' },
global_dec_cols = { { mod, ctrl }, '[' },
global_vert_tile = { { mod }, 't' },
global_horiz_tile = { { mod, ctrl }, 't' },
global_float = { { mod }, 'f' },
global_run_lua = { { mod }, '/' },
global_reset_geom = { { mod }, '0' },
global_toggle_panel = { { mod }, '`' },
global_win_menu = { { mod }, 'Tab' },
global_goto_urgent = { { mod }, 'u' },
global_video_autoconf = { { }, 'XF86Display' },
win_close = { { mod }, 'BackSpace' },
win_toggle_float = { { mod }, '\\' },
win_toggle_max = { { mod }, '=' },
win_toggle_min = { { mod }, '-' },
win_swap_master = { { mod, shift }, ';' },
}
buttons = {
tag_select = { { }, 1 },
tag_move_win = { { shift }, 1 },
tag_toggle_win = { { ctrl }, 1 },
tag_toggle_shown = { { }, 3 },
tag_prev = { { }, 4 },
tag_next = { { }, 5 },
winlist_select = { { }, 1 },
winlist_toggle_max = { { ctrl }, 1 },
winlist_toggle_float = { { }, 2 },
winlist_close = { { ctrl }, 2 },
winlist_menu = { { }, 3 },
winlist_toggle_min = { { ctrl }, 3 },
winlist_prev = { { }, 4 },
winlist_next = { { }, 5 },
layout_prev_click = { { }, 1 },
layout_prev_scroll = { { }, 4 },
layout_next_click = { { }, 3 },
layout_next_scroll = { { }, 5 },
desk_main_menu = { { }, 3 },
desk_prev_tag = { { }, 4 },
desk_next_tag = { { }, 5 },
win_select = { { }, 1 },
win_move = { { mod }, 1 },
win_close = { { mod, ctrl }, 2 },
win_resize = { { mod }, 3 },
win_toggle_float = { { mod }, 2 },
win_toggle_max = { { mod, ctrl }, 1 },
win_toggle_min = { { mod, ctrl }, 3 },
}
awful.menu.menu_keys.up = { 'k', 'Up' }
awful.menu.menu_keys.down = { 'j', 'Down' }
awful.menu.menu_keys.back = { 'h', 'Left' }
awful.menu.menu_keys.exec = { 'l', 'Right', 'Return' }
awful.menu.menu_keys.close = { 'Escape' }
terminal = 'roxterm'
browser = 'firefox'
myconfigmenu = {
{ 'audio', 'pavucontrol' },
{ 'video', 'arandr' },
}
myawesomemenu = {
{ 'restart', awesome.restart },
{ 'quit', awesome.quit },
}
mymainmenu = awful.menu({
items = {
{ 'terminal', terminal },
{ 'web', browser },
{ 'config', myconfigmenu },
{ 'debian', debian.menu.Debian_menu.Debian },
{ 'awesome', myawesomemenu },
}
})
function key(k, f) return awful.key(keys[k][1], keys[k][2], f) end
function button(b, f) return awful.button(buttons[b][1], buttons[b][2], f) end
layouts = {
awful.layout.suit.tile,
awful.layout.suit.tile.bottom,
awful.layout.suit.max,
}
tags = {}
for s = 1, screen.count() do
tags[s] = awful.tag({ 1, 2, 3, 4, 5, 6, 7, 8, 9 }, s, layouts[1])
end
mylauncher = awful.widget.launcher({
image = image(beautiful.awesome_icon),
menu = mymainmenu,
})
mytextclock = awful.widget.textclock({ align = 'right' }, " %F %H:%M")
mybattery = obvious.battery()
mysystray = widget({ type = 'systray' })
mywibox = {}
mypromptbox = {}
mylayoutbox = {}
mytaglist = {}
mytaglist.buttons = awful.util.table.join(
button('tag_select', awful.tag.viewonly),
button('tag_toggle_win', awful.client.toggletag),
button('tag_move_win', awful.client.movetotag),
button('tag_toggle_shown', awful.tag.viewtoggle),
button('tag_prev', awful.tag.viewprev),
button('tag_next', awful.tag.viewnext)
)
mytasklist = {}
mytasklist.buttons = awful.util.table.join(
button('winlist_select', function(c)
if not c:isvisible() then
awful.tag.viewonly(c:tags()[1])
end
client.focus = c
c:raise()
end),
button('winlist_toggle_max', function(c)
c.maximized_vertical = not c.maximized_vertical
c.maximized_horizontal = not c.maximized_horizontal
end),
button('winlist_toggle_float', awful.client.floating.toggle),
button('winlist_close', function(c) c:kill() end),
button('winlist_menu', function()
if instance then
instance:hide()
instance = nil
else
instance = awful.menu.clients({ width = 256 })
end
end),
button('winlist_toggle_min', function(c) c.minimized = not c.minimized end),
button('winlist_prev', function()
awful.client.focus.byidx(-1)
if client.focus then
client.focus:raise()
end
end),
button('winlist_next', function()
awful.client.focus.byidx(1)
if client.focus then
client.focus:raise()
end
end)
)
for s = 1, screen.count() do
mypromptbox[s] = awful.widget.prompt(
{ layout = awful.widget.layout.horizontal.leftright }
)
mylayoutbox[s] = awful.widget.layoutbox(s)
mylayoutbox[s]:buttons(awful.util.table.join(
button('layout_prev_click', function() awful.layout.inc(layouts, -1) end),
button('layout_next_click', function() awful.layout.inc(layouts, 1) end),
button('layout_prev_scroll', function() awful.layout.inc(layouts, -1) end),
button('layout_next_scroll', function() awful.layout.inc(layouts, 1) end)
))
mytaglist[s] =
awful.widget.taglist(s, awful.widget.taglist.label.all, mytaglist.buttons)
mytasklist[s] = awful.widget.tasklist(
function(c) return awful.widget.tasklist.label.currenttags(c, s) end,
mytasklist.buttons
)
mywibox[s] = awful.wibox({ position = 'top', screen = s })
mywibox[s].widgets = {
{
mylauncher,
mytaglist[s],
mypromptbox[s],
layout = awful.widget.layout.horizontal.leftright,
},
mylayoutbox[s],
mytextclock,
mybattery,
s == 1 and mysystray or nil,
mytasklist[s],
layout = awful.widget.layout.horizontal.rightleft,
}
awful.widget.layout.margins[mytextclock] = { right = 8 }
awful.widget.layout.margins[mybattery] = { left = 8, right = 8 }
end
root.buttons(awful.util.table.join(
button('desk_main_menu', function() mymainmenu:toggle() end),
button('desk_prev_tag', awful.tag.viewnext),
button('desk_next_tag', awful.tag.viewprev)
))
globalkeys = awful.util.table.join(
key('global_prev_tag', awful.tag.viewprev),
key('global_next_tag', awful.tag.viewnext),
key('global_prev_win', function()
awful.client.focus.byidx(-1)
if client.focus then
client.focus:raise()
end
end),
key('global_next_win', function()
awful.client.focus.byidx(1)
if client.focus then
client.focus:raise()
end
end),
key('global_main_menu', function()
mymainmenu:show({ keygrabber = true, coords = { x = 0, y = 0 } })
end),
key('global_swap_prev', function() awful.client.swap.byidx(-1) end),
key('global_swap_next', function() awful.client.swap.byidx(1) end),
key('global_goto_urgent', awful.client.urgent.jumpto),
key('global_goto_last', function()
awful.client.focus.history.previous()
if client.focus then
client.focus:raise()
end
end),
key('global_goto_master', function()
client.focus = awful.client.getmaster()
end),
key('global_run_terminal', function() awful.util.spawn(terminal) end),
key('global_run_browser', function() awful.util.spawn(browser) end),
key('global_restart', awesome.restart),
key('global_quit', awesome.quit),
key('global_grow_master', function() awful.tag.incmwfact(0.05) end),
key('global_shrink_master', function() awful.tag.incmwfact(-0.05) end),
key('global_inc_masters', function() awful.tag.incnmaster(1) end),
key('global_dec_masters', function() awful.tag.incnmaster(-1) end),
key('global_inc_cols', function() awful.tag.incncol(1) end),
key('global_dec_cols', function() awful.tag.incncol(-1) end),
key('global_vert_tile', function() awful.layout.set(layouts[1]) end),
key('global_horiz_tile', function() awful.layout.set(layouts[2]) end),
key('global_float', function() awful.layout.set(layouts[3]) end),
key('global_run', function() mypromptbox[mouse.screen]:run() end),
key('global_fancy_run', function() awful.util.spawn('gmrun') end),
key('global_run_lua', function()
awful.prompt.run(
{ prompt = 'Lua: ' },
mypromptbox[mouse.screen].widget,
awful.util.eval,
nil,
awful.util.getdir('cache') .. '/history_eval'
)
end),
key('global_reset_geom', function()
awful.tag.setnmaster(1)
awful.tag.setncol(1)
awful.tag.setmwfact(0.5)
awful.tag.getdata(awful.tag.selected()).windowfact = {}
end),
key('global_toggle_panel', function()
for s = 1, screen.count() do
mywibox[s].visible = not mywibox[s].visible
end
end),
key('global_win_menu', function ()
awful.menu.clients(
{ width = 512 },
{ keygrabber = true, coords = { x = 0, y = 0 } }
)
end),
key('global_video_autoconf', function() awful.util.spawn('xrandr --auto') end)
)
clientkeys = awful.util.table.join(
key('win_close', function(c) c:kill() end),
key('win_toggle_float', awful.client.floating.toggle),
key('win_toggle_max', function(c)
c.maximized_vertical = not c.maximized_vertical
c.maximized_horizontal = not c.maximized_horizontal
end),
key('win_toggle_min', function(c) c.minimized = not c.minimized end),
key('win_swap_master', function(c) c:swap(awful.client.getmaster()) end)
)
keynumber = 0
for s = 1, screen.count() do
keynumber = math.min(9, math.max(#tags[s], keynumber))
end
for i = 1, keynumber do
globalkeys = awful.util.table.join(
globalkeys,
awful.key({ mod }, '#' .. i + 9, function()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewonly(tags[screen][i])
end
end),
awful.key({ mod, ctrl }, '#' .. i + 9, function()
local screen = mouse.screen
if tags[screen][i] then
awful.tag.viewtoggle(tags[screen][i])
end
end),
awful.key({ mod, shift }, '#' .. i + 9, function()
if client.focus and tags[client.focus.screen][i] then
awful.client.movetotag(tags[client.focus.screen][i])
end
end),
awful.key({ mod, ctrl, shift }, '#' .. i + 9, function()
if client.focus and tags[client.focus.screen][i] then
awful.client.toggletag(tags[client.focus.screen][i])
end
end)
)
end
clientbuttons = awful.util.table.join(
button('win_select', function(c)
client.focus = c
c:raise()
end),
button('win_move', awful.mouse.client.move),
button('win_close', function(c) c:kill() end),
button('win_resize', awful.mouse.client.resize),
button('win_toggle_max', function(c)
c.maximized_vertical = not c.maximized_vertical
c.maximized_horizontal = not c.maximized_horizontal
end),
button('win_toggle_min', function(c) c.minimized = not c.minimized end),
button('win_toggle_float', awful.client.floating.toggle)
)
root.keys(globalkeys)
awful.rules.rules = {
{
rule = {},
properties = {
border_width = beautiful.border_width,
border_color = beautiful.border_normal,
focus = true,
keys = clientkeys,
buttons = clientbuttons,
size_hints_honor = false,
}
},
{
rule = { class = 'MPlayer' },
properties = { floating = true },
},
{
rule = { class = 'pinentry' },
properties = { floating = true },
},
{
rule = { instance = 'plugin-container' },
properties = { floating = true },
},
}
client.add_signal('manage', function(c, startup)
c:add_signal('mouse::enter', function(c)
if awful.layout.get(c.screen) ~= awful.layout.suit.magnifier and
awful.client.focus.filter(c)
then
client.focus = c
end
end)
if not startup then
awful.client.setslave(c)
if not c.size_hints.user_position and not c.size_hints.program_position then
awful.placement.no_overlap(c)
awful.placement.no_offscreen(c)
end
end
end)
client.add_signal('focus', function(c)
c.border_color = beautiful.border_focus
end)
client.add_signal('unfocus', function(c)
c.border_color = beautiful.border_normal
end)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment