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
29 changes: 19 additions & 10 deletions module/window_swallowing.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,17 @@ local parent_filter_list = beautiful.parent_filter_list
or { "firefox", "Gimp", "Google-chrome" }
local child_filter_list = beautiful.child_filter_list
or beautiful.dont_swallow_classname_list or { }

Choose a reason for hiding this comment

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

Just a thought I have reading this : There is a corner case where the user can require the module before calling beautiful.init. In this situation, the user defined lists in their theme will be ignored because these variables here are global to the module and initialized only here, at the module first load.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

that is a corner case with all of bling and the docs specify requiring bling after beautiful.init

https://blingcorp.github.io/bling/#/?id=installation

local swallowing_filter = beautiful.swallowing_filter
or beautiful.dont_swallow_filter_activated or true

-- for boolean values the or chain way to set the values breaks with 2 vars
-- and always defaults to true so i had to do this to se the right value...
local swallowing_filter = true
local filter_vars = { beautiful.swallowing_filter, beautiful.dont_swallow_filter_activated }
for _, var in pairs(filter_vars) do
swallowing_filter = var
end

-- check if element exist in table
-- returns true if it is
local function is_in_table(element, table)
local res = false
for _, value in pairs(table) do
Expand All @@ -31,13 +38,16 @@ local function is_in_table(element, table)
return res
end

-- checks if parent's classname can be swallowed
local function check_swallow(class, list)
if not swallowing_filter then
return true
else
return not is_in_table(class, list)
-- if the swallowing filter is active checks the child and parent classes
-- against their filters
local function check_swallow(parent, child)
local res = true
if swallowing_filter then
local prnt = not is_in_table(parent, parent_filter_list)
local chld = not is_in_table(child, child_filter_list)
res = ( prnt and chld )
end
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

-- the function that will be connected to / disconnected from the spawn client signal
Expand All @@ -57,8 +67,7 @@ local function manage_clientspawn(c)
if
-- will search for "(parent_client.pid)" inside the parent_pid string
( tostring(parent_pid):find("("..tostring(parent_client.pid)..")") )
and check_swallow(parent_client.class, parent_filter_list)
and check_swallow(c.class, child_filter_list)
and check_swallow(parent_client.class, c.class)
then
c:connect_signal("unmanage", function()
helpers.client.turn_on(parent_client)
Expand Down