简体   繁体   中英

Create keybinding to focus master client in awesome-wm

I would like to create a keybinding to switch focus to the master client. Profjim on this forum thread notes:

To get the master client on the current tag:

 c = awful.client.getmaster() 

I have tried the following, but it causes my ~/.config/rc.lua file to be ignored, which is the behavior if there is an error in the file. Does anyone know the correct syntax?

awful.key({ modkey,          , "e",  awful.client.getMaster()),

Note: "e" shouldn't cause any conflicts if you have the default key bindings.

Edit: Someone on /r/awesomewm knew the syntax to solve my problem:

awful.key({ modkey,          }, "e",  function() client.focus = awful.client.getmaster(); client.focus:raise() end), 

Lets start with the syntax errors; from the documentation it seems that awful.key is a table, not a function. and it would presumably contain key s ...which are hash tables, not sequences.

Finally your table syntax is wrong; a field may not be syntactically empty, it must have a listed value, even if that value is nil .

So basically you are trying to pass the wrong kind of value to something that can't be called.


As for how to do it correctly...the documentation is confusing, and apparently I'm not the only one that thinks so.

* deep breath *

okay, awful.new(...) creates key binders(?), and awful.key contains key bindings, so clearly we have to put the results of the first into the second.
the code on your link is but a pointer, and only covers focusing the window, not creating a keybinding.

It seems like you want something like this:

function do_focus()
    current = client.focus
    master  = awful.client.getmaster()
    if current then
        client.focus = master
        master:raise()
    end
end

table.insert(awful.key, awful.new (modkey, 'e', nil, do_focus) )

Bare in mind that I have no way of testing the above code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM