logo

drewdevault.com

[mirror] blog and personal website of Drew DeVault git clone https://hacktivis.me/git/mirror/drewdevault.com.git

Why-rewrite-wlc.md (5646B)


  1. ---
  2. date: 2018-05-27
  3. title: Why did we replace wlc?
  4. layout: post
  5. tags: [wayland, sway, wlroots]
  6. ---
  7. For a little over a year, I've been working with a bunch of talented C
  8. developers to build a replacement for the [wlc](https://github.com/Cloudef/wlc)
  9. library. The result is [wlroots](https://github.com/swaywm/wlroots), and we're
  10. still working on completing it and updating our software to use it. The
  11. [conventional
  12. wisdom](https://www.joelonsoftware.com/2000/04/06/things-you-should-never-do-part-i/)
  13. suggests that rewriting your code from scratch is almost never the right idea.
  14. So why did we do it, and how is it working out? I have spoken a little about
  15. this in the past, but we'll answer this question in detail today.
  16. Sway will have been around for 3 years as of this August. When I started the
  17. project, I wanted to skip some of the hard parts and get directly to
  18. implementing i3 features. To this end, I was browsing around for libraries which
  19. provided some of the low-level plumbing for me - stuff like DRM (Display
  20. Resource Management) and KMS (Kernel Mode Setting), EGL and GLES wires, libinput
  21. support, and so on. I was more interested in whatever tool could get me up to
  22. speed and writing sway-specific code quickly. My options at this point came down
  23. to wlc and [swc](https://github.com/michaelforney/swc).
  24. swc's design is a little bit better in retrospect, but I ended up choosing wlc
  25. for the simple reason that it had an X11 backend I could use for easier
  26. debugging. If I had used swc, I would have been forced to work without a display
  27. server and test everything under the DRM backend - which would have been pretty
  28. annoying. So I chose wlc and go to work.
  29. Designwise, wlc is basically a Wayland compositor with a plugin API, except you
  30. get to write `main` yourself and the plugin API communicates entirely
  31. in-process. wlc has its own renderer (which you cannot control) and its own
  32. desktop with its own view abstraction (which you cannot control). You have some
  33. events that it bubbles up for you and you can make some choices like where to
  34. arrange windows. However, if you just wire up some basics and run `wlc_init`,
  35. wlc will do all of the rest of the work and immediately start accepting clients,
  36. rendering windows, and dispatching input.
  37. Over time we were able to make some small improvements to wlc, but sway 0.x
  38. still works with these basic principles today. Though this worked well at first,
  39. over time more and more of sway's bugs and limitations were reflections of
  40. problems with wlc. A lengthy discussion on IRC and [on
  41. GitHub](https://github.com/swaywm/sway/issues/1076) ensued and we debated for
  42. several weeks on how we should proceed. I was originally planning on building a
  43. new compositor entirely in-house (similar to GNOME's mutter and KDE's kwin), and
  44. I wanted to abstract the i3-specific functionality of sway into some kind of
  45. plugin. Then, more "frontends" could be written on top of sway to add
  46. functionality like AwesomeWM, bspwm, Xmonad, etc.
  47. After some discussion among the sway team and with other Wayland compositor
  48. projects [facing similar
  49. problems](https://github.com/way-cooler/way-cooler/issues/248) with wlc, I
  50. decided that we would start developing a standalone library to replace wlc
  51. instead, and with it allow a more diverse Wayland ecosystem to flourish.
  52. Contrary to wlc's design - a Wayland compositor with some knobs - wlroots is a
  53. set of modular tools with which you build the Wayland compositor yourself. This
  54. design allows it to be suited to a huge variety of projects, and as a result
  55. it's now being used for many different Wayland compositors, each with their own
  56. needs and their own approach to leveraging wlroots.
  57. When we started working on this, I wasn't sure if it was going to be successful.
  58. Work began slowly and I knew we had a monumental task ahead of us. We spent a
  59. lot of time and a few large refactorings getting a feel for how we wanted the
  60. library to take shape. Different parts matured at different paces, sometimes
  61. with changes in one area causing us to rethink design decisions that affected
  62. the whole project. Eventually, we fell into our stride and found an approach
  63. that we're very happy with today.
  64. I think that the main difference with the approach that wlroots takes comes from
  65. experience. Each of the people working on sway, wlc, way cooler, and so on were
  66. writing Wayland compositors for the first time. I'd say the problems that arose
  67. as a result can also be seen throughout other projects, including Weston, KWin,
  68. and so on. The problem is that when we all set out, we didn't fully understand
  69. the opportunities afforded by Wayland's design, nor did we see how best to
  70. approach tying together the rather complicated Linux desktop stack into a
  71. cohesive project.
  72. We could have continued to maintain wlc, fixed bugs, refactored parts of it, and
  73. maybe eventually arrived at a place where sway more or less worked. But we'd
  74. simply be carrying on the X11 tradition we've been trying to escape this whole
  75. time. wlc was a kludge and replacing it was well worth the effort - it simply
  76. could not have scaled to the places where wlroots is going. Today, wlroots is
  77. the driving force behind 6 Wayland compositors and is targeting desktops,
  78. tablets, and phones. Novel features never seen on any desktop - even beyond
  79. Linux - are possible with this work. Now we can think about not only replacing
  80. X11, but innovating in ways it never could have.
  81. Our new approach is the way that Wayland compositors should be made. wlroots is
  82. the realization of Wayland's potential. I am hopeful that our design decisions
  83. will have a lasting positive impact on the Wayland ecosystem.