Hacker News new | past | comments | ask | show | jobs | submit login

You don't have to be impressed, but I don't necessarily think it's disingenuous. A "small" Wayland compositor which doesn't use a library like wlroots is nigh impossible. The code for handling DRM+KMS alone is over 2000 lines of code, and that's tangental to the goal of "make a Wayland compositor". I'd compare it to saying a game written with GLFW isn't impressive because they didn't do all of the work to set up an application window.



For a toy compositor, is there any reason not to just use SDL? The DRM and KMS side of things is interesting, but doesn't help much in understanding the Wayland protocol.


You certainly could make a compositor with SDL, but I don't think it would be any better than wlroots. We also provide an abstraction of the underlying window system, the same code which runs your compositor in an X11 window can also run it on KMS+DRM without any changes (the compositor in this very link can run on X11, Wayland, and DRM+KMS with no changes). It also gives you a number of useful things like an implementation[0] of xdg-shell, which alone can be a couple thousand lines long. Also, negotiating graphics resources with clients is going to require you to get into the gritty OpenGL details if you intend to be efficient (and some clients don't even support shared memory, so it's also a matter of compatability). You'd also need to implement the seat to have input support, which can be another ~1,000 lines of code. GTK+ requires the data device to be implemented as well - over 1,000 more lines of code in wlroots[2].

[0] https://github.com/swaywm/wlroots/tree/master/types/xdg_shel... [1] https://github.com/swaywm/wlroots/tree/master/types/seat [2] https://github.com/swaywm/wlroots/tree/master/types/data_dev...

That being said, a simple compositor which only supports a subset of this stuff, uses SDL for rendering, doesn't support a lot of important features (like GTK+ dropdowns and context menus), and directly implements the Wayland protocols, could probably be done in one or two thoundand lines of code. In order to be equivalent in functionality to the TinyWL compositor I posted today, it would probably need to approach 5-6,000 lines.


>That being said, a simple compositor which only supports a subset of this stuff, uses SDL for rendering, doesn't support a lot of important features [...], and directly implements the Wayland protocols, could probably be done in one or two thoundand lines of code.

That's what I'm interested in. wlroots hides pretty much all of the details about what's going on. This would be more about producing an example than an actual functional compositor. My next Rust project, maybe. Or even C#, for that matter.


If you're producing an actual functioning compositor you should be using wlroots anyway. It's unopinionated, we call it "40,000 lines of code you were going to write anyway". It's not practical to make a compositor without leveraging wlroots unless you have a huge team like GNOME or KDE - this is advice from several compositors who tried and are now using wlroots.

Still, if you insist on making everything yourself, the wlroots code is pretty accessible and I've heard from people working on KDE and Mir that it's the best reference code to study for understanding how everything works and applying it to their own software.

https://github.com/swaywm/wlroots


I agree. It's a spectrum and my Python example is showing one extreme of obviously unimpressive. I was just trying to answer the comment I was responding to.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: