quake: use only one quake console for all screens

This commit is contained in:
Vincent Bernat 2019-10-12 11:41:24 +02:00
parent 510fd7146d
commit 119b69b111
2 changed files with 8 additions and 31 deletions

View file

@ -6,21 +6,6 @@
-- are able to detect the Quake console from its name -- are able to detect the Quake console from its name
-- (QuakeConsoleNeedsUniqueName by default). -- (QuakeConsoleNeedsUniqueName by default).
-- Use:
-- local quake = require("quake")
-- 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 }, "`",
-- function () quakeconsole[mouse.screen]:toggle() end)
-- If you have a rule like "awful.client.setslave" for your terminals, -- If you have a rule like "awful.client.setslave" for your terminals,
-- ensure you use an exception for -- ensure you use an exception for
-- QuakeConsoleNeedsUniqueName. Otherwise, you may run into problems -- QuakeConsoleNeedsUniqueName. Otherwise, you may run into problems
@ -47,8 +32,7 @@ function QuakeConsole:display()
for c in awful.client.cycle(function (c) for c in awful.client.cycle(function (c)
-- c.name may be changed! -- c.name may be changed!
return (c.instance == self.name or c.role == self.name) return (c.instance == self.name or c.role == self.name)
end, end) do
nil, self.screen) do
i = i + 1 i = i + 1
if i == 1 then if i == 1 then
client = c client = c
@ -71,13 +55,12 @@ function QuakeConsole:display()
if not client then if not client then
-- The client does not exist, we spawn it -- The client does not exist, we spawn it
awful.util.spawn(self.terminal .. " " .. string.format(self.argname, self.name), awful.util.spawn(self.terminal .. " " .. string.format(self.argname, self.name))
false, self.screen)
return return
end end
-- Comptute size -- Comptute size
local geom = capi.screen[self.screen].workarea local geom = capi.screen[capi.mouse.screen].workarea
local width, height = self.width, self.height local width, height = self.width, self.height
if width <= 1 then width = geom.width * width end if width <= 1 then width = geom.width * width end
if height <= 1 then height = geom.height * height end if height <= 1 then height = geom.height * height end
@ -131,19 +114,18 @@ function QuakeConsole:new(config)
config.vert = config.vert or "top" -- top, bottom or center config.vert = config.vert or "top" -- top, bottom or center
config.horiz = config.horiz or "center" -- left, right or center config.horiz = config.horiz or "center" -- left, right or center
config.screen = config.screen or capi.mouse.screen
config.visible = config.visible or false -- Initially, not visible config.visible = config.visible or false -- Initially, not visible
local console = setmetatable(config, { __index = QuakeConsole }) local console = setmetatable(config, { __index = QuakeConsole })
capi.client.add_signal("manage", capi.client.add_signal("manage",
function(c) function(c)
if (c.instance == console.name or c.role == console.name) and c.screen == console.screen then if (c.instance == console.name or c.role == console.name) then
console:display() console:display()
end end
end) end)
capi.client.add_signal("unmanage", capi.client.add_signal("unmanage",
function(c) function(c)
if (c.instance == console.name or c.role == console.name) and c.screen == console.screen then if (c.instance == console.name or c.role == console.name) then
console.visible = false console.visible = false
end end
end) end)

View file

@ -1,15 +1,10 @@
local quake = loadrc("quake", "vbe/quake") local quake = loadrc("quake", "vbe/quake")
local quakeconsole = quake({ terminal = config.terminal,
local quakeconsole = {}
for s = 1, screen.count() do
quakeconsole[s] = quake({ terminal = config.terminal,
argname = "--name %s", argname = "--name %s",
height = 0.3, height = 0.3 })
screen = s })
end
config.keys.global = awful.util.table.join( config.keys.global = awful.util.table.join(
config.keys.global, config.keys.global,
awful.key({ modkey }, "`", awful.key({ modkey }, "`",
function () quakeconsole[mouse.screen]:toggle() end, function () quakeconsole:toggle() end,
"Toggle Quake console")) "Toggle Quake console"))