RFC: Stop unfocused clients - #111
Conversation
116cba2 to
6fae634
Compare
psychon
left a comment
There was a problem hiding this comment.
What kind of things do you do with Thunderbird and Firefox that you want to SIGSTOP them so much? :-(
| function stop_unfocused.sigstop(c) | ||
| if c.pid then | ||
| awesome.kill(c.pid, 19) | ||
| awful.spawn('pkill -STOP -g ' .. c.pid) |
There was a problem hiding this comment.
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) }
There was a problem hiding this comment.
IIRC this was needed for qutebrowser.
Will double-check.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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);There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
Shouldn't this table have weak keys so that clients are not prevented from being GC'd?
There was a problem hiding this comment.
Makes sense.. do you have some pointer?
It could also get removed on unmanage?!
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Just remove the unused parameter restarting and the luacheck comment.
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
This needs a c.valid check somewhere.
| end | ||
|
|
||
| local function delayed_cont(c, mouse_coords) | ||
| if client.focus == c then |
There was a problem hiding this comment.
This needs to be c.valid and client.focus == c.
6fae634 to
2de3aa0
Compare
Browsers tend to use a lot of resources (CPU) even when not being used actively - which depends on your open tabs, of course. |
|
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). |
Conflicts: recipes.mdwn
This is necessary for when multiple clients are involved, e.g. qutebrowser windows, and custom callbacks are used.
TODO:
Resources: