Reno is the second iteration of the AWMTK-powered AwesomeWM config.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

104 lines
4.2 KiB

2 years ago
12 months ago
  1. -- This file is part of Reno desktop.
  2. --
  3. -- Reno desktop is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
  4. --
  5. -- Reno desktop is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  6. --
  7. -- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
  8. -- XFCE style autostart system with a system to automatically kill children just to fuck over Steam. (now with SMЯT targeting software package!)
  9. local awful = require("awful")
  10. local gears = require("gears")
  11. local gfs = gears.filesystem
  12. local menu_utils = require("menubar.utils")
  13. local hide_ids = {}
  14. local related_ids = {}
  15. local settings = config.autostart
  16. local stop_checking = false
  17. -- I know this is linux specific, blame Steam for creating a triple-forking launcher with no startup id.
  18. -- I love the fact that valve is supportive of linux and thinks it's the future of gaming and all that
  19. -- but you could've just done the due diligence and, yk, maybe research how things work with XDG?
  20. -- P.S. if you know how to make this function work in similar vein on BSD, feel free to contribute
  21. local function is_child_of(pid,related)
  22. related = related or pid
  23. local ppidfile = io.open("/proc/"..tostring(pid).."/status","rb")
  24. if not ppidfile then return false end
  25. local ppid = ppidfile:read("*a"):match("PPid:%s*(%d+)")
  26. ppidfile:close()
  27. if (not ppid) or (ppid == "1") then return false end
  28. if hide_ids[tonumber(ppid)] then
  29. related_ids[related] = tonumber(ppid)
  30. return true
  31. else
  32. return is_child_of(ppid,related)
  33. end
  34. end
  35. -- Play whack-a-mole with the clients that match ids to hide
  36. -- NO MORE MR NICE GUY, until the user EXPLICITLY activates the client,
  37. -- it's being hidden.
  38. local callback = function(c)
  39. if not settings.minimize_enable then return end
  40. if stop_checking then return end
  41. gears.timer.delayed_call(function()
  42. local kill_later = false
  43. if c.pid and hide_ids[c.pid] then
  44. kill_later = true
  45. end
  46. if c.startup_id and hide_ids[c.startup_id] then
  47. kill_later = true
  48. end
  49. if c.pid and is_child_of(c.pid) then
  50. kill_later = true
  51. end
  52. if kill_later then
  53. c.minimized = true
  54. end
  55. end)
  56. end
  57. client.connect_signal("focus",callback)
  58. client.connect_signal("manage",callback)
  59. -- if the client has been mouse pressed we no longer hide it or any of its siblings - user needs the client to be active.
  60. client.connect_signal("request::activate",function(c,reason)
  61. if (reason ~= "mouse_click") and (reason ~= "tasklist") then
  62. return
  63. end
  64. if c.pid then
  65. hide_ids[c.pid] = nil
  66. if related_ids[c.pid] then
  67. hide_ids[related_ids[c.pid]] = nil
  68. end
  69. end
  70. if c.startup_id then
  71. hide_ids[c.startup_id] = nil
  72. end
  73. end)
  74. -- this ain't happy hour - stop hitting everything in sight.
  75. gears.timer {
  76. timeout = settings.minimize_timeout or 30,
  77. autostart = true,
  78. single_shot = true,
  79. callback = function()
  80. stop_checking = true
  81. hide_ids = {}
  82. end
  83. }
  84. local stdir = os.getenv("XDG_RUNTIME_DIR").."/.awesome_startup/"
  85. gfs.make_directories(stdir)
  86. awful.spawn.with_line_callback("find "..gfs.get_xdg_config_home().."autostart/ -name *.desktop",{
  87. stdout = function(line)
  88. local data = menu_utils.parse_desktop_file(line)
  89. if (data.RunHook == "0") or (data.RunHook == nil) then
  90. if not gfs.file_readable(stdir..line:match("[^/]*$")) then
  91. local npid,nsnid = awful.spawn(data.Exec:gsub("%%%w",""))
  92. io.open(stdir..line:match("[^/]*$"),"w"):write(npid):close()
  93. if data.Hidden then
  94. if npid then
  95. hide_ids[npid] = true
  96. end
  97. if nsnid then
  98. hide_ids[nsnid] = true
  99. end
  100. end
  101. end
  102. end
  103. end
  104. })