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
104 lines
4.2 KiB
-- This file is part of Reno desktop.
|
|
--
|
|
-- 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.
|
|
--
|
|
-- 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.
|
|
--
|
|
-- You should have received a copy of the GNU General Public License along with Reno desktop. If not, see <https://www.gnu.org/licenses/>.
|
|
-- XFCE style autostart system with a system to automatically kill children just to fuck over Steam. (now with SMЯT targeting software package!)
|
|
local awful = require("awful")
|
|
local gears = require("gears")
|
|
local gfs = gears.filesystem
|
|
local menu_utils = require("menubar.utils")
|
|
local hide_ids = {}
|
|
local related_ids = {}
|
|
local settings = config.autostart
|
|
local stop_checking = false
|
|
-- I know this is linux specific, blame Steam for creating a triple-forking launcher with no startup id.
|
|
-- I love the fact that valve is supportive of linux and thinks it's the future of gaming and all that
|
|
-- but you could've just done the due diligence and, yk, maybe research how things work with XDG?
|
|
-- P.S. if you know how to make this function work in similar vein on BSD, feel free to contribute
|
|
local function is_child_of(pid,related)
|
|
related = related or pid
|
|
local ppidfile = io.open("/proc/"..tostring(pid).."/status","rb")
|
|
if not ppidfile then return false end
|
|
local ppid = ppidfile:read("*a"):match("PPid:%s*(%d+)")
|
|
ppidfile:close()
|
|
if (not ppid) or (ppid == "1") then return false end
|
|
if hide_ids[tonumber(ppid)] then
|
|
related_ids[related] = tonumber(ppid)
|
|
return true
|
|
else
|
|
return is_child_of(ppid,related)
|
|
end
|
|
end
|
|
-- Play whack-a-mole with the clients that match ids to hide
|
|
-- NO MORE MR NICE GUY, until the user EXPLICITLY activates the client,
|
|
-- it's being hidden.
|
|
local callback = function(c)
|
|
if not settings.minimize_enable then return end
|
|
if stop_checking then return end
|
|
gears.timer.delayed_call(function()
|
|
local kill_later = false
|
|
if c.pid and hide_ids[c.pid] then
|
|
kill_later = true
|
|
end
|
|
if c.startup_id and hide_ids[c.startup_id] then
|
|
kill_later = true
|
|
end
|
|
if c.pid and is_child_of(c.pid) then
|
|
kill_later = true
|
|
end
|
|
if kill_later then
|
|
c.minimized = true
|
|
end
|
|
end)
|
|
end
|
|
client.connect_signal("focus",callback)
|
|
client.connect_signal("manage",callback)
|
|
-- if the client has been mouse pressed we no longer hide it or any of its siblings - user needs the client to be active.
|
|
client.connect_signal("request::activate",function(c,reason)
|
|
if (reason ~= "mouse_click") and (reason ~= "tasklist") then
|
|
return
|
|
end
|
|
if c.pid then
|
|
hide_ids[c.pid] = nil
|
|
if related_ids[c.pid] then
|
|
hide_ids[related_ids[c.pid]] = nil
|
|
end
|
|
end
|
|
if c.startup_id then
|
|
hide_ids[c.startup_id] = nil
|
|
end
|
|
end)
|
|
-- this ain't happy hour - stop hitting everything in sight.
|
|
gears.timer {
|
|
timeout = settings.minimize_timeout or 30,
|
|
autostart = true,
|
|
single_shot = true,
|
|
callback = function()
|
|
stop_checking = true
|
|
hide_ids = {}
|
|
end
|
|
}
|
|
local stdir = os.getenv("XDG_RUNTIME_DIR").."/.awesome_startup/"
|
|
gfs.make_directories(stdir)
|
|
awful.spawn.with_line_callback("find "..gfs.get_xdg_config_home().."autostart/ -name *.desktop",{
|
|
stdout = function(line)
|
|
local data = menu_utils.parse_desktop_file(line)
|
|
if (data.RunHook == "0") or (data.RunHook == nil) then
|
|
if not gfs.file_readable(stdir..line:match("[^/]*$")) then
|
|
local npid,nsnid = awful.spawn(data.Exec:gsub("%%%w",""))
|
|
io.open(stdir..line:match("[^/]*$"),"w"):write(npid):close()
|
|
if data.Hidden then
|
|
if npid then
|
|
hide_ids[npid] = true
|
|
end
|
|
if nsnid then
|
|
hide_ids[nsnid] = true
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
})
|