Add support for Wayland on Linux#335
Conversation
The Wayland support comes from changing the way input and output works: 1. Screen output is captured via DRM (Direct Rendering Manager) 2. Keyboard/Mouse input is injected via libevdev Both of these methods are lower level than the previous X11 code, so they're actually capable of becoming full replacements for the X11 mechanisms, should we ever want to do that. I've tried to make the changes minimally invasive to the existing code, instead of a big refactor into X11 vs DRM code paths. Known issues: 1. Logging out back to the greeter breaks the screen scraping. This is fixable, just requires work to figure some things out. 2. Cursor state is not reflected in the screen output To get the greeter working will require some more surgery. I haven't figured out how all of that session stuff works yet, but it is possible. It's largely just an issue of the system getting confused between Wayland/X11 states. One quite simple solution could be that once we detect Wayland, we remain in that state for the duration of the process life. I'm not sure if people care about dynamic switching between X11 and Wayland during a single boot - and I suspect not, so I think this would be a simple and robust solution to get the greeter working. If cursor state is necessary, then I can look into that. It just hasn't felt like a priority. I don't consider this work 100% finished. We still need to get the greeter working, and more testing/feedback. But if possible, I'd like to get this on a public branch so that I can start getting feedback. This work is sponsored by touchsource.com
|
@bmharper omg thank you so much! ❤️ |
|
Awesome, will be great to get some testing help! |
|
Wow! This is amazing, did you code this all by yourself? AMAZING! |
|
@bmharper ok great ill build and test here, |
|
I haven't tested on arm/pi, but will do that now. |
I have been writing C/C++ for 30 years, but Codex 5.3 certainly had a hand in the implementation here. |
|
@bmharper i dont mind PRs that are AI helped, |
I think most projects will get left behind with a strict "no AI" policy. Ultimately, we just have to judge the work on its merits. |
|
I see this is not working on a Pi5 running Ubuntu 25.10. |
|
@bmharper well i am gob smacked! give your AI a pat on the back from me 👏 it works! EDIT: |
|
@si458 Thanks for that - I'll get that fixed, and also make sure that logging back out the greeter works. |
|
Sorry guys, I'm having a little trouble compiling and installing on Ubuntu 26 - not getting the Desktop tab. Server version 1.1.44. Is there a docker build or a dependency list? Or just post the linux x86_64 build somewhere? Thanks for any help. |
|
@edlins I've discovered a problem on 25.10 and upwards, due to the fact that XOrg/X11 is no longer available there. I have something working on 25.10 - will add it to this PR when it's ready |
This fixes a warning on modern compilers
Previously, we only worked on eg Ubuntu 24.04, where they still shipped Xorg/X11. Without this change the agent does not advertise desktop capability, and the "Desktop" tab in MeshCentral is unavailable.
This prevents us from switching back to X11 mode if we connect at the greeter screen. We may still be able to simplify the wayland detection to just the seat0 read.
It was already in monitor-info.js
|
@edlins Give it another try on ubuntu 26.04 with the latest commits. [Unit] [Service] [Install] And then There are still issues with the agent dying if one disconnects and reconnects at certain times. I'm using the wrong UID for setuid.. but this should be a fairly minor thing to fix. Also, I still haven't fixed the blank screen disconnect issue that @si458 brought up. |
|
@bmharper dont worry about it! just keep at it! we have all the time in the world as its a community project after all! |
|
For clean consistent builds, I can stop the mesh agent service, add Agent says Console says I also tried without the JPEGVER arg and got the same result. You can add this dockerfile to the repo if it's useful. Do you have any other ideas to try? Oh, and terminal and files are working fine. |
|
Bug: Rotate the display to portrait right and the mesh desktop doesn't realign to vertical, and the mouse input is rotated 90 degrees so it appears in a different place in mesh vs on the device. X11 desktops would rotate in mesh so you would see portrait right in a vertical orientation. Currently it shows portrait right in landscape. |
Aiming to find the reason why we're failing on i915
* The screen capture now resumes automatically after a blank screen * Fixed leaking of framebuffer handle * Fixed spurious noisy logs on nvidia capture due to changing handles
Unfortunately I haven't yet found a reliable universal way to detect display rotation on wayland, so I'm adding an env var override, eg For "portrait right": MESH_KVM_ROTATION=270 By setting MESH_KVM_ROTATION to anything besides zero, we force the treatment of the display as rotated by either 90,180,270 degrees. I split it into it's own .c file, because I forsee this getting a bit messy, having to support various compositors.
|
@si458 I've added a fix for the screen blank issue (if I understand correctly - it's when the screen goes into blank/power saving mode). The KVM session should automatically resume. @edlins I've added more logging, to try help figure out why the i915 driver doesn't work - let me know what MeshAgent spits out. Also, I've implemented support for rotated screens, but I have not yet found a universal way of detecting this under Wayland, so at present the only way to get it to work, is with an env var, eg: # for portrait right
MESH_KVM_ROTATION=270Rotation support looks like it's going to need platform-specific code, so I'll make it work on ubuntu 26 first, and then we can add support for other platforms as they appear. |
I confirmed the port is correct. The behavior is that desktop says connected, the input works (mouse at least), but the mesh desktop screen stays black. This could just be ancient i915 not properly supporting newer Alder Lake-N graphics.
Yeah, seems that orientation is completely handled by the compositor and there's nothing in the Wayland protocol to consistently fetch it across compositors. Anyhow, I set my system to portrait right and set the env var to 90 and it was upside down. I've noticed there's a quirk in Gnome where "portrait right" rotates the output CCW 90 degrees which seems the opposite of what it should do. I think what "portrait right" means in Gnome is "after applying this setting you have to rotate your monitor to the right (90 degrees CW). I'll bet there were fist fights over that.. I'm documenting additional issues that may have nothing to do with your work. It seems that when I build new agents they don't update the commit info seen with Some connections don't establish for like 60s after an agent restart, or randomly, not sure. Warning for testers - I switched from default i915 to xe and it worked great I switched back to i915 for some testing, and switched back to xe again but I seem to have hosed up my system. I'm getting a ton of xe errors with a black screen and a mouse pointer.. If I get back into working xe I'll test the screen blanking fix. |
|
@bmharper can you fix the conflict at all please? |
|
I tried this today on my Acer laptop |


The Wayland support comes from changing the way input and output works:
Both of these methods are lower level than the previous X11 code, so they're actually capable of becoming full replacements for the X11 mechanisms, should we ever want to do that.
I've tried to make the changes minimally invasive to the existing code, instead of a big refactor into X11 vs DRM code paths.
Known issues:
To get the greeter working will require some more surgery. I haven't figured out how all of that session stuff works yet, but it is possible. It's largely just an issue of the system getting confused between Wayland/X11 states. One quite simple solution could be that once we detect Wayland, we remain in that state for the duration of the process life. I'm not sure if people care about dynamic switching between X11 and Wayland during a single boot - and I suspect not, so I think this would be a simple and robust solution to get the greeter working.
If cursor state is necessary, then I can look into that. It just hasn't felt like a priority.
I don't consider this work 100% finished. We still need to get the greeter working, and more testing/feedback. But if possible, I'd like to get this on a public branch so that I can start getting feedback.
This work is sponsored by touchsource.com
Fixes #115 Ylianst/MeshCentral#2719