bling/module/window_swallowing.lua

89 lines
2.6 KiB
Lua
Raw Normal View History

2020-10-24 11:40:02 +02:00
local awful = require("awful")
local gears = require("gears")
local beautiful = require("beautiful")
2021-01-23 23:04:22 +01:00
local helpers = require(tostring(...):match(".*bling") .. ".helpers")
2020-10-24 11:40:02 +02:00
-- It might actually swallow too much, that's why there is a filter option by classname
2021-08-27 20:01:22 +02:00
-- without the don't-swallow-list it would also swallow for example
2020-10-24 11:40:02 +02:00
-- file pickers or new firefox windows spawned by an already existing one
local window_swallowing_activated = false
-- you might want to add or remove applications here
2021-08-27 20:01:22 +02:00
local dont_swallow_classname_list = beautiful.dont_swallow_classname_list
or { "firefox", "Gimp", "Google-chrome" }
local activate_dont_swallow_filter = beautiful.dont_swallow_filter_activated
or true
2020-10-24 11:40:02 +02:00
-- checks if client classname matches with any entry of the dont-swallow-list
local function check_if_swallow(c)
if not activate_dont_swallow_filter then
return true
end
for _, classname in ipairs(dont_swallow_classname_list) do
if classname == c.class then
2020-10-24 11:40:02 +02:00
return false
end
end
2020-10-24 11:40:02 +02:00
return true
end
2020-10-24 11:40:02 +02:00
-- 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
2021-08-27 20:01:22 +02:00
local parent_client = awful.client.focus.history.get(c.screen, 1)
if not parent_client then
return
end
-- io.popen is normally discouraged. Should probably be changed
2021-08-27 20:01:22 +02:00
local handle = io.popen(
[[pstree -T -p -a -s ]]
.. tostring(c.pid)
.. [[ | sed '2q;d' | grep -o '[0-9]*$' | tr -d '\n']]
)
local parent_pid = handle:read("*a")
handle:close()
2021-08-27 20:01:22 +02:00
if
(tostring(parent_pid) == tostring(parent_client.pid))
and check_if_swallow(c)
then
2020-10-24 11:40:02 +02:00
c:connect_signal("unmanage", function()
2021-01-23 23:04:22 +01:00
helpers.client.turn_on(parent_client)
2021-03-15 13:50:25 +01:00
helpers.client.sync(parent_client, c)
2020-10-24 11:40:02 +02:00
end)
2021-03-15 13:50:25 +01:00
helpers.client.sync(c, parent_client)
2021-01-23 23:04:22 +01:00
helpers.client.turn_off(parent_client)
2020-10-24 11:40:02 +02:00
end
end
-- without the following functions that module would be autoloaded by require("bling")
2020-10-24 11:40:02 +02:00
-- a toggle window swallowing hotkey is also possible that way
local function start()
client.connect_signal("manage", manage_clientspawn)
window_swallowing_activated = true
2021-08-27 20:01:22 +02:00
end
2020-10-24 11:40:02 +02:00
local function stop()
client.disconnect_signal("manage", manage_clientspawn)
window_swallowing_activated = false
2021-08-27 20:01:22 +02:00
end
2020-10-24 11:40:02 +02:00
local function toggle()
if window_swallowing_activated then
2020-10-24 11:40:02 +02:00
stop()
else
2020-10-24 11:40:02 +02:00
start()
end
end
2020-10-24 11:40:02 +02:00
return {
start = start,
stop = stop,
2021-08-27 20:01:22 +02:00
toggle = toggle,
2020-10-24 11:40:02 +02:00
}