**This is an old revision of the document!**
Table of Contents
Drop-down Terminal
Introduction
A drop-down terminal pops up from the top of the screen in video game console fashion and can be toggled with a single hotkey. Applications such as Yakuake, Guake or Tilda provide drop-down terminal functionality for the regular desktop environments. With awesome and the power of lua, however, we can mimic this functionality and still use our precious light-weight terminal applications.
Adding the following function to your rc.lua and calling it in a keybinding will create a new window for the drop-down terminal when it does not exist, and will toggle between hidden and visible if one does exist. The first argument is the program to run (eg. “urxvtc”), the second argument is the height (absolute pixels when > 1 or a height percentage when < 1, 0.2 (20% of the screen height) by default), and the third argument is the screen to toggle on. The second and third arguments are optional.
Function
-- This function is for awesome versions prior to 3.4
dropdown = {}
function dropdown_toggle(prog, height, s)
if s == nil then s = mouse.screen end
if height == nil then height = 0.2 end
if not dropdown[prog] then
-- Create table
dropdown[prog] = {}
-- Add unmanage hook for dropdown programs
awful.hooks.unmanage.register(function (c)
for scr, cl in pairs(dropdown[prog]) do
if cl == c then
dropdown[prog][scr] = nil
end
end
end)
end
if not dropdown[prog][s] then
spawnw = function (c)
-- Store client
dropdown[prog][s] = c
-- Float client
awful.client.floating.set(c, true)
-- Get screen geometry
screengeom = screen[s].workarea
-- Calculate height
if height < 1 then
height = screengeom.height*height
end
-- I like a different border with for the popup window
-- So I don't confuse it with terminals in the layout
bw = 2
-- Resize client
c:geometry({
x = screengeom.x,
y = screengeom.y - 1000,
width = screengeom.width - bw,
height = height - bw
})
-- Mark terminal as ontop
-- c.ontop = true
-- c.above = true
c.border_width = bw
-- Focus and raise client
c:raise()
client.focus = c
-- Remove hook
awful.hooks.manage.unregister(spawnw)
end
-- Add hook
awful.hooks.manage.register(spawnw)
-- Spawn program
awful.util.spawn(prog)
dropdown.currtag = awful.tag.selected(s)
else
-- Get client
c = dropdown[prog][s]
-- Switch the client to the current workspace
-- Focus and raise if not hidden
if c.hidden then
awful.client.movetotag(awful.tag.selected(s), c)
c.hidden = false
c:raise()
client.focus = c
else
if awful.tag.selected(s) == dropdown.currtag 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(s), c)
c:raise()
client.focus = c
end
end
dropdown.currtag = awful.tag.selected(s)
end
end
