<div dir="ltr"><div>Reply below, focusing on use cases for now<br><br>On Wed, Mar 22, 2017 at 4:59 AM, Pekka Paalanen <<a href="mailto:ppaalanen@gmail.com">ppaalanen@gmail.com</a>> wrote:<br>><br>> On Wed, 22 Mar 2017 12:23:46 +1000<br>> Peter Hutterer <<a href="mailto:peter.hutterer@who-t.net">peter.hutterer@who-t.net</a>> wrote:<br>><br>> > Hi all,<br>> ><br>> > This is an RFC for a new interface to generate input events from arbitrary<br>> > clients. Note that this is only a few days old, so **do not** assume this is<br>> > anything more a thought experiment right now. This email is supposed to start a<br>> > discussion and collection of the various points that need to be addressed.<br>> ><br>> > First: why? There are some commandline tools like xdotool that allow for some<br>> > scripting of desktop interactions. xdotool supports two categories: input<br>> > device emulation and window management.<br>> ><br>> > This RFC primarily addresses the input device emulation bits but there is<br>> > room for adding window management capabilities. I have a basic repo here:<br>> > <a href="http://github.com/whot/woodotool">http://github.com/whot/woodotool</a> but it doesn't contain much beyond what's<br>> > in this email.<br>> ><br>> > This will be a discussion of the interface only because the implementations<br>> > are so specific that there is no real code-sharing beyond the interface<br>> > itself. I've talked privately to some of you already, the general mood is<br>> > somewhere around reluctant acceptance.<br>> ><br>> > So here's a list of talking points:<br>> ><br>> > == DBus ==<br>> > What we need is basic IPC and not directly Wayland related, DBus provides a<br>> > bunch of extras over the wayland protocol: introspection, ease of<br>> > extensibility, bindings, etc. Also, Mir.<br>> ><br>> > == Functionality-based interfaces ==<br>> > We need a mix of capabilities and features, not all of which will/should be<br>> > available to all clients. Right now, I have two for devices:<br>> >  org.freedesktop.WoodoTool.Keyboard (Press, Release)<br>> >  org.freedesktop.WoodoTool.Mouse (Press, Release, MoveRelative, MoveAbsolute)<br>> > Compositors can implement one, both, either, etc. For future extensions,<br>> > having a Touch interface, Joystick, or whatever is deemed useful is<br>> > technically trivial.<br>> ><br>> > There's a manager interface too but that's a technical detail, see the repo<br>> > for more details.<br>> ><br>> > == Control of the event stream ==<br>> > The events are coming in through a custom interface, so it's relatively<br>> > trivial to ignore events based on context, e.g. ignore fake key events while<br>> > the screen is locked. Any uinput-based solution would lack this context.<br>> ><br>> > == Authentication/Identification ==<br>> > The goal is to filter clients based on some white/blacklist, so that e.g.<br>> > xdotool can access this interface but others cannot.<br>><br>> Hi,<br>><br>> if one allows a generic tool that essentially exposes everything at<br>> will, there isn't much point in authenticating that program, because<br>> any other program can simply call it.<br>><br>> > This is a big ¯\_(ツ)_/¯ for now, I don't now how to do this reliably.<br>> > It's trivial to do per user, but per-process is difficult. DBus filters<br>> > are largely limited to per-users. It's possible to get the process ID of a<br>> > sender but going beyond that is unreliable (kernel doesn't guarantee comm<br>> > being accurate).<br>> ><br>> > Requiring applications to bind to a bus name merely restricts them to being<br>> > a singleton, there is no guarantee the application that binds<br>> > org.freedesktop.org.WoodoTool.auth.xdotool is actually xdotool.<br>> ><br>> > The option that comes closest so far is some pre-shared key between<br>> > compositor and application. That would need to be worked into the API, but<br>> > it also relies on all participants to keep the key encrypted in memory and<br>> > the various configuration files.<br>> ><br>> > So it's not clear whether we can do anything beyond a basic on/off toggle on<br>> > whether to allow events from fake input devices. Debatable if such a crude<br>> > mechanism is useful.<br>> ><br>> ><br>> > Either way, this is a problem that *must* be solved but not necessarily one<br>> > that affects the API itself (beyond what is required to make it<br>> > technically feasable, e.g. passing cookies around)<br>><br>> It's essentially the same problem we have with all the privileged<br>> Wayland interfaces, too.<br>><br>> Containers or sandboxing have been mentioned as a possible way to let<br>> the OS reliably identify the running program.<br>><br>><br>> > == Isolation of devices ==<br>> > Compositors should create separate virtual input devices for each client so<br>> > one client can't mess with the state of another one or even detect if<br>> > there's another one active. Plus we get to re-use all the existing code that<br>> > merge state from different (physical) devices. This just makes the actual<br>> > device handling implementation trivial.<br>> ><br>> > It gets a bit more difficult if we want to have this per-seat though. Seat<br>> > is a wayland concept so we could fold that in, but then you're leaking the<br>> > seat configuration. So I'm not 100% sure we even want this, or whether we<br>> > should just make sure it can be retrofitted in the future.<br>><br>> One possibility is to always create at least one new virtual seat<br>> (wl_seat) for the emulated input devices. Woodotool clients would see<br>> the virtual seat and possibly be allowed to create and destroy more<br>> virtual seats at will. This would not leak or interfere with the real<br>> seats.<br>><br>> At the same time it would also exclude use cases where one wants to<br>> hook into the real seat, e.g. a program that provides keyboard events<br>> but relies on the real seat for focus handling.<br>><br>> There can be multiple real seats. How would one pick which real seat to<br>> integrate with?<br>><br>> Hmm, wait, what do mean by "leaking the seat configuration"? Don't we<br>> expose exactly that straight through Wayland? What's the issue you see?<br>><br>> > == Use for testing ==<br>> > Came up several times, I'm not yet convinced this is a good compositor testing<br>> > interface beyond basic input. A good testing interface likely requires<br>> > something more compositor-specific where more of the window state is made<br>> > available. But it could work as an interim solution.<br>> ><br>> > == Input coordinate handling ==<br>> > Keys and mouse buttons are trivial unless we want custom focus (we don't).<br>> > Relative coordinates are ok too, absolute ones are trickier because they<br>> > rely on screen layout not available to the client.<br>> ><br>> > So the specification needs to include a behaviour we can stick to forever,<br>> > something like "in pixels as measured from the logical top-left of the<br>> > top-left-most screen" etc. Not difficult per se, but this stuff is usually<br>> > prone to corner-case unhappiness.<br>><br>> Logical or physical pixels?<br>><br>> Anyway, I think it's ok and even necessary to have it working at all,<br>> even though it will exclude some possible exotic Wayland compositor<br>> designs.<br>><br>> > == Input coordinate filtering ==<br>> > One use-case that was mentioned to me was effectively "intercept button X<br>> > and send key events 'abc' instead". This is not possible with the current<br>> > proposal and I'm not sure it can be without going overboard with<br>> > specifications. It *may* be possible to provide some global hotkey hooks I<br>> > have not come up with a good solution to that.<br>><br>> A global hotkey system has been discussed in the past. IIRC one of the<br>> better ideas was something along the lines of (Wayland) clients<br>> registering "actions" with default "input event" bindings but keeping<br>> the control in the compositor. The binding would not work by default for<br>> most input events, except maybe for some whitelisted things like<br>> Play/Pause keys, and would require the user to accept the binding. The<br>> user would also have the opportunity to bind the actions to any other<br>> input events he wishes.<br>><br>> Again such a "grant permissions" scheme must rely on some form of<br>> persistent application identification, which quickly moves us towards<br>> containers again if we want to be resistant towards clients<br>> deliberately lying what they are.<br>><br>> However, IMHO such button/key etc. remapping is something that should<br>> be done completely in the compositor (if not possible in keymaps) to<br>> make it reliable and fast, unless perhaps when the original input<br>> device is not one that the compositor is already using, like a joystick<br>> or a gamepad. Or a smart phone acting as a touchpad/keyboard for remote<br>> control of a computer.<br>><br>><br>> > == Window management ==<br>> > This is beyond the current suggestion but also where it gets both<br>> > interesting and difficult.<br>> ><br>> > I have a sample org.freedesktop.WoodoTool.Desktop interface that would send<br>> > Edge signals to clients. The compositor decides when these are triggered,<br>> > the client can react to these things with custom commmands.<br>> ><br>> > But this is where we get into the proper scripting territory and that's also<br>> > where the opinions will diverge quite quickly.<br>> ><br>> > For example, xdotool supports things like "search for window with name 'foo'<br>> > and activate it". Implementing this is ... tricky. Now we need some<br>> > definition of what a window classifies as and how windows are sorted within<br>> > a process - compare multiple GIMP windows with multiple gnome-terminal<br>> > windows for example. Not specifying exactly what order we return leaves us<br>> > open to behavioural dependencies which may break in the future.<br>> ><br>> > In other words, an interface to search for windows of a given application<br>> > is technically feasable but extremly hard to get right.<br>> ><br>> > Anyway, with the separation of interfaces this is not something we need in<br>> > the first iterations. But one legitimate question is whether just an<br>> > implementation for virtual input devices is sufficient or whether it's<br>> > largely pointless without any additional window-management capabilities.<br>> ><br>> > == Implementation ==<br>> > Because of what it does, there is no real code-sharing between compositors -<br>> > they would just use their own intrastructure to hook to the dbus interface<br>> > and create virtual devices. On the client-side it's much the same thing,<br>> > binding to dbus is trivial.<br>> ><br>> ><br>> > So 99% of the work here would be to define the interface and get everyone to<br>> > agree on it.<br>><br>> My main concern still is that we don't seem to have any intended use<br>> cases written down, so it's hard to say if this is enough or not.<br>><br><br>Context: I am the maintainer of xdotool.<br><br>I can try to provide a more concrete list of use cases, if that helps? In no particular order and not necessarily involving xdotool:<br><br>* Typing text (KeePass invokes xdotool for this purpose)<br>* Keyboarding input with an on-screen keyboard.<br>* GUI automation (mouse/typing/input/windowing).<br>* Key macros - having one hotkey send a specific key sequence (It sounds weird, but this is a common use for xdotool)<br>* Controlling the cursor with the keyboard (keynav does this, I am also its author)<br>* Scripted window pager activity (switch desktop, move window to a new desktop, list windows)<br>* Window manager actions (close window, resize window, maximize, etc).<br><br>If you'd like feedback on certain areas or want me to give interface ideas, I'm open to that, but I wanted to focus this particular email on just use cases.<br><br>For example, I'll talk about typing (XTEST, etc). I would love an interface worked at a higher level than raw key codes, or at least that possibility could be explored. The reason for this request is that xdotool dedicates a bunch of code to hopping between key symbols, key codes, and key character/glyph representation, and sometimes gets this wrong. For example, to type the letter "t" xdotool has to query the whole keyboard mapping to find the keycode mapped to this symbol, and if none is found, it makes one (and then removes it after). We also cannot, under X11 and to my knowledge, type emoji or other complex unicode entities using the XTEST api. xdotool also often needs users to provide the --clear-modifiers flag to reset any active keyboard state before typing, and it'd be nice not to need that juggling.<br><br> <br>><br>> Testing was kind of discarded as needing something more powerful.<br>> Converting one input event to another was mostly scoped out, apart from<br>> perhaps converting gamepad buttons to keyboard/pointer events for<br>> instance.<br>><br>> What *are* the intended use cases for this interface?<br>><br>> A very big problem that I see is how to direct input:<br>><br>> - If you send keyboard events, how does the program or the user<br>>   control where they go?<br><br><br>This is a good question. With X11 (and apologies if this is already known information), we have XTEST to simulate general input events and XSendEvent (which sometimes is blocked by apps) to send events directly to a specific window. I would love something somehow better (and certainly less of an attack surface!) than XSendEvent/XTEST :)<br> <br>><br>><br>> - If you send pointer events, how do you determine which coordinates to<br>>   send?<br><br><br>This is a good question. With the UI automation use case, I see folks warping the pointer to specific pixel locations. It's unclear how this would be achieved with a virtual absolute-coordinate touchpad without knowing the pixel dimensions of each screen.<br><br>><br>> If you use a gamepad stick to control a pointer, you can just send<br>> relative motion events and the user will be happy because he is<br>> interactively controlling the pointer. But is this the only use case<br>> the interface can support? Is it enough?<br><br><br>For gamepad prior art, there's some interesting things that you can do with Valve's Steam Controller in terms of making the gamepad inputs do a pretty wide variety of things with respect to input. I don't know how common this use case (gamepad/joystick for pointer and keyboard input), but I'm pretty sure X11 has support for gamepad-as-a-pointer, for example.<br><br></div><div>Regards,<br></div>-Jordan<br><div><br>><br>> Would remote desktop control be in scope for this interface? E.g.<br>> letting IT support temporarily take control of your desktop through<br>> their own support software you have installed?<br>><br>><br>> Thanks,<br>> pq<br><br></div></div>