Implement callback arg called on client raise

Existing arg is renamed to spawn_callback.
This commit is contained in:
James Reed 2019-09-09 17:59:13 -06:00
parent 5c2338fad8
commit 9673deca61
No known key found for this signature in database
GPG Key ID: 8F79994F6B8378C1
2 changed files with 21 additions and 10 deletions

View File

@ -31,8 +31,8 @@ awful.rules.add_rule_source("launch",
gears.table.crush(props, data.props)
if data.callback then
table.insert(callbacks, data.callback)
if data.spawn_callback then
table.insert(callbacks, data.spawn_callback)
end
shared.pending[id] = nil
@ -87,7 +87,7 @@ end
-- @param args.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients.
-- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns.
-- @param args.spawn_callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail.
-- @return The client's ID.
@ -98,7 +98,7 @@ local function spawn(cmd, args)
local data = {
props = args.props or {},
pwd = args.pwd,
callback = args.callback,
spawn_callback = args.spawn_callback,
timeout = math.ceil(args.timeout or 10),
}
@ -164,7 +164,7 @@ setmetatable(launch.spawn, {__call = function (_, ...) spawn(...) end})
-- @param args.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients.
-- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns.
-- @param args.spawn_callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered.
@ -189,7 +189,8 @@ end
-- @param args.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients.
-- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns.
-- @param args.spawn_callback Function to call with client when it spawns.
-- @param args.callback Function to call with client when it spawns or is raised.
-- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered.
@ -205,8 +206,18 @@ function launch.spawn.raise_or_spawn(cmd, args)
if c then
c:emit_signal("request::activate", "launch.spawn.raise_or_spawn",
{raise=true})
if args.callback then
args.callback(c)
end
return args.id
end
if args.callback then
local cb = args.spawn_callback
args.spawn_callback = function (c)
if cb then cb(c) end
args.callback(c)
end
end
return spawn(cmd, args)
end

View File

@ -13,8 +13,8 @@ local panel = {}
-- TODO: Reapply args on restart with rule source.
-- See: https://github.com/awesomeWM/awesome/issues/2725
local function spawn(cmd, args)
local cb = args.callback
args.callback = function (c)
local cb = args.spawn_callback
args.spawn_callback = function (c)
c.hidden = true
c.sticky = true
c.floating = true
@ -47,7 +47,7 @@ end
-- @param args.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients.
-- @param args.timeout Seconds after which to stop waiting for a client to spawn.
-- @param args.callback Function to call with client when it spawns.
-- @param args.spawn_callback Function to call with client when it spawns.
-- @param args.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered.
@ -58,7 +58,7 @@ function panel.toggle(cmd, args)
if c then
toggle(c)
else
local a = {callback = function (c) toggle(c) end}
local a = {spawn_callback = function (c) toggle(c) end}
gtable.crush(a, args)
spawn(cmd, a)
end