Shortly put, I'd like to be able to do this:
bindsym F24 forward [class="discord"]
With this example, when F24 is pressed, the first window matching the criteria get a keypress event, exactly as if it was focused and F24 was pressed.
This would allow for a very easy way to handle global hotkeys.
Hm, neat idea.
I think a way of doing it that would be more flexible is allow to send input. And now that I'm typing it I realise that this is already possible with seats.
So in this case you would do:
for_window [class="discord"] bindsym F24 seat - mmmhh, oops, nope, keyboards don't work yet. #1779
I prefer this solution over adding a redundant command.
While I understand your argument, and I would accept it as a solution when it is implement, I have two small concerns:
bindsym XX .... syntax instead of for_window... bindsym XX provides easier grouping of global hotkey in the configI think the config file must be as expressive, concise and easy to organize as possible.
* `bindsym XX ....` syntax instead of `for_window... bindsym XX` provides easier grouping of global hotkey in the config
I'm not sure I understand what you mean here. I would say it's actually the opposite:
for_window [class="discord"] bindsym {
F21 .......
F22 .......
F23 .......
F24 .......
}
Well, that's a matter of taste, for me:
bindsym XX ...
bindsym YY ...
is clearer than:
for_window ... bindsym..., other rules
... a bunch of lines
for_window ... bindsym..., other rules
Because I group my for_window directives not in the same way I would group my bindsym global hostkey. With a list of bindsym it's also easier to ensure you did not override a key.
But this is a matter of taste.
Anyway, there is another problem, the for_window wouldn't bind the key if there is no window, and the whole point of global hotkeys is for them to be always bound, regardless of context, if there is no window matching criteria to forward the key to, then the key is a noop.
My syntax would make that clear and would also permit forwarding to multiple apps:
bindsym F24 forward [app_id=A...], forward [app_id=B...]
This would swallow the key if neither A and B are running, if either A or B is running it would forward the key to it, and if both are running, it would forward the key to both.
forward would require keeping metadata about the key event around and pass it to the command executed by bindsym. Not a fan of this.
forwardwould require keeping metadata about the key event around and pass it to the command executed bybindsym. Not a fan of this.
Well, I guess creating a new event with the same keycode would work, like bindsym F24 emit [app_id...] which would emit the same key, and bindsym F24 emit F12 ... which would remap the key.
The idea is to provide an easy way to bind global hotkeys for app that cannot be scripted. I'm sure we can come up with a nice solution.
If syntax sugar is what you want you could use variables:
set $emit seat - keyboard press
(Ignoring the fact keyboards haven't been implemented yet)
Reread the original comment (https://github.com/swaywm/sway/issues/4937#issue-553647599) and realised I misread it. It won't be as easy as using seats. But regardless I still believe it can be done with seats. Especially with if "virtual seats" become a thing.
Most helpful comment
Hm, neat idea.