Advertisement
Guest User

Awesome autorun

a guest
Sep 9th, 2015
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.77 KB | None | 0 0
  1. M = {}
  2.  
  3. local awful = require("awful")
  4.  
  5. xrdbGetProcPid = function(procKey)
  6.     local xquery = io.popen("xrdb -query")
  7.     for line in xquery:lines() do
  8.         local procName, pid = string.match(line, "Awesome%.autorun%.(.+):%s(.+)")
  9.         if procName == procKey then
  10.             xquery:close()
  11.             return pid
  12.         end
  13.     end
  14.     xquery:close()
  15.     return nil
  16. end
  17.  
  18. xrdbSetProcPid = function(procName, pid)
  19.     local xmerge = io.popen("xrdb -merge", "w")
  20.     xmerge:write("Awesome.autorun."..procName..": "..pid)
  21.     xmerge:close()
  22. end
  23.  
  24. xrdbResetProcPid = function(procName)
  25.     local xmerge = io.popen("xrdb -remove", "w")
  26.     xmerge:write("Awesome.autorun."..procName)
  27.     xmerge:close()
  28. end
  29.  
  30. xrdbRunOnce = function(binary, parameters, procKey, delay)
  31.     if not procKey then
  32.         if string.find(binary, "/") then
  33.             local comp
  34.             for xcomp in string.gmatch(binary, "/([^/]+)") do
  35.                 comp = xcomp
  36.             end
  37.             procKey = comp
  38.         else
  39.             procKey = binary
  40.         end
  41.     end
  42.    
  43.     local pid = xrdbGetProcPid(procKey)
  44.     if pid then
  45.         return nil
  46.     end
  47.  
  48.     if tonumber(delay) then
  49.         local stimer = timer { timeout = delay }
  50.         local run = function()
  51.             stimer:stop()
  52.             pid = awful.util.spawn(binary .. " " .. parameters, false)
  53.             xrdbSetProcPid(procKey, pid)
  54.         end
  55.         stimer:connect_signal("timeout", run)
  56.         stimer:start()
  57.     else
  58.         pid = awful.util.spawn(binary .. " " .. parameters, false)
  59.         xrdbSetProcPid(procKey, pid)
  60.     end
  61. end
  62.  
  63.  
  64. M.xrdbGetProcPid = xrdbGetProcPid
  65. M.xrdbSetProcPid = xrdbSetProcPid
  66. M.xrdbResetProcPid = xrdbResetProcPid
  67. M.xrdbRunOnce = xrdbRunOnce
  68.  
  69. return M
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement