quake: new Quake module that handles awesome restart gracefully

The previous RC file is moved as a module. We don't rely on the fact
that the next window to be managed after spawning a new terminal will
be this terminal. Instead, we rely on terminal name to know if we need
to manage them. For each console, we have a manage hook that tries to
identify if the window to manage is the console. In this case, it is
transformed and fitted as a Quake console.

Moreover, we clean things that look like QuakeConsole but that are not
because we already have one. For example, when switching from a
two-screen setup to a single-screen setup.
This commit is contained in:
Vincent Bernat 2012-07-15 12:44:46 +02:00
parent 94960c5c2b
commit 3b3dd0863d
2 changed files with 160 additions and 62 deletions

View file

@ -1,67 +1,14 @@
-- Quake like console on top
-- See:
-- http://git.sysphere.org/awesome-configs/tree/scratch/drop.lua
local quake = loadrc("quake", "vbe/quake")
local quake = {} -- List of quake consoles
local height = 0.3
-- When a quake console is closed, remove it from the list
client.add_signal("unmanage",
function (c)
for i, cl in pairs(quake) do
if cl == c then
quake[i] = nil
end
end
end)
-- Toggle the console
local function toggle()
local cscreen = mouse.screen
if not quake[cscreen] then
-- We must spawn a new console
local function spawn (c)
-- We assume that c is our Quake console. 99.9% sure.
quake[cscreen] = c
-- Setup on top
awful.client.floating.set(c, true)
c.border_width = 0
c.size_hints_honor = false
local geom = screen[cscreen].workarea
c:geometry({ x = geom.x,
y = geom.y,
width = geom.width,
height = geom.height * height })
c.ontop = true
c.above = true
c.skip_taskbar = true
c.sticky = true
c:raise()
client.focus = c
-- Remove our signal handler
client.remove_signal("manage", spawn)
end
client.add_signal("manage", spawn)
awful.util.spawn(config.terminal, false)
else
-- Display an existing console
c = quake[cscreen]
if c.hidden then
c.hidden = false
c:raise()
client.focus = c
else
c.hidden = true
end
end
local quakeconsole = {}
for s = 1, screen.count() do
quakeconsole[s] = quake({ terminal = config.terminal,
height = 0.3,
screen = s })
end
config.keys.global = awful.util.table.join(
config.keys.global,
awful.key({ modkey }, "`", toggle, "Toggle Quake console"))
awful.key({ modkey }, "`",
function () quakeconsole[mouse.screen]:toggle() end,
"Toggle Quake console"))