Skip to content

Instantly share code, notes, and snippets.

@Elv13
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Elv13/9d75bb8fd62c871702c9 to your computer and use it in GitHub Desktop.
Save Elv13/9d75bb8fd62c871702c9 to your computer and use it in GitHub Desktop.
diff --git a/lib/awful/init.lua.in b/lib/awful/init.lua.in
old mode 100644
new mode 100755
index cb64420..28e3fc5
--- a/lib/awful/init.lua.in
+++ b/lib/awful/init.lua.in
@@ -29,6 +29,7 @@ return
tooltip = require("awful.tooltip");
ewmh = require("awful.ewmh");
titlebar = require("awful.titlebar");
+ spawn = require("awful.spawn");
}
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
diff --git a/lib/awful/spawn.lua.in b/lib/awful/spawn.lua.in
index e69de29..75e0c6a 100644
--- a/lib/awful/spawn.lua.in
+++ b/lib/awful/spawn.lua.in
@@ -0,0 +1,79 @@
+---------------------------------------------------------------------------
+-- @author Julien Danjou <julien@danjou.info>
+-- @author Emmanuel Lepage Vallee <elv1313@gmail.com>
+-- @copyright 2008 Julien Danjou
+-- @copyright 2014 Emmanuel Lepage Vallee
+-- @release @AWESOME_VERSION@
+---------------------------------------------------------------------------
+
+local capi =
+{
+ awesome = awesome,
+ mouse = mouse,
+ client = client,
+}
+local arules = require("awful.rules")
+local util = require("awful.util")
+
+local module = {}
+
+
+module.snid_buffer = {}
+
+function module.on_snid_callback(c)
+ local props = module.snid_buffer[c.startup_id]
+ if props then
+ return arules.execute(c,props,type(props.callback) == "function" and
+ {props.callback} or props.callback )
+ end
+end
+
+
+function module.on_snid_cancel(id)
+ print("TIMEOUT",id)
+ if module.snid_buffer[id] then
+ module.snid_buffer[id] = nil
+ end
+end
+
+--- Spawn a program.
+-- See awful.rules.execute for more details
+-- @param cmd The command.
+-- @param sn_rules a property table ,false to disable startup-notification.
+-- @param callback A callback function (if the client support startup notifications)
+-- @return The forked PID or an error message
+-- @return The startup notification UID, if the spawn was successful
+function module.spawn(cmd, sn_rules, callback)
+ if cmd and cmd ~= "" then
+ local enable_sn = (sn_rules ~= false or callback) and true or true
+ if callback then
+ sn_rules = {callback=callback}
+ end
+ local pid,snid = capi.awesome.spawn(cmd, enable_sn)
+ -- The snid will be nil in case of failure
+ if snid and type(sn_rules) == "table" then
+ module.snid_buffer[snid] = sn_rules
+ end
+ return pid,snid
+ end
+ -- For consistency
+ return "Error: No command to execute"
+end
+util.spawn = module.spawn --DEPRECATED
+
+--- Spawn a program using the shell.
+-- @param cmd The command.
+function module.spawn_with_shell(cmd)
+ if cmd and cmd ~= "" then
+ cmd = { util.shell, "-c", cmd }
+ return capi.awesome.spawn(cmd, false)
+ end
+end
+util.spawn_with_shell = module.spawn_with_shell --DEPRECATED
+
+capi.awesome.connect_signal("spawn::canceled" , module.on_snid_cancel )
+capi.awesome.connect_signal("spawn::timeout" , module.on_snid_cancel )
+capi.client.connect_signal ("manage" , module.on_snid_callback )
+
+return setmetatable(module, { __call = function(_, ...) return spawn(...) end })
+-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
\ No newline at end of file
diff --git a/lib/awful/util.lua.in b/lib/awful/util.lua.in
old mode 100644
new mode 100755
index 123c4a6..1baa2a5
--- a/lib/awful/util.lua.in
+++ b/lib/awful/util.lua.in
@@ -69,26 +69,7 @@ function util.mkdir(dir)
return os.execute("mkdir -p " .. dir)
end
---- Spawn a program.
--- @param cmd The command.
--- @param sn Enable startup-notification.
--- @return The forked PID or an error message
--- @return The startup notification UID, if the spawn was successful
-function util.spawn(cmd, sn)
- if cmd and cmd ~= "" then
- if sn == nil then sn = true end
- return capi.awesome.spawn(cmd, sn)
- end
-end
-
---- Spawn a program using the shell.
--- @param cmd The command.
-function util.spawn_with_shell(cmd)
- if cmd and cmd ~= "" then
- cmd = { util.shell, "-c", cmd }
- return capi.awesome.spawn(cmd, false)
- end
-end
+-- util.spawn moved to awful.spwan
--- Read a program output and returns its output as a string.
-- @param cmd The command to run.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment