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) gears.table.crush(props, data.props)
if data.callback then if data.spawn_callback then
table.insert(callbacks, data.callback) table.insert(callbacks, data.spawn_callback)
end end
shared.pending[id] = nil shared.pending[id] = nil
@ -87,7 +87,7 @@ end
-- @param args.props Properties to apply to the client. -- @param args.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients. -- @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.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.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @return The client's ID. -- @return The client's ID.
@ -98,7 +98,7 @@ local function spawn(cmd, args)
local data = { local data = {
props = args.props or {}, props = args.props or {},
pwd = args.pwd, pwd = args.pwd,
callback = args.callback, spawn_callback = args.spawn_callback,
timeout = math.ceil(args.timeout or 10), 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.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients. -- @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.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.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered. -- @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.props Properties to apply to the client.
-- @param args.pwd Pathname to the working directory for new clients. -- @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.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.factory The factory to use (see wm-launch's -f flag).
-- @param args.firejail If true, run cmd with firejail. -- @param args.firejail If true, run cmd with firejail.
-- @param args.filter Function to filter clients that are considered. -- @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 if c then
c:emit_signal("request::activate", "launch.spawn.raise_or_spawn", c:emit_signal("request::activate", "launch.spawn.raise_or_spawn",
{raise=true}) {raise=true})
if args.callback then
args.callback(c)
end
return args.id return args.id
end 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) return spawn(cmd, args)
end end

View File

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