Always-on-top window and keeping focus, on Awesome

2019-06-22 06:21发布

I am running a script which creates and closes several windows, hence, I added to my rc.lua a way to keep the window where I am working always on top:

awful.key({ modkey, "Control" }, "space",
function(c)
  awful.client.floating.toggle()
  c.ontop = not c.ontop
end),

The problem is:when the new window is created, I lose the focus, which passes to the new window.

Is there a way to make that the previous toggle not only keep the window on top, but also with the focus until I toggle it again?

1条回答
Animai°情兽
2楼-- · 2019-06-22 06:30

Assuming the awful.rules.rules assignment from lines 357-375 of this awesomerc.lua file are in your user's awesomerc.lua file and the awful.client.focus.filter used in that assignment is the one from this file then you should be able to do something like this.

Define a custom focus filter function somewhere in your rc file.

function custom_focus_filter(c)
    if global_focus_disable then
        return nil
    end
    return awful.client.focus.filter(c)
end

Then use that custom filter function in the rules assignment in place of the original filter function.

awful.rules.rules = {
    -- All clients will match this rule.
    { rule = { },
      properties = { ....
                     focus = custom_focus_filter,
                     .... } },

And then your toggle function just needs to set and unset the global as appropriate.

awful.key({ modkey, "Shift" }, "f", function ()
    global_focus_disable = not global_focus_disable
end)
查看更多
登录 后发表回答