2

Is it possible to switch to a specific screen via hotkeys in awesome wm (v4.0)?

Say you have screens DP-1-2, DP-2-2 and eDP-1. You now want to switch to screen DP-1-2 regardless of which screen you are currently on.
Preferably one could use the same technique to also move applications to a specific screen.

Is any of this possible?

1

There are no default bindings for this as far as I know, but the required methods to create them exist:

  • focusing a screen directly awful.screen.focus. Takes a screen object to move focus to.
  • moving a client client:move_to_screen. Note that you'll want to add this to the client bindings table, not the global one.

If you want to create the bindings based on the randr output names, you can use the screen objects' outputs property. This table has the randr output names as keys, so it's a bit convoluted to use for this purpose. I'd try something like this:

for s in screen do
  for out,_ in pairs(s) do
    if out == "eDP1" then
      globalkeys = awful.util.table.join(globalkeys,
        awful.key({modkey}, "F1", function() awful.screen.focus(s) end))
    elseif out == "DP-1-2" then
      -- ...
    end
  end
end

I cannot test it right now, don't have multiple screens available here.

  • How exactly do you use the outputs property? I tried property::outputs.name['DP-1-2'] which does not seem to work. – user346830 Apr 12 at 10:56
  • the documentation to outputs is a bit misleading, there is no name attribute on it, you have to replace it with the actual name. You also cannot get a screen object from it directly. I've expanded the answer a bit to show how you could use it. – crater2150 Apr 13 at 7:53
  • Thanks for the added explanation. Still struggling to actually get the screen names. I tried your suggestion however it gives an error ("bad argument #1 to 'pairs' table expected, got userdata"). I tried several variations like s.name, s.outputs.name and screen.outputs.name because according to the docs outputs should have a table called name which includes the screens as keys. As you said the docs seem a bit misleading as neither of the above worked. – user346830 Apr 15 at 7:37
  • I actually fixed it. I will post the working solution in case anyone else wants to look at it. Thanks again for all your help. – user346830 Apr 15 at 13:57
0

Based on the answer by crater2150 I found a working solution. I post this in case anyone has the same problem.

-- set up keybindings based on existing monitors
for s in screen do
  for screen_name, _ in pairs(s.outputs) do
    if screen_name == "eDP-1" then
      globalkeys = awful.util.table.join(globalkeys,
          awful.key({modkey}, "F1", function() awful.screen.focus(s) end))
    elseif screen_name == "DP-2-2" then
      globalkeys = awful.util.table.join(globalkeys,
          awful.key({modkey}, "F2", function() awful.screen.focus(s) end))
    elseif screen_name == "DP-1-2" then
      globalkeys = awful.util.table.join(globalkeys,
          awful.key({modkey}, "F3", function() awful.screen.focus(s) end))
    end
  end
end

Simply iterate over all screens and if the ones you are interested in exist, add a keybind that switches to the respective screen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.