Snake Oil

…is a great single. Putting that aside, however, it’s time for yet another exciting update from the hot and magma-filled world of XWayland! This joke brought to you by the Wayland-related part of xserver that everyone wants, but nobody wants to maintain, and that joke was brought to you by the bitterness of having to fully reimplement ICCCM selection support over the past week.

Let’s take a look at how Wayland handles selections:

Selection “owner” creates object -> offers mime types to potential receiver clients -> receiver accepts/rejects mime types -> data is written directly between clients using file descriptors

This is a simplified explanation which won’t cause heads to explode. Drag operations are similar, except the compositor also needs to manage enter/leave/position/drop events based on the drag’s position over a window (surface).

Here’s how X11 handles selections:

Read the 20 page selection spec that I linked above. Seriously.


And so it was that last week, after some time in which I definitely was not procrastinating, I set out to start/continue/finish Wayland clipboard and DnD (Drag-n-drop) support in Enlightenment. My knowledge of such things was equivalent to my interest in doing cardio-related activities, but I figured that it couldn’t be that hard if there was already a reference implementation. This was a mostly-correct assumption, provided that I was using test applications which were competently written–which I wasn’t.

After fixing up pure Wayland DnD by sticking a surface onto the existing internal DnD infrastructure and propagating mouse events, I decided to move on to X11->Wayland DnD. Chris “I hate you, Devilhorns” Michael linked me this gem from the mutter compositor, and I understood basically nothing from it due to an even higher reliance on COM-style interfaces than Weston. I wasn’t about to let that stop me though, and I charged onwards only to discover that ecore-x was written in a frustrating manner which prevented me from making any useful calls to XConvertSelection(the function which takes lots of parameters). One dlsym later and I was mostly done; creating a fake Wayland data source allowed me to create offers to send to prospective drop clients once the event for xdnd selection owner change arrived, and then it was a simple matter of forcing those square X11 bits down the round Wayland socket to complete the drop operation.

Next up was Wayland->X11 DnD. This required sending client messages to the X11 window to represent the state of the Wayland drag. Probably the biggest hassle was…well, nothing. This direction was much easier since Wayland interfaces provide all the mime types and related info naturally without the need to constantly message the xserver to get properties and data. By using the existing X11 compositor selection window, I was able to mimic normal DnD behavior, complete with the non-stop client messaging and property sending. Then the drop would trigger, and I’d get to suck up those delicious Wayland bytes and punt them off into an X11 window property, never to be seen again.

Clipboard support was by far the easiest yet the most frustrating. Due to the similarities between how clipboard and DnD work in both protocols, after finishing DnD I’d already mostly finished clipboard as well. Unfortunately, the test apps that I chose were not ideal. Elementary’s test app for clipboard doesn’t actually do anything in most cases when you attempt to paste onto it, even though it will try to pretend like it does; after an hour of banging my head against it, I ended up adding a debug print to determine if it was actually receiving a selection. Magically, it was, and so I moved on from Wayland->X11 to X11->Wayland. At this point, I again chose poorly: gedit has some strange bug where it will try to accept mime types which were never available (GTK_TEXT_BUFFER_CONTENTS), and then it hangs while awaiting that selection, its cursor blinking accusingly as though I’m the one at fault for not offering its favorite mime type. Eventually it accepts the selection, but grudgingly, like a kid being forced to eat broccoli. After I’d already finished this part, the very same Chris “I hate you, Devilhorns” Michael informed me that weston-terminal has paste support if you sacrifice enough pixmaps to your gpu.


Lessons learned from this process:

  • I hate all client communication protocols.
  • The complexity of X11 selection support is mind boggling. I wish that it could somehow be transformed by XWayland to emit Wayland events, but it’s just impossible because it’s so damn complicated.
  • gedit gets angry and rage quits if you pause the compositor during a Wayland data offer accept method call.
  • Never write your Wayland wrapper libraries in such a way that there is a global connection which would require you to have to reimplement client DnD entirely inside the compositor in order to support nested compositors.


Tune in next time, when I rant about how much I hate reimplementing client DnD entirely inside the compositor in order to support nested compositors!


Join the flame war

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s