From 9673deca6117bf6ca20dba22db0aff609e81af76 Mon Sep 17 00:00:00 2001 From: James Reed Date: Mon, 9 Sep 2019 17:59:13 -0600 Subject: [PATCH] Implement callback arg called on client raise Existing arg is renamed to spawn_callback. --- init.lua | 23 +++++++++++++++++------ panel.lua | 8 ++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/init.lua b/init.lua index 89d92fe..0dcc636 100644 --- a/init.lua +++ b/init.lua @@ -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 diff --git a/panel.lua b/panel.lua index 49458b5..cd4304c 100644 --- a/panel.lua +++ b/panel.lua @@ -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