Okay, time to summon DuckDuckFedi.

I have a program that is running on my sway session (so, Wayland, more precisely XWayland).
I use ydotool to run some keystrokes.
Everything works fine as-is, but it means that I can't use the computer for anything else as the keystrokes are sent to the active window.

Do you know if there is a way to create a kind of "virtual keyboard/input device" attached to said application which I could use for the keystrokes? Some kind of containers or something?

Thank you for your ideas! Boosts appreciated!  

#wayland #swaywm #xwayland #ydotool

@ShadowJonathan @Soblow if it's actually an X11 application running in XWayland, then i think you can just use xdotool with the --window parameter? i haven't checked it though..

for wayland apps you could theoretically run another wayland compositor (weston i guess?), configure it to only receive keyboard/mouse events from a certain virtual input source (idk how to do that), emulate that virtual input source, and then run the application inside of that nested wayland compositor by setting the WAYLAND_DESKTOP environment variable

idk if there are any ready-made solutions for this though 

@Soblow have you tried hacking with swaymsg ?
https://github.com/swaywm/sway/issues/4937
[Feature request] Allow forwarding of key events · Issue #4937 · swaywm/sway

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...

GitHub
@iona well, it seems pretty unstable, as it'll constantly shift between windows...
@Soblow I don't really know how sway handles inputs, i guess you fear race conditions ? Maybe try stress testing it ?
@Soblow
Assigning a device to a separate seat seems to work for the most part

`swaymsg seat ydotoold attach '9011:26214:ydotoold_virtual_device'`

this allows multiple applications to have focus, creates a separate pointer and all that jazz, but it's also very finnicky, causing problems like having the ydotool cursor move when I open a new terminal window
@Soblow ah I think that's caused by `mouse_warping` if you disable that things should work
@Soblow keep in mind applications might now support multiseat properly, so if you have multiple cursors over the same window weird things might happen
@Soblow really depends on your use case, if you can share more I can try to help
@Soblow sorry for the chain but you can create an output with `swaymsg create_output`(you can delete it with `swaymsg output HEADLESS-1 unplug`), assign it to a separate workspace and set it's position so your mouse doesn't accidentally enter it, then have ydotool use that, that way you shouldn't have any conflicts
@Soblow another solution(probably best) is to not use ydotool, and instead run a nested sway instance, and use something that supports `wlr_virtual_pointer_unstable_v1`, or just call the swaymsg input emulation commands(`seat <seat> cursor move|set <x> <y>`)
@Soblow (https://git.sr.ht/~brocellous/wlrctl seems promising but I've never used it)
~brocellous/wlrctl - Utility for miscellaneous wlroots extensions - sourcehut git

@Mae The only reason I use ydotool is because I know how to use it, so I'm not stuck to it  
As long as I can simulate key presses (namely arrow keys and space key) it's okay.
I don't need mouse at all
@Soblow wlrctl is perfect then, just run sway inside another wayland compositor(literally by running `sway`, you can do that and it's so cool!!!), and then set `WAYLAND_DISPLAY` to `wayland-2` in your script, and everything should just work I think

sorry if I'm being too much with this, I assume you know this already

@Mae Honestly, I have only basic knowledge about Wayland and tools around it, so I highly appreciate the detailed explainations!  

I'll try this ASAP and keep you informed, many thanks!!

@Mae Oh, I just checked, wlrctl doesn't seem to handle key press/release event separately, mmmh...
Either I check if I can patch wlrctl to do this, or I check for an other tool...