Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Stop unfocused clients #111

Open
wants to merge 17 commits into
base: master
Choose a base branch
from

Conversation

Copy link
Member

@psychon psychon left a comment

Choose a reason for hiding this comment

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

What kind of things do you do with Thunderbird and Firefox that you want to SIGSTOP them so much? :-(

recipes.mdwn Outdated Show resolved Hide resolved
recipes/stop_unfocused.lua Outdated Show resolved Hide resolved
function stop_unfocused.sigstop(c)
if c.pid then
awesome.kill(c.pid, 19)
awful.spawn('pkill -STOP -g ' .. c.pid)
Copy link
Member

Choose a reason for hiding this comment

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

Hm. :-(
What is this needed for? Which programs (which make sure they are always their process group leader) have "evil stuff" in their group? I doubt a lot that this works reliably and only happens to work accidentally for things started from a shell.
Also: { "pkill", "-STOP", "-g", tostring(c.pid) }

Copy link
Member Author

Choose a reason for hiding this comment

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

IIRC this was needed for qutebrowser.
Will double-check.

Copy link
Member

Choose a reason for hiding this comment

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

Of course, WebKit uses child processes nowadays (to everyone reading this: And if your webkit version does not, you might have quite an ancient version of a browser engine, which is never a good sign).

Copy link
Member

Choose a reason for hiding this comment

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

Feel free to do something with the following:

diff --git a/luaa.c b/luaa.c
index 2bd5e30..662146a 100644
--- a/luaa.c
+++ b/luaa.c
@@ -254,7 +254,9 @@ luaA_restart(lua_State *L)
 
 /** Send a signal to a process identified by its process id. See
  * `awesome.unix_signal` for a list of signals.
- * @tparam integer pid Process identifier
+ * @tparam integer pid Either a process identifier, `0` for awesome's process
+ * group, `-1` for all processes, or `-pgid` for all processes in the process group
+ * `pgid`. See `man 3 kill` for details.
  * @tparam integer sig Signal number
  * @treturn boolean true if the signal was successfully sent, else false
  * @function kill
@@ -262,7 +264,7 @@ luaA_restart(lua_State *L)
 static int
 luaA_kill(lua_State *L)
 {
-    int pid = luaA_checknumber_range(L, 1, 1, INT_MAX);
+    int pid = luaL_checkinteger(L, 1);
     int sig = luaA_checknumber_range(L, 2, 0, INT_MAX);
 
     int result = kill(pid, sig);

Copy link
Member Author

Choose a reason for hiding this comment

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

JFI: Using awesome.kill with a negative pgid works quite good by itself now, but I've noticed an issue with Thunderbird, where child processes are in the same process group then (https://bugzilla.mozilla.org/show_bug.cgi?id=1517425). This is relevant for when handling both Thunderbird and qutebrowser, and the browser was started from Thunderbird. In this case stopping either of them would also stop the other.

stop_timeout = 10,
}

stop_unfocused.ignore_clients = {}
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this table have weak keys so that clients are not prevented from being GC'd?

Copy link
Member Author

Choose a reason for hiding this comment

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

Makes sense.. do you have some pointer?
It could also get removed on unmanage?!

Copy link
Member

Choose a reason for hiding this comment

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

stop_unfocused.ignore_clients = setmetatable({}, { __mode = "k" })

stop_unfocused.sigcont(c)
else
timer.start_new(0.05, function()
timer.delayed_call(function() delayed_cont(c, coords) end)
Copy link
Member

Choose a reason for hiding this comment

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

timer.delayed_call(delayed_cont, c, coords)

end)

-- Restart any stopped clients when exiting/restarting.
awesome.connect_signal("exit", function(restarting) -- luacheck: no unused args
Copy link
Member

Choose a reason for hiding this comment

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

Just remove the unused parameter restarting and the luacheck comment.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done.
Somehow I've imagined it to be better to copy/see the function signature.

end
end
local sigstop_unfocus = function(c)
if c.pid and not sigstopped_clients[c] and not c.ontop and not stop_unfocused.ignore_clients[c] then
Copy link
Member

Choose a reason for hiding this comment

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

Can't this "ignore ontop" be moved into a rule? Perhaps timeout = false means to ignore such a client, or something like that?

if timeout then
if sigstop_timers[c] then
sigstop_timers[c]:stop()
end
Copy link
Member

Choose a reason for hiding this comment

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

Can this happen? Such a timer is only started when a client is unfocused and a client cannot be unfocused twice in a row (without being focused in between, in which case the focus-callback stops the timer).

sigstop_timers[c]:stop()
end
sigstop_timers[c] = timer.start_new(timeout, function()
if c ~= client.focus and c.pid ~= client.focus.pid then
Copy link
Member

Choose a reason for hiding this comment

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

This needs a c.valid check somewhere.

end

local function delayed_cont(c, mouse_coords)
if client.focus == c then
Copy link
Member

Choose a reason for hiding this comment

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

This needs to be c.valid and client.focus == c.

@blueyed
Copy link
Member Author

blueyed commented Aug 23, 2017

What kind of things do you do with Thunderbird and Firefox that you want to SIGSTOP them so much? :-(

Browsers tend to use a lot of resources (CPU) even when not being used actively - which depends on your open tabs, of course.
One very bad website in this regard seems to be Travis CI (where it seems to depend on the number of repos they are polling in the background all the time).

@blueyed
Copy link
Member Author

blueyed commented Sep 21, 2018

Need to come back to this (but am using a very modified version still).

Just wanted to leave this for reference: https://vermaden.wordpress.com/2018/09/19/freebsd-desktop-part-16-configuration-pause-any-application/ (via https://news.ycombinator.com/item?id=18022540).

blueyed added a commit to blueyed/dotfiles that referenced this pull request Mar 7, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants