-- {{{ License -- Awesome dropdown Quake like console -- 2012, Emmanuel Bouthenot -- -- (very) partially inspired from http://awesome.naquadah.org/wiki/Drop-down_terminal -- -- This file is distributed in the hope that it will be useful, -- but WITHOUT ANY WARRANTY -- -- }}} -- {{{ Libraries require('utils') -- }}} -- {{{ Variables awq = {} awq_tag = nil awq_name = '' awq_scr = nil awq_idx = 0 awqterm_prog = 'xterm' -- }}} -- {{{ Keys awqkeys = awful.util.table.join( awful.key({ "Control" }, "Prior", function(c) awq_client_show_next() end), awful.key({ "Control" }, "Next" , function(c) awq_client_show_prev() end), awful.key({ "Mod1" } , "Up" , function(c) awq_client_new() end) ) -- }}} -- {{{ Functions (“private”) function awq_client_show_pos(reverse) local keys = awful.util.table.keys(awq) if reverse then keys = awful.util.table.reverse(keys) end local pos = table.pos(keys, awq_name) if not (pos == nil) then local pos = pos+1 local newname = table.keypos(keys, pos) if newname == nil then newname = table.keyfirst(keys) end if not (awq_name == newname) then awq_client_hide(awq_name) awq_name = newname awq_client_show(awq_name) end end end function awq_client_show_next() awq_client_show_pos(true) end function awq_client_show_prev() awq_client_show_pos(false) end function awq_client_new() awq_idx = awq_idx+1 awq_name = 'awq_' .. awq_idx local name = awq_name if not awq[name] then -- Create table awq[name] = {} -- Add unmanage hook for awq programs client.add_signal("unmanage", function (c, startup) awq_client_show_prev() for name,data in pairs(awq) do for s, cl in pairs(data) do if cl == c then awq[name] = nil end end end end) end -- Get workarea local workarea = screen[awq_scr].workarea spawnw = function (c) -- Store client awq[name][awq_scr] = c -- Float client awful.client.floating.set(c, true) -- Resize client c:geometry({ x = workarea.x, y = workarea.y-19, width = workarea.width, height = workarea.height+20 }) -- Set keys c:keys(awful.util.table.join( c:keys(), awqkeys )) -- Focus and raise client c:raise() client.focus = c -- Remove hook client.remove_signal("manage", spawnw) end -- Add hook client.add_signal("manage", spawnw) -- Spawn program awful.util.spawn(awqterm_prog) awq_tag = awful.tag.selected(awq_scr) end function awq_client_show(name) -- Get client local c = awq[name][awq_scr] awful.client.movetotag(awful.tag.selected(awq_scr), c) c.hidden = false c:raise() client.focus = c end function awq_client_hide(name) -- Get client local c = awq[name][awq_scr] if awful.tag.selected(awq_scr) == awq_tag then c.hidden = true local ctags = c:tags() for i, t in pairs(ctags) do ctags[i] = nil end c:tags(ctags) else awful.client.movetotag(awful.tag.selected(awq_scr), c) c:raise() client.focus = c end end function awq_client_toggle() -- Get client if awq[awq_name] then c = awq[awq_name][awq_scr] end if c == nil then awq_client_new() else if c.hidden then awq_client_show(awq_name) else awq_client_hide(awq_name) end awq_tag = awful.tag.selected(awq_scr) end end -- }}} -- {{{ Functions (“public”) function awqterm_toggle() awq_scr = mouse.screen if next(awq) == nil then awq_client_new() else awq_client_toggle() end end -- }}} -- vim: foldmethod=marker