-
Notifications
You must be signed in to change notification settings - Fork 34
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
base: master
Are you sure you want to change the base?
Conversation
116cba2
to
6fae634
Compare
There was a problem hiding this 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/stop_unfocused.lua
Outdated
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.
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) }
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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);
There was a problem hiding this comment.
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 = {} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?!
There was a problem hiding this comment.
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" })
recipes/stop_unfocused.lua
Outdated
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.
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)
recipes/stop_unfocused.lua
Outdated
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.
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.
There was a problem hiding this comment.
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.
recipes/stop_unfocused.lua
Outdated
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.
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?
recipes/stop_unfocused.lua
Outdated
if timeout then | ||
if sigstop_timers[c] then | ||
sigstop_timers[c]:stop() | ||
end |
There was a problem hiding this comment.
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).
recipes/stop_unfocused.lua
Outdated
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.
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.
recipes/stop_unfocused.lua
Outdated
end | ||
|
||
local function delayed_cont(c, mouse_coords) | ||
if client.focus == c then |
There was a problem hiding this comment.
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
.
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: