7

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?

Alejandro DC
  • 225
  • 3
  • 11
  • Just in case: my workaround was to set a rule for that program to open on a specific tag... but I really want a toggle to pin my window on top of everything else, and not to lose focus when other windows appear. – Alejandro DC Apr 16 '15 at 17:35
  • Does any new window opening switch focus or just the windows from this application/script? – Etan Reisner Apr 16 '15 at 18:10
  • Any window, but it is not common that I have windows popping up, just with this script. – Alejandro DC Apr 17 '15 at 00:29
  • Does [this discussion](https://bbs.archlinux.org/viewtopic.php?id=81828) help any? – Etan Reisner Apr 17 '15 at 02:06
  • Well, not really. I could avoid focus styling altogether, but for me it is in general a feature (if you open a new program, the focus goes to its window), what I am asking for is a way to toggle it, so if I have something creating new windows in a mad way, as this script I mentioned, I can switch off the focus styling temporarily. – Alejandro DC Apr 17 '15 at 10:17
  • If the general advice works there (and the control is in a function) and you can toggle a global then you should be able to get your desired behavior with that, no? – Etan Reisner Apr 17 '15 at 11:44
  • You can say: whenever a new window appear, focus or not focus on it. What I want to say is: toggle the behaviour on new windows from now on. And I do not know how to do so. – Alejandro DC Apr 17 '15 at 11:58
  • Is that option a boolean option or a function whose behavior/code you can control/modify? That was my question. – Etan Reisner Apr 17 '15 at 12:00
  • It is a rule for new windows. I am not sure how to toggle rules. I will try to investigate that. Thanks for the tip. – Alejandro DC Apr 17 '15 at 12:05
  • You don't need to toggle the rule if you can extend its behavior to check for some other global (but toggling the rule might work also).. – Etan Reisner Apr 17 '15 at 12:27
  • Yes, I can make a rule for that specific script (which is what I have done in fact, read my first comment), but what I want is to have a way to toggle the focus to new windows in general, and toggle it again whenever I want (without editing the rc.lua). – Alejandro DC Apr 17 '15 at 15:50
  • You are missing my point. If their is a function that controls whether new windows get focus and you can edit that function you can have that function decide whether to give a new window focus based on the state of some global variable and then your "toggle" is changing the state of that global variable. – Etan Reisner Apr 17 '15 at 15:59
  • There is a function controlling to give focus to a window: you add a rule to "new windows", and you say "give control to it, when it appears". What I do not have is a way to globally say "do not give control to new windows", and this to be toggled when I want. I would need to be able to dynamically add rules, which is not what you do with, for example, what I put in the main post: the c.ontop is "the current window (c) must be on top". How to say "the new window which has not been created yet, must not get the focus". That I do not know. – Alejandro DC Apr 17 '15 at 18:49
  • I just added a new question, more specifically on how to modify rules dynamically. If I get a reply to it, I will be able to reply this question too. http://stackoverflow.com/questions/29707357/is-there-any-way-to-add-a-new-rule-to-the-awful-rules-table-dynamically-in-aweso – Alejandro DC Apr 17 '15 at 18:58

1 Answers1

6

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)
Etan Reisner
  • 77,877
  • 8
  • 106
  • 148