213 points · by AdmiralAsshat · 3y ago · 151 comments
But it's preferable to have applications directly use the Wayland protocol, which is what Firefox is experimenting with. For most applications, this is easy because they use some standard toolkit like GTK or Qt, which will transparently use Wayland without the application caring about it. But Firefox uses its own toolkit, so it's a bit more work.
Regardless of the OS, when the applications want to directly render things they have to communicate with the lower level graphics backend (Wayland, X, DWM, Metal etc) to agree on a memory area and pixel format and some other things. The OS, the direct rendering system and the window management system together manages what application gets the rendering signal, what area, at what display with what metadata (e.g. DPI, or pixel bits) it is drawn.
Since browsers are writing their rendering system and the components from scratch (not everything, they still use some system GUI components or text input / font rendering stuff), they need to communicate with the lower layer directly to request screen areas to render, to get the correct display DPI/scale to draw things at the correct size with well-aligned pixels and to utilize various hardware stuff like hardware video decoders.
However, running programs under XWayland comes with issues such as lack of proper fractional scaling. This means that although not strictly necessary, from a user's point of view it is desirable to have applications move to Wayland.
However if you want things toolkits don't provide then you need to talk to the underlying API yourself.
My distro ships both plain Firefox and firefox-wayland. I've been using it for... At least a year. No noticeable difference to normal Firefox.
(Wayland is a set of protocols and the toolkit may not support all the protocols or have sub-par support -- in which case the application can choose to do those bits itself.)
Many applications for Windows, OS X, and Linux interface directly with Win32, Cocoa, or X11/Wayland. For example, the Foot terminal emulator only works with Wayland, because the author has chosen not to implement the X11 protocol.
But there should be performance and rendering quality advantages to speaking Wayland natively.
Core X for instance has zero concept of a frame or buffer swapping, X apps like games generally get that via GL. So your average X GUI application tends to be inherently flickery/tear-ful, since draws just get sent out to the X server and display whenever. XOrg drivers have implemented various hacks to try minimize those effects, but it's all very vendor-specific[0] and never perfect since it's a fundamental limitation of the X protocol. You can at best eliminate literal tearing[1], but nothing prevents displaying a partially refreshed window full of changing widgets, each implemented as X subwindows in the classic X fashion, because nothing in the core protocol says "Ok, this top-level window update is finished, present it (and its descendants)!".
That's not even getting into the issues of high dpi and fractional scaling...
[0] https://manpages.debian.org/bookworm/xserver-xorg-video-inte...
"Render as quickly as possible (even if imperfect)" is also a viable strategy. Some people seem to really hate it, but I've never even noticed it, much less been bothered by it. I certainly prefer the reduced latency. I'm probably not that special. It very much seems like a trade-off thing, rather than "this is the one true correct way"-thing.
Of course, it would be better if Xorg would support both, but that also applies to Wayland.
With XOrg, especially in the pre-compositing days, you could choose whatever WM you want and it wouldn't have any impact on the rendering performance of X clients. Once the Composite extension was added and everyone started running composited X desktops, that started to change, and the increased latency already started appearing - in an arguably worse architecture than Wayland because there were often three processes involved with lots of IPC/context switches per draw: X-Client->X-Server->X-Compositor->X-Server->CRTC. At least in Wayland it's more like Wayland-Client->Wayland-Compositor->CRTC.
If you're unhappy with the rendering latency of your Wayland sessions, it may be worth trying alternative compositors... they likely vary significantly. The Valve/Steam folks have made a minimal one specifically optimized for games/low-latency [0]. I doubt the SteamDeck would be seeing as much success as it is if Wayland were so problematic in this department.
The idea is that GTK+ and Qt can (and do) add support for Wayland and it's trivial for applications to support Wayland, often without even recompiling.
Applications built for X can still run on Wayland via Xwayland. But Xwayland is a bodge to allow legacy applications to continue running, an interim solution while toolkits, libraries, and applications are converted to use Wayland directly. To paraphrase the hit song:
Once we have enough Wayland software
At our call, hackers, at our call,
We'll throw out those dirty X code paths,
Ever more, hackers, ever more.See SDL_DYNAMIC_API: https://www.reddit.com/r/linux_gaming/comments/1upn39/sdl2_a...
Any information most welcome.
The protocol is defined in the libwayland library. Most apps don't use libwayland directly, but their widget toolkit like GTK or Qt does it for them.
instead it's all shared memory buffers
I imagine there's a lot of concerns that have to be carefully considered, as it is a very non-trivial change. Like, does WebGL work? Video acceleration? Will there be a performance regression for anything? How about accessibility, do screen readers still work as intended? (They should since for now that's all out-of-band, but you never know.) Does it have trouble with any specific vendor of GPU?
An interesting consequence of Wayland's design is that a lot of the information conveyed about X windows, like ICCCM properties, are basically non-existent in the Wayland world. This means that for a tiling window manager like SwayWM, it's actually a lot harder for say, pop-up windows to not accidentally get treated like other tiled windows. So if you use e.g. Dolphin file browser, the copy dialogs will try to "tile" since there's no way for Sway to know they're supposed to be popups. This was not an issue for i3wm. This is both fixable and possible to workaround, and in the grand scheme of things not my biggest priority (I'm much more concerned about issues like stability) but I think that issues like these are of prime concern for Wayland adoption.
Am I the only one to have the expectation that software I use should never crash?
My chair holds me up every day. My fridge keeps my food cold every day. My windows keep out the rain every day. My washing machine washes my clothes every time. Why should my firefox get a pass to sometimes randomly crash and that be okay?
All of those things break. Congratulations if you've managed to experience life without that.
Anyway, comparing software to chairs is unlikely to yield any useful wisdom IMO, so I'm not actually going to attempt to make an argument based on that. I know that any non-trivial piece of software will have millions of potential codepaths, and Firefox likely has a number of potential total codepaths so large that we could not ever hope to calculate it through the entirety of humanity's existence, so I think it's just only reasonable to expect that some of those codepaths may crash.
For safety-critical applications where you can't afford to have a software bug kill a bunch of people, there's only one realistic option: you can't rely on never having a software bug. You instead must do your best to ensure that as many classes of software bug as possible can't, on their own, cause damage. Ideally you would combine safeguards at every possible level: of course try to eliminate bugs, but also add hardware protections, redundancy, and realistically any kind of mitigation you can.
I do not know how much better software engineering could be with more discipline, but I do know that simply asking humans to not make mistakes when writing millions of lines of code isn't reasonable, and the stakes are not always high enough to warrant writing everything in Ada.
Anyway, if my fridge fails, I have to order some replacement parts or worse, maybe a new fridge. If Firefox crashes, I am annoyed for like 30 seconds until I hit "Restore Session" and it happens infrequently enough that I'm not even sure when the last time was.
(P.S.: It's also worth noting that despite regulation and despite the rigor of traditional engineering, gas-lifted chairs occasionally explode and kill the people sitting on them. I don't think I've ever heard of a Firefox crash directly killing someone, so there's at least that.)
Update: In middle of trying to post this, HN stopped processing requests for maybe 15 minutes. Almost poetic.
Physical things wear out. That's an entirely different situation from a product that breaks because it was faulty when sold.
It's true that expecting perfection from any complex system is unrealistic, but good software should at least be lacking in crashing bugs that happen with common operations (such as dragging a tab).
Just to clarify, I'm not saying that FF (or Wayland) isn't good software. I'm just saying that nobody should just shrug their shoulders and say "that's life" when common operations cause a crash.
Am I the only one to have the expectation that software I use should never crash?
Firefox has 20+ million lines of code. Honestly, I can't tell: Are you trolling? A modern web browser is some of the most complex software ever written.Case in point - I had to run some x86 Docker containers on an M1 Mac recently - PHP and nodejs ran without issue using Docker's under-the-hood emulator but Chrome continually crashed during emulation.
Your appliances are UL listed and interact with an electrical grid that is heavily regulated. Other than their extremely simple interface with that system (and your plumbing in the case of the washing machine) they entirely self contained.
If your windows do keep out the rain, they do so because they were installed properly within a much larger system of overlapping parts. Even on new construction subject to inspection, failures in this system commonly evade detection until after they have done years of damage.
Meanwhile, the browser crashing rarely makes you lose what, 15 seconds of time to start it back up and continue? It's annoying, but it's also not really... a big deal?
One would hope your chair or fridge never "crash", like one hopes a piece of software never does, but they come in all levels of quality and face all kinds of edge-cases. One day, for instance, maybe a 3 tonne man sits on your chair, which has held you up just fine every day, and the chair fails to hold him up, crashing him to the ground. You wouldn't turn around and reasonably say your chair is now a failure, really.
Nope. That's one of my two baseline expectations (the other, more important one, is that software I use should never cause data loss).
Of course it works perfectly if I disable the Nvidia driver. It also works fine in XWayland, but then rendering (to my eyes) looks choppier.
Slack is almost there, but not perfect. My cursor becomes like 1/10th the size in Slack .. but the crisp rendering is worth it. Dragging a PNG file into it never works though, so I always need to upload via the little + button.
Spotify is 100% flawless, to my surprise. Even works flawlessly with the whole device handoff thing between iPhone, my Macbook, etc.
vscode renders much better with wayland, like the latency difference is pretty significant. but... I use Toshy to get macos keybindings on Linux and those fail to work when vscode is booted in wayland mode ... so I am still suffering with xwayland. If I do not think about it, I don't mind lol. If I go back to native and see how much better rendering is, I feel sad.
It mostly looks fine until I stress the UI, and I can see significantly more CPU being used. In fact, I only really know its busted in VSCode because it spits out the same errors in the console as Chromium (where I can check about:gpu and see that everything is off).
--enable-features=UseOzonePlatform --ozone-platform=waylandhttps://github.com/solarkraft/awesome-wlroots is a pretty nice list of various CLI utils you can use. Sadly I don't think anyone aimed to 1:1 replicate APIs of xdotool etc, so you will need to change the syntax in your scripts a bit.
xdotool: ydotool, but it might miss some features
xwininfo: this is compositor specific. Sway has swaymsg, that's what I use.
Sway starts, but crashes within seconds. Longest I've got it to run was half an hour before everything froze.
Do any other WM's/DE's work better for old Nvidia cards? I don't particularly want to start installing all the Wayland things out there until one works hah.
I understand Nvidia isn't great for Wayland...
Other than that for the first time in like a decade of dealing with Optimus bullshit laptops off and on everything finally works plug and play, even running different refresh rate screens at the same time. Nvidia finally shipped support for controlling gamma in wayland on Halloween so I can use gammastep to shift my screens red at night.
In short: Have that patch for wlroots (which sway uses), use newest proprietary driver, block/uninstall nouveau, and make sure the system isn't loading CPU rendering due to a misconfiguration (firefox you can check about:support, chromium/electron-based shit check chrome://gpu)
EDIT: oh and since chromium/electron will inevitably temporarily break graphics at some point due to an update... --disable-gpu is your friend to get those apps working (with CPU rendering). Obviously drop it out once those problems subside, it's happened maybe twice to me in the past few months running Gentoo unstable. Firefox seems more resilient and will find a way to run in less ideal circumstances on wayland.
I think it's mainly just environment variables, so if you're on another distro you can have a look at the the GitHub repo and implement it yourself.
The biggest nvidia issue I encountered are problems with display managers, GDM would sometimes not start wayland compositors or not start x11 WMs. I tried several others as well and always had issues (never had issues on my previous AMD or Intel machines). I ended up just autostarting a locked sway desktop and everything just works.
It is possible natively. The logic, however, needs to be implemented in the compositor not the applications, because it's the compositor that keeps track of the positions of the windows.
... for years, on i3 (X11) and Sway (Wayland).
I'm lazy and use basically the same config files between them! Point being, it's probably fine: for wlroots things at the very least, perhaps more :)
Very neat!
Edit: Thanks for all the responses. But I'm still not understanding what all this has to do with Firefox. I boot up my linux machine that runs KDE, I launch Firefox and then what? Does this help with something on my local machine? Or does Firefox now provide a UI for remote systems that I SSH into? Whatever Firefox can do now, why should this be a feature of a browser?
Edit 2: Ah, I get it now, Firefox simply renders itself using the Wayland protocol, correct?
Essentially, in an operating system you need a way to "draw" things on the screen. And a way to properly "move" the boxes "draw".
Previously, the usual* way to do that was using XServer (XOrg). Now you would imagine that the server would take commands from applications, and would draw them. But it was the inverse (for various historical reasons)! However, the most egregious thing was that it ALWAYS ran as root. And while tries had been made to reduce the attack surface, it had to fundamentally change (I am skipping over other parts related to performance, scalability, or future proofing).
And that's where Wayland comes in, and literally flips the whole thing on its head. Now the issue is XOrg has been around for maybe 40 years or more ! And that was not going to change easily. Distros did their absolute best to allow double use, but adoption grew very slowly. Eventually, supporting and testing for two envs will grow complicated.
Anyway long story short, almost everything about Wayland is better IMO, actively supported and is the future. But migrating to it has been complicated because they were undoing 40 years of habits, hardcoded bugs that grew into features, and had to come up with new testing.
This is something I typed up rather quickly so please take a peek at the Wiki page for Wayland you will find a much more complete history
That hasn't really been a thing for over a decade now. As a decent metric, https://wiki.ubuntu.com/X/Rootless says Ubuntu switched to rootless by default for most drivers in Lucid==10.04
In the old world, they talked to an X server that implemented the X protocol. It's not KDE drawing stuff to your screen, it's X, but KDE is a little special in that it can move windows around and draw title bars and borders. This is called a window manager.
Two big issues with X, this was defined in the early 90s by a consortium of Unix vendors and is somewhat of an overly complicated nightmare.
It's also a security nightmare, any app can snoop on any other app.
Wayland is an attempt to simplify things. The server, called a compositor, is much simpler and is implemented as a library, usually by former window managers that now actually handle drawing stuff to the screen. Applications can no longer snoop, they must ask permission.
If you run an older app designed for X, it uses an almost invisible compatibility shim called XWayland, basically a tiny X server that takes in X draw commands and converts them to Wayland ones. Firefox enabling Wayland support means that on most modern systems, it no longer has to use this shim.
Wayland is a step forward for desktop Linux, but like any big change there are some annoyances. The asking for permission model means things like screensharing tools or apps that do weird shit like macros or capturing keystrokes need to be updated to ask permission. Nvidia didn't really support Wayland well until very recently because they got into some weird argument about driver APIs that took years to resolve.
I swear I've been reading this for a decade.
Wayland meanwhile actually has 99.9% of what you need working today not 25 years from now. There's some bits and pieces already progressing well and likely to be fixed in the next few weeks/months/years and not 25 years in the future. Very different situation to X11, IMHO.
I encounter the same thing when dealing with code reviews as well - people love to document the WHAT or HOW of things, but rarely if ever consider talking about WHY it matters, or WHO it matters too.
To borrow from a favourite corpo speak: answer the "so what" for the reader to make something actually useful to more people.
Wayland looks a bit more likely to achieve its goal, but we'll see. For my part, it'll take a long time yet before it's worth the hassle to consider switching.
[1] https://en.wikipedia.org/wiki/General_Graphics_Interface
Until recently, "Xorg" was the main centralized implementation of a display server on unix-likes, and any program wishing to display graphics had to speak its native protocol, "X11". Now many systems run display servers which speak a new protocol, "Wayland"[note]. While a compatibility shim does exist (XWayland), ideally a program wishing to display graphics on such a system should do so using the new protocol directly, for better performance and features.
Porting an application to a new graphics backend obviously requires some effort and testing. Until now, out of an abundance of caution, Firefox simply spoke the old X11 protocol by default, even when running on a new Wayland system, relying on the XWayland compatibility shim. Now Firefox is essentially announcing that they believe their Wayland backend is robust and complete enough to enable by default.
I hope this helps!
[note] the nature of Wayland is such that there are many implementations of such servers, not just one main one like with Xorg. This is because the semantics of the Wayland protocol have taken over some of the functions previously handled (on X11) by a separate piece of software, called a "window manager", which contributed heavily to the look, feel, and behavior of a particular desktop GUI. Thus, while Xorg was agnostic and could be shared by different GUIs, with Wayland each GUI system must implement its own display server.
Window managers can be separate with Wayland too. It just seems like the Wayland people don't want to unify under one implementation and have separate window managers.
But perhaps that version of the GTK doesn't support X itself, so that's an acceptable proxy? Or perhaps that's not the real check, and it exists elsewhere?
Wayland is a modern replacement, but it is not a drop-in. That is because it has a completely different architecture and approach.
I cannot ELI5 the differences between the two, because they are somewhat vast.
If you are on a platform that supports Wayland, it is undoubtedly a smoother, prettier and overall better experience. This falls apart due to the lack of direct support from certain apps, desktop environments, etc. The migration has taken some time - but alas this is an open source effort in a massive/fragmented environment so it is obviously a very hard challenge. Like herding 100,000 cats.
Unfortunately not everything will just work. A stopgap is something called xwayland which allows x apps to communicate with wayland - although it is not perfect.
Firefox will work with Wayland. It will work with X. It will work with XWayland. The default though is X or XWayland. You normally need to explicitly tell Firefox to boot up using Wayland. Firefox is now considering making it enabled by default, which would be great for those of us who run on Wayland all the time. It would of course still work on X.
X is a mature architecture which Just Works Fine. I don't know why it's considered "not suited for the way modern desktops operate", because as an X(org) user, all my desktops operate Just Fine whereas whenever I try Wayland my desktops do not operate Just Fine.
>> Wayland is a modern replacement, but it is not a drop-in. That is because it has a completely different architecture and approach.
Wayland is a newcomer and alternative to X(org) - the authors of Wayland want it to take over from X(org) and for X(org) to die off. I hope that X(org) stays.
I still don't understand the hate for X/Xorg [0]. It must be a generational thing. Maybe I'm just being a grumpy greybeard? Who knows. But I do know that whenever I try, say, KDE Plasma (Wayland) I get problems, for example, playing games with WINE, and other annoying glitches and hitches which I don't get using MATE/Xorg.
And no, I don't care if Gnome works great with Wayland - I have a visceral contempt for the modern iteration of the Gnome desktop (and had nasty experiences with the Gtk toolkit way back when which put me off developing with it forever.)
[0] https://old.reddit.com/r/linuxmemes/comments/175chou/linux_b...
Whilst most of the newer things implemented Wayland could theoretically be implemented within the X architecture nobody wants to do it both due to the architecture of X and the age of the Xorg codebase.
X will presumably be around for another 50 years but it will not receive the development needed for modern tech.
Wasn’t trying to shit on it I’m just telling it as it is.
I also dislike Gnome. I run KDE on Wayland on a 5K display and everything is fast, low latency and gorgeous.
Mozilla has been working toward making Firefox work with wayland for a while, seems they've finally gotten in to a shipable state.
When I said "shipable state" I was thinking "shipped, enabled by default". Probably should've just said that instead.