Skip to content
This repository has been archived by the owner on Dec 18, 2024. It is now read-only.

Improved swallowing #140

Merged
merged 14 commits into from
Jan 4, 2022
30 changes: 24 additions & 6 deletions module/window_swallowing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,23 @@ local function check_swallow(parent, child)
return res

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't the function returns false when window_swallowing_activated is false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from what i can tell no, since window_swallowing_activated = false means that the swallowing function will be disconected from all clients.

105 local function start()
106     client.connect_signal("manage", manage_clientspawn)
107     window_swallowing_activated = true
108 end
109
110 local function stop()
111     client.disconnect_signal("manage", manage_clientspawn)
112     window_swallowing_activated = false
113 end
114
115 local function toggle()
116     if window_swallowing_activated then
117         stop()
118     else
119         start()
120     end
121 end

however if you meant the boolean value of swallowing_filter then reffering back to the truth table the output value of this function should only be false when the filter is active and either parent or child is in any of the filtering lists.

Copy link

@Aire-One Aire-One Dec 19, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I have forgotten the use of this variable and thought it has what the user change to activate the module... My bad.

end

-- async function to get the parent's pid
-- recieves a child process pid and a callback function
-- parent_pid in format "init(1)---ancestorA(pidA)---ancestorB(pidB)...---process(pid)"
function get_parent_pid(child_ppid, callback)
local ppid_cmd = string.format("pstree -A -p -s %s", child_ppid)
awful.spawn.easy_async(ppid_cmd, function(stdout, stderr, reason, exit_code)
-- primitive error checking
if stderr and stderr ~= "" then
callback(stderr)
return
end
local ppid = stdout
callback(nil, ppid)
end)
end


-- the function that will be connected to / disconnected from the spawn client signal
local function manage_clientspawn(c)
-- get the last focused window to check if it is a parent window
Expand All @@ -60,12 +77,12 @@ local function manage_clientspawn(c)
return
end

-- io.popen is normally discouraged. Should probably be changed
-- returns "init(1)---ancestorA(pidA)---ancestorB(pidB)...---process(pid)"
local handle = io.popen("pstree -A -p -s " .. tostring(c.pid))
local parent_pid = handle:read("*a")
handle:close()

get_parent_pid(c.pid, function(err, ppid)
if err then
error(err)
eylles marked this conversation as resolved.
Show resolved Hide resolved
return
end
parent_pid = ppid
if
-- will search for "(parent_client.pid)" inside the parent_pid string
( tostring(parent_pid):find("("..tostring(parent_client.pid)..")") )
Expand All @@ -79,6 +96,7 @@ local function manage_clientspawn(c)
helpers.client.sync(c, parent_client)
helpers.client.turn_off(parent_client)
end
end)
end

-- without the following functions that module would be autoloaded by require("bling")
Expand Down